diff --git a/frontend/src/hooks/metadata-status.js b/frontend/src/hooks/metadata-status.js index 3ad877450e..79dbb7143f 100644 --- a/frontend/src/hooks/metadata-status.js +++ b/frontend/src/hooks/metadata-status.js @@ -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; diff --git a/frontend/src/pages/lib-content-view/lib-content-view.js b/frontend/src/pages/lib-content-view/lib-content-view.js index 3498f72986..e6db920784 100644 --- a/frontend/src/pages/lib-content-view/lib-content-view.js +++ b/frontend/src/pages/lib-content-view/lib-content-view.js @@ -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}>