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 {
ApartmentOutlined,
FullscreenExitOutlined,
FullscreenOutlined, LineHeightOutlined, MenuOutlined,
ShareAltOutlined
FullscreenOutlined,
LineHeightOutlined,
MenuOutlined,
ShareAltOutlined,
} from '@ant-design/icons';
import { Graph } from '@antv/x6';
import '@antv/x6-react-shape';
@ -10,13 +12,18 @@ import { css, cx } from '@emotion/css';
import { SchemaOptionsContext } from '@formily/react';
import {
APIClientProvider,
collection, CollectionManagerContext, CollectionManagerProvider,
collection,
CollectionManagerContext,
CollectionManagerProvider,
CurrentAppInfoContext,
SchemaComponent,
SchemaComponentOptions, Select, useAPIClient,
SchemaComponentOptions,
Select,
useAPIClient,
useCollectionManager,
useCompile,
useCurrentAppInfo
useCurrentAppInfo,
CollectionCategroriesProvider,
} from '@nocobase/client';
import { useFullscreen } from 'ahooks';
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 { SimpleNodeView } from './components/ViewNode';
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 NODE_WIDTH = 250;
@ -392,7 +406,6 @@ export const GraphDrawPage = React.memo(() => {
};
const refreshGM = async () => {
const data = await refreshCM();
console.log(data);
targetGraph.collections = data;
targetGraph.updatePositionAction = useUpdatePositionAction;
const currentNodes = targetGraph.getNodes();
@ -491,15 +504,17 @@ export const GraphDrawPage = React.memo(() => {
<CurrentAppInfoContext.Provider value={database}>
<APIClientProvider apiClient={api}>
<SchemaComponentOptions inherit scope={scope} components={components}>
<CollectionManagerProvider
collections={targetGraph?.collections}
refreshCM={refreshGM}
interfaces={ctx.interfaces}
>
<div style={{ height: 'auto' }}>
<Entity node={node} setTargetNode={setTargetNode} targetGraph={targetGraph} />
</div>
</CollectionManagerProvider>
<CollectionCategroriesProvider>
<CollectionManagerProvider
collections={targetGraph?.collections}
refreshCM={refreshGM}
interfaces={ctx.interfaces}
>
<div style={{ height: 'auto' }}>
<Entity node={node} setTargetNode={setTargetNode} targetGraph={targetGraph} />
</div>
</CollectionManagerProvider>
</CollectionCategroriesProvider>
</SchemaComponentOptions>
</APIClientProvider>
</CurrentAppInfoContext.Provider>

View File

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