Skip to content

Commit 6f8b511

Browse files
committed
feat:Double-click to open the table directly
1 parent cecf152 commit 6f8b511

14 files changed

Lines changed: 209 additions & 220 deletions

File tree

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

Lines changed: 0 additions & 4 deletions
This file was deleted.

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

Lines changed: 0 additions & 18 deletions
This file was deleted.

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

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,3 @@
1919
flex: 1;
2020
position: relative;
2121
}
22-
23-
.tableLoading {
24-
position: absolute;
25-
top: 0;
26-
left: 0;
27-
right: 0;
28-
bottom: 0;
29-
z-index: 9999;
30-
// height: 100%;
31-
display: flex;
32-
flex-direction: column;
33-
justify-content: center;
34-
align-items: center;
35-
// background-color: var(--color-fill);
36-
.stopExecuteSql {
37-
cursor: pointer;
38-
margin-top: 30px;
39-
&:hover {
40-
color: var(--color-primary);
41-
}
42-
}
43-
}

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

Lines changed: 23 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
import React, { memo, useRef, useState, useEffect } from 'react';
1+
import React, { memo, useRef, useState } from 'react';
22
import { connect } from 'umi';
33
import styles from './index.less';
44
import classnames from 'classnames';
55
import DraggableContainer from '@/components/DraggableContainer';
66
import Console, { IAppendValue } from '@/components/Console';
77
import SearchResult from '@/components/SearchResult';
8-
import { DatabaseTypeCode, ConsoleStatus, TreeNodeType } from '@/constants';
9-
import { IManageResultData, IResultConfig } from '@/typings';
8+
import { DatabaseTypeCode, ConsoleStatus } from '@/constants';
109
import { IWorkspaceModelState, IWorkspaceModelType } from '@/models/workspace';
1110
import { IAIState } from '@/models/ai';
12-
import sqlServer, { IExecuteSqlParams } from '@/service/sql';
13-
import { v4 as uuidV4 } from 'uuid';
14-
import { Spin } from 'antd';
1511
import { useUpdateEffect } from '@/hooks/useUpdateEffect';
16-
import i18n from '@/i18n';
1712
interface IProps {
1813
className?: string;
1914
isActive: boolean;
@@ -31,78 +26,35 @@ interface IProps {
3126
};
3227
}
3328

