Skip to content

Commit 4bf4038

Browse files
committed
Merge branch 'dev' of github.com:chat2db/Chat2DB into dev
2 parents f2158a2 + 6e12b2a commit 4bf4038

7 files changed

Lines changed: 126 additions & 57 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"pgsql",
4545
"pnpm",
4646
"Popconfirm",
47+
"quickinput",
4748
"redownload",
4849
"remaininguses",
4950
"RESTAI",

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
**Changelog**
55
- ⭐【New Features】Query results can be refreshed
66
- ⚡️【Optimize】Console Tabs adaptive width
7-
- 🐞【Fixed】
7+
- 🐞【Fixed】console save bug
88

99
**更新日志**
1010
- ⭐【新功能】查询结果支持刷新
1111
- ⚡️【优化】控制台Tabs自适应宽度
12-
- 🐞【修复】
12+
- 🐞【修复】console保存bug
1313

1414

1515
# 3.0.5

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React, { memo, useRef, useState } from 'react';
1+
import React, { memo, useRef } from 'react';
22
import { connect } from 'umi';
33
import styles from './index.less';
44
import classnames from 'classnames';
55
import DraggableContainer from '@/components/DraggableContainer';
6-
import Console, { IAppendValue } from '@/components/Console';
6+
import Console, { IConsoleRef } from '@/components/Console';
77
import SearchResult, { ISearchResultRef } from '@/components/SearchResult';
88
import { DatabaseTypeCode, ConsoleStatus } from '@/constants';
99
import { IWorkspaceModelState, IWorkspaceModelType } from '@/models/workspace';
@@ -23,16 +23,17 @@ interface IProps {
2323
consoleId: number;
2424
consoleName: string;
2525
initDDL: string;
26+
status?: ConsoleStatus;
2627
};
2728
}
2829

