Skip to content

Commit 5f62c0a

Browse files
committed
create schema
1 parent 4120b63 commit 5f62c0a

23 files changed

Lines changed: 217 additions & 141 deletions

File tree

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ export default memo<IProps>((props) => {
4444
[styles.showCreateConnections]: connectionDetail,
4545
})}
4646
>
47-
<ConnectionEdit connectionData={connectionDetail as any} submit={handleSubmit} />
47+
<ConnectionEdit
48+
closeCreateConnection={() => {
49+
setConnectionDetail(null);
50+
}}
51+
connectionData={connectionDetail as any}
52+
submit={handleSubmit}
53+
/>
4854
</div>
4955
)}
5056
{!connectionDetail && (
@@ -77,8 +83,8 @@ export default memo<IProps>((props) => {
7783
);
7884
});
7985

80-
81-
{/* <div className={styles.notPermission}>
86+
{
87+
/* <div className={styles.notPermission}>
8288
<div className={styles.notPermissionIconBox}>
8389
<Iconfont className={styles.notPermissionIcon} code="&#xe658;" />
8490
</div>
@@ -95,4 +101,5 @@ export default memo<IProps>((props) => {
95101
{i18n('connection.button.connect')}
96102
</Button>
97103
</div>
98-
</div> */}
104+
</div> */
105+
}

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { useMemo } from 'react';
1313

1414
// ----- store -----
1515
import { createConsole, addWorkspaceTab } from '@/store/console';
16+
import { useWorkspaceStore } from '@/store/workspace';
1617

1718
// ---- functions -----
1819
import { openView, openFunction, openProcedure, openTrigger } from '../functions/openAsyncSql';
@@ -35,6 +36,26 @@ interface IOperationColumnConfigItem {
3536
export const useGetRightClickMenu = (props: IProps) => {
3637
const { treeNodeData, loadData } = props;
3738

39+
const { openCreateDatabaseModal } = useWorkspaceStore((state) => {
40+
return {
41+
openCreateDatabaseModal: state.openCreateDatabaseModal,
42+
};
43+
});
44+
45+
const handelOpenCreateDatabaseModal = (type: 'database' |'schema') => {
46+
openCreateDatabaseModal?.({
47+
type,
48+
relyOnParams: {
49+
databaseType: treeNodeData.extraParams!.databaseType,
50+
dataSourceId: treeNodeData.extraParams!.dataSourceId!,
51+
databaseName: treeNodeData?.name,
52+
},
53+
executedCallback: () => {
54+
loadData(true);
55+
}
56+
});
57+
}
58+
3859
const rightClickMenu = useMemo(() => {
3960
// 拿出当前节点的配置
4061
const treeNodeConfig: ITreeConfigItem = treeConfig[treeNodeData.treeNodeType];
@@ -169,7 +190,7 @@ export const useGetRightClickMenu = (props: IProps) => {
169190
doubleClickTrigger: true,
170191
handle: () => {
171192
const databaseName = compatibleDataBaseName(
172-
treeNodeData.extraParams!.databaseName!,
193+
treeNodeData.name!,
173194
treeNodeData.extraParams!.databaseType,
174195
);
175196
addWorkspaceTab({
@@ -181,7 +202,7 @@ export const useGetRightClickMenu = (props: IProps) => {
181202
databaseType: treeNodeData.extraParams!.databaseType!,
182203
databaseName: treeNodeData.extraParams?.databaseName,
183204
schemaName: treeNodeData.extraParams?.schemaName,
184-
sql: `select * from ${databaseName}`,
205+
sql: "select * from " + databaseName,
185206
},
186207
});
187208
},
@@ -238,6 +259,24 @@ export const useGetRightClickMenu = (props: IProps) => {
238259
});
239260
},
240261
},
262+
263+
// 创建数据库
264+
[OperationColumn.CreateDatabase]: {
265+
text: i18n('workspace.menu.createDatabase'),
266+
icon: '\ue816',
267+
handle: () => {
268+
handelOpenCreateDatabaseModal('database');
269+
},
270+
},
271+
272+
// 创建schema
273+
[OperationColumn.CreateSchema]: {
274+
text: i18n('workspace.menu.createSchema'),
275+
icon: '\ue696',
276+
handle: () => {
277+
handelOpenCreateDatabaseModal('schema');
278+
},
279+
}
241280
};
242281

243282
// 根据配置生成右键菜单

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
box-sizing: border-box;
66
overflow: hidden;
77
overflow-y: auto;
8+
height: 100%;
9+
}
10+
11+
.leftModuleTitleShadow{
12+
border-top: 1px solid red;
813
}
914

