Skip to content

Commit 78df03b

Browse files
committed
refactor-workspace-tabs
1 parent 6502c1e commit 78df03b

53 files changed

Lines changed: 339 additions & 140 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 9 additions & 0 deletions

CHANGELOG_CN.md

Lines changed: 9 additions & 0 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import '../../styles/var.less';
22

3-
.box {
3+
.sqlExecute {
44
height: 100%;
55
}
66

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,92 @@
1-
import React, { memo, useRef } from 'react';
2-
import { connect } from 'umi';
1+
import React, { memo, useRef, createContext } from 'react';
32
import styles from './index.less';
43
import classnames from 'classnames';
54
import DraggableContainer from '@/components/DraggableContainer';
6-
import Console, { IConsoleRef } from '@/components/Console';
5+
import ConsoleEditor, { IConsoleRef } from '@/components/ConsoleEditor';
76
import SearchResult, { ISearchResultRef } from '@/components/SearchResult';
8-
import { DatabaseTypeCode, ConsoleStatus } from '@/constants';
9-
import { IWorkspaceModelState, IWorkspaceModelType } from '@/models/workspace';
10-
import { IAIState } from '@/models/ai';
7+
import { DatabaseTypeCode } from '@/constants';
118
import { useUpdateEffect } from '@/hooks/useUpdateEffect';
129
interface IProps {
13-
className?: string;
14-
isActive: boolean;
15-
workspaceModel: IWorkspaceModelState;
16-
aiModel: IAIState;
17-
dispatch: any;
18-
data: {
10+
boundInfo: {
1911
databaseName: string;
2012
dataSourceId: number;
2113
type: DatabaseTypeCode;
2214
schemaName?: string;
23-
consoleId: number;
24-
consoleName: string;
25-
initDDL: string;
26-
status?: ConsoleStatus;
2715
};
16+
initDDL: string;
17+
consoleId: number;
2818
}
2919

20+
interface IContext {
21+
boundInfo: {
22+
databaseName: string;
23+
dataSourceId: number;
24+
type: DatabaseTypeCode;
25+
schemaName?: string;
26+
};
27+
consoleId: number;
28+
}
29+
30+
export const SQLExecuteContext = createContext<IContext>({} as any);
31+
3032
const SQLExecute = memo<IProps>((props) => {
31-
const { data, workspaceModel, aiModel, isActive, dispatch } = props;
33+
const { boundInfo, initDDL } = props;
3234
const draggableRef = useRef<any>();
33-
const { curTableList, curWorkspaceParams } = workspaceModel;
34-
// const [sql, setSql] = useState<string>('');
3535
const searchResultRef = useRef<ISearchResultRef>(null);
3636
const consoleRef = useRef<IConsoleRef>(null);
3737

3838
useUpdateEffect(() => {
39-
consoleRef.current?.editorRef?.setValue(data.initDDL, 'cover');
40-
}, [data.initDDL]);
39+
consoleRef.current?.editorRef?.setValue(initDDL, 'cover');
40+
}, [initDDL]);
4141

4242
return (
43-
<div className={classnames(styles.box)}>
44-
<DraggableContainer layout="column" className={styles.boxRightCenter}>
45-
<div ref={draggableRef} className={styles.boxRightConsole}>
46-
<Console
47-
ref={consoleRef}
48-
source="workspace"
49-
defaultValue={data.initDDL}
50-
isActive={isActive}
51-
executeParams={{ ...data }}
52-
hasAiChat={true}
53-
hasAi2Lang={true}
54-
onExecuteSQL={(sql) => {
55-
searchResultRef.current?.handleExecuteSQL(sql);
56-
}}
57-
onConsoleSave={() => {
58-
dispatch({
59-
type: 'workspace/fetchGetSavedConsole',
60-
payload: {
61-
status: ConsoleStatus.RELEASE,
62-
orderByDesc: true,
63-
...curWorkspaceParams,
64-
},
65-
callback: (res: any) => {
66-
dispatch({
67-
type: 'workspace/setConsoleList',
68-
payload: res.data,
69-
});
70-
},
71-
});
72-
}}
73-
tables={curTableList || []}
74-
remainingUse={aiModel.remainingUse}
75-
/>
76-
</div>
77-
<div className={styles.boxRightResult}>
78-
<SearchResult ref={searchResultRef} executeSqlParams={data} />
79-
</div>
80-
</DraggableContainer>
81-
</div>
43+
<SQLExecuteContext.Provider
44+
value={{
45+
boundInfo,
46+
consoleId: props.consoleId,
47+
}}
48+
>
49+
<div className={classnames(styles.sqlExecute)}>
50+
<DraggableContainer layout="column" className={styles.boxRightCenter}>
51+
<div ref={draggableRef} className={styles.boxRightConsole}>
52+
<ConsoleEditor
53+
ref={consoleRef}
54+
source="workspace"
55+
defaultValue={initDDL}
56+
executeParams={boundInfo}
57+
hasAiChat={true}
58+
hasAi2Lang={true}
59+
onExecuteSQL={(sql) => {
60+
searchResultRef.current?.handleExecuteSQL(sql);
61+
}}
62+
// isActive={isActive}
63+
// onConsoleSave={() => {
64+
// dispatch({
65+
// type: 'workspace/fetchGetSavedConsole',
66+
// payload: {
67+
// status: ConsoleStatus.RELEASE,
68+
// orderByDesc: true,
69+
// ...curWorkspaceParams,
70+
// },
71+
// callback: (res: any) => {
72+
// dispatch({
73+
// type: 'workspace/setConsoleList',
74+
// payload: res.data,
75+
// });
76+
// },
77+
// });
78+
// }}
79+
// tables={curTableList || []}
80+
// remainingUse={aiModel.remainingUse}
81+
/>
82+
</div>
83+
<div className={styles.boxRightResult}>
84+
<SearchResult ref={searchResultRef} executeSqlParams={boundInfo} />
85+
</div>
86+
</DraggableContainer>
87+
</div>
88+
</SQLExecuteContext.Provider>
8289
);
8390
});
8491

