mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Guess numeric formatting options
Summary: Change NumberParse.parse to return not just the parsed number but also information it gathered along the way about how the input string was formatted. Use this in the new NumberParse.guessOptions to guess the actual widget options based on an array of strings. Use NumberParse.guessOptions in TypeConversion (for when a user explicitly chooses to change type) and in ValueGuesser (for guesses about strings entered into empty columns). Test Plan: Adds unit tests for NumberParse and ValueGuesser and updates the TypeChange2 nbrowser test. Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3294
This commit is contained in:
@@ -4,11 +4,13 @@
|
||||
*/
|
||||
// tslint:disable:no-console
|
||||
|
||||
import {isString} from 'app/client/lib/sessionObs';
|
||||
import {DocModel} from 'app/client/models/DocModel';
|
||||
import {ColumnRec} from 'app/client/models/entities/ColumnRec';
|
||||
import * as gristTypes from 'app/common/gristTypes';
|
||||
import {isFullReferencingType} from 'app/common/gristTypes';
|
||||
import * as gutil from 'app/common/gutil';
|
||||
import NumberParse from 'app/common/NumberParse';
|
||||
import {dateTimeWidgetOptions, guessDateFormat} from 'app/common/parseDate';
|
||||
import {TableData} from 'app/common/TableData';
|
||||
import {decodeObject} from 'app/plugin/objtypes';
|
||||
@@ -108,6 +110,17 @@ export async function prepTransformColInfo(docModel: DocModel, origCol: ColumnRe
|
||||
widgetOptions = dateTimeWidgetOptions(dateFormat, true);
|
||||
break;
|
||||
}
|
||||
case 'Numeric':
|
||||
case 'Int': {
|
||||
if (["Numeric", "Int"].includes(sourceCol.type())) {
|
||||
widgetOptions = prevOptions;
|
||||
} else {
|
||||
const numberParse = NumberParse.fromSettings(docModel.docData.docSettings());
|
||||
const colValues = tableData.getColValues(sourceCol.colId()) || [];
|
||||
widgetOptions = numberParse.guessOptions(colValues.filter(isString));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'Choice': {
|
||||
if (Array.isArray(prevOptions.choices)) {
|
||||
// Use previous choices if they are set, e.g. if converting from ChoiceList
|
||||
|
||||
Reference in New Issue
Block a user