Skip to content

Commit

Permalink
feat:edit table base info
Browse files Browse the repository at this point in the history
  • Loading branch information
shanhexi committed Sep 24, 2023
1 parent 38dc7bb commit e5b69c5
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 54 deletions.
19 changes: 14 additions & 5 deletions chat2db-client/src/blocks/DatabaseTableEditor/BaseInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const BaseInfo = forwardRef((props: IProps, ref: ForwardedRef<IBaseInfoRef>) =>
form.setFieldsValue({
name: tableDetails.name,
comment: tableDetails.comment,
charset: tableDetails.charset,
engine: tableDetails.engine,
incrementValue: tableDetails.incrementValue,
});
}, [tableDetails]);

Expand All @@ -38,20 +41,26 @@ const BaseInfo = forwardRef((props: IProps, ref: ForwardedRef<IBaseInfoRef>) =>
<div className={classnames(className, styles.box)}>
<div className={styles.formBox}>
<Form
// labelCol={{
// style: { width: 90 },
// }}
layout="vertical"
form={form}
initialValues={{ remember: true }}
autoComplete="off"
className={styles.form}
>
<Form.Item label={`${i18n('editTable.label.tableName')}:`} name="name">
<Input />
<Input autoComplete="off" />
</Form.Item>
<Form.Item label={`${i18n('editTable.label.comment')}:`} name="comment">
<Input />
<Input autoComplete="off" />
</Form.Item>
<Form.Item label={`${i18n('editTable.label.characterSet')}:`} name="charset">
<Input autoComplete="off" />
</Form.Item>
<Form.Item label={`${i18n('editTable.label.engine')}:`} name="engine">
<Input autoComplete="off" />
</Form.Item>
<Form.Item label={`${i18n('editTable.label.incrementValue')}:`} name="incrementValue">
<Input autoComplete="off" />
</Form.Item>
</Form>
</div>
Expand Down
28 changes: 23 additions & 5 deletions chat2db-client/src/blocks/DatabaseTableEditor/ColumnList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ const createInitialData = () => {
ordinalPosition: null,
nullable: null,
generatedColumn: null,
charSetName: null,
collationName: null,
value: null,
editStatus: EditColumnOperationType.Add,
};
};
Expand Down Expand Up @@ -230,7 +233,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)
const editable = isEditing(record);
return editable ? (
<Form.Item name="name" style={{ margin: 0 }}>
<Input />
<Input autoComplete="off" />
</Form.Item>
) : (
<div className={styles.editableCell}>{text}</div>
Expand Down Expand Up @@ -297,7 +300,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)
const editable = isEditing(record);
return editable ? (
<Form.Item name="comment" style={{ margin: 0 }}>
<Input disabled={!editingConfig?.supportComments} />
<Input autoComplete="off" disabled={!editingConfig?.supportComments} />
</Form.Item>
) : (
<div className={styles.editableCell}>{text}</div>
Expand Down Expand Up @@ -429,6 +432,16 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)

