Skip to content

Commit 96a6357

Browse files
committed
【New Features】Edit table structure supports setting primary keys in columns
1 parent 63cefc1 commit 96a6357

6 files changed

Lines changed: 55 additions & 1 deletion

File tree

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"chmod",
1616
"CLOB",
1717
"datasource",
18+
"Datetime",
1819
"DBAI",
1920
"DBHUB",
2021
"Dchat",
@@ -46,6 +47,7 @@
4647
"pgsql",
4748
"pnpm",
4849
"Popconfirm",
50+
"Prec",
4951
"quickinput",
5052
"redownload",
5153
"remaininguses",
@@ -62,6 +64,7 @@
6264
"umirc",
6365
"USERANDPASSWORD",
6466
"uuidv",
67+
"VARCHAR",
6568
"VIEWCOLUMN",
6669
"VIEWCOLUMNS",
6770
"wechat",

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@
8585
// }
8686
// }
8787

88+
.keyBox{
89+
width: 26px;
90+
height: 26px;
91+
display: flex;
92+
justify-content: center;
93+
align-items: center;
94+
cursor: pointer;
95+
i{
96+
color: var(--color-warning);
97+
}
98+
}
99+
88100
.operationBar {
89101
display: flex;
90102
justify-content: end;

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,23 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)
226226
);
227227
},
228228
},
229+
{
230+
title: i18n('editTable.label.primaryKey'),
231+
dataIndex: 'primaryKey',
232+
width: '50px',
233+
render: (primaryKey: boolean, record: IColumnItemNew) => {
234+
return (
235+
<div>
236+
<div className={styles.keyBox} onClick={()=>{handelPrimaryKey(record)} }>
237+
{
238+
primaryKey &&
239+
<Iconfont code="&#xe775;" />
240+
}
241+
</div>
242+
</div>
243+
);
244+
},
245+
},
229246
{
230247
title: i18n('editTable.label.comment'),
231248
dataIndex: 'comment',
@@ -263,6 +280,26 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)
263280
},
264281
];
265282

283+
const handelPrimaryKey = (_data: IColumnItemNew)=>{
284+
const newData = dataSource.map((item) => {
285+
if (item.key === _data?.key) {
286+
// 判断当前数据是新增的数据还是编辑后的数据
287+
let editStatus = item.editStatus;
288+
if (editStatus !== EditColumnOperationType.Add) {
289+
editStatus = EditColumnOperationType.Modify;
290+
}
291+
const editingDataItem = {
292+
...item,
293+
primaryKey: !item.primaryKey,
294+
editStatus,
295+
};
296+
return editingDataItem;
297+
}
298+
return item;
299+
});
300+
setDataSource(newData);
301+
}
302+
266303
const onDragEnd = ({ active, over }: DragEndEvent) => {
267304
if (active.id !== over?.id) {
268305
setDataSource((previous) => {

chat2db-client/src/i18n/en-us/editTable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default {
3131
'editTable.label.engine': 'Engine',
3232
'editTable.label.incrementValue': 'Increment value',
3333
'editTable.label.order': 'Order',
34+
'editTable.label.primaryKey': 'Key',
3435
'editTable.title.sqlPreview': 'SQL preview',
3536
'editTable.button.addColumn': 'Add column',
3637
'editTable.button.addIndex': 'Add Index',

chat2db-client/src/i18n/zh-cn/editTable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default {
3131
'editTable.label.engine': '引擎',
3232
'editTable.label.incrementValue': '自增值',
3333
'editTable.label.order': '排序',
34+
'editTable.label.primaryKey': '键',
3435
'editTable.title.sqlPreview': 'sql预览',
3536
'editTable.button.addColumn': '添加列',
3637
'editTable.button.addIndex': '添加索引',

chat2db-client/src/typings/editTable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface IColumnItemNew {
2525
defaultValue: string | null; // 默认值
2626
autoIncrement: string | null; // 是否自增
2727
comment: string | null; // 注释
28-
primaryKey: string | null; // 是否主键
28+
primaryKey: boolean | null; // 是否主键
2929
typeName: string | null; // 类型名
3030
columnSize: number | null; // 列的长度
3131
bufferLength: number | null; // 缓冲区长度

0 commit comments

Comments
 (0)