mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) Parsing pasting in reflist columns
Summary: Handle reflist columns in ViewFieldRec.parseValue Test Plan: Reused section of test of reference columns Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D3105
This commit is contained in:
parent
ab7af2b2ef
commit
0f946616b6
@ -1,9 +1,9 @@
|
||||
import { ReferenceUtils } from 'app/client/lib/ReferenceUtils';
|
||||
import { ColumnRec, DocModel, IRowModel, refRecord, ViewSectionRec } from 'app/client/models/DocModel';
|
||||
import * as modelUtil from 'app/client/models/modelUtil';
|
||||
import { ReferenceUtils } from 'app/client/lib/ReferenceUtils';
|
||||
import * as UserType from 'app/client/widgets/UserType';
|
||||
import { DocumentSettings } from 'app/common/DocumentSettings';
|
||||
import { extractTypeFromColType } from 'app/common/gristTypes';
|
||||
import { isFullReferencingType, isRefListType } from 'app/common/gristTypes';
|
||||
import { BaseFormatter, createFormatter } from 'app/common/ValueFormatter';
|
||||
import { createParser } from 'app/common/ValueParser';
|
||||
import { Computed, fromKo } from 'grainjs';
|
||||
@ -186,13 +186,30 @@ export function createViewFieldRec(this: ViewFieldRec, docModel: DocModel): void
|
||||
const docSettings = this.documentSettings();
|
||||
const type = this.column().type();
|
||||
|
||||
if (extractTypeFromColType(type) === "Ref") { // TODO reflists
|
||||
if (!isFullReferencingType(type)) {
|
||||
return createParser(type, this.widgetOptionsJson(), docSettings);
|
||||
} else {
|
||||
const vcol = this.visibleColModel();
|
||||
const vcolParser = createParser(vcol.type(), vcol.widgetOptionsJson(), docSettings);
|
||||
const refUtils = new ReferenceUtils(this, docModel.docData); // uses several more observables immediately
|
||||
return (s: string) => refUtils.parseValue(vcolParser(s));
|
||||
return (s: string) => {
|
||||
const result = refUtils.parseValue(vcolParser(s));
|
||||
// If `result` is a number that means it successfully parsed a reference (row ID).
|
||||
// For a reflist we need to wrap that row ID in a list.
|
||||
// Otherwise `result` is a string meaning it couldn't be parsed
|
||||
// and it will be saved as AltText (i.e. invalid for the column type).
|
||||
// We don't try to parse multiple references from a single string.
|
||||
if (isRefListType(type) && typeof result === "number") {
|
||||
if (result > 0) {
|
||||
return ['L', result];
|
||||
} else {
|
||||
return createParser(type, this.widgetOptionsJson(), docSettings);
|
||||
// parseValue returns 0 sometimes because that's the default for reference columns.
|
||||
// The default for a reflist column is null.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user