|
1 | | -import React, { memo, useRef, createContext } from 'react'; |
| 1 | +import React, { memo, useRef, useState } from 'react'; |
2 | 2 | import styles from './index.less'; |
3 | 3 | import classnames from 'classnames'; |
4 | 4 | import DraggableContainer from '@/components/DraggableContainer'; |
5 | 5 | import ConsoleEditor, { IConsoleRef } from '@/components/ConsoleEditor'; |
6 | 6 | import SearchResult, { ISearchResultRef } from '@/components/SearchResult'; |
7 | | -import { DatabaseTypeCode } from '@/constants'; |
| 7 | +import { DatabaseTypeCode, ConsoleStatus } from '@/constants'; |
8 | 8 | import { useUpdateEffect } from '@/hooks/useUpdateEffect'; |
9 | 9 | interface IProps { |
10 | 10 | boundInfo: { |
11 | 11 | databaseName: string; |
12 | 12 | dataSourceId: number; |
13 | 13 | type: DatabaseTypeCode; |
14 | 14 | schemaName?: string; |
| 15 | + consoleId: number; |
| 16 | + status: ConsoleStatus; |
15 | 17 | }; |
16 | 18 | initDDL: string; |
17 | | - consoleId: number; |
18 | 19 | } |
19 | 20 |
|
20 | 21 | interface IContext { |
21 | | - boundInfo: { |
| 22 | + boundInfoContext: { |
22 | 23 | databaseName: string; |
23 | 24 | dataSourceId: number; |
24 | 25 | type: DatabaseTypeCode; |
25 | 26 | schemaName?: string; |
| 27 | + consoleId: number; |
| 28 | + status: ConsoleStatus; |
26 | 29 | }; |
27 | | - consoleId: number; |
| 30 | + setBoundInfoContext: (boundInfo: IContext['boundInfoContext']) => void; |
28 | 31 | } |
29 | 32 |
|
30 | | -export const SQLExecuteContext = createContext<IContext>({} as any); |
31 | | - |
32 | 33 | const SQLExecute = memo<IProps>((props) => { |
33 | | - const { boundInfo, initDDL } = props; |
| 34 | + const { boundInfo: _boundInfo, initDDL } = props; |
34 | 35 | const draggableRef = useRef<any>(); |
35 | 36 | const searchResultRef = useRef<ISearchResultRef>(null); |
36 | 37 | const consoleRef = useRef<IConsoleRef>(null); |
| 38 | + const [boundInfo, setBoundInfo] = useState(_boundInfo) |
37 | 39 |
|
38 | 40 | useUpdateEffect(() => { |
39 | 41 | consoleRef.current?.editorRef?.setValue(initDDL, 'cover'); |
40 | 42 | }, [initDDL]); |
41 | 43 |
|
42 | 44 | return ( |
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> |
| 45 | + <div className={classnames(styles.sqlExecute)}> |
| 46 | + <DraggableContainer layout="column" className={styles.boxRightCenter}> |
| 47 | + <div ref={draggableRef} className={styles.boxRightConsole}> |
| 48 | + <ConsoleEditor |
| 49 | + ref={consoleRef} |
| 50 | + source="workspace" |
| 51 | + defaultValue={initDDL} |
| 52 | + boundInfo={boundInfo} |
| 53 | + setBoundInfo={setBoundInfo} |
| 54 | + hasAiChat={true} |
| 55 | + hasAi2Lang={true} |
| 56 | + onExecuteSQL={(sql) => { |
| 57 | + searchResultRef.current?.handleExecuteSQL(sql); |
| 58 | + }} |
| 59 | + // isActive={isActive} |
| 60 | + // tables={curTableList || []} |
| 61 | + // remainingUse={aiModel.remainingUse} |
| 62 | + /> |
| 63 | + </div> |
| 64 | + <div className={styles.boxRightResult}> |
| 65 | + <SearchResult ref={searchResultRef} executeSqlParams={boundInfo} /> |
| 66 | + </div> |
| 67 | + </DraggableContainer> |
| 68 | + </div> |
89 | 69 | ); |
90 | 70 | }); |
91 | 71 |
|
|
0 commit comments