2023-08-28 11:16:17 +02:00
|
|
|
import {TableData} from 'app/common/TableData';
|
|
|
|
|
import {UIRowId} from 'app/plugin/GristAPI';
|
2021-10-04 19:52:20 -04:00
|
|
|
|
|
|
|
|
/**
|
2022-07-06 00:41:09 -07:00
|
|
|
* Return whether a table (identified by the rowId of its metadata record) should
|
|
|
|
|
* normally be hidden from the user (e.g. as an option in the page-widget picker).
|
2021-10-04 19:52:20 -04:00
|
|
|
*/
|
2022-02-04 13:13:03 +02:00
|
|
|
export function isHiddenTable(tablesData: TableData, tableRef: UIRowId): boolean {
|
2021-10-04 19:52:20 -04:00
|
|
|
const tableId = tablesData.getValue(tableRef, 'tableId') as string|undefined;
|
2022-09-02 09:21:03 -04:00
|
|
|
// The `!tableId` check covers the case of censored tables (see isTableCensored() below).
|
2022-07-21 15:46:29 +02:00
|
|
|
return !tableId || isSummaryTable(tablesData, tableRef) || tableId.startsWith('GristHidden_');
|
2022-04-27 19:46:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-07-06 00:41:09 -07:00
|
|
|
* Return whether a table (identified by the rowId of its metadata record) is a
|
|
|
|
|
* summary table.
|
2022-04-27 19:46:24 +02:00
|
|
|
*/
|
2022-07-06 00:41:09 -07:00
|
|
|
export function isSummaryTable(tablesData: TableData, tableRef: UIRowId): boolean {
|
|
|
|
|
return tablesData.getValue(tableRef, 'summarySourceTable') !== 0;
|
2021-10-04 19:52:20 -04:00
|
|
|
}
|
2022-09-02 09:21:03 -04:00
|
|
|
|
|
|
|
|
// Check if a table record (from _grist_Tables) is censored.
|
|
|
|
|
// Metadata records get censored by clearing certain of their fields, so it's expected that a
|
|
|
|
|
// record may exist even though various code should consider it as hidden.
|
|
|
|
|
export function isTableCensored(tablesData: TableData, tableRef: UIRowId): boolean {
|
|
|
|
|
const tableId = tablesData.getValue(tableRef, 'tableId');
|
|
|
|
|
return !tableId;
|
|
|
|
|
}
|