From aeadaee07b6e05d173260fc21552ce9b2a2f82a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=93=E5=BA=B7?= Date: Tue, 26 Sep 2023 20:34:51 +0800 Subject: [PATCH] add multi database load control --- .../SideBar/ResourceTree/Datasource/index.tsx | 119 ++++++++++-------- .../Workspace/SideBar/ResourceTree/index.tsx | 11 +- 2 files changed, 74 insertions(+), 56 deletions(-) diff --git a/src/page/Workspace/SideBar/ResourceTree/Datasource/index.tsx b/src/page/Workspace/SideBar/ResourceTree/Datasource/index.tsx index 53d06c46a..2a6210099 100644 --- a/src/page/Workspace/SideBar/ResourceTree/Datasource/index.tsx +++ b/src/page/Workspace/SideBar/ResourceTree/Datasource/index.tsx @@ -232,63 +232,74 @@ export default forwardRef(function DatasourceTree(props, ref) { titleRender={(node) => { return ( <> - { - e.domEvent?.stopPropagation(); - setEditDatasourceId(node.key); - }, - }, - { - label: formatMessage({ id: 'odc.ResourceTree.Datasource.Delete' }), //删除 - key: 'delete', - onClick: (e) => { - e.domEvent?.stopPropagation(); - const name = node.title; - deleteDataSource(name as string, node.key as string); - }, - }, - ], - }} + + } > - - } +
- {node.title} - - - {login.isPrivateSpace() && ( -
- - setEditDatasourceId(node.key)} - key={'edit'} - > - {formatMessage({ id: 'odc.ResourceTree.Datasource.Edit' })} - - - deleteDataSource(node.title as string, node.key as string) - } - key={'delete'} - > - {formatMessage({ id: 'odc.ResourceTree.Datasource.Delete' })} - - + { + e.domEvent?.stopPropagation(); + setEditDatasourceId(node.key); + }, + }, + { + label: formatMessage({ + id: 'odc.ResourceTree.Datasource.Delete', + }), //删除 + key: 'delete', + onClick: (e) => { + e.domEvent?.stopPropagation(); + const name = node.title; + deleteDataSource(name as string, node.key as string); + }, + }, + ], + }} + > + {node.title} + + {login.isPrivateSpace() && ( +
+ + setEditDatasourceId(node.key)} + key={'edit'} + > + {formatMessage({ id: 'odc.ResourceTree.Datasource.Edit' })} + + + deleteDataSource(node.title as string, node.key as string) + } + key={'delete'} + > + {formatMessage({ id: 'odc.ResourceTree.Datasource.Delete' })} + + +
+ )}
- )} + ); }} diff --git a/src/page/Workspace/SideBar/ResourceTree/index.tsx b/src/page/Workspace/SideBar/ResourceTree/index.tsx index 00cca59c5..4934a0592 100644 --- a/src/page/Workspace/SideBar/ResourceTree/index.tsx +++ b/src/page/Workspace/SideBar/ResourceTree/index.tsx @@ -29,6 +29,7 @@ import { DataBaseTreeData } from './Nodes/database'; import TreeNodeMenu from './TreeNodeMenu'; import { ResourceNodeType, TreeDataNode } from './type'; import tracert from '@/util/tracert'; +import { useUpdate } from 'ahooks'; interface IProps { sessionManagerStore?: SessionManagerStore; @@ -47,7 +48,13 @@ const ResourceTree: React.FC = function ({ reloadDatabase, showTip = false, }) { - const [databaseSessions, setDatabaseSessions] = useState>({}); + const databaseSessionsRef = useRef>({}); + const update = useUpdate(); + const databaseSessions = databaseSessionsRef.current; + function setDatabaseSessions(map: any) { + databaseSessionsRef.current = map; + update(); + } const [wrapperHeight, setWrapperHeight] = useState(0); const [searchValue, setSearchValue] = useState(''); const treeWrapperRef = useRef(); @@ -119,7 +126,7 @@ const ResourceTree: React.FC = function ({ const dbSession = await sessionManagerStore.createSession(null, data?.id, true); if (dbSession !== 'NotFound') { setDatabaseSessions({ - ...databaseSessions, + ...databaseSessionsRef.current, [dbId]: dbSession.sessionId, }); }