(core) Don't show hidden tables in table data options when adding widgets

Summary:
As reported in https://grist.slack.com/archives/C069RUP71/p1655316194602829, when a table is hidden by ACL, it was still showing as a blank 'ghost' option to select data when adding a widget:

{F55498}

The fix is simply to return `true` from `isHiddenTable` for empty table IDs, which indicate a table hidden by ACL. `TableRec.isHidden` is supposed to match this so I updated it too, and I cleaned up a tiny bit of other related code.

Test Plan: Extended `nbrowser/AccessRules1.ts` to test the data options when adding widgets.

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D3530
This commit is contained in:
Alex Hall 2022-07-21 15:46:29 +02:00
parent 4e805a4d9c
commit 460f22b701
5 changed files with 8 additions and 5 deletions

View File

@ -189,8 +189,6 @@ class FinderImpl implements IFinder {
if ('data' === this._gristDoc.activeViewId.get()) { if ('data' === this._gristDoc.activeViewId.get()) {
// Get all raw sections. // Get all raw sections.
const rawSections = this._gristDoc.docModel.visibleTables.peek() const rawSections = this._gristDoc.docModel.visibleTables.peek()
// Filter out those we don't have permissions to see (through ACL-tableId will be empty).
.filter(t => Boolean(t.tableId.peek()))
// sort in order that is the same as on the raw data list page, // sort in order that is the same as on the raw data list page,
.sort((a, b) => nativeCompare(a.tableNameDef.peek(), b.tableNameDef.peek())) .sort((a, b) => nativeCompare(a.tableNameDef.peek(), b.tableNameDef.peek()))
// get rawViewSection, // get rawViewSection,

View File

@ -15,7 +15,7 @@ export function createPageRec(this: PageRec, docModel: DocModel): void {
const viewId = this.view().id(); const viewId = this.view().id();
const tables = docModel.rawDataTables.all(); const tables = docModel.rawDataTables.all();
const primaryTable = tables.find(t => t.primaryViewId() === viewId); const primaryTable = tables.find(t => t.primaryViewId() === viewId);
return !!primaryTable && primaryTable.isHidden(); return !!primaryTable && primaryTable.tableId()?.startsWith("GristHidden_");
}; };
// Page is hidden when any of this is true: // Page is hidden when any of this is true:
// - It has an empty name (or no name at all) // - It has an empty name (or no name at all)

View File

@ -52,7 +52,7 @@ export function createTableRec(this: TableRec, docModel: DocModel): void {
this.summarySource = refRecord(docModel.tables, this.summarySourceTable); this.summarySource = refRecord(docModel.tables, this.summarySourceTable);
this.isHidden = this.autoDispose( this.isHidden = this.autoDispose(
// This is repeated logic from isHiddenTable. // This is repeated logic from isHiddenTable.
ko.pureComputed(() => !!this.summarySourceTable() || this.tableId()?.startsWith("GristHidden")) ko.pureComputed(() => !this.tableId() || !!this.summarySourceTable() || this.tableId().startsWith("GristHidden_"))
); );
// A Set object of colRefs for all summarySourceCols of this table. // A Set object of colRefs for all summarySourceCols of this table.

View File

@ -7,7 +7,7 @@ import {UIRowId} from 'app/common/UIRowId';
*/ */
export function isHiddenTable(tablesData: TableData, tableRef: UIRowId): boolean { export function isHiddenTable(tablesData: TableData, tableRef: UIRowId): boolean {
const tableId = tablesData.getValue(tableRef, 'tableId') as string|undefined; const tableId = tablesData.getValue(tableRef, 'tableId') as string|undefined;
return isSummaryTable(tablesData, tableRef) || Boolean(tableId?.startsWith('GristHidden')); return !tableId || isSummaryTable(tablesData, tableRef) || tableId.startsWith('GristHidden_');
} }
/** /**

View File

@ -902,6 +902,11 @@ export async function addNewSection(typeRe: RegExp|string, tableRe: RegExp|strin
await selectWidget(typeRe, tableRe, options); await selectWidget(typeRe, tableRe, options);
} }
export async function openAddWidgetToPage() {
await driver.findWait('.test-dp-add-new', 2000).doClick();
await driver.findWait('.test-dp-add-widget-to-page', 2000).doClick();
}
// Select type and table that matches respectively typeRe and tableRe and save. The widget picker // Select type and table that matches respectively typeRe and tableRe and save. The widget picker
// must be already opened when calling this function. // must be already opened when calling this function.
export async function selectWidget( export async function selectWidget(