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, }); }