(core) Parsing pasted ChoiceLists

Summary:
Added ChoiceListParser capable of parsing JSON, CSVs, and other strings containing user-configured choices (e.g. separated by spaces)

I got a little carried away here. It works, and I can't think of any bugs, but it's complicated enough that there could be hidden edge cases or difficulties maintaining it in the future. The advantage of the current method is that it should work well for ambiguous or poorly formatted inputs, e.g. choices separated only by spaces or choices containing commas which are not escaped/quoted properly. The code can be vastly simplified if we don't try to support that and require that users paste proper JSON or CSVs.

Test Plan: Added a new file test/common/ChoiceListParser.ts with pure unit tests. Waiting for approval of the overall approach before adding to the nbrowser CopyPaste test.

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D3141
This commit is contained in:
Alex Hall
2021-11-19 20:54:42 +02:00
parent 7f8f3dc0be
commit 0d460ac2d4
3 changed files with 50 additions and 8 deletions

View File

@@ -242,6 +242,8 @@ export class ChoiceListEntry extends Disposable {
const rename = async (to: string) => {
const tokenField = this._tokenFieldHolder.get();
if (!tokenField) { return; }
to = to.trim();
// If user removed the label, revert back to original one.
if (!to) {
choiceText.set(token.label);