mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Fuller guessing of type and options when adding first data to blank columns
Summary: Adds `common/ValueGuesser.ts` with logic for guessing column type and widget options (only for dates/datetimes) from an array of strings, and converting the strings to the guessed type in a lossless manner, so that converting back to Text gives the original values. Changes `_ensure_column_accepts_data` in Python to call an exported JS method using the new logic where possible. Test Plan: Added `test/common/ValueGuesser.ts` to unit test the core guessing logic and a DocApi end-to-end test for what happens to new columns. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3290
This commit is contained in:
@@ -3,13 +3,17 @@
|
||||
* subscribes to actions which change it, and forwards those actions to individual tables.
|
||||
* It also provides the interface to apply actions to data.
|
||||
*/
|
||||
import {DocumentSettings} from 'app/common/DocumentSettings';
|
||||
import {safeJsonParse} from 'app/common/gutil';
|
||||
import {schema, SchemaTypes} from 'app/common/schema';
|
||||
import fromPairs = require('lodash/fromPairs');
|
||||
import groupBy = require('lodash/groupBy');
|
||||
import {ActionDispatcher} from './ActionDispatcher';
|
||||
import {BulkColValues, ColInfo, ColInfoWithId, ColValues, DocAction,
|
||||
RowRecord, TableDataAction} from './DocActions';
|
||||
import {ColTypeMap, MetaTableData, TableData} from './TableData';
|
||||
import {
|
||||
BulkColValues, ColInfo, ColInfoWithId, ColValues, DocAction,
|
||||
RowRecord, TableDataAction
|
||||
} from './DocActions';
|
||||
import {ColTypeMap, MetaRowRecord, MetaTableData, TableData} from './TableData';
|
||||
|
||||
type FetchTableFunc = (tableId: string) => Promise<TableDataAction>;
|
||||
|
||||
@@ -108,6 +112,15 @@ export class DocData extends ActionDispatcher {
|
||||
}
|
||||
}
|
||||
|
||||
public docInfo(): MetaRowRecord<'_grist_DocInfo'> {
|
||||
const docInfoTable = this.getMetaTable('_grist_DocInfo');
|
||||
return docInfoTable.getRecord(1)!;
|
||||
}
|
||||
|
||||
public docSettings(): DocumentSettings {
|
||||
return safeJsonParse(this.docInfo().documentSettings, {});
|
||||
}
|
||||
|
||||
// ---- The following methods implement ActionDispatcher interface ----
|
||||
|
||||
protected onAddTable(action: DocAction, tableId: string, columns: ColInfoWithId[]): void {
|
||||
|
||||
Reference in New Issue
Block a user