return (
<>
{editingConfig?.supportAutoIncrement && (
<Form.Item
labelCol={labelCol}
label={i18n('editTable.label.autoIncrement')}
name="autoIncrement"
valuePropName="checked"
>
<Checkbox />
</Form.Item>
)}
{editingConfig?.supportDefaultValue && (
<Form.Item labelCol={labelCol} label={i18n('editTable.label.defaultValue')} name="defaultValue">
<CustomSelect
Expand All @@ -446,18 +459,23 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef<IColumnListRef>)
</Form.Item>
)}
{editingConfig?.supportCharset && (
<Form.Item labelCol={labelCol} label={i18n('editTable.label.characterSet')} name="characterSet">
<Form.Item labelCol={labelCol} label={i18n('editTable.label.characterSet')} name="charSetName">
<CustomSelect options={databaseSupportField.charsets} />
</Form.Item>
)}
{editingConfig?.supportCollation && (
<Form.Item labelCol={labelCol} label={i18n('editTable.label.collation')} name="collation">
<Form.Item labelCol={labelCol} label={i18n('editTable.label.collation')} name="collationName">
<CustomSelect options={databaseSupportField.collations} />
</Form.Item>
)}
{editingConfig?.supportScale && (
<Form.Item labelCol={labelCol} label={i18n('editTable.label.decimalPoint')} name="decimalPoint">
<Input />
<Input autoComplete="off" />
</Form.Item>
)}
{editingConfig?.supportValue && (
<Form.Item labelCol={labelCol} label={i18n('editTable.label.value')} name="value">
<Input autoComplete="off" />
</Form.Item>
)}
</>
Expand Down
41 changes: 23 additions & 18 deletions chat2db-client/src/blocks/DatabaseTableEditor/IncludeCol/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,33 @@ interface IProps {
const createInitialData = () => {
return {
key: uuidv4(),
name: null,
ascOrDesc: null, // 升序还是降序
cardinality: null, // 基数
collation: null, // 排序规则
columnName: null, // 列名
comment: null, // 注释
filterCondition: null, // 过滤条件
indexName: null, // 索引名
indexQualifier: null, // 索引限定符
nonUnique: null, // 是否唯一
ordinalPosition: null, // 位置
schemaName: null, // 模式名
type: null, // 类型
pages: null, // 页数

databaseName: null, // 数据库名
tableName: null, // 表名
};
};

export interface IIncludeColRef {
getIncludeColInfo: () => IIndexIncludeColumnItem[];
}

const InitialDataSource = [createInitialData()];

const IncludeCol = forwardRef((props: IProps, ref: ForwardedRef<IIncludeColRef>) => {
const { includedColumnList } = props;
const { columnListRef } = useContext(Context);
const [dataSource, setDataSource] = useState<any[]>(InitialDataSource);
const [dataSource, setDataSource] = useState<IIndexIncludeColumnItem[]>([createInitialData()]);
const [form] = Form.useForm();
const [editingKey, setEditingKey] = useState<string | null>(null);
const isEditing = (record: IIndexIncludeColumnItem) => record.key === editingKey;
Expand All @@ -41,8 +54,8 @@ const IncludeCol = forwardRef((props: IProps, ref: ForwardedRef<IIncludeColRef>)
setDataSource(
includedColumnList.map((t) => {
return {
...t,
key: uuidv4(),
name: t.name,
};
}),
);
Expand Down Expand Up @@ -81,12 +94,12 @@ const IncludeCol = forwardRef((props: IProps, ref: ForwardedRef<IIncludeColRef>)
},
{
title: i18n('editTable.label.columnName'),
dataIndex: 'name',
dataIndex: 'columnName',
// width: '45%',
render: (text: string, record: IIndexIncludeColumnItem) => {
const editable = isEditing(record);
return editable ? (
<Form.Item name="name" style={{ margin: 0 }}>
<Form.Item name="columnName" style={{ margin: 0 }}>
<Select options={columnList.map((i) => ({ label: i.name, value: i.name }))} />
</Form.Item>
) : (
Expand Down Expand Up @@ -131,18 +144,10 @@ const IncludeCol = forwardRef((props: IProps, ref: ForwardedRef<IIncludeColRef>)
setDataSource(newData);
};

const getIncludeColInfo = () => {
const includeColInfo: IIndexIncludeColumnItem[] = [];
dataSource.forEach((t) => {
columnList.forEach((columnItem) => {
if (t.name === columnItem.name) {
includeColInfo.push({
...lodash.omit(columnItem, 'key'),
});
}
});
const getIncludeColInfo = (): IIndexIncludeColumnItem[] => {
return dataSource.map((t) => {
return lodash.omit(t, 'key');
});
return includeColInfo;
};

useImperativeHandle(ref, () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, {
useRef,
useMemo,
useEffect,
useCallback,
} from 'react';
import styles from './index.less';
import classnames from 'classnames';
Expand Down Expand Up @@ -195,7 +194,7 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef<IIndexListRef>) =
const editable = isEditing(record);
return editable ? (
<Form.Item name="name" style={{ margin: 0 }}>
<Input />
<Input autoComplete="off" />
</Form.Item>
) : (
<div className={styles.editableCell}>{text}</div>
Expand Down Expand Up @@ -230,7 +229,7 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef<IIndexListRef>) =
const editable = isEditing(record);
const text = columnList
?.map((t) => {
return `${t.name}`;
return `${t.columnName}`;
})
.join(',');
return editable ? (
Expand Down
19 changes: 3 additions & 16 deletions chat2db-client/src/blocks/DatabaseTableEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,6 @@ export default memo((props: IProps) => {
};
sqlService.getTableDetails(params).then((res) => {
const newTableDetails = lodash.cloneDeep(res);
newTableDetails.indexList.forEach((i) => {
i.columnList = i.columnList.map((j: any) => {
let newColumn: any = {};
newTableDetails.columnList.forEach((k: any) => {
if (j.columnName === k.name) {
newColumn = k;
}
});
return newColumn;
});
});
console.log(newTableDetails);
setTableDetails(newTableDetails || {});
setOldTableDetails(res);
});
Expand Down Expand Up @@ -130,9 +118,8 @@ export default memo((props: IProps) => {
schemaName,
};

// 获取当前SQL的查询结果
sqlService.executeSql(executeSQLParams).then((res) => {
message.success('修改成功');
sqlService.executeSql(executeSQLParams).then(() => {
message.success(i18n('common.text.successfulExecution'));
setViewSqlModal(false);
});
};
Expand Down Expand Up @@ -179,7 +166,7 @@ export default memo((props: IProps) => {
</div>
</div>
<Modal
title="sql预览"
title={i18n('editTable.title.sqlPreview')}
open={!!viewSqlModal}
onCancel={() => {
setViewSqlModal(false);
Expand Down
11 changes: 10 additions & 1 deletion chat2db-client/src/blocks/Setting/AiSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function SettingAI(props: IProps) {
const [aiConfig, setAiConfig] = useState<IAiConfig>();
const [userInfo, setUserInfo] = useState<ILoginUser>();
const [loading, setLoading] = useState(false);

const queryUserInfo = async () => {
setLoading(true);
try {
Expand Down Expand Up @@ -89,6 +89,7 @@ export default function SettingAI(props: IProps) {
<div className={styles.title}>Api Key</div>
<div className={classnames(styles.content, styles.chatGPTKey)}>
<Input
autoComplete="off"
placeholder={i18n('setting.placeholder.chat2dbApiKey')}
value={aiConfig.apiKey}
onChange={(e) => {
Expand All @@ -103,6 +104,7 @@ export default function SettingAI(props: IProps) {
<div className={styles.title}>Api Key</div>
<div className={classnames(styles.content, styles.chatGPTKey)}>
<Input
autoComplete="off"
placeholder={i18n('setting.placeholder.apiKey')}
value={aiConfig.apiKey}
onChange={(e) => {
Expand All @@ -113,6 +115,7 @@ export default function SettingAI(props: IProps) {
<div className={styles.title}>Api Host</div>
<div className={classnames(styles.content, styles.chatGPTKey)}>
<Input
autoComplete="off"
placeholder={i18n('setting.placeholder.apiHost')}
value={aiConfig.apiHost}
onChange={(e) => {
Expand All @@ -123,6 +126,7 @@ export default function SettingAI(props: IProps) {
<div className={styles.title}>HTTP Proxy Host</div>
<div className={classnames(styles.content, styles.chatGPTKey)}>
<Input
autoComplete="off"
placeholder={i18n('setting.placeholder.httpsProxy', 'host')}
value={aiConfig.httpProxyHost}
onChange={(e) => {
Expand All @@ -136,6 +140,7 @@ export default function SettingAI(props: IProps) {
<div className={styles.title}>HTTP Proxy Port</div>
<div className={classnames(styles.content, styles.chatGPTKey)}>
<Input
autoComplete="off"
placeholder={i18n('setting.placeholder.httpsProxy', 'port')}
value={aiConfig.httpProxyPort}
onChange={(e) => {
Expand All @@ -153,6 +158,7 @@ export default function SettingAI(props: IProps) {
<div className={styles.title}>Api Key</div>
<div className={classnames(styles.content, styles.chatGPTKey)}>
<Input
autoComplete="off"
placeholder={i18n('setting.placeholder.azureOpenAIKey')}
value={aiConfig.apiKey}
onChange={(e) => {
Expand All @@ -163,6 +169,7 @@ export default function SettingAI(props: IProps) {
<div className={styles.title}>Endpoint</div>
<div className={classnames(styles.content, styles.chatGPTKey)}>
<Input
autoComplete="off"
placeholder={i18n('setting.placeholder.azureEndpoint')}
value={aiConfig.apiHost}
onChange={(e) => {
Expand All @@ -173,6 +180,7 @@ export default function SettingAI(props: IProps) {
<div className={styles.title}>DeploymentId</div>
<div className={classnames(styles.content, styles.chatGPTKey)}>
<Input
autoComplete="off"
placeholder={i18n('setting.placeholder.azureDeployment')}
value={aiConfig.model}
onChange={(e) => {
Expand All @@ -190,6 +198,7 @@ export default function SettingAI(props: IProps) {
<div className={styles.title}>{i18n('setting.label.customAiUrl')}</div>
<div className={classnames(styles.content, styles.chatGPTKey)}>
<Input
autoComplete="off"
placeholder={i18n('setting.placeholder.customUrl')}
value={aiConfig.apiHost}
onChange={(e) => {
Expand Down
5 changes: 5 additions & 0 deletions chat2db-client/src/i18n/en-us/editTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ export default {
'editTable.label.defaultValue': 'Default value',
'editTable.label.characterSet': 'Character set',
'editTable.label.collation': 'Collation',
'editTable.label.value': 'Value',
'editTable.label.autoIncrement': 'Auto increment',
'editTable.label.engine': 'Engine',
'editTable.label.incrementValue': 'Increment value',
'editTable.title.sqlPreview': 'SQL preview',
};
5 changes: 5 additions & 0 deletions chat2db-client/src/i18n/zh-cn/editTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ export default {
'editTable.label.characterSet': '字符集',
'editTable.label.collation': '排序规则',
'editTable.label.decimalPoint': '小数点',
'editTable.label.value': '值',
'editTable.label.autoIncrement': '是否自增',
'editTable.label.engine': '引擎',
'editTable.label.incrementValue': '自增值',
'editTable.title.sqlPreview': 'sql预览',
};
1 change: 1 addition & 0 deletions chat2db-client/src/typings/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ export interface IColumnTypes {
supportLength: boolean; // 是否支持长度
supportNullable: boolean; // 是否支持为空
supportScale: boolean; // 是否支持小数位
supportValue: boolean; // 是否支持值
}
Loading

0 comments on commit e5b69c5

Please sign in to comment.