fix(graphical-interface): collection category does not display title (#1503)

This commit is contained in:
katherinehhh 2023-02-27 09:17:13 +08:00 committed by GitHub
parent 68fcadf092
commit 4e0a1dedda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 17 deletions

View File

@ -1,8 +1,10 @@
import { import {
ApartmentOutlined, ApartmentOutlined,
FullscreenExitOutlined, FullscreenExitOutlined,
FullscreenOutlined, LineHeightOutlined, MenuOutlined, FullscreenOutlined,
ShareAltOutlined LineHeightOutlined,
MenuOutlined,
ShareAltOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import { Graph } from '@antv/x6'; import { Graph } from '@antv/x6';
import '@antv/x6-react-shape'; import '@antv/x6-react-shape';
@ -10,13 +12,18 @@ import { css, cx } from '@emotion/css';
import { SchemaOptionsContext } from '@formily/react'; import { SchemaOptionsContext } from '@formily/react';
import { import {
APIClientProvider, APIClientProvider,
collection, CollectionManagerContext, CollectionManagerProvider, collection,
CollectionManagerContext,
CollectionManagerProvider,
CurrentAppInfoContext, CurrentAppInfoContext,
SchemaComponent, SchemaComponent,
SchemaComponentOptions, Select, useAPIClient, SchemaComponentOptions,
Select,
useAPIClient,
useCollectionManager, useCollectionManager,
useCompile, useCompile,
useCurrentAppInfo useCurrentAppInfo,
CollectionCategroriesProvider,
} 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';
@ -28,7 +35,14 @@ import { AddCollectionAction } from './components/AddCollectionAction';
import Entity from './components/Entity'; import Entity from './components/Entity';
import { SimpleNodeView } from './components/ViewNode'; import { SimpleNodeView } from './components/ViewNode';
import { collectionListClass, graphCollectionContainerClass } from './style'; import { collectionListClass, graphCollectionContainerClass } from './style';
import { formatData, getChildrenCollections, getDiffEdge, getDiffNode, getInheritCollections, useGCMTranslation } from './utils'; import {
formatData,
getChildrenCollections,
getDiffEdge,
getDiffNode,
getInheritCollections,
useGCMTranslation,
} from './utils';
const LINE_HEIGHT = 40; const LINE_HEIGHT = 40;
const NODE_WIDTH = 250; const NODE_WIDTH = 250;
@ -392,7 +406,6 @@ export const GraphDrawPage = React.memo(() => {
}; };
const refreshGM = async () => { const refreshGM = async () => {
const data = await refreshCM(); const data = await refreshCM();
console.log(data);
targetGraph.collections = data; targetGraph.collections = data;
targetGraph.updatePositionAction = useUpdatePositionAction; targetGraph.updatePositionAction = useUpdatePositionAction;
const currentNodes = targetGraph.getNodes(); const currentNodes = targetGraph.getNodes();
@ -491,6 +504,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>
<CollectionManagerProvider <CollectionManagerProvider
collections={targetGraph?.collections} collections={targetGraph?.collections}
refreshCM={refreshGM} refreshCM={refreshGM}
@ -500,6 +514,7 @@ export const GraphDrawPage = React.memo(() => {
<Entity node={node} setTargetNode={setTargetNode} targetGraph={targetGraph} /> <Entity node={node} setTargetNode={setTargetNode} targetGraph={targetGraph} />
</div> </div>
</CollectionManagerProvider> </CollectionManagerProvider>
</CollectionCategroriesProvider>
</SchemaComponentOptions> </SchemaComponentOptions>
</APIClientProvider> </APIClientProvider>
</CurrentAppInfoContext.Provider> </CurrentAppInfoContext.Provider>

View File

@ -23,10 +23,11 @@ import {
useCompile, useCompile,
useCurrentAppInfo, useCurrentAppInfo,
useRecord, useRecord,
CollectionCategroriesContext,
} from '@nocobase/client'; } from '@nocobase/client';
import { Badge, Dropdown, Popover, Tag } from 'antd'; import { Badge, Dropdown, Popover, Tag } from 'antd';
import { groupBy } from 'lodash'; import { groupBy } from 'lodash';
import React, { useRef, useState } from 'react'; import React, { useRef, useState, useContext } from 'react';
import { import {
useAsyncDataSource, useAsyncDataSource,
useCancelAction, useCancelAction,
@ -59,6 +60,7 @@ const Entity: React.FC<{
} = node; } = node;
const database = useCurrentAppInfo(); const database = useCurrentAppInfo();
const collectionData = useRef(); const collectionData = useRef();
const categoryData = useContext(CollectionCategroriesContext);
collectionData.current = { ...item, title, inherits: item.inherits && new Proxy(item.inherits, {}) }; collectionData.current = { ...item, title, inherits: item.inherits && new Proxy(item.inherits, {}) };
const { category } = item; const { category } = item;
const compile = useCompile(); const compile = useCompile();
@ -68,6 +70,12 @@ const Entity: React.FC<{
value: collection.name, value: collection.name,
})); }));
}; };
const loadCategories = async () => {
return categoryData.data.map((item: any) => ({
label: compile(item.name),
value: item.id,
}));
};
const portsProps = { const portsProps = {
targetGraph, targetGraph,
collectionData, collectionData,
@ -104,6 +112,7 @@ const Entity: React.FC<{
useUpdateCollectionActionAndRefreshCM, useUpdateCollectionActionAndRefreshCM,
useCancelAction, useCancelAction,
loadCollections, loadCollections,
loadCategories,
useAsyncDataSource, useAsyncDataSource,
Action, Action,
DeleteOutlined, DeleteOutlined,