mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-06 05:59:25 +08:00
refactor: adjust collection categories to be loaded from the main data source and remove from global (#5602)
This commit is contained in:
parent
932f1c1fa5
commit
49968f8636
@ -28,16 +28,7 @@ export const CollectionManagerProvider_deprecated: React.FC<CollectionManagerOpt
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const coptions = {
|
|
||||||
url: 'collectionCategories:list',
|
|
||||||
params: {
|
|
||||||
paginate: false,
|
|
||||||
sort: ['sort'],
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const RemoteCollectionManagerProvider = (props: any) => {
|
export const RemoteCollectionManagerProvider = (props: any) => {
|
||||||
const api = useAPIClient();
|
|
||||||
const dm = useDataSourceManager();
|
const dm = useDataSourceManager();
|
||||||
const { refreshCH } = useCollectionHistory();
|
const { refreshCH } = useCollectionHistory();
|
||||||
|
|
||||||
@ -46,26 +37,13 @@ export const RemoteCollectionManagerProvider = (props: any) => {
|
|||||||
}>(() => {
|
}>(() => {
|
||||||
return dm.reload().then(refreshCH);
|
return dm.reload().then(refreshCH);
|
||||||
});
|
});
|
||||||
const result = useRequest<{
|
|
||||||
data: any;
|
|
||||||
}>(coptions);
|
|
||||||
|
|
||||||
const { render } = useAppSpin();
|
const { render } = useAppSpin();
|
||||||
const refreshCategory = useCallback(async () => {
|
|
||||||
const { data } = await api.request(coptions);
|
|
||||||
result.mutate(data);
|
|
||||||
return data?.data || [];
|
|
||||||
}, [result]);
|
|
||||||
|
|
||||||
if (service.loading) {
|
if (service.loading) {
|
||||||
return render();
|
return render();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <CollectionManagerProvider_deprecated {...props}></CollectionManagerProvider_deprecated>;
|
||||||
<CollectionCategoriesProvider service={result} refreshCategory={refreshCategory}>
|
|
||||||
<CollectionManagerProvider_deprecated {...props}></CollectionManagerProvider_deprecated>
|
|
||||||
</CollectionCategoriesProvider>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CollectionCategoriesProvider = (props) => {
|
export const CollectionCategoriesProvider = (props) => {
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* This file is part of the NocoBase (R) project.
|
||||||
|
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
||||||
|
* Authors: NocoBase Team.
|
||||||
|
*
|
||||||
|
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||||
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { useCallback } from 'react';
|
||||||
|
import { CollectionCategoriesProvider, useAPIClient, useRequest } from '@nocobase/client';
|
||||||
|
import { Outlet } from 'react-router-dom';
|
||||||
|
|
||||||
|
export const CollectionMainProvider = (props) => {
|
||||||
|
const api = useAPIClient();
|
||||||
|
|
||||||
|
const coptions = {
|
||||||
|
url: 'collectionCategories:list',
|
||||||
|
params: {
|
||||||
|
paginate: false,
|
||||||
|
sort: ['sort'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = useRequest<{
|
||||||
|
data: any;
|
||||||
|
}>(coptions);
|
||||||
|
|
||||||
|
const refreshCategory = useCallback(async () => {
|
||||||
|
const { data } = await api.request(coptions);
|
||||||
|
result.mutate(data);
|
||||||
|
return data?.data || [];
|
||||||
|
}, [result]);
|
||||||
|
return (
|
||||||
|
<CollectionCategoriesProvider service={result} refreshCategory={refreshCategory}>
|
||||||
|
{<Outlet />}
|
||||||
|
</CollectionCategoriesProvider>
|
||||||
|
);
|
||||||
|
};
|
@ -19,6 +19,7 @@ import { DatabaseConnectionManagerPane } from './component/DatabaseConnectionMan
|
|||||||
import { MainDataSourceManager } from './component/MainDataSourceManager';
|
import { MainDataSourceManager } from './component/MainDataSourceManager';
|
||||||
import { DataSourcePermissionManager } from './component/PermissionManager';
|
import { DataSourcePermissionManager } from './component/PermissionManager';
|
||||||
import { NAMESPACE } from './locale';
|
import { NAMESPACE } from './locale';
|
||||||
|
import { CollectionMainProvider } from './component/MainDataSourceManager/CollectionMainProvider';
|
||||||
|
|
||||||
export class PluginDataSourceManagerClient extends Plugin {
|
export class PluginDataSourceManagerClient extends Plugin {
|
||||||
types = new Map();
|
types = new Map();
|
||||||
@ -46,6 +47,7 @@ export class PluginDataSourceManagerClient extends Plugin {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
this.app.use(DatabaseConnectionProvider);
|
this.app.use(DatabaseConnectionProvider);
|
||||||
|
|
||||||
this.app.pluginSettingsManager.add(NAMESPACE, {
|
this.app.pluginSettingsManager.add(NAMESPACE, {
|
||||||
title: `{{t("Data sources", { ns: "${NAMESPACE}" })}}`,
|
title: `{{t("Data sources", { ns: "${NAMESPACE}" })}}`,
|
||||||
icon: 'ClusterOutlined',
|
icon: 'ClusterOutlined',
|
||||||
@ -74,6 +76,7 @@ export class PluginDataSourceManagerClient extends Plugin {
|
|||||||
sort: 100,
|
sort: 100,
|
||||||
skipAclConfigure: true,
|
skipAclConfigure: true,
|
||||||
aclSnippet: 'pm.data-source-manager.data-source-main',
|
aclSnippet: 'pm.data-source-manager.data-source-main',
|
||||||
|
Component: CollectionMainProvider,
|
||||||
});
|
});
|
||||||
this.app.pluginSettingsManager.add(`${NAMESPACE}/main.collections`, {
|
this.app.pluginSettingsManager.add(`${NAMESPACE}/main.collections`, {
|
||||||
title: `{{t("Collections", { ns: "${NAMESPACE}" })}}`,
|
title: `{{t("Collections", { ns: "${NAMESPACE}" })}}`,
|
||||||
|
@ -20,7 +20,6 @@ import {
|
|||||||
APIClientProvider,
|
APIClientProvider,
|
||||||
ApplicationContext,
|
ApplicationContext,
|
||||||
CollectionCategoriesContext,
|
CollectionCategoriesContext,
|
||||||
CollectionCategoriesProvider,
|
|
||||||
CurrentAppInfoContext,
|
CurrentAppInfoContext,
|
||||||
DataSourceApplicationProvider,
|
DataSourceApplicationProvider,
|
||||||
SchemaComponent,
|
SchemaComponent,
|
||||||
@ -38,7 +37,7 @@ import {
|
|||||||
import { App, Button, ConfigProvider, Layout, Spin, Switch, Tooltip } from 'antd';
|
import { App, Button, ConfigProvider, Layout, Spin, Switch, Tooltip } from 'antd';
|
||||||
import dagre from 'dagre';
|
import dagre from 'dagre';
|
||||||
import lodash from 'lodash';
|
import lodash from 'lodash';
|
||||||
import React, { createContext, forwardRef, useContext, useEffect, useLayoutEffect, useState } from 'react';
|
import React, { createContext, forwardRef, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
import { useAsyncDataSource, useCreateActionAndRefreshCM } from './action-hooks';
|
import { useAsyncDataSource, useCreateActionAndRefreshCM } from './action-hooks';
|
||||||
import { AddCollectionAction } from './components/AddCollectionAction';
|
import { AddCollectionAction } from './components/AddCollectionAction';
|
||||||
@ -384,13 +383,15 @@ export const GraphDrawPage = React.memo(() => {
|
|||||||
const [collectionList, setCollectionList] = useState<any>([]);
|
const [collectionList, setCollectionList] = useState<any>([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const { collections, getCollections } = useCollectionManager_deprecated();
|
const { collections, getCollections } = useCollectionManager_deprecated();
|
||||||
|
const categoryCtx = useContext(CollectionCategoriesContext);
|
||||||
|
const categoryCtxRef = useRef<any>();
|
||||||
|
categoryCtxRef.current = categoryCtx;
|
||||||
const dm = useDataSourceManager();
|
const dm = useDataSourceManager();
|
||||||
const currentAppInfo = useCurrentAppInfo();
|
const currentAppInfo = useCurrentAppInfo();
|
||||||
const app = useApp();
|
const app = useApp();
|
||||||
const {
|
const {
|
||||||
data: { database },
|
data: { database },
|
||||||
} = currentAppInfo;
|
} = currentAppInfo;
|
||||||
const categoryCtx = useContext(CollectionCategoriesContext);
|
|
||||||
const scope = { ...options?.scope };
|
const scope = { ...options?.scope };
|
||||||
const components = { ...options?.components };
|
const components = { ...options?.components };
|
||||||
const saveGraphPositionAction = async (data) => {
|
const saveGraphPositionAction = async (data) => {
|
||||||
@ -442,7 +443,6 @@ export const GraphDrawPage = React.memo(() => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const dataSource = useDataSource();
|
const dataSource = useDataSource();
|
||||||
|
|
||||||
const initGraphCollections = () => {
|
const initGraphCollections = () => {
|
||||||
targetGraph = new Graph({
|
targetGraph = new Graph({
|
||||||
container: document.getElementById('container')!,
|
container: document.getElementById('container')!,
|
||||||
@ -520,7 +520,7 @@ export const GraphDrawPage = React.memo(() => {
|
|||||||
<DataSourceApplicationProvider dataSourceManager={dm} dataSource={dataSource?.key}>
|
<DataSourceApplicationProvider dataSourceManager={dm} dataSource={dataSource?.key}>
|
||||||
<APIClientProvider apiClient={api}>
|
<APIClientProvider apiClient={api}>
|
||||||
<SchemaComponentOptions inherit scope={scope} components={components}>
|
<SchemaComponentOptions inherit scope={scope} components={components}>
|
||||||
<CollectionCategoriesProvider {...categoryCtx}>
|
<CollectionCategoriesContext.Provider value={categoryCtxRef.current}>
|
||||||
{/* TODO: 因为画布中的卡片是一次性注册进 Graph 的,这里的 theme 是存在闭包里的,因此当主题动态变更时,并不会触发卡片的重新渲染 */}
|
{/* TODO: 因为画布中的卡片是一次性注册进 Graph 的,这里的 theme 是存在闭包里的,因此当主题动态变更时,并不会触发卡片的重新渲染 */}
|
||||||
<ConfigProvider theme={theme as any}>
|
<ConfigProvider theme={theme as any}>
|
||||||
<div style={{ height: 'auto' }}>
|
<div style={{ height: 'auto' }}>
|
||||||
@ -531,7 +531,7 @@ export const GraphDrawPage = React.memo(() => {
|
|||||||
</App>
|
</App>
|
||||||
</div>
|
</div>
|
||||||
</ConfigProvider>
|
</ConfigProvider>
|
||||||
</CollectionCategoriesProvider>
|
</CollectionCategoriesContext.Provider>
|
||||||
</SchemaComponentOptions>
|
</SchemaComponentOptions>
|
||||||
</APIClientProvider>
|
</APIClientProvider>
|
||||||
</DataSourceApplicationProvider>
|
</DataSourceApplicationProvider>
|
||||||
|
@ -420,7 +420,7 @@ const Entity: React.FC<{
|
|||||||
<Badge.Ribbon
|
<Badge.Ribbon
|
||||||
key={index}
|
key={index}
|
||||||
color={v.color}
|
color={v.color}
|
||||||
style={{ width: '103%', height: '3px', marginTop: index * 5 - 8, borderRadius: 0 }}
|
style={{ width: '103%', height: '3px', marginTop: index * 5 - 4, borderRadius: 0 }}
|
||||||
placement="start"
|
placement="start"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user