(core) Showing a raw data section on a popup

Summary:
Show raw data will now open a popup with
raw section instead of redirecting to raw data page.

Adding new anchor link type "a2" that is able to open
any section in a popup on a current view.

Not related:
Fixing highlightMatches function, after merging core PR.

Test Plan: Updated tests

Reviewers: alexmojaki, georgegevoian

Reviewed By: alexmojaki, georgegevoian

Subscribers: georgegevoian, alexmojaki

Differential Revision: https://phab.getgrist.com/D3592
This commit is contained in:
Jarosław Sadziński
2022-08-24 13:43:15 +02:00
parent 177b9d83d9
commit 2997434815
8 changed files with 186 additions and 67 deletions

View File

@@ -250,7 +250,7 @@ export function encodeUrl(gristConfig: Partial<GristLoadConfig>,
const hashParts: string[] = [];
if (state.hash && state.hash.rowId) {
const hash = state.hash;
hashParts.push(`a1`);
hashParts.push(state.hash?.popup ? 'a2' : `a1`);
for (const key of ['sectionId', 'rowId', 'colRef'] as Array<keyof HashLink>) {
if (hash[key]) { hashParts.push(`${key[0]}${hash[key]}`); }
}
@@ -372,9 +372,9 @@ export function decodeUrl(gristConfig: Partial<GristLoadConfig>, location: Locat
for (const part of hashParts) {
hashMap.set(part.slice(0, 1), part.slice(1));
}
if (hashMap.has('#') && hashMap.get('#') === 'a1') {
if (hashMap.has('#') && ['a1', 'a2'].includes(hashMap.get('#') || '')) {
const link: HashLink = {};
for (const key of ['sectionId', 'rowId', 'colRef'] as Array<keyof HashLink>) {
for (const key of ['sectionId', 'rowId', 'colRef'] as Array<Exclude<keyof HashLink, 'popup'>>) {
const ch = key.substr(0, 1);
if (!hashMap.has(ch)) { continue; }
const value = hashMap.get(ch);
@@ -384,6 +384,9 @@ export function decodeUrl(gristConfig: Partial<GristLoadConfig>, location: Locat
link[key] = parseInt(value!, 10);
}
}
if (hashMap.get('#') === 'a2') {
link.popup = true;
}
state.hash = link;
}
state.welcomeTour = hashMap.get('#') === 'repeat-welcome-tour';
@@ -773,6 +776,7 @@ export interface HashLink {
sectionId?: number;
rowId?: UIRowId;
colRef?: number;
popup?: boolean;
}
// Check whether a urlId is a prefix of the docId, and adequately long to be