Skip to content

Commit 1bb0e97

Browse files
author
单贺喜
committed
delete table add table pin
1 parent 311c6d0 commit 1bb0e97

10 files changed

Lines changed: 130 additions & 84 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@import '../../styles/var.less';
2+
3+
.box {
4+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, { memo, useEffect, useRef, useState, ForwardedRef } from 'react';
2+
import styles from './index.less';
3+
import classnames from 'classnames';
4+
import MonacoEditor, { IExportRefFunction, IRangeType } from '@/components/Console/MonacoEditor';
5+
import { Modal } from 'antd'
6+
7+
interface IProps {
8+
className?: string;
9+
verifyDialog: boolean;
10+
title: string;
11+
value: {
12+
text: string;
13+
range: IRangeType;
14+
}
15+
}
16+
17+
export default memo<IProps>(function EditDialog(props) {
18+
const { className, verifyDialog, value, title } = props;
19+
const [open, setOpen] = useState<boolean>();
20+
const monacoEditorRef = useRef<any>();
21+
22+
useEffect(() => {
23+
setOpen(verifyDialog)
24+
}, [verifyDialog])
25+
26+
27+
useEffect(() => {
28+
if (monacoEditorRef.current) {
29+
monacoEditorRef.current?.setValue(value.text, value.range)
30+
}
31+
}, [value])
32+
33+
return <div className={classnames(styles.box, className)}>
34+
<Modal
35+
title={title}
36+
open={open}
37+
width={800}
38+
// onCancel={(() => { setVerifyDialog(false) })}
39+
>
40+
<MonacoEditor id='edit-dialog' ref={monacoEditorRef}></MonacoEditor>
41+
</Modal>
42+
</div>
43+
})

chat2db-client/src/components/Tabs/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
.tab {
2222
display: flex;
23-
padding: 18px 10px 0px 10px;
23+
padding: 18px 4px 0px 4px;
2424
}
2525

2626
.tabList {

chat2db-client/src/models/workspace.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ const WorkspaceModel: IWorkspaceModelType = {
110110
payload: res.data,
111111
});
112112
},
113-
*fetchGetCurTableList({ payload }, { put }) {
113+
*fetchGetCurTableList({ payload, callback }, { put,call }) {
114114
// yield put({
115115
// type: 'setCurTableList',
116116
// payload: undefined,
@@ -120,6 +120,10 @@ const WorkspaceModel: IWorkspaceModelType = {
120120
pageSize: 999,
121121
...payload,
122122
})) as ITreeNode[];
123+
// 异步操作完成后调用回调函数
124+
if (callback && typeof callback === 'function') {
125+
callback(res);
126+
}
123127
yield put({
124128
type: 'setCurTableList',
125129
payload: res,

chat2db-client/src/pages/main/workspace/components/Tree/TreeNodeRightClick/index.tsx

Lines changed: 52 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ import { ITreeConfigItem, ITreeConfig, treeConfig } from '@/pages/main/workspace
1313
import { ITreeNode } from '@/typings';
1414
// import { DatabaseContext } from '@/context/database';
1515
import connectionServer from '@/service/connection';
16+
import historyService from '@/service/history';
1617
import mysqlServer from '@/service/sql';
1718
import { OperationColumn } from '../treeConfig';
1819
import { dataSourceFormConfigs } from '@/components/CreateConnection/config/dataSource';
1920
import { IConnectionConfig } from '@/components/CreateConnection/config/types';
2021
import { IWorkspaceModelType } from '@/models/workspace';
21-
22+
import EditDialog from '@/components/EditDialog';
23+
import { ConsoleStatus, ConsoleOpenedStatus } from '@/constants'
2224

2325
type MenuItem = Required<MenuProps>['items'][number];
2426

@@ -64,13 +66,7 @@ function TreeNodeRightClick(props: IProps) {
6466
text: '导出ddl',
6567
icon: '\ue613',
6668
handle: () => {
67-
const operationData: IOperationData = {
68-
type: 'export',
69-
nodeData: data
70-
}
71-
if (operationData.type === 'export') {
72-
// setOperationDataDialog(operationData);
73-
}
69+
7470
}
7571
}
7672
},
@@ -105,14 +101,7 @@ function TreeNodeRightClick(props: IProps) {
105101
text: '新建查询',
106102
icon: '\ue619',
107103
handle: () => {
108-
console.log(data)
109-
// setCreateConsoleDialog({
110-
// dataSourceId: data.dataSourceId!,
111-
// dataSourceName: data.dataSourceName!,
112-
// databaseName: data.databaseName!,
113-
// schemaName: data.schemaName!,
114-
// databaseType: data.dataType! as DatabaseTypeCode
115-
// })
104+
116105
}
117106
}
118107
},
@@ -121,41 +110,17 @@ function TreeNodeRightClick(props: IProps) {
121110
text: '删除表',
122111
icon: '\ue6a7',
123112
handle: () => {
124-
modalApi.confirm({
125-
title: i18n('common.tips.deleteTable'),
126-
icon: <ExclamationCircleFilled />,
127-
content: `${i18n('common.text.tableName')}${data.name}`,
128-
okText: i18n('common.button.delete'),
129-
okType: 'danger',
130-
cancelText: i18n('common.button.cancel'),
131-
onOk() {
132-
let p: any = {
133-
...data.extraParams,
134-
tableName: data.name,
135-
}
136-
mysqlServer.deleteTable(p).then(res => {
137-
notificationApi.success(
138-
{
139-
message: '删除成功',
140-
}
141-
)
142-
dispatch({
143-
type: 'workspace/fetchGetCurTableList',
144-
payload: {
145-
...curWorkspaceParams,
146-
extraParams: curWorkspaceParams,
147-
}
148-
})
149-
})
150-
},
151-
});
152-
// setCreateConsoleDialog({
153-
// dataSourceId: data.dataSourceId!,
154-
// dataSourceName: data.dataSourceName!,
155-
// databaseName: data.databaseName!,
156-
// schemaName: data.schemaName!,
157-
// databaseType: data.dataType! as DatabaseTypeCode
158-
// })
113+
setVerifyDialog(true);
114+
// modalApi.confirm({
115+
// title: i18n('common.tips.deleteTable'),
116+
// icon: <ExclamationCircleFilled />,
117+
// content: `${i18n('common.text.tableName')}:${data.name}`,
118+
// okText: i18n('common.button.delete'),
119+
// okType: 'danger',
120+
// cancelText: i18n('common.button.cancel'),
121+
// onOk() {
122+
// },
123+
// });
159124
}
160125
}
161126
},
@@ -183,7 +148,19 @@ function TreeNodeRightClick(props: IProps) {
183148
}
184149

