mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Move most of the reference parsing code into common so that the server can use it
Summary: Refactoring in preparation for parsing strings from the API. The plan is that the API code will only need to do a server-side version of the code in ViewFieldRec.valueParser (minus ReferenceUtils) which is quite minimal. Test Plan: Nothing extra here, I don't think it's needed. This stuff will get tested more in a future diff which changes the API. Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D3164
This commit is contained in:
@@ -10,8 +10,6 @@ import { countIf } from 'app/common/gutil';
|
||||
import { TableData as BaseTableData, ColTypeMap } from 'app/common/TableData';
|
||||
import { Emitter } from 'grainjs';
|
||||
|
||||
export type SearchFunc = (value: any) => boolean;
|
||||
|
||||
/**
|
||||
* TableData class to maintain a single table's data.
|
||||
*/
|
||||
@@ -60,33 +58,6 @@ export class TableData extends BaseTableData {
|
||||
this.dataLoadedEmitter.emit(rowIds, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a colId and a search function, returns a list of matching row IDs, optionally limiting their number.
|
||||
* @param {String} colId: identifies the column to search.
|
||||
* @param {Function} searchFunc: A function which, given a column value, returns whether to include it.
|
||||
* @param [Number] optMaxResults: if given, limit the number of returned results to this.
|
||||
* @returns Array[Number] array of row IDs.
|
||||
*/
|
||||
public columnSearch(colId: string, searchFunc: SearchFunc, optMaxResults?: number) {
|
||||
const maxResults = optMaxResults || Number.POSITIVE_INFINITY;
|
||||
|
||||
const rowIds = this.getRowIds();
|
||||
const valColumn = this.getColValues(colId);
|
||||
const ret = [];
|
||||
if (!valColumn) {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.warn(`TableData.columnSearch called on invalid column ${this.tableId}.${colId}`);
|
||||
} else {
|
||||
for (let i = 0; i < rowIds.length && ret.length < maxResults; i++) {
|
||||
const value = valColumn[i];
|
||||
if (value && searchFunc(value)) {
|
||||
ret.push(rowIds[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user