Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doi: handle UI for optional DOI feature #1896

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ export class RDMDepositApiClient extends DepositApiClient {
);
return new DepositApiClientResponse(data, errors);
} catch (error) {
const errorData = error.response.data;
let errorData = error.response.data;
const errors = this.recordSerializer.deserializeErrors(
error.response.data.errors || []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need the empty array?

);
// this is to serialize raised error from the backend on publish
if (errors) errorData = errors;
throw new DepositApiClientResponse({}, errorData);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
DepositFormSubmitContext,
} from "../../api/DepositFormSubmitContext";
import { DRAFT_PUBLISH_STARTED } from "../../state/types";
import { scrollTop } from "../../utils";
import { DRAFT_PUBLISH_FAILED_WITH_VALIDATION_ERRORS } from "../../state/types";

class PublishButtonComponent extends Component {
state = { isConfirmModalOpen: false };
Expand All @@ -30,14 +32,36 @@ class PublishButtonComponent extends Component {

handlePublish = (event, handleSubmit, publishWithoutCommunity) => {
const { setSubmitContext } = this.context;

setSubmitContext(
publishWithoutCommunity
? DepositFormSubmitActions.PUBLISH_WITHOUT_COMMUNITY
: DepositFormSubmitActions.PUBLISH
);
handleSubmit(event);
this.closeConfirmModal();
const { formik, raiseDOINeededButNotReserved, isDOIRequired } = this.props;
const noINeedOne = formik?.values?.noINeedOne;
// Check for explicit DOI reservation via the "GET DOI button" only when DOI is
// optional in the instance's settings. If it is required, backend will automatically
// mint one even if it was not explicitly reserved
const shouldCheckForExplicitDOIReservation =
isDOIRequired !== undefined && // isDOIRequired is undefined when no value was provided from Invenio-app-rdm
!isDOIRequired &&
noINeedOne &&
Object.keys(formik?.values?.pids).length === 0;
if (shouldCheckForExplicitDOIReservation) {
const errors = {
pids: {
doi: i18next.t("DOI is needed. Please click on the button to reserve it."),
},
};
formik.setErrors(errors);
raiseDOINeededButNotReserved(formik?.values, errors);
this.closeConfirmModal();
} else {
setSubmitContext(
publishWithoutCommunity
? DepositFormSubmitActions.PUBLISH_WITHOUT_COMMUNITY
: DepositFormSubmitActions.PUBLISH
);
handleSubmit(event);
this.closeConfirmModal();
}
// scroll top to show the global error
scrollTop();
};

isDisabled = (values, isSubmitting, filesState) => {
Expand Down Expand Up @@ -67,6 +91,7 @@ class PublishButtonComponent extends Component {
publishWithoutCommunity,
formik,
publishModalExtraContent,
raiseDOINeededButNotReserved,
...ui
} = this.props;
const { isConfirmModalOpen } = this.state;
Expand Down Expand Up @@ -139,6 +164,8 @@ PublishButtonComponent.propTypes = {
formik: PropTypes.object.isRequired,
publishModalExtraContent: PropTypes.string,
filesState: PropTypes.object,
raiseDOINeededButNotReserved: PropTypes.func.isRequired,
isDOIRequired: PropTypes.bool,
};

PublishButtonComponent.defaultProps = {
Expand All @@ -147,15 +174,22 @@ PublishButtonComponent.defaultProps = {
actionState: undefined,
publishModalExtraContent: undefined,
filesState: undefined,
isDOIRequired: undefined,
};

const mapStateToProps = (state) => ({
actionState: state.deposit.actionState,
publishModalExtraContent: state.deposit.config.publish_modal_extra,
filesState: state.files,
isDOIRequired: state.deposit.config.is_doi_required,
});

export const PublishButton = connect(
mapStateToProps,
null
)(connectFormik(PublishButtonComponent));
export const PublishButton = connect(mapStateToProps, (dispatch) => {
return {
raiseDOINeededButNotReserved: (data, errors) =>
dispatch({
type: DRAFT_PUBLISH_FAILED_WITH_VALIDATION_ERRORS,
payload: { data: data, errors: errors },
}),
};
})(connectFormik(PublishButtonComponent));
Loading
Loading