185150
function handelTop() {
186-
data.pinned
151+
const api = data.pinned ? 'deleteTablePin' : 'addTablePin'
152+
mysqlServer[api]({
153+
...curWorkspaceParams,
154+
tableName: data.name
155+
} as any).then(res => {
156+
dispatch({
157+
type: 'workspace/fetchGetCurTableList',
158+
payload: {
159+
...curWorkspaceParams,
160+
extraParams: curWorkspaceParams,
161+
}
162+
})
163+
})
187164
}
188165

189166
function refresh() {
@@ -201,19 +178,29 @@ function TreeNodeRightClick(props: IProps) {
201178
}
202179

203180
function handleOk() {
204-
let p = {
205-
tableName: verifyTableName,
206-
dataSourceId: data.dataSourceId!,
207-
databaseName: data.databaseName!
208-
}
209-
if (verifyTableName === data.tableName) {
181+
if (verifyTableName === data.name) {
182+
let p: any = {
183+
...data.extraParams,
184+
tableName: data.name,
185+
}
210186
mysqlServer.deleteTable(p).then(res => {
211-
setVerifyDialog(false);
212-
// setNeedRefreshNodeTree({
213-
// databaseName: data.databaseName,
214-
// dataSourceId: data.dataSourceId,
215-
// nodeType: TreeNodeType.TABLES
216-
// })
187+
notificationApi.success(
188+
{
189+
message: '删除成功',
190+
}
191+
)
192+
dispatch({
193+
type: 'workspace/fetchGetCurTableList',
194+
payload: {
195+
...curWorkspaceParams,
196+
extraParams: curWorkspaceParams,
197+
},
198+
callback: () => {
199+
setVerifyDialog(false);
200+
setVerifyTableName('');
201+
}
202+
})
203+
217204
})
218205
} else {
219206
message.error('输入的表名与要删除的表名不一致,请再次确认')
@@ -272,22 +259,9 @@ function TreeNodeRightClick(props: IProps) {
272259
</div>
273260
</Dropdown>
274261
}
275-
{/* <div className={styles.menuBox}>
276-
<div>
277-
{
278-
excludeSomeOperation()?.map((item, index) => {
279-
const concrete = OperationColumnConfig[item](data);
280-
return <div key={index} onClick={() => { concrete.handle(); }}>
281-
{concrete.text}
282-
<Iconfont code={concrete.icon} />
283-
</div>
284-
})
285-
}
286-
</div>
287-
</div> */}
288262
<Modal
289263
maskClosable={false}
290-
title="删除确认"
264+
title={`删除表-${data.name}`}
291265
open={verifyDialog}
292266
onOk={handleOk}
293267
width={400}

chat2db-client/src/pages/main/workspace/components/Tree/treeConfig.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export const treeConfig: { [key in TreeNodeType]: ITreeConfigItem } = {
224224
})
225225
},
226226
operationColumn: [
227-
OperationColumn.CreateConsole, OperationColumn.ExportDDL, OperationColumn.DeleteTable, OperationColumn.Top
227+
OperationColumn.ExportDDL, OperationColumn.DeleteTable, OperationColumn.Top
228228
],
229229
},
230230
[TreeNodeType.COLUMNS]: {

chat2db-client/src/pages/main/workspace/components/WorkspaceLeft/index.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
flex-direction: column;
66
height: 100%;
77
background-color: var(--color-bg-elevated);
8-
border-left: 1px solid var(--color-border);
98
padding: 10px 20px 0px;
109
box-sizing: border-box;
1110
min-width: 200px;

chat2db-client/src/pages/main/workspace/index.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
width: 220px;
1010
height: 100%;
1111
overflow: hidden;
12+
border: 1px solid var(--color-border-secondary);
13+
border-top: 0px;
14+
border-bottom: 0px;
1215
}
1316

1417
.boxRight {

chat2db-client/src/service/sql.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import createRequest from './base';
2-
import { IPageResponse, IPageParams } from '@/typings';
2+
import { IPageResponse, IPageParams, IUniversalTableParams } from '@/typings';
33
import { DatabaseTypeCode } from '@/constants';
44

55
export interface IGetListParams extends IPageParams {
@@ -102,6 +102,16 @@ const getDatabaseSchemaList = createRequest<{ dataSourceId: number; }, MetaSchem
102102
{ method: 'get' }
103103
);
104104

105+
const addTablePin = createRequest<IUniversalTableParams, void>(
106+
'/api/pin/table/add',
107+
{ method: 'post' }
108+
);
109+
110+
const deleteTablePin = createRequest<IUniversalTableParams, void>(
111+
'/api/pin/table/delete',
112+
{ method: 'post' }
113+
);
114+
105115
export default {
106116
getList,
107117
executeSql,
@@ -115,5 +125,7 @@ export default {
115125
getIndexList,
116126
getKeyList,
117127
getSchemaList,
118-
getDatabaseSchemaList
128+
getDatabaseSchemaList,
129+
addTablePin,
130+
deleteTablePin
119131
};

chat2db-client/src/typings/common.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ export interface Option {
3636
}
3737

3838
export type ICreateConsole = Omit<IConsole, 'id' | 'dataSourceName' | 'connectable'>;
39+
40+
export interface IUniversalTableParams {
41+
dataSourceId: string;
42+
databaseName?: string;
43+
schemaName?: string;
44+
tableName?: string;
45+
}

0 commit comments

Comments
 (0)