2930
const SQLExecute = memo<IProps>((props) => {
3031
const { data, workspaceModel, aiModel, isActive, dispatch } = props;
3132
const draggableRef = useRef<any>();
32-
const [appendValue, setAppendValue] = useState<IAppendValue>();
3333
const { curTableList, curWorkspaceParams } = workspaceModel;
3434
// const [sql, setSql] = useState<string>('');
3535
const searchResultRef = useRef<ISearchResultRef>(null);
36+
const consoleRef = useRef<IConsoleRef>(null);
3637

3738
// useEffect(() => {
3839
// if (!doubleClickTreeNodeData) {
@@ -53,18 +54,18 @@ const SQLExecute = memo<IProps>((props) => {
5354
// }, [doubleClickTreeNodeData]);
5455

5556
useUpdateEffect(() => {
56-
setAppendValue({ text: data.initDDL });
57+
consoleRef.current?.editorRef?.setValue(data.initDDL, 'cover');
5758
}, [data.initDDL]);
5859

5960
return (
6061
<div className={classnames(styles.box)}>
6162
<DraggableContainer layout="column" className={styles.boxRightCenter}>
6263
<div ref={draggableRef} className={styles.boxRightConsole}>
6364
<Console
65+
ref={consoleRef}
6466
source="workspace"
6567
defaultValue={data.initDDL}
6668
isActive={isActive}
67-
appendValue={appendValue}
6869
executeParams={{ ...data }}
6970
hasAiChat={true}
7071
hasAi2Lang={true}

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

Lines changed: 78 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
112112
const closeEventSource = useRef<any>();
113113
// 上一次同步的console数据
114114
const lastSyncConsole = useRef<any>(defaultValue);
115+
const [saveStatus, setSaveStatus] = useState<ConsoleStatus>(executeParams.status || ConsoleStatus.DRAFT);
115116

116117
/**
117118
* 当前选择的AI类型是Chat2DBAI
@@ -131,70 +132,91 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
131132
}
132133
}, [appendValue]);
133134

134-
useImperativeHandle(ref, () => ({
135-
editorRef: editorRef?.current,
136-
}));
135+
useImperativeHandle(
136+
ref,
137+
() => ({
138+
editorRef: editorRef?.current,
139+
}),
140+
[editorRef?.current],
141+
);
137142

138143
useEffect(() => {
139144
if (source !== 'workspace') {
140145
return;
141146
}
142147
// 离开时保存
143-
if (!isActive && timerRef.current) {
148+
if (!isActive) {
144149
// 离开时清除定时器
145-
indexedDB.updateData('chat2db', 'workspaceConsoleDDL', {
146-
consoleId: executeParams.consoleId!,
147-
ddl: editorRef?.current?.getAllContent(),
148-
userId: getCookie('CHAT2DB.USER_ID'),
149-
});
150-
clearInterval(timerRef.current);
150+
if (timerRef.current) {
151+
clearInterval(timerRef.current);
152+
}
153+
const curValue = editorRef?.current?.getAllContent();
154+
if (curValue === lastSyncConsole.current) {
155+
return;
156+
}
157+
if (saveStatus === ConsoleStatus.RELEASE) {
158+
saveConsole(curValue, true);
159+
} else {
160+
indexedDB
161+
.updateData('chat2db', 'workspaceConsoleDDL', {
162+
consoleId: executeParams.consoleId!,
163+
ddl: curValue,
164+
userId: getCookie('CHAT2DB.USER_ID'),
165+
})
166+
.then(() => {
167+
lastSyncConsole.current = curValue;
168+
});
169+
}
170+
} else {
171+
timingAutoSave();
172+
}
173+
return () => {
174+
if (timerRef.current) {
175+
clearInterval(timerRef.current);
176+
}
177+
};
178+
}, [isActive]);
179+
180+
useEffect(() => {
181+
if (saveStatus === ConsoleStatus.RELEASE) {
182+
editorRef?.current?.setValue(defaultValue, 'cover');
151183
} else {
152-
// 活跃时自动保存
153184
indexedDB
154185
.getDataByCursor('chat2db', 'workspaceConsoleDDL', {
155186
consoleId: executeParams.consoleId!,
156187
userId: getCookie('CHAT2DB.USER_ID'),
157188
})
158189
.then((res: any) => {
159-
const value = defaultValue || res?.[0]?.ddl || '';
190+
// oldValue是为了处理函数视图等,他们是带着值来的,不需要去数据库取值
160191
const oldValue = editorRef?.current?.getAllContent();
161-
if (value !== oldValue) {
162-
editorRef?.current?.setValue(value, 'reset');
192+
if (!oldValue) {
193+
editorRef?.current?.setValue(res?.[0]?.ddl || '', 'cover');
163194
}
164-
setTimeout(() => {
165-
timingAutoSave();
166-
}, 0);
167195
});
168196
}
169-
return () => {
170-
if (timerRef.current) {
171-
clearInterval(timerRef.current);
172-
}
173-
};
174-
}, [isActive]);
197+
}, []);
175198

176-
function timingAutoSave(status?: ConsoleStatus) {
199+
function timingAutoSave(_status?: ConsoleStatus) {
177200
if (timerRef.current) {
178201
clearInterval(timerRef.current);
179202
}
180203
timerRef.current = setInterval(() => {
181-
const ddl = editorRef?.current?.getAllContent();
182-
if (ddl === lastSyncConsole.current) {
204+
const curValue = editorRef?.current?.getAllContent();
205+
if (curValue === lastSyncConsole.current) {
183206
return;
184207
}
185-
lastSyncConsole.current = ddl;
186-
if (executeParams.status === ConsoleStatus.RELEASE || status === ConsoleStatus.RELEASE) {
187-
const p: any = {
188-
id: executeParams.consoleId,
189-
ddl,
190-
};
191-
historyServer.updateSavedConsole(p);
208+
if (saveStatus === ConsoleStatus.RELEASE || _status === ConsoleStatus.RELEASE) {
209+
saveConsole(curValue, true);
192210
} else {
193-
indexedDB.updateData('chat2db', 'workspaceConsoleDDL', {
194-
consoleId: executeParams.consoleId!,
195-
ddl,
196-
userId: getCookie('CHAT2DB.USER_ID'),
197-
});
211+
indexedDB
212+
.updateData('chat2db', 'workspaceConsoleDDL', {
213+
consoleId: executeParams.consoleId!,
214+
ddl: curValue,
215+
userId: getCookie('CHAT2DB.USER_ID'),
216+
})
217+
.then(() => {
218+
lastSyncConsole.current = curValue;
219+
});
198220
}
199221
}, 5000);
200222
}
@@ -384,8 +406,7 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
384406
props.onExecuteSQL && props.onExecuteSQL(sqlContent);
385407
};
386408

387-
const saveConsole = (value?: string) => {
388-
// const a = editorRef.current?.getAllContent();
409+
const saveConsole = (value?: string, noPrompting?: boolean) => {
389410
const p: any = {
390411
id: executeParams.consoleId,
391412
status: ConsoleStatus.RELEASE,
@@ -394,6 +415,11 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
394415

395416
historyServer.updateSavedConsole(p).then(() => {
396417
indexedDB.deleteData('chat2db', 'workspaceConsoleDDL', executeParams.consoleId!);
418+
lastSyncConsole.current = value;
419+
setSaveStatus(ConsoleStatus.RELEASE);
420+
if (noPrompting) {
421+
return;
422+
}
397423
message.success(i18n('common.tips.saveSuccessfully'));
398424
props.onConsoleSave && props.onConsoleSave();
399425
timingAutoSave(ConsoleStatus.RELEASE);
@@ -570,8 +596,16 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
570596
);
571597
}
572598

573-
const dvaModel = connect(({ ai, loading }: { ai: IAIState; loading: any }) => ({
574-
aiModel: ai,
575-
remainingBtnLoading: loading.effects['ai/fetchRemainingUse'],
576-
}));
599+
const dvaModel = connect(
600+
({ ai, loading }: { ai: IAIState; loading: any }) => {
601+
return {
602+
aiModel: ai,
603+
remainingBtnLoading: loading.effects['ai/fetchRemainingUse'],
604+
};
605+
},
606+
null,
607+
null,
608+
{ forwardRef: true },
609+
);
610+
577611
export default dvaModel(forwardRef(Console));
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
.page {
2-
> div {
3-
margin-bottom: 30px;
4-
}
2+
height: 500px;
53
}

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import React, { useEffect, useState } from 'react';
2+
import styles from './index.less';
3+
import MonacoEditor from '@/components/Console/MonacoEditor';
4+
import { Tabs } from 'antd';
25

36
export enum CustomerTypeEnum {
47
visitor = 'visitor',
@@ -10,13 +13,46 @@ export enum CustomerTypeEnum2 {
1013
person = 'person',
1114
}
1215

16+
const list = [
17+
"select if((`performance_schema`.`accounts`.`HOST` is null),'background',`performance_schema`.`accounts`.`HOST`) AS `host`,sum(`sys`.`stmt`.`total`) AS `statements`,format_pico_time(sum(`sys`.`stmt`.`total_latency`)) AS `statement_latency`,format_pico_time(ifnull((sum(`sys`.`stmt`.`total_latency`) / nullif(sum(`sys`.`stmt`.`total`),0)),0)) AS `statement_avg_latency`,sum(`sys`.`stmt`.`full_scans`) AS `table_scans`,sum(`sys`.`io`.`ios`) AS `file_ios`,format_pico_time(sum(`sys`.`io`.`io_latency`)) AS `file_io_latency`,sum(`performance_schema`.`accounts`.`CURRENT_CONNECTIONS`) AS `current_connections`,sum(`performance_schema`.`accounts`.`TOTAL_CONNECTIONS`) AS `total_connections`,count(distinct `performance_schema`.`accounts`.`USER`) AS `unique_users`,format_bytes(sum(`sys`.`mem`.`current_allocated`)) AS `current_memory`,format_bytes(sum(`sys`.`mem`.`total_allocated`)) AS `total_memory_allocated` from (((`performance_schema`.`accounts` join `sys`.`x$host_summary_by_statement_latency` `stmt` on((`performance_schema`.`accounts`.`HOST` = `sys`.`stmt`.`host`))) join `sys`.`x$host_summary_by_file_io` `io` on((`performance_schema`.`accounts`.`HOST` = `sys`.`io`.`host`))) join `sys`.`x$memory_by_host_by_current_bytes` `mem` on((`performance_schema`.`accounts`.`HOST` = `sys`.`mem`.`host`))) group by if((`performance_schema`.`accounts`.`HOST` is null),'background',`performance_schema`.`accounts`.`HOST`)",
18+
'Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!Bug: chatglm3 不支持!',
19+
'建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名建议: 鼠标移上去显示表全名,目前表名太长,看不全表名',
20+
];
21+
1322
export type CustomerType1 = CustomerTypeEnum | CustomerTypeEnum2;
1423

1524
const App: React.FC = () => {
16-
25+
const items = [
26+
{
27+
key: '1',
28+
label: 'Tab 1',
29+
forceRender: true,
30+
children:<div className={styles.page}>
31+
<MonacoEditor id="001" defaultValue={list[0]} />
32+
</div>
33+
},
34+
{
35+
key: '2',
36+
label: 'Tab 2',
37+
forceRender: true,
38+
children: <div className={styles.page}>
39+
<MonacoEditor id="002" defaultValue={list[1]} />
40+
</div>
41+
},
42+
{
43+
key: '3',
44+
label: 'Tab 3',
45+
forceRender: true,
46+
children:
47+
<div className={styles.page}>
48+
<MonacoEditor id="003" defaultValue={list[2]} />
49+
</div>
50+
},
51+
];
1752

1853
return (
19-
<div>demo</div>
54+
55+
<Tabs items={items} />
2056
);
2157
};
2258

chat2db-client/src/pages/main/workspace/components/WorkspaceRight/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,6 @@ const WorkspaceRight = memo<IProps>((props: IProps) => {
618618
activeKey={activeConsoleId}
619619
editableNameOnBlur={editableNameOnBlur}
620620
items={tabsList}
621-
// lastTabCannotClosed
622621
/>
623622
</div>
624623
{/* <WorkspaceExtend className={styles.workspaceExtend} /> */}

0 commit comments

Comments
 (0)