forked from inveniosoftware/invenio-app-rdm
-
Notifications
You must be signed in to change notification settings - Fork 0
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
105 additions
and
31 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
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
62 changes: 62 additions & 0 deletions
62
...theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ShareOptions/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,62 @@ | ||
// 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 "./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; | ||
return isSubmitting || filesMissing; | ||
}; | ||
|
||
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