From 3455c5b1b96cfe7dfea1e57d43dde999ef0527bc Mon Sep 17 00:00:00 2001 From: Michael An <2331806369@qq.com> Date: Fri, 13 Dec 2024 14:06:16 +0800 Subject: [PATCH] fix transfer repo --- .../src/components/dialog/transfer-dialog.js | 28 ++++++++----------- .../src/pages/my-libs/mylib-repo-list-item.js | 6 ++-- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/dialog/transfer-dialog.js b/frontend/src/components/dialog/transfer-dialog.js index a200063e6f5..378f284b578 100644 --- a/frontend/src/components/dialog/transfer-dialog.js +++ b/frontend/src/components/dialog/transfer-dialog.js @@ -17,12 +17,11 @@ import '../../css/transfer-dialog.css'; const propTypes = { itemName: PropTypes.string.isRequired, toggleDialog: PropTypes.func.isRequired, - submit: PropTypes.func.isRequired, + onTransferRepo: PropTypes.func.isRequired, canTransferToDept: PropTypes.bool, isOrgAdmin: PropTypes.bool, isSysAdmin: PropTypes.bool, isDepAdminTransfer: PropTypes.bool, - }; const TRANS_USER = 'transUser'; @@ -47,17 +46,9 @@ class TransferDialog extends React.Component { }; submit = () => { - const { activeTab, reshare } = this.state; - if (activeTab === TRANS_DEPART) { - let department = this.state.selectedOption; - this.props.submit(department, reshare); - } else if (activeTab === TRANS_USER) { - let selectedOption = this.state.selectedOption; - if (selectedOption && selectedOption[0]) { - let user = selectedOption[0]; - this.props.submit(user, reshare); - } - } + const { activeTab, reshare, selectedOption } = this.state; + const email = activeTab === TRANS_DEPART ? selectedOption.email : selectedOption[0].email; + this.props.onTransferRepo(email, reshare); }; componentDidMount() { @@ -88,13 +79,13 @@ class TransferDialog extends React.Component { } updateOptions = (departmentsRes) => { - departmentsRes.data.forEach(item => { + this.options = departmentsRes.data.map(item => { let option = { value: item.name, email: item.email, label: item.name, }; - this.options.push(option); + return option; }); }; @@ -211,9 +202,14 @@ class TransferDialog extends React.Component { }; render() { + const { selectedOption } = this.state; const { itemName: repoName } = this.props; let title = gettext('Transfer Library {library_name}'); title = title.replace('{library_name}', '' + Utils.HTMLescape(repoName) + ''); + let buttonDisabled = false; + if (selectedOption === null || (Array.isArray(selectedOption) && selectedOption.length === 0)) { + buttonDisabled = true; + } return ( @@ -224,7 +220,7 @@ class TransferDialog extends React.Component { - + ); diff --git a/frontend/src/pages/my-libs/mylib-repo-list-item.js b/frontend/src/pages/my-libs/mylib-repo-list-item.js index 3931b9f2a96..a7ac34db0a5 100644 --- a/frontend/src/pages/my-libs/mylib-repo-list-item.js +++ b/frontend/src/pages/my-libs/mylib-repo-list-item.js @@ -250,9 +250,9 @@ class MylibRepoListItem extends React.Component { this.setState({ isRenaming: !this.state.isRenaming }); }; - onTransferRepo = (user, reshare) => { + onTransferRepo = (email, reshare) => { let repoID = this.props.repo.repo_id; - userAPI.transferRepo(repoID, user.email, reshare).then(res => { + userAPI.transferRepo(repoID, email, reshare).then(res => { this.props.onTransferRepo(repoID); let message = gettext('Successfully transferred the library.'); toaster.success(message); @@ -487,7 +487,7 @@ class MylibRepoListItem extends React.Component {