Skip to content

Commit

Permalink
[publication] Fix number of files in Upload tab (#9179)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
CamilleBeau committed Apr 16, 2024
1 parent e96d5a8 commit 92dbd76
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions modules/publication/jsx/uploadForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 11 additions & 3 deletions modules/publication/jsx/viewProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions modules/publication/test/TestPlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 92dbd76

Please # to comment.