Skip to content

Commit c382108

Browse files
committed
fix: 切换数据库bug
1 parent 9c23ef3 commit c382108

7 files changed

Lines changed: 151 additions & 115 deletions

File tree

chat2db-client/src/components/CreateConnection/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ export default function CreateConnection(props: IProps) {
176176
: i18n('connection.message.testConnectResult', i18n('common.text.successful')),
177177
);
178178
} else {
179-
submitCallback?.();
180179
message.success(
181180
type === submitType.UPDATE
182181
? i18n('common.message.modifySuccessfully')
@@ -189,6 +188,7 @@ export default function CreateConnection(props: IProps) {
189188
id: res,
190189
});
191190
}
191+
submitCallback?.();
192192
}
193193
})
194194
.finally(() => {
@@ -284,8 +284,7 @@ function RenderForm(props: IRenderFormProps) {
284284
const [dataSourceFormConfig, setDataSourceFormConfig] = useState<IConnectionConfig>(dataSourceFormConfigProps);
285285

286286
useEffect(() => {
287-
setDataSourceFormConfig(dataSourceFormConfigProps)
288-
console.log(dataSourceFormConfigProps)
287+
setDataSourceFormConfig(dataSourceFormConfigProps);
289288
}, [dataSourceFormConfigProps])
290289

291290
const initialValuesMemo = useMemo(() => {

chat2db-client/src/components/SearchResult/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export default memo<IProps>(function SearchResult(props) {
5959
return;
6060
}
6161

62-
// debugger;
6362
if (!currentTab || !manageResultDataList.find((d) => d.uuid === currentTab)) {
6463
setCurrentTab(manageResultDataList[0].uuid);
6564
}

chat2db-client/src/hooks/useUpdateEffect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useRef, useEffect} from 'react';
1+
import { useRef, useEffect } from 'react';
22

33
export function useUpdateEffect(fn: Function, arr: any[]) {
44
const first = useRef(true);

chat2db-client/src/pages/main/connection/index.less

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@
9595

9696
.layoutRight {
9797
flex: 1;
98+
overflow: auto;
9899
display: flex;
99100
justify-content: center;
100101
align-items: center;
101102
position: relative;
103+
102104
}
103105

104106
.dataBaseList {

chat2db-client/src/pages/main/connection/index.tsx

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,10 @@ interface IProps {
2929
function Connections(props: IProps) {
3030
const { connectionModel, workspaceModel, dispatch } = props;
3131
const { connectionList } = connectionModel;
32+
const { curWorkspaceParams } = workspaceModel;
3233
const volatileRef = useRef<any>();
33-
// const [connectionList, setConnectionList] = useState<IConnectionDetails[]>();
3434
const [curConnection, setCurConnection] = useState<Partial<IConnectionDetails>>({});
3535

36-
useEffect(() => {
37-
getConnectionList();
38-
}, []);
39-
40-
const getConnectionList = () => {
41-
dispatch({
42-
type: 'connection/fetchConnectionList',
43-
});
44-
};
45-
4636
function handleCreateConnections(database: IDatabase) {
4737
setCurConnection({
4838
type: database.code,
@@ -100,25 +90,42 @@ function Connections(props: IProps) {
10090
{
10191
key: 'EnterWorkSpace',
10292
label: i18n('connection.button.connect'),
103-
onClick: () => {
93+
onClick: ({ domEvent }) => {
94+
domEvent.stopPropagation();
10495
handleMenuItemDoubleClick(t);
10596
},
10697
},
10798
{
10899
key: 'Delete',
109100
label: i18n('common.button.delete'),
110-
onClick: async ({ domEvent }) => {
101+
onClick: ({ domEvent }) => {
111102
// 禁止冒泡到menuItem
112103
domEvent.stopPropagation();
113-
await connectionService.remove({ id: key });
114-
setCurConnection({});
115-
getConnectionList();
104+
connectionService.remove({ id: key }).then(() => {
105+
if (curConnection.id === key) {
106+
setCurConnection({});
107+
}
108+
// // 如果当前工作区正好选中了这个连接,那么就把当前工作区的记录清空
109+
// if (curWorkspaceParams.dataSourceId === key) {
110+
// dispatch({
111+
// type: 'workspace/setCurWorkspaceParams',
112+
// payload: {}
113+
// })
114+
// dispatch({
115+
// type: 'connection/setCurConnection',
116+
// payload: {}
117+
// })
118+
// }
119+
dispatch({
120+
type: 'connection/fetchConnectionList',
121+
});
122+
})
116123
},
117124
},
118125
],
119126
}}
120127
>
121-
<div className={styles.moreButton}>
128+
<div className={styles.moreButton} onClick={(e) => { e.stopPropagation() }}>
122129
<Iconfont code="&#xe601;"></Iconfont>
123130
</div>
124131
</Dropdown>
@@ -161,7 +168,14 @@ function Connections(props: IProps) {
161168
closeCreateConnection={() => {
162169
setCurConnection({});
163170
}}
164-
submitCallback={getConnectionList}
171+
submitCallback={() => {
172+
dispatch({
173+
type: 'connection/fetchConnectionList',
174+
callback: (res: any) => {
175+
setCurConnection(res.data[res.data?.length - 1]);
176+
}
177+
});
178+
}}
165179
/>
166180
}
167181
</div>

chat2db-client/src/pages/main/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,14 @@ interface IProps {
6060
function MainPage(props: IProps) {
6161
const { mainModel, workspaceModel, connectionModel, dispatch } = props;
6262
const { curPage } = mainModel;
63-
const { curConnection } = connectionModel;
6463
const [activeNav, setActiveNav] = useState<INavItem>(navConfig[activeIndex]);
6564

65+
useEffect(() => {
66+
dispatch({
67+
type: 'connection/fetchConnectionList',
68+
});
69+
}, []);
70+
6671
useEffect(() => {
6772
// activeNav 发生变化,同步到全局状态管理
6873
activeNav.isLoad = true;
@@ -99,7 +104,7 @@ function MainPage(props: IProps) {
99104
return (
100105
<div className={styles.page}>
101106
<div className={styles.layoutLeft}>
102-
<BrandLogo size={40} onClick={() => {}} className={styles.brandLogo} />
107+
<BrandLogo size={40} onClick={() => { }} className={styles.brandLogo} />
103108
<ul className={styles.navList}>
104109
{navConfig.map((item, index) => {
105110
return (

0 commit comments

Comments
 (0)