Skip to content

Commit a687891

Browse files
committed
change boundInfo
1 parent f8f3e66 commit a687891

13 files changed

Lines changed: 132 additions & 24 deletions

File tree

chat2db-client/.umirc.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export default defineConfig({
2424
path: '/',
2525
component: '@/layouts/GlobalLayout',
2626
routes: [
27+
{
28+
path: '/demo',
29+
component: '@/pages/demo',
30+
},
2731
{
2832
path: '/connections',
2933
component: 'main',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const useGetRightClickMenu = (props: IProps) => {
122122
icon: '\ue619',
123123
handle: () => {
124124
createConsole({
125-
name: 'create console',
125+
name: 'new console',
126126
dataSourceId: treeNodeData.extraParams!.dataSourceId!,
127127
dataSourceName: treeNodeData.extraParams!.dataSourceName!,
128128
databaseType: treeNodeData.extraParams!.databaseType!,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
1+
@import '../../../../styles/var.less';
2+
13
.consoleOptionsRight {
4+
flex: 1;
25
display: flex;
6+
justify-content: flex-end;
7+
}
8+
9+
.boundInfoBoxSpacer{
10+
flex: 1;
311
}
412

513
.boundInfoBox {
14+
max-width: 160px;
615
display: flex;
716
align-items: center;
817
padding: 5px 6px 5px 8px;
918
border-radius: 4px;
1019
cursor: pointer;
1120

1221
.boundInfoName {
22+
.f-single-line();
1323
margin: 0px 6px 0px 4px;
1424
}
1525

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ 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'
1011

1112
import {
1213
// registerIntelliSenseField,
@@ -50,6 +51,7 @@ const SelectBoundInfo = memo(
5051
// 当数据源变化时,重新获取数据库列表
5152
useEffect(() => {
5253
getDatabaseList();
54+
setSchemaList([]);
5355
}, [boundInfo.dataSourceId]);
5456

5557
// 当数据库名变化时,重新获取schema列表
@@ -79,8 +81,9 @@ const SelectBoundInfo = memo(
7981
if (!_databaseNameList.length) {
8082
getSchemaList();
8183
}
84+
setRegisterProvider(boundInfo.dataSourceId, editorDatabaseTips);
8285
setDatabaseNameList(_databaseNameList);
83-
registerIntelliSenseDatabase(editorDatabaseTips);
86+
// registerIntelliSenseDatabase(editorDatabaseTips);
8487
});
8588
}
8689

@@ -108,7 +111,6 @@ const SelectBoundInfo = memo(
108111
// 选择数据源
109112
const changeDataSource = (item) => {
110113
const currentData = dataSourceList.find((i) => i.key === item.key)!;
111-
112114
setBoundInfo({
113115
...boundInfo,
114116
dataSourceId: currentData.value,
@@ -117,6 +119,11 @@ const SelectBoundInfo = memo(
117119
databaseName: void 0,
118120
schemaName: void 0,
119121
});
122+
historyService.updateSavedConsole({
123+
id: boundInfo.consoleId,
124+
dataSourceId: currentData.value,
125+
dataSourceName: currentData.label
126+
})
120127
};
121128

122129
// 选择数据库
@@ -146,11 +153,10 @@ const SelectBoundInfo = memo(
146153
schemaName: _schemaName,
147154
})
148155
};
149-
150-
console.log(boundInfo)
151156

152157
return (
153158
<div className={styles.consoleOptionsRight}>
159+
<div className={styles.boundInfoBoxSpacer} />
154160
<Dropdown
155161
menu={{
156162
items: dataSourceList,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface IProps {
2929
className?: string;
3030
sql?: string;
3131
executeSqlParams: any;
32+
concealTabHeader?: boolean;
3233
}
3334

3435
const defaultResultConfig: IResultConfig = {
@@ -50,7 +51,7 @@ interface IContext {
5051
export const Context = createContext<IContext>({} as any);
5152

5253
export default forwardRef((props: IProps, ref: ForwardedRef<ISearchResultRef>) => {
53-
const { className, sql, executeSqlParams } = props;
54+
const { className, sql, executeSqlParams, concealTabHeader } = props;
5455
const [resultDataList, setResultDataList] = useState<IManageResultData[]>();
5556
const [tableLoading, setTableLoading] = useState(false);
5657
const controllerRef = useRef<AbortController>();
@@ -206,7 +207,7 @@ export default forwardRef((props: IProps, ref: ForwardedRef<ISearchResultRef>) =
206207
onChange={onChange as any}
207208
onEdit={onEdit as any}
208209
items={tabsList}
209-
concealTabHeader={tabsList.length === 1}
210+
concealTabHeader={concealTabHeader}
210211
/>
211212
) : (
212213
<div className={styles.noData}>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default memo<IProps>((props) => {
6969
);
7070
})}
7171
</div>
72-
<div className={styles.slot}>{slot()}</div>
72+
{slot()}
7373
</div>
7474
);
7575
});

chat2db-client/src/hooks/useCreateConsole.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface ICreateConsoleParams {
1010
dataSourceName?: string;
1111
databaseName?: string;
1212
schemaName?: string;
13-
databaseType?: DatabaseTypeCode;
13+
type?: DatabaseTypeCode;
1414
operationType?: string;
1515
}
1616

@@ -24,12 +24,11 @@ function useCreateConsole() {
2424
const createConsole = (params: ICreateConsoleParams) => {
2525
const newConsole = {
2626
...params,
27-
name: params.name || 'create console',
27+
name: params.name || 'new console',
2828
ddl: params.ddl || '',
2929
status: ConsoleStatus.DRAFT,
3030
tabOpened: ConsoleOpenedStatus.IS_OPEN,
3131
operationType: WorkspaceTabType.CONSOLE,
32-
databaseType: params.databaseType,
3332
dataSourceId: params.dataSourceId,
3433
dataSourceName: params.dataSourceName,
3534
};
@@ -40,7 +39,10 @@ function useCreateConsole() {
4039
id: res,
4140
title: newConsole.name,
4241
type: newConsole.operationType,
43-
uniqueData: newConsole,
42+
uniqueData: {
43+
...newConsole,
44+
databaseType: newConsole.type,
45+
},
4446
},
4547
];
4648
setWorkspaceTabList(newList);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.introduce{
2+
height: 100%;
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
import styles from './index.less';
3+
import MonacoEditor from '@/components/MonacoEditor';
4+
5+
function Test() {
6+
return (
7+
<div className={styles.introduce}>
8+
<MonacoEditor language='sql' id='121212121' />
9+
</div>
10+
);
11+
}
12+
13+
export default Test;

chat2db-client/src/pages/main/store/monaco/index.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,45 @@ import { devtools } from 'zustand/middleware';
33
import { shallow } from 'zustand/shallow';
44
import { StoreApi } from 'zustand';
55

6+
// 表信息
7+
export interface tableItem {
8+
columnList: {
9+
columnName?: string;
10+
columnType?: string;
11+
}[];
12+
}
13+
14+
// schema信息
15+
export interface schemaItem {
16+
tableList?: tableItem[];
17+
}
18+
19+
// 数据库信息
20+
export type databaseItem = {
21+
schemaList?: schemaItem[];
22+
} | {
23+
databaseName: string;
24+
tableList: tableItem[];
25+
}
26+
27+
// monaco store
628
export interface IMonacoStore {
729
registerProvider: {
8-
[key: string]: {
9-
databaseNameList: (databaseName: Array<{
10-
name: string;
11-
dataSourceName: string,
12-
}>) => void;
13-
}
14-
} | null
30+
// 数据源id
31+
[key: number]: databaseItem[]
32+
}
1533
}
1634

1735
const initMonacoStore = {
18-
registerProvider: null
36+
registerProvider: {}
1937
}
2038

2139
export const useMonacoStore: UseBoundStoreWithEqualityFn<StoreApi<IMonacoStore>> = createWithEqualityFn(
2240
devtools(() => (initMonacoStore)),
2341
shallow
2442
);
2543

44+
export const setRegisterProvider = (id: number, data: databaseItem[]) => {
45+
useMonacoStore.getState().registerProvider[id] = data;
46+
}
47+

0 commit comments

Comments
 (0)