From 5f37f7a523bfe064802013cab2fc71c0e3f80c44 Mon Sep 17 00:00:00 2001 From: dream2023 <1098626505@qq.com> Date: Fri, 12 Jan 2024 15:20:23 +0800 Subject: [PATCH] fix: bug --- .../application/collection/CollectionManager.tsx | 2 ++ .../src/collection-manager/collectionPlugin.ts | 1 + .../hooks/useCollectionManager.ts | 16 ++++++++-------- .../src/client/GraphDrawPage.tsx | 8 +++++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/core/client/src/application/collection/CollectionManager.tsx b/packages/core/client/src/application/collection/CollectionManager.tsx index 9d12a94694..886dc8f5dd 100644 --- a/packages/core/client/src/application/collection/CollectionManager.tsx +++ b/packages/core/client/src/application/collection/CollectionManager.tsx @@ -305,6 +305,8 @@ export class CollectionManagerV2 { private getInheritData() { return { collections: this.collections, + collectionFieldGroups: this.collectionFieldGroups, + reloadCallbacks: this.reloadCallbacks, collectionTemplateInstances: this.collectionTemplateInstances, fieldInterfaceInstances: this.fieldInterfaceInstances, collectionMixins: this.collectionMixins, diff --git a/packages/core/client/src/collection-manager/collectionPlugin.ts b/packages/core/client/src/collection-manager/collectionPlugin.ts index 3370503861..4ad956da73 100644 --- a/packages/core/client/src/collection-manager/collectionPlugin.ts +++ b/packages/core/client/src/collection-manager/collectionPlugin.ts @@ -55,6 +55,7 @@ export class CollectionPlugin extends Plugin { this.addFieldInterfaces(); this.addCollectionTemplates(); this.addFieldInterfaces(); + this.addFieldGroups(); this.collectionManager.setReloadFn(this.reloadCollections.bind(this)); } diff --git a/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts b/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts index eebf20a052..d0dd23dce7 100644 --- a/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts +++ b/packages/core/client/src/collection-manager/hooks/useCollectionManager.ts @@ -12,14 +12,13 @@ export const useCollectionManager = () => { const [random, setRandom] = useState(uid()); const interfaces = useMemo(() => cm?.getFieldInterfaces(), [cm, random]); const templates = useMemo(() => cm?.getCollectionTemplates(), [cm, random]); - const collections = useMemo( - () => - cm - ?.getCollections() - .filter((item) => !item.isLocal) - .map((item) => item.getOptions()), - [cm, random], - ); + const getCollections = useCallback(() => { + return cm + ?.getCollections() + .filter((item) => !item.isLocal) + .map((item) => item.getOptions()); + }, [cm]); + const collections = useMemo(() => getCollections(), [cm, random]); const { refresh } = useSchemaComponentContext(); const service = useCallback(() => cm?.reload(refresh), [cm]); const updateCollection = cm?.setCollections.bind(cm); @@ -236,6 +235,7 @@ export const useCollectionManager = () => { templates, getTemplate, getInterface, + getCollections, getParentCollectionFields, getInheritCollections, getChildrenCollections, diff --git a/packages/plugins/@nocobase/plugin-graph-collection-manager/src/client/GraphDrawPage.tsx b/packages/plugins/@nocobase/plugin-graph-collection-manager/src/client/GraphDrawPage.tsx index 41635d27e5..e8d785c04c 100644 --- a/packages/plugins/@nocobase/plugin-graph-collection-manager/src/client/GraphDrawPage.tsx +++ b/packages/plugins/@nocobase/plugin-graph-collection-manager/src/client/GraphDrawPage.tsx @@ -372,7 +372,7 @@ export const GraphDrawPage = React.memo(() => { const [collectionData, setCollectionData] = useState([]); const [collectionList, setCollectionList] = useState([]); const [loading, setLoading] = useState(false); - const { collections } = useCollectionManager(); + const { collections, getCollections } = useCollectionManager(); const cm = useCollectionManagerV2(); const currentAppInfo = useCurrentAppInfo(); const app = useApp(); @@ -412,7 +412,9 @@ export const GraphDrawPage = React.memo(() => { refreshPositions(); } }; - const reloadCallback = async (collections) => { + const reloadCallback = async () => { + const collections = getCollections(); + if (!targetGraph) return; targetGraph.collections = collections; targetGraph.updatePositionAction = updatePositionAction; targetGraph.saveGraphPositionAction = saveGraphPositionAction; @@ -1072,7 +1074,7 @@ export const GraphDrawPage = React.memo(() => { setLoading(true); refreshPositions() .then(async () => { - await reloadCallback(collections); + await reloadCallback(); setLoading(false); }) .catch((err) => {