From 0a25426f318589eae88aee4da359135848ea9d07 Mon Sep 17 00:00:00 2001 From: katherinehhh Date: Thu, 23 Mar 2023 12:18:52 +0800 Subject: [PATCH] fix: repeat request categories when switching between graph interface and collection&fields (#1590) --- .../CollectionManagerProvider.tsx | 52 +++++++++---------- .../CollectionManagerShortcut.tsx | 2 +- .../src/client/GraphDrawPage.tsx | 4 +- .../src/client/components/Entity.tsx | 2 +- 4 files changed, 31 insertions(+), 29 deletions(-) diff --git a/packages/core/client/src/collection-manager/CollectionManagerProvider.tsx b/packages/core/client/src/collection-manager/CollectionManagerProvider.tsx index 46ac952c7..48ad0fb17 100644 --- a/packages/core/client/src/collection-manager/CollectionManagerProvider.tsx +++ b/packages/core/client/src/collection-manager/CollectionManagerProvider.tsx @@ -45,11 +45,19 @@ export const RemoteCollectionManagerProvider = (props: any) => { sort: ['sort'], }, }; + const coptions = { + url: 'collectionCategories:list', + params: { + paginate: false, + sort: ['sort'], + }, + }; const service = useRequest(options); + const result = useRequest(coptions); + if (service.loading) { return ; } - const refreshCM = async (opts) => { if (opts?.reload) { setContentLoading(true); @@ -62,40 +70,32 @@ export const RemoteCollectionManagerProvider = (props: any) => { } return data?.data || []; }; + const refreshCategory = async () => { + const { data } = await api.request(coptions); + result.mutate(data); + return data?.data || []; + }; return ( - + + + ); }; export const CollectionCategroriesProvider = (props) => { - const api = useAPIClient(); - const options = { - url: 'collectionCategories:list', - params: { - paginate: false, - sort: ['sort'], - }, - }; - const result = useRequest(options); - if (result.loading) { - return ; - } + const { service, refreshCategory } = props; return ( { - const { data } = await api.request(options); - result.mutate(data); - return data?.data || []; - }, + data: service?.data?.data, + refresh: refreshCategory, + ...props }} > {props.children} diff --git a/packages/core/client/src/collection-manager/CollectionManagerShortcut.tsx b/packages/core/client/src/collection-manager/CollectionManagerShortcut.tsx index a5e3eafc0..656fdcd47 100644 --- a/packages/core/client/src/collection-manager/CollectionManagerShortcut.tsx +++ b/packages/core/client/src/collection-manager/CollectionManagerShortcut.tsx @@ -50,7 +50,7 @@ const schema2: ISchema = { type: 'object', properties: { [uid()]: { - 'x-decorator': 'CollectionCategroriesProvider', + // 'x-decorator': 'CollectionCategroriesProvider', 'x-component': 'ConfigurationTable', }, }, diff --git a/packages/plugins/graph-collection-manager/src/client/GraphDrawPage.tsx b/packages/plugins/graph-collection-manager/src/client/GraphDrawPage.tsx index 6119d2eed..ea24dd984 100644 --- a/packages/plugins/graph-collection-manager/src/client/GraphDrawPage.tsx +++ b/packages/plugins/graph-collection-manager/src/client/GraphDrawPage.tsx @@ -24,6 +24,7 @@ import { useCompile, useCurrentAppInfo, CollectionCategroriesProvider, + CollectionCategroriesContext, } from '@nocobase/client'; import { useFullscreen } from 'ahooks'; import { Button, Input, Layout, Menu, Popover, Switch, Tooltip } from 'antd'; @@ -374,6 +375,7 @@ export const GraphDrawPage = React.memo(() => { const { data: { database }, } = useCurrentAppInfo(); + const categoryCtx = useContext(CollectionCategroriesContext); const scope = { ...options?.scope }; const components = { ...options?.components }; const useSaveGraphPositionAction = async (data) => { @@ -504,7 +506,7 @@ export const GraphDrawPage = React.memo(() => { - + { - return categoryData.data.map((item: any) => ({ + return categoryData?.data.map((item: any) => ({ label: compile(item.name), value: item.id, }));