Skip to content

Commit 0f9114d

Browse files
committed
reconstruction
1 parent 585f56c commit 0f9114d

25 files changed

Lines changed: 220 additions & 927 deletions

File tree

chat2db-client/.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"uuidv",
8686
"VARCHAR",
8787
"VIEWCOLUMN",
88+
"VIEWCOLUMNS",
8889
"webp",
8990
"wireframe",
9091
"Wppk",

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

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

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

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

chat2db-client/src/blocks/Tree/hooks/useGetRightClickMenu.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ export const useGetRightClickMenu = (props: IProps) => {
122122
icon: '\ue619',
123123
handle: () => {
124124
createConsole({
125-
name: 'new console',
126125
dataSourceId: treeNodeData.extraParams!.dataSourceId!,
127126
dataSourceName: treeNodeData.extraParams!.dataSourceName!,
128127
databaseType: treeNodeData.extraParams!.databaseType!,
@@ -132,6 +131,23 @@ export const useGetRightClickMenu = (props: IProps) => {
132131
},
133132
},
134133

134+
// 查看所有表
135+
[OperationColumn.ViewAllTable]: {
136+
text: i18n('workspace.menu.viewAllTable'),
137+
icon: '\ue611',
138+
handle: () => {
139+
addWorkspaceTab({
140+
id: uuid(),
141+
type: WorkspaceTabType.ViewAllTable,
142+
title: `${treeNodeData.extraParams!.databaseName!}-tables`,
143+
uniqueData: {
144+
145+
},
146+
})
147+
148+
},
149+
},
150+
135151
// 创建表
136152
[OperationColumn.CreateTable]: {
137153
text: i18n('editTable.button.createTable'),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ const TreeNode = memo((props: TreeNodeIProps) => {
178178

179179
// 双击节点
180180
const handelDoubleClickTreeNode = () => {
181-
rightClickMenu.find((item) => item.doubleClickTrigger)?.onClick();
181+
rightClickMenu.find((item) => item.doubleClickTrigger)?.onClick(treeNodeData);
182182
};
183183

184184
// 递归渲染

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,12 @@ export const treeConfig: { [key in TreeNodeType]: ITreeConfigItem } = {
274274
});
275275
});
276276
},
277-
operationColumn: [OperationColumn.CreateConsole, OperationColumn.CreateTable, OperationColumn.Refresh],
277+
operationColumn: [
278+
OperationColumn.CreateConsole,
279+
OperationColumn.ViewAllTable,
280+
OperationColumn.CreateTable,
281+
OperationColumn.Refresh,
282+
],
278283
},
279284

280285
[TreeNodeType.TABLE]: {

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

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import historyService from '@/service/history';
77
import Iconfont from '@/components/Iconfont';
88
import { databaseMap } from '@/constants/database';
99
import styles from './index.less';
10-
import { setRegisterProvider } from '@/store/monaco';
1110
import sqlService from '@/service/sql';
1211

1312
import {
@@ -36,10 +35,11 @@ const emptyOption = {
3635

3736
const SelectBoundInfo = memo((props: IProps) => {
3837
const { boundInfo, setBoundInfo } = props;
39-
const { setSelectedTables, setTableNameList } = useContext(IntelligentEditorContext);
38+
const { setSelectedTables, setTableNameList, isActive } = useContext(IntelligentEditorContext);
4039
const connectionList = useConnectionStore((state) => state.connectionList);
4140
const [databaseNameList, setDatabaseNameList] = useState<IOption<string>[]>([emptyOption]);
4241
const [schemaList, setSchemaList] = useState<IOption<string>[]>([emptyOption]);
42+
const [allTableList, setAllTableList] = useState<any>([]);
4343

4444
const dataSourceList = useMemo(() => {
4545
return (
@@ -115,9 +115,7 @@ const SelectBoundInfo = memo((props: IProps) => {
115115
if (!_databaseNameList.length) {
116116
getSchemaList();
117117
}
118-
setRegisterProvider(boundInfo.dataSourceId, editorDatabaseTips);
119118
setDatabaseNameList([emptyOption, ..._databaseNameList]);
120-
registerIntelliSenseDatabase(editorDatabaseTips);
121119
});
122120
};
123121

@@ -141,6 +139,37 @@ const SelectBoundInfo = memo((props: IProps) => {
141139
});
142140
};
143141

142+
// 注册表名
143+
useEffect(() => {
144+
if (isActive) {
145+
const tableNameListTemp = allTableList.map((t) => t.name);
146+
setTableNameList(tableNameListTemp);
147+
registerIntelliSenseTable(
148+
allTableList,
149+
boundInfo.databaseType,
150+
boundInfo.dataSourceId,
151+
boundInfo.databaseName,
152+
boundInfo.schemaName,
153+
);
154+
registerIntelliSenseField(
155+
tableNameListTemp,
156+
boundInfo.dataSourceId,
157+
boundInfo.databaseName,
158+
boundInfo.schemaName,
159+
);
160+
setSelectedTables(tableNameListTemp.slice(0, 1));
161+
}
162+
}, [allTableList, isActive]);
163+
164+
// 注册数据库名
165+
useEffect(() => {
166+
const editorDatabaseTips = databaseNameList.map((item) => ({
167+
name: item.value,
168+
dataSourceName: boundInfo.dataSourceName,
169+
}));
170+
registerIntelliSenseDatabase(editorDatabaseTips);
171+
}, [databaseNameList]);
172+
144173
// 选择数据源
145174
const changeDataSource = (item) => {
146175
const currentData = dataSourceList.find((i) => i.key === item.key)!;
@@ -198,25 +227,7 @@ const SelectBoundInfo = memo((props: IProps) => {
198227
schemaName,
199228
})
200229
.then((data) => {
201-
const tableNameListTemp = data.map((t) => t.name);
202-
203-
registerIntelliSenseTable(
204-
data,
205-
boundInfo.databaseType,
206-
boundInfo.dataSourceId,
207-
boundInfo.databaseName,
208-
boundInfo.schemaName,
209-
);
210-
211-
registerIntelliSenseField(
212-
tableNameListTemp,
213-
boundInfo.dataSourceId,
214-
boundInfo.databaseName,
215-
boundInfo.schemaName,
216-
);
217-
218-
setTableNameList(tableNameListTemp);
219-
setSelectedTables(tableNameListTemp.slice(0, 1));
230+
setAllTableList(data);
220231
});
221232
};
222233

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface IBoundInfo {
6060
interface IProps {
6161
/** 调用来源 */
6262
source: 'workspace';
63-
consoleIsActive: boolean;
63+
isActive: boolean;
6464
/** 添加或修改的内容 */
6565
appendValue?: IAppendValue;
6666
defaultValue?: string;
@@ -82,6 +82,7 @@ export interface IConsoleRef {
8282
}
8383

8484
interface IIntelligentEditorContext {
85+
isActive: boolean;
8586
tableNameList: string[];
8687
setTableNameList: (tables: string[]) => void;
8788
selectedTables: string[];
@@ -99,7 +100,7 @@ function ConsoleEditor(props: IProps, ref: ForwardedRef<IConsoleRef>) {
99100
hasSaveBtn = true,
100101
source,
101102
defaultValue,
102-
consoleIsActive,
103+
isActive,
103104
} = props;
104105
const uid = useMemo(() => uuidv4(), []);
105106
const chatResult = useRef('');
@@ -125,8 +126,8 @@ function ConsoleEditor(props: IProps, ref: ForwardedRef<IConsoleRef>) {
125126
// ---------------- new-code ----------------
126127
const { saveConsole } = useSaveEditorData({
127128
editorRef,
129+
isActive,
128130
boundInfo: props.boundInfo,
129-
// isActive,
130131
source,
131132
defaultValue,
132133
});
@@ -391,6 +392,7 @@ function ConsoleEditor(props: IProps, ref: ForwardedRef<IConsoleRef>) {
391392
return (
392393
<IntelligentEditorContext.Provider
393394
value={{
395+
isActive,
394396
tableNameList,
395397
setTableNameList,
396398
selectedTables,
@@ -412,7 +414,6 @@ function ConsoleEditor(props: IProps, ref: ForwardedRef<IConsoleRef>) {
412414
onSelectTables={(tables: string[]) => {
413415
setSelectedTables(tables);
414416
}}
415-
// onClickRemainBtn={handleClickRemainBtn}
416417
syncTableModel={syncTableModel}
417418
onSelectTableSyncModel={(model: number) => {
418419
setSyncTableModel(model);
@@ -425,7 +426,6 @@ function ConsoleEditor(props: IProps, ref: ForwardedRef<IConsoleRef>) {
425426
}}
426427
/>
427428
)}
428-
429429
<MonacoEditor
430430
id={uid}
431431
defaultValue={defaultValue}
@@ -434,9 +434,8 @@ function ConsoleEditor(props: IProps, ref: ForwardedRef<IConsoleRef>) {
434434
addAction={addAction}
435435
options={props.editorOptions}
436436
shortcutKey={registerShortcutKey}
437-
conceal={!consoleIsActive}
437+
isActive={isActive}
438438
/>
439-
440439
<Drawer
441440
open={isAiDrawerOpen}
442441
getContainer={false}
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
.editorContainer {
22
height: 100%;
33
}
4-
5-
.concealEditor {
6-
display: none;
7-
}

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const databaseTypeList = Object.keys(DatabaseTypeCode).map((d) => ({
2525

2626
interface IProps {
2727
id: string;
28-
conceal?: boolean;
2928
language?: string;
3029
className?: string;
3130
options?: IEditorOptions;
@@ -35,6 +34,7 @@ interface IProps {
3534
appendValue?: IAppendValue;
3635
didMount?: (editor: IEditorIns) => any;
3736
shortcutKey?: (editor, monaco) => void;
37+
isActive?: boolean;
3838
}
3939

4040
export interface IExportRefFunction {
@@ -45,7 +45,17 @@ export interface IExportRefFunction {
4545
}
4646

4747
function MonacoEditor(props: IProps, ref: ForwardedRef<IExportRefFunction>) {
48-
const { id, className, language = 'sql', didMount, options, conceal, defaultValue, appendValue, shortcutKey } = props;
48+
const {
49+
id,
50+
className,
51+
language = 'sql',
52+
didMount,
53+
options,
54+
isActive,
55+
defaultValue,
56+
appendValue,
57+
shortcutKey,
58+
} = props;
4959
const editorRef = useRef<IEditorIns>();
5060
const quickInputCommand = useRef<any>();
5161
const [appTheme] = useTheme();
@@ -99,13 +109,13 @@ function MonacoEditor(props: IProps, ref: ForwardedRef<IExportRefFunction>) {
99109
}, []);
100110

101111
useEffect(() => {
102-
if (editorRef.current) {
112+
if (editorRef.current && isActive) {
103113
// eg:
104114
// editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.KeyL, () => {
105115
// });
106116
shortcutKey?.(editorRef.current, monaco);
107117
}
108-
}, [editorRef.current]);
118+
}, [editorRef.current, isActive]);
109119

110120
useEffect(() => {
111121
// 监听浏览器窗口大小变化,重新渲染编辑器
@@ -206,8 +216,6 @@ function MonacoEditor(props: IProps, ref: ForwardedRef<IExportRefFunction>) {
206216
return <div ref={ref as any} id={`monaco-editor-${id}`} className={cs(className, styles.editorContainer)} />;
207217
}
208218

209-
// , { [styles.concealEditor]: conceal }
210-
211219
// text 需要添加的文本
212220
// range 添加到的位置
213221
// 'end' 末尾

0 commit comments

Comments
 (0)