85-
const dvaModel = connect(({ workspace, ai }: { workspace: IWorkspaceModelType; ai: IAIState }) => ({
86-
workspaceModel: workspace,
87-
aiModel: ai,
88-
}));
89-
90-
export default dvaModel(SQLExecute);
92+
export default SQLExecute;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import styles from './index.less';
77
// ----- components -----
88
import { dataSourceFormConfigs } from '@/components/ConnectionEdit/config/dataSource';
99
import { IConnectionConfig } from '@/components/ConnectionEdit/config/types';
10-
import MonacoEditor, { IExportRefFunction } from '@/components/Console/MonacoEditor';
10+
import MonacoEditor, { IExportRefFunction } from '@/components/ConsoleEditor/MonacoEditor';
1111
import MenuLabel from '@/components/MenuLabel';
1212

1313
// ----- constants -----

chat2db-client/src/components/Console/ChatInput/index.less renamed to chat2db-client/src/components/ConsoleEditor/ChatInput/index.less

File renamed without changes.

chat2db-client/src/components/Console/ChatInput/index.tsx renamed to chat2db-client/src/components/ConsoleEditor/ChatInput/index.tsx

File renamed without changes.

chat2db-client/src/components/Console/MonacoEditor/index.less renamed to chat2db-client/src/components/ConsoleEditor/MonacoEditor/index.less

File renamed without changes.

chat2db-client/src/components/Console/MonacoEditor/index.tsx renamed to chat2db-client/src/components/ConsoleEditor/MonacoEditor/index.tsx

File renamed without changes.

chat2db-client/src/components/Console/MonacoEditor/monacoEditorConfig.ts renamed to chat2db-client/src/components/ConsoleEditor/MonacoEditor/monacoEditorConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IEditorOptions } from '@/components/Console/MonacoEditor';
1+
import { IEditorOptions } from '@/components/ConsoleEditor/MonacoEditor';
22

33
export const editorDefaultOptions: IEditorOptions = {
44
fontFamily: `"Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace`,

0 commit comments

Comments
 (0)