(core) Hiding censored pages and all their leaves

Summary:
Page is now hidden when any of its ancestor (or the page itself)
is censored.

Test Plan: Updated

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D4319
pull/1150/head
Jarosław Sadziński 1 month ago
parent fbc0418118
commit 9509b2edcb

@ -223,16 +223,21 @@ export class DocModel {
this.allPages = ko.computed(() => allPages.all()); this.allPages = ko.computed(() => allPages.all());
this.menuPages = ko.computed(() => { this.menuPages = ko.computed(() => {
const pagesToShow = this.allPages().filter(p => !p.isSpecial()).sort((a, b) => a.pagePos() - b.pagePos()); const pagesToShow = this.allPages().filter(p => !p.isSpecial()).sort((a, b) => a.pagePos() - b.pagePos());
// Helper to find all children of a page. const parent = memoize((page: PageRec) => {
const children = memoize((page: PageRec) => { const myIdentation = page.indentation();
const following = pagesToShow.slice(pagesToShow.indexOf(page) + 1); if (myIdentation === 0) { return null; }
const firstOutside = following.findIndex(p => p.indentation() <= page.indentation()); const idx = pagesToShow.indexOf(page);
return firstOutside >= 0 ? following.slice(0, firstOutside) : following; // Find first page starting from before that has lower indentation then mine.
const beforeMe = pagesToShow.slice(0, idx).reverse();
return beforeMe.find(p => p.indentation() < myIdentation) ?? null;
}); });
// Helper to test if the page is hidden and all its children are hidden. const ancestors = memoize((page: PageRec): PageRec[] => {
// In that case, we won't show it at all. const anc = parent(page);
const hide = memoize((page: PageRec): boolean => page.isCensored() && children(page).every(p => hide(p))); return anc ? [anc, ...ancestors(anc)] : [];
return pagesToShow.filter(p => !hide(p)); });
// Helper to test if the page is hidden or is in a hidden branch.
const hidden = memoize((page: PageRec): boolean => page.isHidden() || ancestors(page).some(p => p.isHidden()));
return pagesToShow.filter(p => !hidden(p));
}); });
this.visibleDocPages = ko.computed(() => this.allPages().filter(p => !p.isHidden())); this.visibleDocPages = ko.computed(() => this.allPages().filter(p => !p.isHidden()));

@ -38,43 +38,34 @@ describe('Pages', function() {
assert.deepEqual(await gu.getPageTree(), [ assert.deepEqual(await gu.getPageTree(), [
{ {
label: 'Interactions', children: [ label: 'Interactions', children: [
{ label: 'Documents' }, {label: 'Documents' },
] ]
}, },
{ {
label: 'People', children: [ label: 'People', children: [
{ label: 'User & Leads', children: [{ label: 'Overview' }] }, {label: 'User & Leads', children: [
{label: 'Overview'}] },
] ]
}, },
]); ]);
const revertAcl = await gu.beginAclTran(api, doc.id); const revertAcl = await gu.beginAclTran(api, doc.id);
// Update ACL, hide People table from all users. // Update ACL, hide Overview table from all users.
await hideTable("People"); await hideTable("Overview");
// We will be reloaded, but it's not easy to wait for it, so do the refresh manually. // We will be reloaded, but it's not easy to wait for it, so do the refresh manually.
await gu.reloadDoc(); await gu.reloadDoc();
assert.deepEqual(await gu.getPageTree(), [ assert.deepEqual(await gu.getPageTree(), [
{ {
label: 'Interactions', children: [ label: 'Interactions', children: [
{ label: 'Documents'}, {label: 'Documents'},
] ]
}, },
{ {
label: 'CENSORED', children: [ label: 'People', children: [
{ label: 'User & Leads', children: [{ label: 'Overview' }] }, {label: 'User & Leads'},
] ]
}, },
]); ]);
// Test that we can't click this page.
await driver.findContent('.test-treeview-itemHeader', /CENSORED/).click();
await gu.waitForServer();
assert.equal(await gu.getSectionTitle(), 'INTERACTIONS');
// Test that we don't have move handler.
assert.isFalse(
await driver.findContent('.test-treeview-itemHeaderWrapper', /CENSORED/)
.find('.test-treeview-handle').isPresent()
);
// Now hide User_Leads // Now hide User_Leads
await hideTable("User_Leads"); await hideTable("User_Leads");
@ -86,14 +77,12 @@ describe('Pages', function() {
] ]
}, },
{ {
label: 'CENSORED', children: [ label: 'People'
{ label: 'CENSORED', children: [{ label: 'Overview' }] },
]
}, },
]); ]);
// Now hide Overview, and test that whole node is hidden. // Now hide People, and test that whole node is hidden.
await hideTable("Overview"); await hideTable("People");
await gu.reloadDoc(); await gu.reloadDoc();
assert.deepEqual(await gu.getPageTree(), [ assert.deepEqual(await gu.getPageTree(), [
{ {

Loading…
Cancel
Save