34-
const defaultResultConfig: IResultConfig = {
35-
pageNo: 1,
36-
pageSize: 200,
37-
total: 0,
38-
hasNextPage: true,
39-
};
40-
4129
const SQLExecute = memo<IProps>((props) => {
4230
const { data, workspaceModel, aiModel, isActive, dispatch } = props;
4331
const draggableRef = useRef<any>();
4432
const [appendValue, setAppendValue] = useState<IAppendValue>();
45-
const [resultData, setResultData] = useState<IManageResultData[]>([]);
46-
const { doubleClickTreeNodeData, curTableList, curWorkspaceParams } = workspaceModel;
47-
const [tableLoading, setTableLoading] = useState(false);
48-
const controllerRef = useRef<AbortController>();
33+
const { curTableList, curWorkspaceParams } = workspaceModel;
34+
const [sql, setSql] = useState<string>('');
4935

50-
useEffect(() => {
51-
if (!doubleClickTreeNodeData) {
52-
return;
53-
}
54-
if (doubleClickTreeNodeData.treeNodeType === TreeNodeType.TABLE) {
55-
const { extraParams } = doubleClickTreeNodeData;
56-
const { tableName } = extraParams || {};
57-
const ddl = `SELECT * FROM ${tableName};\n`;
58-
if (isActive) {
59-
setAppendValue({ text: ddl });
60-
}
61-
}
62-
dispatch({
63-
type: 'workspace/setDoubleClickTreeNodeData',
64-
payload: '',
65-
});
66-
}, [doubleClickTreeNodeData]);
36+
// useEffect(() => {
37+
// if (!doubleClickTreeNodeData) {
38+
// return;
39+
// }
40+
// if (doubleClickTreeNodeData.treeNodeType === TreeNodeType.TABLE) {
41+
// const { extraParams } = doubleClickTreeNodeData;
42+
// const { tableName } = extraParams || {};
43+
// const ddl = `SELECT * FROM ${tableName};\n`;
44+
// if (isActive) {
45+
// setAppendValue({ text: ddl });
46+
// }
47+
// }
48+
// dispatch({
49+
// type: 'workspace/setDoubleClickTreeNodeData',
50+
// payload: '',
51+
// });
52+
// }, [doubleClickTreeNodeData]);
6753

6854
useUpdateEffect(() => {
6955
setAppendValue({ text: data.initDDL });
7056
}, [data.initDDL]);
7157

72-
/**
73-
* 执行SQL
74-
* @param sql
75-
*/
76-
const handleExecuteSQL = async (sql: string) => {
77-
setTableLoading(true);
78-
79-
const executeSQLParams: IExecuteSqlParams = {
80-
sql,
81-
...defaultResultConfig,
82-
...data,
83-
};
84-
85-
controllerRef.current = new AbortController();
86-
// 获取当前SQL的查询结果
87-
let sqlResult = await sqlServer.executeSql(executeSQLParams, {
88-
signal: controllerRef.current.signal,
89-
});
90-
91-
sqlResult = sqlResult.map((res) => ({
92-
...res,
93-
uuid: uuidV4(),
94-
}));
95-
96-
setResultData(sqlResult);
97-
setTableLoading(false);
98-
};
99-
100-
const stopExecuteSql = () => {
101-
controllerRef.current && controllerRef.current.abort();
102-
setResultData([]);
103-
setTableLoading(false);
104-
};
105-
10658
return (
10759
<div className={classnames(styles.box)}>
10860
<DraggableContainer layout="column" className={styles.boxRightCenter}>
@@ -115,7 +67,7 @@ const SQLExecute = memo<IProps>((props) => {
11567
executeParams={{ ...data }}
11668
hasAiChat={true}
11769
hasAi2Lang={true}
118-
onExecuteSQL={handleExecuteSQL}
70+
onExecuteSQL={setSql}
11971
onConsoleSave={() => {
12072
dispatch({
12173
type: 'workspace/fetchGetSavedConsole',
@@ -137,16 +89,7 @@ const SQLExecute = memo<IProps>((props) => {
13789
/>
13890
</div>
13991
<div className={styles.boxRightResult}>
140-
{tableLoading ? (
141-
<div className={styles.tableLoading}>
142-
<Spin />
143-
<div className={styles.stopExecuteSql} onClick={stopExecuteSql}>
144-
{i18n('common.button.cancelRequest')}
145-
</div>
146-
</div>
147-
) : (
148-
<SearchResult executeSqlParams={data} queryResultDataList={resultData} />
149-
)}
92+
<SearchResult executeSqlParams={data} sql={sql} />
15093
</div>
15194
</DraggableContainer>
15295
</div>

chat2db-client/src/components/SearchResult/TableBox/index.less

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,8 @@
5555
overflow: hidden !important;
5656
top: 0px !important;
5757
}
58-
.art-table-body {
59-
// 隐藏滚动条
60-
::-webkit-scrollbar {
61-
display: none;
62-
}
58+
.art-table-body::-webkit-scrollbar {
59+
display: none;
6360
}
6461
.art-table-body-scroll {
6562
padding-right: 6px;
@@ -189,13 +186,15 @@
189186
background-color: var(--color-bg-base);
190187

191188
.tableItemContent {
192-
overflow: hidden;
193189
max-height: 30px;
194190
line-height: 30px;
195191
flex: 1;
192+
width: 100%;
193+
overflow: hidden;
194+
white-space: nowrap;
196195
&:hover {
197-
overflow: auto;
198-
line-height: 16px;
196+
overflow-x: auto;
197+
// line-height: 14px;
199198
}
200199
}
201200

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,10 @@ export default function TableBox(props: ITableProps) {
822822
</div>
823823
</div>
824824
{allDataReady && (
825-
<div ref={tableBoxRef} className={classnames(styles.supportBaseTableBox, styles.supportBaseTableBoxHidden)}>
825+
<div
826+
ref={tableBoxRef}
827+
className={classnames(styles.supportBaseTableBox, { [styles.supportBaseTableBoxHidden]: tableLoading })}
828+
>
826829
{tableLoading && <Spin className={styles.supportBaseTableSpin} />}
827830
<SupportBaseTable
828831
className={classnames('supportBaseTable', props.className, styles.table)}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
height: 100%;
55
display: flex;
66
flex-direction: column;
7+
position: relative;
78
}
89

910
.tabs {
@@ -84,3 +85,25 @@
8485
align-items: center;
8586
}
8687
}
88+
89+
.tableLoading {
90+
position: absolute;
91+
top: 0;
92+
left: 0;
93+
right: 0;
94+
bottom: 0;
95+
z-index: 9999;
96+
// height: 100%;
97+
display: flex;
98+
flex-direction: column;
99+
justify-content: center;
100+
align-items: center;
101+
// background-color: var(--color-fill);
102+
.stopExecuteSql {
103+
cursor: pointer;
104+
margin-top: 30px;
105+
&:hover {
106+
color: var(--color-primary);
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)