(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:
Alex Hall
2021-12-06 14:07:52 +02:00
parent 7f08934cf0
commit 116fb15eda
5 changed files with 130 additions and 137 deletions

View File

@@ -8,6 +8,7 @@ import {getDefaultForType} from 'app/common/gristTypes';
import {arrayRemove, arraySplice} from 'app/common/gutil';
import {SchemaTypes} from "app/common/schema";
import {UIRowId} from 'app/common/UIRowId';
import isEqual = require('lodash/isEqual');
import fromPairs = require('lodash/fromPairs');
export interface ColTypeMap { [colId: string]: string; }
@@ -330,7 +331,7 @@ export class TableData extends ActionDispatcher implements SkippableRows {
return 0;
}
return this._rowIdCol.find((id, i) =>
props.every((p) => (p.col.values[i] === p.value))
props.every((p) => isEqual(p.col.values[i], p.value))
) || 0;
}
@@ -471,7 +472,7 @@ export class TableData extends ActionDispatcher implements SkippableRows {
const props = Object.keys(properties).map(p => ({col: this._columns.get(p)!, value: properties[p]}));
this._rowIdCol.forEach((id, i) => {
// Collect the indices of the matching rows.
if (props.every((p) => (p.col.values[i] === p.value))) {
if (props.every((p) => isEqual(p.col.values[i], p.value))) {
rowIndices.push(i);
}
});