Skip to content

Commit 886ec8a

Browse files
committed
Repeated request
1 parent 5c85d00 commit 886ec8a

2 files changed

Lines changed: 52 additions & 24 deletions

File tree

  • chat2db-client/src
    • components/ConsoleEditor/components/SelectBoundInfo
    • pages/main/workspace/store

chat2db-client/src/components/ConsoleEditor/components/SelectBoundInfo/index.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ const SelectBoundInfo = memo((props: IProps) => {
6767

6868
// 当数据源变化时,重新获取数据库列表
6969
useEffect(() => {
70+
if (!isActive) {
71+
return;
72+
}
7073
if (supportDatabase) {
7174
setSchemaList([]);
7275
setDatabaseNameList([]);
@@ -79,6 +82,9 @@ const SelectBoundInfo = memo((props: IProps) => {
7982

8083
// 当数据库名变化时,重新获取schema列表
8184
useEffect(() => {
85+
if (!isActive) {
86+
return;
87+
}
8288
if (supportSchema) {
8389
getSchemaList();
8490
}
@@ -88,6 +94,9 @@ const SelectBoundInfo = memo((props: IProps) => {
8894
}, [boundInfo.databaseName]);
8995

9096
useEffect(() => {
97+
if (!isActive) {
98+
return;
99+
}
91100
if (supportSchema && boundInfo.schemaName) {
92101
getAllTableNameList(boundInfo.dataSourceId, boundInfo.databaseName, boundInfo.schemaName);
93102
}

chat2db-client/src/pages/main/workspace/store/console.ts

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,76 +8,95 @@ export interface IConsoleStore {
88
consoleList: IConsole[] | null;
99
activeConsoleId: string | number | null;
1010
workspaceTabList: IWorkspaceTab[] | null;
11+
createConsoleLoading: boolean
1112
}
1213

1314
export const initConsoleStore = {
1415
consoleList: null,
1516
activeConsoleId: null,
1617
workspaceTabList: null,
17-
}
18+
createConsoleLoading: false
19+
};
1820

1921
export const getSavedConsoleList = () => {
20-
historyService.getSavedConsoleList({
21-
tabOpened: 'y',
22-
pageNo: 1,
23-
pageSize: 20,
24-
}).then((res) => {
25-
useWorkspaceStore.setState({ consoleList: res?.data });
26-
});
27-
}
22+
historyService
23+
.getSavedConsoleList({
24+
tabOpened: 'y',
25+
pageNo: 1,
26+
pageSize: 20,
27+
})
28+
.then((res) => {
29+
useWorkspaceStore.setState({ consoleList: res?.data });
30+
});
31+
};
2832

2933
export const setActiveConsoleId = (id: IConsoleStore['activeConsoleId']) => {
3034
useWorkspaceStore.setState({ activeConsoleId: id });
31-
}
35+
};
3236

3337
export const setWorkspaceTabList = (items: IConsoleStore['workspaceTabList']) => {
3438
useWorkspaceStore.setState({ workspaceTabList: items });
35-
}
39+
};
3640

37-
export const createConsole = (params: ICreateConsoleParams)=>{
41+
export const createConsole = (params: ICreateConsoleParams) => {
3842
const workspaceTabList = useWorkspaceStore.getState().workspaceTabList;
3943
const newConsole = {
4044
...params,
4145
name: params.name || 'new console',
4246
ddl: params.ddl || '',
4347
status: ConsoleStatus.DRAFT,
4448
operationType: WorkspaceTabType.CONSOLE,
45-
type: params.databaseType
49+
type: params.databaseType,
4650
};
4751

48-
return new Promise((resolve, j) => {
52+
return new Promise((resolve) => {
4953
if ((workspaceTabList?.length || 0) > 20) {
50-
j('tab数量超过上限');
51-
return
54+
return;
5255
}
56+
useWorkspaceStore.setState({ createConsoleLoading: true });
5357
historyService.createConsole(newConsole).then((res) => {
58+
// 找到活跃的id的位置
59+
// const activeIndex = workspaceTabList?.findIndex(
60+
// (item) => item?.id === useWorkspaceStore.getState().activeConsoleId,
61+
// );
62+
// // 向活跃的位置后插入数据
63+
// if (activeIndex !== -1) {
64+
// workspaceTabList?.splice(activeIndex + 1, 0, {
65+
// id: res,
66+
// title: newConsole.name,
67+
// type: newConsole.operationType,
68+
// uniqueData: newConsole,
69+
// });
70+
// }
71+
5472
const newList = [
55-
...(workspaceTabList||[]),
73+
...(workspaceTabList || []),
5674
{
5775
id: res,
5876
title: newConsole.name,
5977
type: newConsole.operationType,
6078
uniqueData: newConsole,
6179
},
6280
];
81+
6382
setWorkspaceTabList(newList);
6483
setActiveConsoleId(res);
6584
resolve(res);
85+
})
86+
.finally(() => {
87+
useWorkspaceStore.setState({ createConsoleLoading: false });
6688
});
6789
});
68-
}
90+
};
6991

7092
export const addWorkspaceTab = (params: IWorkspaceTab) => {
7193
const workspaceTabList = useWorkspaceStore.getState().workspaceTabList;
72-
if(workspaceTabList?.findIndex((item) => item?.id === params?.id) !== -1){
94+
if (workspaceTabList?.findIndex((item) => item?.id === params?.id) !== -1) {
7395
setActiveConsoleId(params.id);
7496
return;
7597
}
76-
77-
const newList = [
78-
...(workspaceTabList||[]),
79-
params,
80-
];
98+
99+
const newList = [...(workspaceTabList || []), params];
81100

82101
setWorkspaceTabList(newList);
83102
setActiveConsoleId(params.id);

0 commit comments

Comments
 (0)