|
1 | | -import React, { memo, useRef } from 'react'; |
2 | | -import { connect } from 'umi'; |
| 1 | +import React, { memo, useRef, createContext } from 'react'; |
3 | 2 | import styles from './index.less'; |
4 | 3 | import classnames from 'classnames'; |
5 | 4 | import DraggableContainer from '@/components/DraggableContainer'; |
6 | | -import Console, { IConsoleRef } from '@/components/Console'; |
| 5 | +import ConsoleEditor, { IConsoleRef } from '@/components/ConsoleEditor'; |
7 | 6 | 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'; |
11 | 8 | import { useUpdateEffect } from '@/hooks/useUpdateEffect'; |
12 | 9 | interface IProps { |
13 | | - className?: string; |
14 | | - isActive: boolean; |
15 | | - workspaceModel: IWorkspaceModelState; |
16 | | - aiModel: IAIState; |
17 | | - dispatch: any; |
18 | | - data: { |
| 10 | + boundInfo: { |
19 | 11 | databaseName: string; |
20 | 12 | dataSourceId: number; |
21 | 13 | type: DatabaseTypeCode; |
22 | 14 | schemaName?: string; |
23 | | - consoleId: number; |
24 | | - consoleName: string; |
25 | | - initDDL: string; |
26 | | - status?: ConsoleStatus; |
27 | 15 | }; |
| 16 | + initDDL: string; |
| 17 | + consoleId: number; |
28 | 18 | } |
29 | 19 |
|
| 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 | + |
30 | 32 | const SQLExecute = memo<IProps>((props) => { |
31 | | - const { data, workspaceModel, aiModel, isActive, dispatch } = props; |
| 33 | + const { boundInfo, initDDL } = props; |
32 | 34 | const draggableRef = useRef<any>(); |
33 | | - const { curTableList, curWorkspaceParams } = workspaceModel; |
34 | | - // const [sql, setSql] = useState<string>(''); |
35 | 35 | const searchResultRef = useRef<ISearchResultRef>(null); |
36 | 36 | const consoleRef = useRef<IConsoleRef>(null); |
37 | 37 |
|
38 | 38 | useUpdateEffect(() => { |
39 | | - consoleRef.current?.editorRef?.setValue(data.initDDL, 'cover'); |
40 | | - }, [data.initDDL]); |
| 39 | + consoleRef.current?.editorRef?.setValue(initDDL, 'cover'); |
| 40 | + }, [initDDL]); |
41 | 41 |
|
42 | 42 | 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> |
82 | 89 | ); |
83 | 90 | }); |
84 | 91 |
|
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; |
0 commit comments