From 92dbd762c2fe2821732c35d9a88ebd7c92d98d41 Mon Sep 17 00:00:00 2001 From: CamilleBeau <51176779+CamilleBeau@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:44:55 -0400 Subject: [PATCH] [publication] Fix number of files in Upload tab (#9179) In the uploadForm.js file is modified to increase / decrease the numFiles value according to whether a file was actually selected or not. If a file is selected, the numFiles increases. If a file is not selected, the numFiles decreases. This prevents the bug where "File to Upload" field is added indefinitely if the file is browsed and then cancelled. Fixes #9136 --- CHANGELOG.md | 1 + modules/publication/jsx/uploadForm.js | 14 +++++++++++--- modules/publication/jsx/viewProject.js | 14 +++++++++++--- modules/publication/test/TestPlan.md | 3 +++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69bb846efe0..add186aae70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ changes in the following format: PR #1234*** - DoB and DoD format respected in candidate parameters (PR #9001) - Fix delete file in upload (PR #9181) - Fix profile level feedback display in behavioural QC module (PR #9192) +- While proposing a project or editing a project in publications module, prevent indefinite "File to upload" fields from being added if files are browsed then cancelled (PR #9179) ## LORIS 25.0 (Release Date: ????-??-??) ### Core diff --git a/modules/publication/jsx/uploadForm.js b/modules/publication/jsx/uploadForm.js index ebb28285006..17a4a1184b8 100644 --- a/modules/publication/jsx/uploadForm.js +++ b/modules/publication/jsx/uploadForm.js @@ -83,9 +83,17 @@ class PublicationUploadForm extends React.Component { */ setFileData(formElement, value) { let numFiles = this.state.numFiles; - if (!this.state.formData[formElement]) { - numFiles += 1; - this.setState({numFiles: numFiles}); + if (value) { + if (!this.state.formData[formElement]) { + numFiles += 1; + this.setState({numFiles: numFiles}); + } + } else { + // File is being removed + if (this.state.formData[formElement]) { + numFiles -= 1; + this.setState({numFiles: numFiles}); + } } this.setFormData(formElement, value); } diff --git a/modules/publication/jsx/viewProject.js b/modules/publication/jsx/viewProject.js index b479ba224f9..6f49f0ffd6c 100644 --- a/modules/publication/jsx/viewProject.js +++ b/modules/publication/jsx/viewProject.js @@ -436,9 +436,17 @@ class ViewProject extends React.Component { */ setFileData(formElement, value) { let numFiles = this.state.numFiles; - if (!this.state.formData[formElement]) { - numFiles += 1; - this.setState({numFiles: numFiles}); + if (value) { + if (!this.state.formData[formElement]) { + numFiles += 1; + this.setState({numFiles: numFiles}); + } + } else { + // File is being removed + if (this.state.formData[formElement]) { + numFiles -= 1; + this.setState({numFiles: numFiles}); + } } this.setFormData(formElement, value); } diff --git a/modules/publication/test/TestPlan.md b/modules/publication/test/TestPlan.md index 5441e5a4231..07d212e589e 100644 --- a/modules/publication/test/TestPlan.md +++ b/modules/publication/test/TestPlan.md @@ -15,6 +15,9 @@ and ensure that the project proposal page is now accessible. 5. Fill out all the fields in the form and try to submit. Make sure you have a corresponding directory to the directory specified in Config if you are attempting a file upload. Try submitting without filling in required fields. +6. Try adding a file to upload, and then adding another file to upload. Next, +select browse in the second file that was uploaded, but cancel the file. The +file should be removed, and no extra "File to upload" fields should be added. 6. Login under one of the accounts you specified under the "Users with Edit Permission" and access the project page and make edits to the proposal.