mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Show count of formula errors in the column config in the right-side panel.
Summary: - Cache the count by column, factoring out ColumnCache from ColumnACIndexes, which uses a similar pattern. - Update error counts in response to column selection and to data changes. Test Plan: Adds a test case for the new message Reviewers: paulfitz Reviewed By: paulfitz Differential Revision: https://phab.getgrist.com/D2780
This commit is contained in:
@@ -9,11 +9,10 @@
|
||||
* It is currently used for auto-complete in the ReferenceEditor widget.
|
||||
*/
|
||||
import {ACIndex, ACIndexImpl} from 'app/client/lib/ACIndex';
|
||||
import {ColumnCache} from 'app/client/models/ColumnCache';
|
||||
import {UserError} from 'app/client/models/errors';
|
||||
import {TableData} from 'app/client/models/TableData';
|
||||
import {DocAction} from 'app/common/DocActions';
|
||||
import {isBulkUpdateRecord, isUpdateRecord} from 'app/common/DocActions';
|
||||
import {getSetMapValue, localeCompare, nativeCompare} from 'app/common/gutil';
|
||||
import {localeCompare, nativeCompare} from 'app/common/gutil';
|
||||
import {BaseFormatter} from 'app/common/ValueFormatter';
|
||||
|
||||
export interface ICellItem {
|
||||
@@ -24,13 +23,9 @@ export interface ICellItem {
|
||||
|
||||
|
||||
export class ColumnACIndexes {
|
||||
private _cachedColIndexes = new Map<string, ACIndex<ICellItem>>();
|
||||
private _columnCache = new ColumnCache<ACIndex<ICellItem>>(this._tableData);
|
||||
|
||||
constructor(private _tableData: TableData) {
|
||||
// Whenever a table action is applied, consider invalidating per-column caches.
|
||||
this._tableData.tableActionEmitter.addListener(this._invalidateCache, this);
|
||||
this._tableData.dataLoadedEmitter.addListener(this._clearCache, this);
|
||||
}
|
||||
constructor(private _tableData: TableData) {}
|
||||
|
||||
/**
|
||||
* Returns the column index for the given column, using a cached one if available.
|
||||
@@ -38,7 +33,7 @@ export class ColumnACIndexes {
|
||||
* getColACIndex() is called for the same column with the the same formatter.
|
||||
*/
|
||||
public getColACIndex(colId: string, formatter: BaseFormatter): ACIndex<ICellItem> {
|
||||
return getSetMapValue(this._cachedColIndexes, colId, () => this._buildColACIndex(colId, formatter));
|
||||
return this._columnCache.getValue(colId, () => this._buildColACIndex(colId, formatter));
|
||||
}
|
||||
|
||||
private _buildColACIndex(colId: string, formatter: BaseFormatter): ACIndex<ICellItem> {
|
||||
@@ -56,23 +51,6 @@ export class ColumnACIndexes {
|
||||
items.sort(itemCompare);
|
||||
return new ACIndexImpl(items);
|
||||
}
|
||||
|
||||
private _invalidateCache(action: DocAction): void {
|
||||
if (isUpdateRecord(action) || isBulkUpdateRecord(action)) {
|
||||
// If the update only affects existing records, only invalidate affected columns.
|
||||
const colValues = action[3];
|
||||
for (const colId of Object.keys(colValues)) {
|
||||
this._cachedColIndexes.delete(colId);
|
||||
}
|
||||
} else {
|
||||
// For add/delete actions and all schema changes, drop the cache entirelly to be on the safe side.
|
||||
this._clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
private _clearCache(): void {
|
||||
this._cachedColIndexes.clear();
|
||||
}
|
||||
}
|
||||
|
||||
function itemCompare(a: ICellItem, b: ICellItem) {
|
||||
|
||||
Reference in New Issue
Block a user