(core) Value parsing for refs, parsing data entry for numbers

Summary:
Handle reference columns in ViewFieldRec.valueParser.

Extracted code for reuse from ReferenceEditor to look up values in the visible column. While I was at it, also extracted a bit of common code from ReferenceEditor and ReferenceListEditor into a new class ReferenceUtils. More refactoring could be done in this area but it's out of scope.

Changed NTextEditor to use field.valueParser, which affects numeric and reference fields. In particular this means numbers are parsed on data entry, it doesn't change anything for references.

Test Plan:
Added more CopyPaste testing to test references.

Tested entering slightly formatted numbers in NumberFormatting.

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D3094
This commit is contained in:
Alex Hall
2021-11-01 17:48:08 +02:00
parent f0da3eb3b2
commit d63da496a8
9 changed files with 222 additions and 167 deletions

View File

@@ -159,6 +159,10 @@ export class TableData extends ActionDispatcher implements SkippableRows {
return colData && index !== undefined ? colData.values[index] : undefined;
}
public hasRowId(rowId: number): boolean {
return this._rowMap.has(rowId);
}
/**
* Given a column name, returns a function that takes a rowId and returns the value for that
* column of that row. The returned function is faster than getValue() calls.

View File

@@ -64,10 +64,11 @@ delete parsers.DateTime;
export function createParser(
type: string, widgetOpts: FormatOptions, docSettings: DocumentSettings
): ((value: string) => any) | undefined {
): (value: string) => any {
const cls = parsers[gristTypes.extractTypeFromColType(type)];
if (cls) {
const parser = new cls(type, widgetOpts, docSettings);
return parser.cleanParse.bind(parser);
}
return value => value;
}