(core) Fix converting column to ChoiceList when cells contain JSON arrays with non-string values

Summary: title

Test Plan: Tested manually, I don't think this needs an automated test. Made a text column with a value `[1, 2]` and converted the column to choice list. Previously this threw a JS error that `tag.trim` wasn't a function. Works now, suggests `1` and `2` as choices in the configuration.

Reviewers: georgegevoian

Reviewed By: georgegevoian

Differential Revision: https://phab.getgrist.com/D3128
pull/115/head
Alex Hall 3 years ago
parent 822372ed7c
commit 45fc46070d

@ -124,9 +124,9 @@ export async function prepTransformColInfo(docModel: DocModel, origCol: ColumnRe
for (let value of tableData.getColValues(colId) || []) {
if (value === null) { continue; }
value = String(decodeObject(value)).trim();
const tags: string[] = (value.startsWith('[') && gutil.safeJsonParse(value, null)) || value.split(",");
const tags: unknown[] = (value.startsWith('[') && gutil.safeJsonParse(value, null)) || value.split(",");
for (const tag of tags) {
choices.add(tag.trim());
choices.add(String(tag).trim());
if (choices.size > 100) { break; } // Don't suggest excessively many choices.
}
}

Loading…
Cancel
Save