1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-04-27 11:01:14 +00:00

feat: metadata status callback (#7716)

* feat: metadata status callback

* feat: optimzie code

---------

Co-authored-by: 杨国璇 <ygx@Hello-word.local>
This commit is contained in:
杨国璇 2025-04-08 15:00:02 +08:00 committed by GitHub
parent a865aecb6f
commit 53bedae485
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 8 deletions

View File

@ -7,7 +7,7 @@ import { MetadataAIOperationsProvider } from './metadata-ai-operation';
// This hook provides content related to seahub interaction, such as whether to enable extended attributes
const MetadataStatusContext = React.createContext(null);
export const MetadataStatusProvider = ({ repoID, repoInfo, hideMetadataView, updateUsedRepoTags, clearRepoTags, children }) => {
export const MetadataStatusProvider = ({ repoID, repoInfo, hideMetadataView, statusCallback, children }) => {
const enableMetadataManagement = useMemo(() => {
if (repoInfo?.encrypted) return false;
return window.app.pageOptions.enableMetadataManagement;
@ -60,9 +60,6 @@ export const MetadataStatusProvider = ({ repoID, repoInfo, hideMetadataView, upd
if (!enableMetadata) {
cancelMetadataURL();
}
if (enableTags) {
updateUsedRepoTags();
}
setEnableTags(enableTags);
setTagsLang(tagsLang || 'en');
setDetailsSettings(JSON.parse(detailsSettings));
@ -79,6 +76,11 @@ export const MetadataStatusProvider = ({ repoID, repoInfo, hideMetadataView, upd
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [repoID, enableMetadataManagement]);
useEffect(() => {
statusCallback && statusCallback({ enableMetadata, enableTags });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [enableMetadata, enableTags]);
const updateEnableMetadata = useCallback((newValue) => {
if (newValue === enableMetadata) return;
if (!newValue) {
@ -96,12 +98,10 @@ export const MetadataStatusProvider = ({ repoID, repoInfo, hideMetadataView, upd
if (newValue === enableTags && lang === tagsLang) return;
if (!newValue) {
cancelMetadataURL(true);
clearRepoTags();
}
setEnableTags(newValue);
if (newValue) updateUsedRepoTags();
setTagsLang(lang);
}, [enableTags, tagsLang, cancelMetadataURL, clearRepoTags, updateUsedRepoTags]);
}, [enableTags, tagsLang, cancelMetadataURL]);
const updateEnableOCR = useCallback((newValue) => {
if (newValue === enableOCR) return;

View File

@ -2245,6 +2245,14 @@ class LibContentView extends React.Component {
this.setState({ isDirentSelected });
};
metadataStatusCallback = ({ enableMetadata, enableTags }) => {
if (enableMetadata && enableTags) {
this.updateUsedRepoTags();
return;
}
this.clearRepoTags();
};
render() {
const { repoID } = this.props;
let { currentRepoInfo, userPerm, isCopyMoveProgressDialogShow, isDeleteFolderDialogOpen, errorMsg,
@ -2320,7 +2328,7 @@ class LibContentView extends React.Component {
}
const detailDirent = currentDirent || currentNode?.object || null;
return (
<MetadataStatusProvider repoID={repoID} repoInfo={currentRepoInfo} hideMetadataView={this.hideMetadataView} updateUsedRepoTags={this.updateUsedRepoTags} clearRepoTags={this.clearRepoTags} >
<MetadataStatusProvider repoID={repoID} repoInfo={currentRepoInfo} hideMetadataView={this.hideMetadataView} statusCallback={this.metadataStatusCallback} >
<TagsProvider repoID={repoID} currentPath={path} repoInfo={currentRepoInfo} selectTagsView={this.onTreeNodeClick} >
<MetadataProvider repoID={repoID} currentPath={path} repoInfo={currentRepoInfo} selectMetadataView={this.onTreeNodeClick} >
<CollaboratorsProvider repoID={repoID}>