Skip to content

Commit 4120b63

Browse files
committed
refactor-workspace-tree
2 parents 9a8aed4 + 5319732 commit 4120b63

49 files changed

Lines changed: 736 additions & 185 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 3.0.13
2+
3+
`2023-11-15`
4+
5+
**Changelog**
6+
7+
- 🐞【Fixed】oracle datatype error
8+
- 🐞【Fixed】DM index error
9+
10+
111
## 3.0.12
212

313
`2023-11-13`

CHANGELOG_CN.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 3.0.13
2+
3+
`2023-11-15`
4+
5+
**更新日志**
6+
7+
- 🐞【修复】oracle datatype 错误
8+
- 🐞【修复】DM index 错误
9+
110
## 3.0.12
211

312
`2023-11-13`

chat2db-client/src/blocks/DatabaseTableEditor/ColumnList/index.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -503,18 +503,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)
503503
)}
504504
{editingConfig?.supportDefaultValue && (
505505
<Form.Item labelCol={labelCol} label={i18n('editTable.label.defaultValue')} name="defaultValue">
506-
<CustomSelect
507-
options={[
508-
{
509-
label: 'EMPTY_STRING',
510-
value: 'EMPTY_STRING',
511-
},
512-
{
513-
label: 'NULL',
514-
value: 'NULL',
515-
},
516-
]}
517-
/>
506+
<CustomSelect options={databaseSupportField.defaultValues} />
518507
</Form.Item>
519508
)}
520509
{editingConfig?.supportCharset && (

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface IDatabaseSupportField {
5454
charsets: IOption[];
5555
collations: IOption[];
5656
indexTypes: IOption[];
57+
defaultValues: IOption[];
5758
}
5859

5960
export default memo((props: IProps) => {
@@ -93,6 +94,7 @@ export default memo((props: IProps) => {
9394
charsets: [],
9495
collations: [],
9596
indexTypes: [],
97+
defaultValues: [],
9698
});
9799
const [isLoading, setIsLoading] = useState<boolean>(false);
98100

@@ -148,11 +150,20 @@ export default memo((props: IProps) => {
148150
};
149151
}) || [];
150152

153+
const defaultValues =
154+
res?.defaultValues?.map((i) => {
155+
return {
156+
value: i.defaultValue,
157+
label: i.defaultValue,
158+
};
159+
}) || [];
160+
151161
setDatabaseSupportField({
152162
columnTypes,
153163
charsets,
154164
collations,
155165
indexTypes,
166+
defaultValues,
156167
});
157168
});
158169
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import { createConsole, addWorkspaceTab } from '@/store/console';
1717
// ---- functions -----
1818
import { openView, openFunction, openProcedure, openTrigger } from '../functions/openAsyncSql';
1919

20+
// ----- utils -----
21+
import { compatibleDataBaseName } from '@/utils/database';
22+
2023
interface IProps {
2124
treeNodeData: ITreeNode;
2225
loadData: any;
@@ -25,6 +28,7 @@ interface IProps {
2528
interface IOperationColumnConfigItem {
2629
text: string;
2730
icon: string;
31+
doubleClickTrigger?: boolean;
2832
handle: () => void;
2933
}
3034

@@ -162,7 +166,12 @@ export const useGetRightClickMenu = (props: IProps) => {
162166
[OperationColumn.OpenTable]: {
163167
text: i18n('workspace.menu.openTable'),
164168
icon: '\ue618',
169+
doubleClickTrigger: true,
165170
handle: () => {
171+
const databaseName = compatibleDataBaseName(
172+
treeNodeData.extraParams!.databaseName!,
173+
treeNodeData.extraParams!.databaseType,
174+
);
166175
addWorkspaceTab({
167176
id: `${OperationColumn.OpenTable}-${treeNodeData.uuid}`,
168177
title: treeNodeData.name,
@@ -172,7 +181,7 @@ export const useGetRightClickMenu = (props: IProps) => {
172181
databaseType: treeNodeData.extraParams!.databaseType!,
173182
databaseName: treeNodeData.extraParams?.databaseName,
174183
schemaName: treeNodeData.extraParams?.schemaName,
175-
sql: `select * from ${treeNodeData.name}`,
184+
sql: `select * from ${databaseName}`,
176185
},
177186
});
178187
},
@@ -182,6 +191,7 @@ export const useGetRightClickMenu = (props: IProps) => {
182191
[OperationColumn.OpenView]: {
183192
text: i18n('workspace.menu.view'),
184193
icon: '\ue651',
194+
doubleClickTrigger: true,
185195
handle: () => {
186196
openView({
187197
addWorkspaceTab,
@@ -194,6 +204,7 @@ export const useGetRightClickMenu = (props: IProps) => {
194204
[OperationColumn.OpenFunction]: {
195205
text: i18n('workspace.menu.view'),
196206
icon: '\ue651',
207+
doubleClickTrigger: true,
197208
handle: () => {
198209
openFunction({
199210
addWorkspaceTab,
@@ -206,6 +217,7 @@ export const useGetRightClickMenu = (props: IProps) => {
206217
[OperationColumn.OpenProcedure]: {
207218
text: i18n('workspace.menu.view'),
208219
icon: '\ue651',
220+
doubleClickTrigger: true,
209221
handle: () => {
210222
openProcedure({
211223
addWorkspaceTab,
@@ -218,6 +230,7 @@ export const useGetRightClickMenu = (props: IProps) => {
218230
[OperationColumn.OpenTrigger]: {
219231
text: i18n('workspace.menu.view'),
220232
icon: '\ue651',
233+
doubleClickTrigger: true,
221234
handle: () => {
222235
openTrigger({
223236
addWorkspaceTab,
@@ -234,6 +247,7 @@ export const useGetRightClickMenu = (props: IProps) => {
234247
key: i,
235248
onClick: concrete?.handle,
236249
type: t,
250+
doubleClickTrigger: concrete.doubleClickTrigger,
237251
labelProps: {
238252
icon: concrete?.icon,
239253
label: concrete?.text,

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
.treeBox {
44
padding: 0px 6px 10px;
55
box-sizing: border-box;
6-
height: 100%;
76
overflow: hidden;
87
overflow-y: auto;
98
}
@@ -55,7 +54,7 @@
5554
display: flex;
5655
align-items: center;
5756
height: 100%;
58-
padding-left: 10px;
57+
padding-left: 4px;
5958
border-radius: 2px;
6059
.moreBox {
6160
width: 22px;
@@ -151,7 +150,7 @@
151150
&::before {
152151
position: absolute;
153152
top: 0;
154-
right: 3px;
153+
right: 9px;
155154
bottom: -4px;
156155
border-right: 1px solid var(--color-border);
157156
content: '';

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

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
1-
import React, { memo, useEffect, useMemo, useState } from 'react';
1+
import React, { memo, useEffect, useMemo, useState, forwardRef, createContext, useContext } from 'react';
22
import styles from './index.less';
33
import classnames from 'classnames';
44
import Iconfont from '@/components/Iconfont';
55
import { Tooltip, Dropdown } from 'antd';
66
import { ITreeNode } from '@/typings';
7-
import { OperationColumn, TreeNodeType, databaseMap } from '@/constants';
7+
import { TreeNodeType, databaseMap } from '@/constants';
88
import { treeConfig, switchIcon, ITreeConfigItem } from './treeConfig';
99
import { useCommonStore } from '@/store/common';
1010
import LoadingGracile from '@/components/Loading/LoadingGracile';
1111
import { setFocusId, useTreeStore } from './treeStore';
1212
import { useGetRightClickMenu } from './hooks/useGetRightClickMenu';
1313
import MenuLabel from '@/components/MenuLabel';
14+
import LoadingContent from '@/components/Loading/LoadingContent'
1415

1516
interface IProps {
1617
className?: string;
1718
initialData: ITreeNode[] | null;
19+
searchValue: string;
20+
ref: any;
1821
}
1922

2023
interface TreeNodeIProps {
2124
data: ITreeNode;
2225
level: number;
26+
setShowParentNode?: (value: boolean) => void;
2327
}
2428

25-
const Tree = memo((props: IProps) => {
26-
const { className, initialData } = props;
29+
interface IContext {
30+
searchValue?: string;
31+
}
32+
33+
export const Context = createContext<IContext>({} as any);
34+
35+
const Tree = (props: IProps, ref: any) => {
36+
const { className, initialData, searchValue } = props;
2737
const [treeData, setTreeData] = useState<ITreeNode[] | null>(null);
2838

2939
useEffect(() => {
@@ -36,18 +46,45 @@ const Tree = memo((props: IProps) => {
3646
});
3747
}, [treeData]);
3848

39-
return <div className={classnames(className, styles.treeBox)}>{treeNodes}</div>;
40-
});
49+
return (
50+
<Context.Provider value={{ searchValue }}>
51+
<LoadingContent isLoading={!treeData} ref={ref} className={classnames(className, styles.treeBox)}>
52+
{treeNodes}
53+
</LoadingContent>
54+
</Context.Provider>
55+
);
56+
};
4157

4258
const TreeNode = memo((props: TreeNodeIProps) => {
43-
const { data: initData, level } = props;
59+
const { data: initData, level, setShowParentNode: _setShowParentNode } = props;
4460
const [isLoading, setIsLoading] = useState(false);
4561
const indentArr = new Array(level).fill('indent');
4662
const [treeNodeData, setTreeNodeData] = useState<ITreeNode>({
4763
...initData,
4864
});
65+
const { searchValue } = useContext(Context);
4966
const isFocus = useTreeStore((state) => state.focusId) === treeNodeData.uuid;
5067

68+
const showTreeNode = useMemo(() => {
69+
const reg = new RegExp(searchValue || '', 'i');
70+
return reg.test(treeNodeData.name || '');
71+
}, [searchValue]);
72+
73+
// 如果showTreeNode为true,那么他的父节点也要展示
74+
const [showParentNode, setShowParentNode] = useState<boolean>(false);
75+
76+
useEffect(() => {
77+
if(showTreeNode){
78+
_setShowParentNode?.(true);
79+
}
80+
}, [showTreeNode]);
81+
82+
useEffect(() => {
83+
if(showParentNode){
84+
_setShowParentNode?.(true);
85+
}
86+
}, [showParentNode]);
87+
5188
// 加载数据
5289
function loadData(_props?: { refresh: boolean }) {
5390
const treeNodeConfig: ITreeConfigItem = treeConfig[treeNodeData.pretendNodeType || treeNodeData.treeNodeType];
@@ -118,24 +155,6 @@ const TreeNode = memo((props: TreeNodeIProps) => {
118155
}
119156
};
120157

121-
// function nodeDoubleClick() {
122-
// if (
123-
// data.treeNodeType === TreeNodeType.TABLE ||
124-
// data.treeNodeType === TreeNodeType.FUNCTION ||
125-
// data.treeNodeType === TreeNodeType.TRIGGER ||
126-
// data.treeNodeType === TreeNodeType.VIEW ||
127-
// data.treeNodeType === TreeNodeType.PROCEDURE
128-
// ) {
129-
// dispatch({
130-
// type: 'workspace/setDoubleClickTreeNodeData',
131-
// payload: data,
132-
// });
133-
// }
134-
// else {
135-
// handleClick(data);
136-
// }
137-
// }
138-
139158
// 点击节点
140159
const handelClickTreeNode = () => {
141160
useCommonStore.setState({
@@ -144,17 +163,15 @@ const TreeNode = memo((props: TreeNodeIProps) => {
144163
setFocusId(treeNodeData.uuid || '');
145164
};
146165

147-
//
166+
//
148167
const handelDoubleClickTreeNode = () => {
149-
if (treeNodeData.treeNodeType === TreeNodeType.TABLE) {
150-
rightClickMenu.find((item) => item.type === OperationColumn.OpenTable)?.onClick();
151-
}
152-
}
168+
rightClickMenu.find((item) => item.doubleClickTrigger)?.onClick();
169+
};
153170

154171
// 递归渲染
155172
const treeNodes = useMemo(() => {
156173
return treeNodeData.children?.map((item: any, index: number) => {
157-
return <TreeNode key={item.name + index} level={level + 1} data={item} />;
174+
return <TreeNode setShowParentNode={setShowParentNode} key={item.name + index} level={level + 1} data={item} />;
158175
});
159176
}, [treeNodeData]);
160177

@@ -234,10 +251,10 @@ const TreeNode = memo((props: TreeNodeIProps) => {
234251

235252
return (
236253
<>
237-
{treeNodeDom}
254+
{(showTreeNode || showParentNode) && treeNodeDom}
238255
{treeNodes}
239256
</>
240257
);
241258
});
242259

243-
export default Tree;
260+
export default memo(forwardRef(Tree)) ;

chat2db-client/src/components/ConnectionEdit/config/dataSource.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,8 @@ export const dataSourceFormConfigs: IConnectionConfig[] = [
450450
},
451451
}],
452452
onChange: (data: IConnectionConfig) => {
453-
data.baseInfo.pattern = /jdbc:oracle:(.*):@\/\/(.*):(\d+):(.*)/;
454-
data.baseInfo.template = 'jdbc:oracle:{driver}:@//{host}:{port}:{serviceName}';
453+
data.baseInfo.pattern = /jdbc:oracle:(.*):@\/\/(.*):(\d+)\/(.*)/;
454+
data.baseInfo.template = 'jdbc:oracle:{driver}:@//{host}:{port}/{serviceName}';
455455
return data
456456
}
457457
},
@@ -470,15 +470,17 @@ export const dataSourceFormConfigs: IConnectionConfig[] = [
470470
labelTextAlign: 'right',
471471
selects: [
472472
{
473-
value: 'thin',
473+
value: 'THIN',
474+
label: 'thin',
474475
},
475476
{
476-
477-
value: 'oci',
477+
value: 'OCI',
478+
label: 'oci',
478479
},
479480
{
480481

481-
value: 'oci8',
482+
value: 'OCI8',
483+
label: 'oci8',
482484
},
483485
],
484486
styles: {

0 commit comments

Comments
 (0)