Skip to content

Commit

Permalink
Merge branch 'master' into creatibutor-modal-overridable
Browse files Browse the repository at this point in the history
  • Loading branch information
karkraeg authored Sep 12, 2024
2 parents 4108c81 + 8139d44 commit 4d5e9d9
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
Changes
=======

Version v12.1.0 (released 2024-08-30)

- config: added links for thumbnails (#1799)

Version v12.0.4 (released 2024-08-28)

- stats: add missing "is_machine" field
Expand Down
2 changes: 1 addition & 1 deletion invenio_rdm_records/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

from .ext import InvenioRDMRecords

__version__ = "12.0.4"
__version__ = "12.1.0"

__all__ = ("__version__", "InvenioRDMRecords")
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -64,7 +77,7 @@ class PublishButtonComponent extends Component {
return (
<>
<Button
disabled={this.isDisabled(values, isSubmitting, numberOfFiles)}
disabled={this.isDisabled(values, isSubmitting, filesState)}
name="publish"
onClick={this.openConfirmModal}
positive
Expand Down Expand Up @@ -123,22 +136,23 @@ PublishButtonComponent.propTypes = {
buttonLabel: PropTypes.string,
publishWithoutCommunity: PropTypes.bool,
actionState: PropTypes.string,
numberOfFiles: PropTypes.number.isRequired,
formik: PropTypes.object.isRequired,
publishModalExtraContent: PropTypes.string,
filesState: PropTypes.object,
};

PublishButtonComponent.defaultProps = {
buttonLabel: i18next.t("Publish"),
publishWithoutCommunity: false,
actionState: undefined,
publishModalExtraContent: undefined,
filesState: undefined,
};

const mapStateToProps = (state) => ({
actionState: state.deposit.actionState,
numberOfFiles: Object.values(state.files.entries).length,
publishModalExtraContent: state.deposit.config.publish_modal_extra,
filesState: state.files,
});

export const PublishButton = connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,26 @@ class SubmitReviewButtonComponent extends Component {
this.closeConfirmModal();
};

isDisabled = (numberOfFiles, disableSubmitForReviewButton) => {
isDisabled = (disableSubmitForReviewButton, filesState) => {
const { formik } = this.props;
const { values, isSubmitting } = formik;

if (disableSubmitForReviewButton || isSubmitting) {
return true;
}

const filesEnabled = _get(values, "files.enabled", false);
const filesMissing = filesEnabled && !numberOfFiles;
return isSubmitting || filesMissing || disableSubmitForReviewButton;
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() {
Expand All @@ -59,8 +72,8 @@ class SubmitReviewButtonComponent extends Component {
directPublish,
formik,
isRecordSubmittedForReview,
numberOfFiles,
publishModalExtraContent,
filesState,
...ui
} = this.props;

Expand All @@ -80,7 +93,7 @@ class SubmitReviewButtonComponent extends Component {
return (
<>
<Button
disabled={this.isDisabled(numberOfFiles, disableSubmitForReviewButton)}
disabled={this.isDisabled(disableSubmitForReviewButton, filesState)}
name="SubmitReview"
onClick={this.openConfirmModal}
positive={directPublish}
Expand Down Expand Up @@ -112,20 +125,20 @@ SubmitReviewButtonComponent.propTypes = {
actionState: PropTypes.string,
actionStateExtra: PropTypes.object.isRequired,
community: PropTypes.object.isRequired,
numberOfFiles: PropTypes.number,
disableSubmitForReviewButton: PropTypes.bool,
isRecordSubmittedForReview: PropTypes.bool.isRequired,
directPublish: PropTypes.bool,
formik: PropTypes.object.isRequired,
publishModalExtraContent: PropTypes.string,
filesState: PropTypes.object,
};

SubmitReviewButtonComponent.defaultProps = {
actionState: undefined,
numberOfFiles: undefined,
disableSubmitForReviewButton: undefined,
publishModalExtraContent: undefined,
directPublish: false,
filesState: undefined,
};

const mapStateToProps = (state) => ({
Expand All @@ -135,8 +148,8 @@ const mapStateToProps = (state) => ({
isRecordSubmittedForReview: state.deposit.record.status === DepositStatus.IN_REVIEW,
disableSubmitForReviewButton:
state.deposit.editorState.ui.disableSubmitForReviewButton,
numberOfFiles: Object.values(state.files.entries).length,
publishModalExtraContent: state.deposit.config.publish_modal_extra,
filesState: state.files,
});

export const SubmitReviewButton = connect(
Expand Down
2 changes: 1 addition & 1 deletion invenio_rdm_records/resources/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ def search(self):
)
return items.to_dict(), 200

# No response_handler here because we dont want to process the response with the schema
@request_view_args
@response_handler()
@request_data
def add(self):
"""Include record in communities."""
Expand Down

0 comments on commit 4d5e9d9

Please sign in to comment.