(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:
Dmitry S
2021-04-20 17:57:45 -04:00
parent 5479159960
commit 65a722501d
4 changed files with 123 additions and 32 deletions

View File

@@ -2,8 +2,11 @@
* TableData maintains a single table's data.
*/
import {ColumnACIndexes} from 'app/client/models/ColumnACIndexes';
import {ColumnCache} from 'app/client/models/ColumnCache';
import {DocData} from 'app/client/models/DocData';
import {DocAction, ReplaceTableData, TableDataAction, UserAction} from 'app/common/DocActions';
import {isRaisedException} from 'app/common/gristTypes';
import {countIf} from 'app/common/gutil';
import {ColTypeMap, TableData as BaseTableData} from 'app/common/TableData';
import {BaseFormatter} from 'app/common/ValueFormatter';
import {Emitter} from 'grainjs';
@@ -19,6 +22,8 @@ export class TableData extends BaseTableData {
public readonly columnACIndexes = new ColumnACIndexes(this);
private _columnErrorCounts = new ColumnCache<number|undefined>(this);
/**
* Constructor for TableData.
* @param {DocData} docData: The root DocData object for this document.
@@ -92,6 +97,17 @@ export class TableData extends BaseTableData {
return ret;
}
/**
* Counts and returns the number of error values in the given column. The count is cached to
* keep it faster for large tables, and the cache is cleared as needed on changes to the table.
*/
public countErrors(colId: string): number|undefined {
return this._columnErrorCounts.getValue(colId, () => {
const values = this.getColValues(colId);
return values && countIf(values, isRaisedException);
});
}
/**
* Sends an array of table-specific action to the server to be applied. The tableId should be
* omitted from each `action` parameter and will be inserted automatically.