Skip to content

Commit bc8a050

Browse files
committed
fix: delete connection bug
1 parent 3b1c197 commit bc8a050

21 files changed

Lines changed: 162 additions & 96 deletions

File tree

chat2db-client/src/blocks/DatabaseTableEditor/index.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
border-radius: 4px;
5353
cursor: pointer;
5454
font-size: 13px;
55+
user-select: none;
5556
&:hover {
5657
color: var(--color-primary);
5758
}

chat2db-client/src/blocks/Setting/index.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,16 @@ import BaseSetting from './BaseSetting';
77
import AISetting from './AiSetting';
88
import ProxySetting from './ProxySetting';
99
import About from './About';
10-
import { IAiConfig } from '@/typings';
1110
import styles from './index.less';
1211
import { ILatestVersion } from '@/service/config';
1312
import UpdateDetection, { IUpdateDetectionRef, UpdatedStatusEnum } from '@/blocks/Setting/UpdateDetection';
1413

1514
// ---- store -----
16-
import { useSettingStore, getAiSystemConfig, setAiSystemConfig } from '@/store/setting'
15+
import { useSettingStore, getAiSystemConfig, setAiSystemConfig } from '@/store/setting';
1716

1817
interface IProps {
19-
aiConfig: IAiConfig;
2018
className?: string;
2119
render?: ReactNode;
22-
dispatch: (params: any) => void;
2320
noLogin?: boolean; // 用于在没有登录的页面使用,不显示ai设置等需要登录的功能
2421
defaultArouse?: boolean; // 是否默认弹出
2522
defaultMenu?: number; // 默认选中的菜单
@@ -35,7 +32,7 @@ function Setting(props: IProps) {
3532
const [currentMenu, setCurrentMenu] = useState<number>(defaultMenu);
3633
const [updateDetectionData, setUpdateDetectionData] = useState<IUpdateDetectionData | null>(null);
3734
const updateDetectionRef = React.useRef<IUpdateDetectionRef>(null);
38-
const aiConfig = useSettingStore(state => state.aiConfig);
35+
const aiConfig = useSettingStore((state) => state.aiConfig);
3936

4037
useEffect(() => {
4138
if (defaultArouse) {
@@ -166,9 +163,4 @@ function Setting(props: IProps) {
166163
);
167164
}
168165

169-
// export default connect(({ ai }: { ai: IAIState }) => ({
170-
// aiConfig: ai.aiConfig,
171-
// }))();
172-
173166
export default Setting;
174-

chat2db-client/src/blocks/Tree/index.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,17 @@ const TreeNode = memo((props: TreeNodeIProps) => {
283283
);
284284
}, [isFocus, isLoading, rightClickMenu]);
285285

286-
const sectionHeight = useMemo(() => {
287-
console.log(treeNodeData.total);
288-
289-
if (treeNodeData.total) {
290-
return `${treeNodeData.total * 26}px`;
291-
} else {
292-
return 'auto';
293-
}
294-
}, [treeNodeData.total]);
286+
// const sectionHeight = useMemo(() => {
287+
// if (treeNodeData.total && treeNodeData.children) {
288+
// return `${treeNodeData.total * 26}px`;
289+
// } else {
290+
// return 'auto';
291+
// }
292+
// }, [treeNodeData.total, treeNodeData.children]);
295293

296294
return (
297-
<div style={{ height: sectionHeight }}>
295+
// style={{ height: sectionHeight }}
296+
<div>
298297
{(showTreeNode || showParentNode) && treeNodeDom}
299298
{treeNodes}
300299
</div>

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useMemo, useState, memo, useContext } from 'react';
2-
import { IBoundInfo, IntelligentEditorContext } from '../../index';
2+
import { IntelligentEditorContext } from '../../index';
33
import { Dropdown } from 'antd';
44
import { useConnectionStore } from '@/pages/main/store/connection';
55
import connectionService from '@/service/connection';
@@ -8,6 +8,7 @@ import Iconfont from '@/components/Iconfont';
88
import { databaseMap } from '@/constants/database';
99
import styles from './index.less';
1010
import sqlService from '@/service/sql';
11+
import { IBoundInfo } from '@/typings';
1112

1213
import {
1314
registerIntelliSenseField,
@@ -67,7 +68,7 @@ const SelectBoundInfo = memo((props: IProps) => {
6768

6869
// 当数据源变化时,重新获取数据库列表
6970
useEffect(() => {
70-
if (!isActive) {
71+
if (!isActive || boundInfo.connectable === false) {
7172
return;
7273
}
7374
if (supportDatabase) {
@@ -82,7 +83,7 @@ const SelectBoundInfo = memo((props: IProps) => {
8283

8384
// 当数据库名变化时,重新获取schema列表
8485
useEffect(() => {
85-
if (!isActive) {
86+
if (!isActive || boundInfo.connectable === false) {
8687
return;
8788
}
8889
if (supportSchema) {
@@ -94,7 +95,7 @@ const SelectBoundInfo = memo((props: IProps) => {
9495
}, [boundInfo.databaseName, isActive]);
9596

9697
useEffect(() => {
97-
if (!isActive) {
98+
if (!isActive || boundInfo.connectable === false) {
9899
return;
99100
}
100101
if (supportSchema && boundInfo.schemaName) {

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import ChatInput, { SyncModelType } from './components/ChatInput';
1515
import MonacoEditor, { IEditorOptions, IExportRefFunction, IRangeType } from '../MonacoEditor';
1616
import aiServer from '@/service/ai';
1717
import { v4 as uuidv4 } from 'uuid';
18-
import { DatabaseTypeCode, ConsoleStatus } from '@/constants';
19-
import { IAiConfig } from '@/typings';
18+
import { IAiConfig, IBoundInfo } from '@/typings';
2019
import Popularize from '@/components/Popularize';
2120
import OperationLine from './components/OperationLine';
2221
import { chatErrorForKey, chatErrorToLogin } from '@/constants/chat';
@@ -47,16 +46,6 @@ export type IAppendValue = {
4746
range?: IRangeType;
4847
};
4948

50-
export interface IBoundInfo {
51-
consoleId?: number;
52-
dataSourceId: number;
53-
dataSourceName: string;
54-
databaseType: DatabaseTypeCode;
55-
databaseName?: string;
56-
schemaName?: string;
57-
status: ConsoleStatus;
58-
}
59-
6049
interface IProps {
6150
/** 调用来源 */
6251
source?: 'workspace';

chat2db-client/src/hooks/getConnection.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
import connectionService from '@/service/connection';
22
import { setConnectionEnvList, getConnectionList } from '@/pages/main/store/connection';
33
import { useWorkspaceStore } from '@/pages/main/workspace/store';
4+
5+
const getConnectionEnvList = () => {
6+
connectionService.getEnvList().then((res) => {
7+
setConnectionEnvList(res);
8+
});
9+
};
410
import { setCurrentConnectionDetails } from '@/pages/main/workspace/store/common';
511

612
const getConnection = () => {
713
const currentConnectionDetails = useWorkspaceStore.getState().currentConnectionDetails;
814

9-
const getConnectionEnvList = () => {
10-
connectionService.getEnvList().then((res) => {
11-
setConnectionEnvList(res);
12-
});
13-
};
1415

1516
getConnectionList().then((res) => {
1617
// 如果连接列表为空,则设置当前连接为空
17-
if(res.length === 0){
18+
if (res.length === 0) {
1819
setCurrentConnectionDetails(null);
1920
return;
2021
}
22+
2123
// 如果当前连接不存在,则设置当前连接为第一个连接
2224
if (!currentConnectionDetails?.id) {
2325
setCurrentConnectionDetails(res[0]);
2426
return;
2527
}
28+
2629
// 如果存在但是不在列表中,则设置当前连接为第一个连接
2730
const currentConnection = res.find((item) => item.id === currentConnectionDetails?.id);
2831
if (!currentConnection) {

chat2db-client/src/i18n/en-us/workspace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ export default {
3131
'workspace.tree.search.placeholder': 'Search in the expand node',
3232
'workspace.tree.delete.tip': 'I understand that this operation is permanently deleted',
3333
'workspace.tree.delete.table.tip': 'Are you sure you want to delete the table {1}?',
34+
'workspace.tips.noConnection': 'You have not created a connection yet',
3435
};

chat2db-client/src/i18n/zh-cn/workspace.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ export default {
3030
'workspace.tree.search.placeholder': '在展开节点中搜索',
3131
'workspace.tree.delete.tip': '我了解该操作是永久性删除',
3232
'workspace.tree.delete.table.tip': '确定要删除表{1}吗?',
33+
'workspace.tips.noConnection': '你还没有创建连接',
3334

3435
};

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { useConnectionStore, getConnectionList } from '@/pages/main/store/connec
2626
import { setMainPageActiveTab } from '@/pages/main/store/main';
2727
import { setCurrentConnectionDetails } from '@/pages/main/workspace/store/common';
2828

29-
3029
import styles from './index.less';
3130

3231
const ConnectionsPage = () => {
@@ -50,7 +49,7 @@ const ConnectionsPage = () => {
5049
// 处理列表双击事件
5150
const handleMenuItemDoubleClick = (t: IConnectionListItem) => {
5251
setCurrentConnectionDetails(t);
53-
setMainPageActiveTab('workspace')
52+
setMainPageActiveTab('workspace');
5453
};
5554

5655
// 处理列表单击和双击事件
@@ -81,6 +80,7 @@ const ConnectionsPage = () => {
8180
getConnectionList();
8281
if (connectionActiveId === t.id) {
8382
setConnectionActiveId(null);
83+
setConnectionDetail(null);
8484
}
8585
});
8686
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import connectionService from '@/service/connection';
2+
import { setConnectionEnvList } from '@/pages/main/store/connection';
3+
4+
const getConnectionEnvList = () => {
5+
connectionService.getEnvList().then((res) => {
6+
setConnectionEnvList(res);
7+
});
8+
};
9+
10+
export default getConnectionEnvList;

0 commit comments

Comments
 (0)