From 1eead8d17e207a3fcfafe82b6afe83bee0b8e81b Mon Sep 17 00:00:00 2001 From: alejandromumo Date: Mon, 2 Sep 2024 12:31:06 +0200 Subject: [PATCH 1/2] controls: refactored isDisabled function * Refactored isDisabled function in PublishButton and SubmitReviewButton components to check if all files are finished uploading before enabling the button. * Passed filesState instead of just the number of files to the function. * Added a check for non-finished files. * Added early returns to avoid unnecessary checks on possible large objects / arrays. --- .../controls/PublishButton/PublishButton.js | 28 +++++++++++++----- .../PublishButton/SubmitReviewButton.js | 29 ++++++++++++++----- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js index 6e88f0a31..a925ad5f1 100644 --- a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js +++ b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/controls/PublishButton/PublishButton.js @@ -40,16 +40,29 @@ class PublishButtonComponent extends Component { this.closeConfirmModal(); }; - isDisabled = (values, isSubmitting, numberOfFiles) => { + isDisabled = (values, isSubmitting, filesState) => { + if (isSubmitting) { + return true; + } + const filesEnabled = _get(values, "files.enabled", false); - const filesMissing = filesEnabled && !numberOfFiles; - return isSubmitting || filesMissing; + const filesArray = Object.values(filesState.entries ?? {}); + const filesMissing = filesEnabled && filesArray.length === 0; + + if (filesMissing) { + return true; + } + + // All files must be finished uploading + const allCompleted = filesArray.every(file => file.status === "finished") + + return !allCompleted; }; render() { const { actionState, - numberOfFiles, + filesState, buttonLabel, publishWithoutCommunity, formik, @@ -64,7 +77,7 @@ class PublishButtonComponent extends Component { return ( <>