fix: repeat request categories when switching between graph interface and collection&fields (#1590)
This commit is contained in:
parent
48fb4855af
commit
0a25426f31
@ -45,11 +45,19 @@ export const RemoteCollectionManagerProvider = (props: any) => {
|
|||||||
sort: ['sort'],
|
sort: ['sort'],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
const coptions = {
|
||||||
|
url: 'collectionCategories:list',
|
||||||
|
params: {
|
||||||
|
paginate: false,
|
||||||
|
sort: ['sort'],
|
||||||
|
},
|
||||||
|
};
|
||||||
const service = useRequest(options);
|
const service = useRequest(options);
|
||||||
|
const result = useRequest(coptions);
|
||||||
|
|
||||||
if (service.loading) {
|
if (service.loading) {
|
||||||
return <Spin />;
|
return <Spin />;
|
||||||
}
|
}
|
||||||
|
|
||||||
const refreshCM = async (opts) => {
|
const refreshCM = async (opts) => {
|
||||||
if (opts?.reload) {
|
if (opts?.reload) {
|
||||||
setContentLoading(true);
|
setContentLoading(true);
|
||||||
@ -62,40 +70,32 @@ export const RemoteCollectionManagerProvider = (props: any) => {
|
|||||||
}
|
}
|
||||||
return data?.data || [];
|
return data?.data || [];
|
||||||
};
|
};
|
||||||
|
const refreshCategory = async () => {
|
||||||
|
const { data } = await api.request(coptions);
|
||||||
|
result.mutate(data);
|
||||||
|
return data?.data || [];
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<CollectionCategroriesProvider service={{ ...result }} refreshCategory={refreshCategory}>
|
||||||
<CollectionManagerProvider
|
<CollectionManagerProvider
|
||||||
service={{ ...service, contentLoading, setContentLoading }}
|
service={{ ...service, contentLoading, setContentLoading }}
|
||||||
collections={service?.data?.data}
|
collections={service?.data?.data}
|
||||||
refreshCM={refreshCM}
|
refreshCM={refreshCM}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
|
</CollectionCategroriesProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CollectionCategroriesProvider = (props) => {
|
export const CollectionCategroriesProvider = (props) => {
|
||||||
const api = useAPIClient();
|
const { service, refreshCategory } = props;
|
||||||
const options = {
|
|
||||||
url: 'collectionCategories:list',
|
|
||||||
params: {
|
|
||||||
paginate: false,
|
|
||||||
sort: ['sort'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const result = useRequest(options);
|
|
||||||
if (result.loading) {
|
|
||||||
return <Spin />;
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<CollectionCategroriesContext.Provider
|
<CollectionCategroriesContext.Provider
|
||||||
value={{
|
value={{
|
||||||
...result,
|
data: service?.data?.data,
|
||||||
data: result?.data?.data,
|
refresh: refreshCategory,
|
||||||
refresh: async () => {
|
...props
|
||||||
const { data } = await api.request(options);
|
|
||||||
result.mutate(data);
|
|
||||||
return data?.data || [];
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
|
@ -50,7 +50,7 @@ const schema2: ISchema = {
|
|||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
[uid()]: {
|
[uid()]: {
|
||||||
'x-decorator': 'CollectionCategroriesProvider',
|
// 'x-decorator': 'CollectionCategroriesProvider',
|
||||||
'x-component': 'ConfigurationTable',
|
'x-component': 'ConfigurationTable',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -24,6 +24,7 @@ import {
|
|||||||
useCompile,
|
useCompile,
|
||||||
useCurrentAppInfo,
|
useCurrentAppInfo,
|
||||||
CollectionCategroriesProvider,
|
CollectionCategroriesProvider,
|
||||||
|
CollectionCategroriesContext,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import { useFullscreen } from 'ahooks';
|
import { useFullscreen } from 'ahooks';
|
||||||
import { Button, Input, Layout, Menu, Popover, Switch, Tooltip } from 'antd';
|
import { Button, Input, Layout, Menu, Popover, Switch, Tooltip } from 'antd';
|
||||||
@ -374,6 +375,7 @@ export const GraphDrawPage = React.memo(() => {
|
|||||||
const {
|
const {
|
||||||
data: { database },
|
data: { database },
|
||||||
} = useCurrentAppInfo();
|
} = useCurrentAppInfo();
|
||||||
|
const categoryCtx = useContext(CollectionCategroriesContext);
|
||||||
const scope = { ...options?.scope };
|
const scope = { ...options?.scope };
|
||||||
const components = { ...options?.components };
|
const components = { ...options?.components };
|
||||||
const useSaveGraphPositionAction = async (data) => {
|
const useSaveGraphPositionAction = async (data) => {
|
||||||
@ -504,7 +506,7 @@ export const GraphDrawPage = React.memo(() => {
|
|||||||
<CurrentAppInfoContext.Provider value={database}>
|
<CurrentAppInfoContext.Provider value={database}>
|
||||||
<APIClientProvider apiClient={api}>
|
<APIClientProvider apiClient={api}>
|
||||||
<SchemaComponentOptions inherit scope={scope} components={components}>
|
<SchemaComponentOptions inherit scope={scope} components={components}>
|
||||||
<CollectionCategroriesProvider>
|
<CollectionCategroriesProvider {...categoryCtx}>
|
||||||
<CollectionManagerProvider
|
<CollectionManagerProvider
|
||||||
collections={targetGraph?.collections}
|
collections={targetGraph?.collections}
|
||||||
refreshCM={refreshGM}
|
refreshCM={refreshGM}
|
||||||
|
@ -71,7 +71,7 @@ const Entity: React.FC<{
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
const loadCategories = async () => {
|
const loadCategories = async () => {
|
||||||
return categoryData.data.map((item: any) => ({
|
return categoryData?.data.map((item: any) => ({
|
||||||
label: compile(item.name),
|
label: compile(item.name),
|
||||||
value: item.id,
|
value: item.id,
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user