1015
.treeNode {
@@ -74,7 +79,7 @@
7479
.arrows {
7580
flex-shrink: 0;
7681
height: 20px;
77-
width: 20px;
82+
width: 18px;
7883
display: flex;
7984
align-items: center;
8085
transform: rotate(0deg);

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ 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'
14+
import LoadingContent from '@/components/Loading/LoadingContent';
1515

1616
interface IProps {
1717
className?: string;
1818
initialData: ITreeNode[] | null;
1919
searchValue: string;
20-
ref: any;
2120
}
22-
2321
interface TreeNodeIProps {
2422
data: ITreeNode;
2523
level: number;
@@ -32,7 +30,7 @@ interface IContext {
3230

3331
export const Context = createContext<IContext>({} as any);
3432

35-
const Tree = (props: IProps, ref: any) => {
33+
const Tree = (props: IProps) => {
3634
const { className, initialData, searchValue } = props;
3735
const [treeData, setTreeData] = useState<ITreeNode[] | null>(null);
3836

@@ -48,8 +46,10 @@ const Tree = (props: IProps, ref: any) => {
4846

4947
return (
5048
<Context.Provider value={{ searchValue }}>
51-
<LoadingContent isLoading={!treeData} ref={ref} className={classnames(className, styles.treeBox)}>
52-
{treeNodes}
49+
<LoadingContent isLoading={!treeData} className={classnames(className)}>
50+
<div className={styles.treeBox}>
51+
{treeNodes}
52+
</div>
5353
</LoadingContent>
5454
</Context.Provider>
5555
);
@@ -74,13 +74,13 @@ const TreeNode = memo((props: TreeNodeIProps) => {
7474
const [showParentNode, setShowParentNode] = useState<boolean>(false);
7575

7676
useEffect(() => {
77-
if(showTreeNode){
77+
if (showTreeNode) {
7878
_setShowParentNode?.(true);
7979
}
8080
}, [showTreeNode]);
8181

8282
useEffect(() => {
83-
if(showParentNode){
83+
if (showParentNode) {
8484
_setShowParentNode?.(true);
8585
}
8686
}, [showParentNode]);
@@ -257,4 +257,4 @@ const TreeNode = memo((props: TreeNodeIProps) => {
257257
);
258258
});
259259

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type ITreeConfig = Partial<{ [key in TreeNodeType]: ITreeConfigItem }>;
99

1010
export const switchIcon: Partial<{ [key in TreeNodeType]: { icon: string; unfoldIcon?: string } }> = {
1111
[TreeNodeType.DATABASE]: {
12-
icon: '\ue62c',
12+
icon: '\ue669',
1313
},
1414
[TreeNodeType.SCHEMAS]: {
1515
icon: '\ue696',
@@ -181,7 +181,7 @@ export const treeConfig: { [key in TreeNodeType]: ITreeConfigItem } = {
181181
},
182182
operationColumn: [
183183
OperationColumn.CreateConsole,
184-
OperationColumn.CreateTable,
184+
OperationColumn.CreateSchema,
185185
OperationColumn.CopyName,
186186
OperationColumn.Refresh,
187187
],
@@ -234,7 +234,7 @@ export const treeConfig: { [key in TreeNodeType]: ITreeConfigItem } = {
234234
r(data);
235235
});
236236
},
237-
operationColumn: [OperationColumn.CreateConsole, OperationColumn.CreateTable, OperationColumn.Refresh],
237+
operationColumn: [OperationColumn.CreateConsole, OperationColumn.Refresh],
238238
},
239239

240240
[TreeNodeType.TABLES]: {

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export enum submitType {
2828
}
2929

3030
interface IProps {
31-
className?: string;
32-
// closeCreateConnection: () => void;
31+
closeCreateConnection: () => void;
3332
connectionData: IConnectionDetails;
3433
submitCallback?: any;
3534
submit?: (data: IConnectionDetails) => void;
@@ -40,7 +39,7 @@ export interface ICreateConnectionFunction {
4039
}
4140

4241
const ConnectionEdit = forwardRef((props: IProps, ref: ForwardedRef<ICreateConnectionFunction>) => {
43-
const { className, submitCallback, connectionData, submit } = props;
42+
const { closeCreateConnection, submitCallback, connectionData, submit } = props;
4443
const [baseInfoForm] = Form.useForm();
4544
const [sshForm] = Form.useForm();
4645
const [driveData, setDriveData] = useState<any>({});
@@ -228,12 +227,11 @@ const ConnectionEdit = forwardRef((props: IProps, ref: ForwardedRef<ICreateConne
228227
}
229228

230229
function onCancel() {
231-
// closeCreateConnection();
232-
// setEditDataSourceData(false)
230+
closeCreateConnection();
233231
}
234232

235233
function testSSH() {
236-
let p = sshForm.getFieldsValue();
234+
const p = sshForm.getFieldsValue();
237235
setLoading({
238236
...loadings,
239237
sshTestLoading: true,
@@ -279,9 +277,9 @@ const ConnectionEdit = forwardRef((props: IProps, ref: ForwardedRef<ICreateConne
279277
}
280278
</div>
281279
<div className={styles.rightButton}>
282-
{/* <Button onClick={onCancel} className={styles.cancel}>
280+
<Button onClick={onCancel} className={styles.cancel}>
283281
{i18n('common.button.cancel')}
284-
</Button> */}
282+
</Button>
285283
<Button
286284
className={styles.save}
287285
type="primary"

0 commit comments

Comments
 (0)