-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: section * feat: update code --------- Co-authored-by: 杨国璇 <[email protected]>
- Loading branch information
1 parent
9fcef01
commit e252f50
Showing
16 changed files
with
466 additions
and
318 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
Empty file.
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,75 @@ | ||
import React, { useCallback, useEffect, useMemo, useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { gettext } from '../../../utils/constants'; | ||
import { Utils } from '../../../utils/utils'; | ||
import TreeSection from '../../tree-section'; | ||
import MetadataStatusManagementDialog from '../../metadata-manage/metadata-status-manage-dialog'; | ||
import metadataManagerAPI from '../../metadata-manage/api'; | ||
import toaster from '../../toast'; | ||
import MetadataViews from '../../metadata-manage/metadata-views'; | ||
|
||
const DirViews = ({ userPerm, repoID }) => { | ||
const enableMetadataManagement = useMemo(() => { | ||
return window.app.pageOptions.enableMetadataManagement; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [window.app.pageOptions.enableMetadataManagement]); | ||
|
||
const [loading, setLoading] = useState(true); | ||
const [showMetadataStatusManagementDialog, setShowMetadataStatusManagementDialog] = useState(false); | ||
const [metadataStatus, setMetadataStatus] = useState(false); | ||
const moreOperations = useMemo(() => { | ||
if (!enableMetadataManagement) return []; | ||
if (userPerm !== 'rw' && userPerm !== 'admin') return []; | ||
return [ | ||
{ key: 'extended-properties', value: gettext('Extended properties') } | ||
]; | ||
}, [enableMetadataManagement, userPerm]); | ||
|
||
useEffect(() => { | ||
const repoMetadataManagementEnabledStatusRes = metadataManagerAPI.getRepoMetadataManagementEnabledStatus(repoID); | ||
Promise.all([repoMetadataManagementEnabledStatusRes]).then(results => { | ||
const [repoMetadataManagementEnabledStatusRes] = results; | ||
setMetadataStatus(repoMetadataManagementEnabledStatusRes.data.enabled); | ||
setLoading(false); | ||
}).catch(error => { | ||
const errorMsg = Utils.getErrorMsg(error, true); | ||
toaster.danger(errorMsg); | ||
setLoading(false); | ||
}); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
const moreOperationClick = useCallback((operationKey) => { | ||
if (operationKey === 'extended-properties') { | ||
setShowMetadataStatusManagementDialog(true); | ||
return; | ||
} | ||
}, []); | ||
|
||
const closeMetadataManagementDialog = useCallback(() => { | ||
setShowMetadataStatusManagementDialog(false); | ||
}, []); | ||
|
||
const toggleMetadataStatus = useCallback((value) => { | ||
if (metadataStatus === value) return; | ||
setMetadataStatus(value); | ||
}, [metadataStatus]); | ||
|
||
return ( | ||
<> | ||
<TreeSection title={gettext('Views')} moreKey={{ name: 'views' }} moreOperations={moreOperations} moreOperationClick={moreOperationClick}> | ||
{!loading && metadataStatus && (<MetadataViews repoID={repoID} />)} | ||
</TreeSection> | ||
{showMetadataStatusManagementDialog && ( | ||
<MetadataStatusManagementDialog value={metadataStatus} repoID={repoID} toggle={closeMetadataManagementDialog} submit={toggleMetadataStatus} /> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
DirViews.propTypes = { | ||
userPerm: PropTypes.string, | ||
repoID: PropTypes.string, | ||
}; | ||
|
||
export default DirViews; |
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
129 changes: 0 additions & 129 deletions
129
frontend/src/components/metadata-manage/metadata-manage-view.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.