-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
102 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/deposit/ShareDraftButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// This file is part of InvenioRDM | ||
// Copyright (C) 2024 CERN. | ||
// | ||
// Invenio RDM Records is free software; you can redistribute it and/or modify it | ||
// under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { connect as connectFormik } from "formik"; | ||
import { connect } from "react-redux"; | ||
import _get from "lodash/get"; | ||
import { ShareButton } from "../landing_page/ShareOptions/ShareButton"; | ||
|
||
class ShareDraftButtonComponent extends Component { | ||
isDisabled = (values, isSubmitting, numberOfFiles) => { | ||
const { disabled } = this.props; | ||
if (disabled) return true; | ||
|
||
const filesEnabled = _get(values, "files.enabled", false); | ||
const filesMissing = filesEnabled && !numberOfFiles; | ||
const dataEmpty = Object.keys(values.expanded).length === 0; | ||
|
||
return isSubmitting || filesMissing || dataEmpty; | ||
}; | ||
|
||
render() { | ||
const { numberOfFiles, record, permissions, groupsEnabled, formik } = this.props; | ||
const { values, isSubmitting } = formik; | ||
|
||
record.expanded = values.expanded; | ||
record.links = values.links; | ||
record.parent.access["settings"] = values.parent?.access?.settings; | ||
|
||
return ( | ||
<ShareButton | ||
disabled={this.isDisabled(values, isSubmitting, numberOfFiles)} | ||
record={record} | ||
permissions={permissions} | ||
groupsEnabled={groupsEnabled} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
ShareDraftButtonComponent.propTypes = { | ||
disabled: PropTypes.bool, | ||
record: PropTypes.object.isRequired, | ||
permissions: PropTypes.object.isRequired, | ||
groupsEnabled: PropTypes.bool.isRequired, | ||
formik: PropTypes.object.isRequired, | ||
numberOfFiles: PropTypes.number.isRequired, | ||
}; | ||
|
||
ShareDraftButtonComponent.defaultProps = { | ||
disabled: false, | ||
}; | ||
|
||
const mapStateToProps = (state) => ({ | ||
numberOfFiles: Object.values(state.files.entries).length, | ||
}); | ||
|
||
export const ShareDraftButton = connect( | ||
mapStateToProps, | ||
null | ||
)(connectFormik(ShareDraftButtonComponent)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters