From b3dd407602361cfbb45e8c7a18613c464107927a Mon Sep 17 00:00:00 2001 From: Anika Churilova Date: Fri, 6 Dec 2024 10:39:11 +0100 Subject: [PATCH] doi: add error handling on the component --- .../deposit/controls/PublishButton/PublishButton.js | 7 +------ .../src/deposit/fields/Identifiers/PIDField.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 7 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 ac0755859..0153da865 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 @@ -34,14 +34,10 @@ class PublishButtonComponent extends Component { const { setSubmitContext } = this.context; const { formik, raiseDOINeededButNotReserved } = this.props; const noINeedOne = formik?.values?.noINeedOne; - // TODO - // - You need to check if DOI is enabled here, otherwise you will not see field - // - The error message is not shown on the field, maybe missing an error label - // - Maybe show it also in the global? if (noINeedOne && Object.keys(formik?.values?.pids).length === 0) { const errors = { pids: { - doi: "No DOI was reserved and one was needed.", + doi: "DOI is needed. Please click on the button to reserve it.", }, }; formik.setErrors(errors); @@ -180,7 +176,6 @@ export const PublishButton = connect(mapStateToProps, (dispatch) => { return { raiseDOINeededButNotReserved: (data, errors) => dispatch({ - // TODO: maybe you need another error because the message is misleading type: DRAFT_PUBLISH_FAILED_WITH_VALIDATION_ERRORS, payload: { data: data, errors: errors }, }), diff --git a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/Identifiers/PIDField.js b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/Identifiers/PIDField.js index c1db21448..da890fca6 100644 --- a/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/Identifiers/PIDField.js +++ b/invenio_rdm_records/assets/semantic-ui/js/invenio_rdm_records/src/deposit/fields/Identifiers/PIDField.js @@ -33,7 +33,7 @@ const getFieldErrors = (form, fieldPath) => { */ class ReservePIDBtn extends Component { render() { - const { disabled, handleReservePID, label, loading } = this.props; + const { disabled, handleReservePID, label, loading, fieldError } = this.props; return ( {({ form: formik }) => ( @@ -44,6 +44,7 @@ class ReservePIDBtn extends Component { disabled={disabled || loading} onClick={(e) => handleReservePID(e, formik)} content={label} + error={fieldError} /> )} @@ -54,6 +55,7 @@ class ReservePIDBtn extends Component { ReservePIDBtn.propTypes = { disabled: PropTypes.bool, handleReservePID: PropTypes.func.isRequired, + fieldError: PropTypes.object, label: PropTypes.string.isRequired, loading: PropTypes.bool, }; @@ -61,6 +63,7 @@ ReservePIDBtn.propTypes = { ReservePIDBtn.defaultProps = { disabled: false, loading: false, + fieldError: null, }; /** @@ -215,6 +218,8 @@ class ManagedIdentifierComponent extends Component { identifier, pidPlaceholder, pidType, + form, + fieldPath, } = this.props; const hasIdentifier = identifier !== ""; @@ -226,6 +231,7 @@ class ManagedIdentifierComponent extends Component { actionState === RESERVE_PID_STARTED && actionStateExtra.pidType === pidType } handleReservePID={this.handleReservePID} + fieldError={getFieldErrors(form, fieldPath)} /> ); @@ -270,6 +276,8 @@ ManagedIdentifierComponent.propTypes = { btnLabelDiscardPID: PropTypes.string.isRequired, pidPlaceholder: PropTypes.string.isRequired, pidType: PropTypes.string.isRequired, + form: PropTypes.object.isRequired, + fieldPath: PropTypes.string.isRequired, /* from Redux */ actionState: PropTypes.string, actionStateExtra: PropTypes.object, @@ -480,6 +488,7 @@ class CustomPIDField extends Component { form.setFieldValue("pids", {}); form.setFieldValue("noINeedOne", true); } else if (userSelectedNoNeed) { + form.setFieldValue("pids", {}); form.setFieldValue("noINeedOne", false); } else { this.onExternalIdentifierChanged(""); @@ -501,6 +510,7 @@ class CustomPIDField extends Component { btnLabelDiscardPID={btnLabelDiscardPID} btnLabelGetPID={btnLabelGetPID} form={form} + fieldPath={fieldPath} identifier={managedIdentifier} helpText={managedHelpText} pidPlaceholder={pidPlaceholder}