Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.

fix: don't clear list when CSV import column prompt is cancelled#10080

Open
Chessing234 wants to merge 1 commit into
scratchfoundation:developfrom
Chessing234:fix/list-import-cancel-clears-list
Open

fix: don't clear list when CSV import column prompt is cancelled#10080
Chessing234 wants to merge 1 commit into
scratchfoundation:developfrom
Chessing234:fix/list-import-cancel-clears-list

Conversation

@Chessing234

Copy link
Copy Markdown

Resolves

Resolves #7313

Proposed Changes

When importing a multi-column .csv/.tsv into a list, Monitor's handleImport asks which column to use with window.prompt. The return value was passed straight into parseInt(...):

columnNumber = parseInt(prompt(msg), 10);

If the user presses Cancel, prompt returns null, so parseInt(null, 10) is NaN. Every row[NaN - 1] is then undefined, the .filter(item => typeof item === 'string') drops them all, and the list is overwritten with an empty array — silently deleting the list's existing contents.

This change reads the prompt response first and returns early when it is null, leaving the list untouched on cancel. Entering a valid column still works exactly as before.

Reason for Changes

Pressing Cancel should abort the import without changing the project, as described in the issue. The old code treated a cancelled prompt as "import an empty column," which wiped the list (High Severity data loss).

Test Coverage

Added test/unit/containers/monitor.test.jsx with two cases:

  • cancelling the column prompt (promptnull) does not call setVariableValue, so the list is unchanged;
  • choosing a column (prompt'2') imports that column (['a2', 'b2']).

The first test fails on the current master and passes with this change; the second guards against regressing normal imports. npm run test:unit -- test/unit/containers/monitor.test.jsx passes and eslint . --ext .js,.jsx is clean.

When importing a multi-column CSV into a list, the user is asked which
column to use via window.prompt. Pressing Cancel returns null, so
parseInt(null, 10) is NaN and every row[NaN - 1] is undefined; the
subsequent filter drops them all, leaving an empty list value that
overwrites the existing contents.

Bail out of the import when the prompt is cancelled so the list is left
unchanged.

Fixes scratchfoundation#7313
@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENA-121 Cancelling a csv import deletes all items in the list

1 participant