(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
This commit is contained in:
Alex Hall 2021-11-08 20:25:41 +02:00
parent 822372ed7c
commit 45fc46070d

View File

@ -124,9 +124,9 @@ export async function prepTransformColInfo(docModel: DocModel, origCol: ColumnRe
for (let value of tableData.getColValues(colId) || []) { for (let value of tableData.getColValues(colId) || []) {
if (value === null) { continue; } if (value === null) { continue; }
value = String(decodeObject(value)).trim(); 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) { 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. if (choices.size > 100) { break; } // Don't suggest excessively many choices.
} }
} }