mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Fix imports into reference columns, and support two ways to import Numeric as a reference.
Summary: - When importing into a Ref column, use lookupOne() formula for correct previews. - When selecting columns to import into a Ref column, now a Numeric column like 'Order' will produce two options: "Order" and "Order (as row ID)". - Fixes exports to correct the formatting of visible columns. This addresses multiple bugs: 1. Formatting wasn't used, e.g. a Ref showing a custom-formatted date was still presented as YYYY-MM-DD in CSVs. 2. Ref showing a Numeric column was formatted as if a row ID (e.g. `Table1[1.5]`), which is very wrong. - If importing into a table that doesn't have a primary view, don't switch page after import. Refactorings: - Generalize GenImporterView to be usable in more cases; removed near-duplicated logic from node side - Some other refactoring in importing code. - Fix field/column option selection in ValueParser - Add NUM() helper to turn integer-valued floats into ints, useful for "as row ID" lookups. Test Plan: Added test cases for imports into reference columns, updated Exports test fixtures. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3875
This commit is contained in:
@@ -70,7 +70,7 @@ export type IsRightTypeFunc = (value: CellValue) => boolean;
|
||||
export class BaseFormatter {
|
||||
protected isRightType: IsRightTypeFunc;
|
||||
|
||||
constructor(public type: string, public widgetOpts: object, public docSettings: DocumentSettings) {
|
||||
constructor(public type: string, public widgetOpts: FormatOptions, public docSettings: DocumentSettings) {
|
||||
this.isRightType = gristTypes.isRightType(gristTypes.extractTypeFromColType(type)) ||
|
||||
gristTypes.isRightType('Any')!;
|
||||
}
|
||||
@@ -144,7 +144,7 @@ export interface DateFormatOptions {
|
||||
}
|
||||
|
||||
class DateFormatter extends BaseFormatter {
|
||||
private _dateTimeFormat: string;
|
||||
protected _dateTimeFormat: string;
|
||||
private _timezone: string;
|
||||
|
||||
constructor(type: string, widgetOpts: DateFormatOptions, docSettings: DocumentSettings, timezone: string = 'UTC') {
|
||||
@@ -194,9 +194,11 @@ export interface DateTimeFormatOptions extends DateFormatOptions {
|
||||
class DateTimeFormatter extends DateFormatter {
|
||||
constructor(type: string, widgetOpts: DateTimeFormatOptions, docSettings: DocumentSettings) {
|
||||
const timezone = gutil.removePrefix(type, "DateTime:") || '';
|
||||
// Pass up the original widgetOpts. It's helpful to have them available; e.g. ExcelFormatter
|
||||
// takes options from an initialized ValueFormatter.
|
||||
super(type, widgetOpts, docSettings, timezone);
|
||||
const timeFormat = widgetOpts.timeFormat === undefined ? 'h:mma' : widgetOpts.timeFormat;
|
||||
const dateFormat = (widgetOpts.dateFormat || 'YYYY-MM-DD') + " " + timeFormat;
|
||||
super(type, {dateFormat}, docSettings, timezone);
|
||||
this._dateTimeFormat = (widgetOpts.dateFormat || 'YYYY-MM-DD') + " " + timeFormat;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -268,7 +268,8 @@ export function createParserOrFormatterArguments(
|
||||
const col = columnsTable.getRecord(colRef)!;
|
||||
let fieldOrCol: MetaRowRecord<'_grist_Tables_column' | '_grist_Views_section_field'> = col;
|
||||
if (fieldRef) {
|
||||
fieldOrCol = fieldsTable.getRecord(fieldRef) || col;
|
||||
const field = fieldsTable.getRecord(fieldRef);
|
||||
fieldOrCol = field?.widgetOptions ? field : col;
|
||||
}
|
||||
|
||||
return createParserOrFormatterArgumentsRaw(docData, col.type, fieldOrCol.widgetOptions, fieldOrCol.visibleCol);
|
||||
|
||||
Reference in New Issue
Block a user