From 254c1259c14ba2e4fd943290783b25a2c37eca02 Mon Sep 17 00:00:00 2001 From: SwallowGG <1558143046@qq.com> Date: Sun, 24 Sep 2023 14:38:04 +0800 Subject: [PATCH 1/3] update --- .../ai/chat2db/plugin/mysql/type/MysqlColumnTypeEnum.java | 4 ++-- .../java/ai/chat2db/plugin/mysql/type/MysqlIndexTypeEnum.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlColumnTypeEnum.java b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlColumnTypeEnum.java index e9f15e53c..eb7d16259 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlColumnTypeEnum.java +++ b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlColumnTypeEnum.java @@ -56,9 +56,9 @@ public enum MysqlColumnTypeEnum implements ColumnBuilder { TIMESTAMP("TIMESTAMP", true, false, true, false, false, false, true, true, true), TIME("TIME", true, false, true, false, false, false, true, true, false), YEAR("YEAR", false, false, true, false, false, false, true, true, false), - CHAR("CHAR", true, false, true, false, false, true, true, true, false), + CHAR("CHAR", true, false, true, false, true, true, true, true, false), - VARCHAR("VARCHAR", true, false, true, false, false, true, true, true, false), + VARCHAR("VARCHAR", true, false, true, false, true, true, true, true, false), BINARY("BINARY", true, false, true, false, false, false, true, true, false), diff --git a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlIndexTypeEnum.java b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlIndexTypeEnum.java index 530786e46..c8674010d 100644 --- a/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlIndexTypeEnum.java +++ b/chat2db-server/chat2db-plugins/chat2db-mysql/src/main/java/ai/chat2db/plugin/mysql/type/MysqlIndexTypeEnum.java @@ -38,7 +38,7 @@ public String getKeyword() { public static MysqlIndexTypeEnum getByType(String type) { for (MysqlIndexTypeEnum value : MysqlIndexTypeEnum.values()) { - if (value.name.equals(type)) { + if (value.name.equalsIgnoreCase(type)) { return value; } } From d45354a47d363f590a6fd055e736739f020c0e6b Mon Sep 17 00:00:00 2001 From: shanhexi Date: Sun, 24 Sep 2023 15:36:34 +0800 Subject: [PATCH 2/3] fix:The drop-down search box supports custom input --- .../DatabaseTableEditor/ColumnList/index.tsx | 100 ++++++++------ .../DatabaseTableEditor/IndexList/index.tsx | 124 +++++++++--------- .../src/components/CustomSelect/index.tsx | 17 ++- chat2db-client/src/constants/editTable.ts | 11 +- 4 files changed, 141 insertions(+), 111 deletions(-) diff --git a/chat2db-client/src/blocks/DatabaseTableEditor/ColumnList/index.tsx b/chat2db-client/src/blocks/DatabaseTableEditor/ColumnList/index.tsx index e1db2def0..2ac3ec44e 100644 --- a/chat2db-client/src/blocks/DatabaseTableEditor/ColumnList/index.tsx +++ b/chat2db-client/src/blocks/DatabaseTableEditor/ColumnList/index.tsx @@ -1,4 +1,12 @@ -import React, { useContext, useEffect, useState, forwardRef, ForwardedRef, useImperativeHandle } from 'react'; +import React, { + useContext, + useEffect, + useState, + useCallback, + forwardRef, + ForwardedRef, + useImperativeHandle, +} from 'react'; import styles from './index.less'; import { MenuOutlined } from '@ant-design/icons'; import { DndContext, type DragEndEvent } from '@dnd-kit/core'; @@ -104,7 +112,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef) const { dataSourceId, databaseName, schemaName, tableDetails } = useContext(Context); const [dataSource, setDataSource] = useState([createInitialData()]); const [form] = Form.useForm(); - const [editingKey, setEditingKey] = useState(null); + const [editingData, setEditingData] = useState(null); const [editingConfig, setEditingConfig] = useState(null); const [databaseSupportField, setDatabaseSupportField] = useState<{ columnTypes: IColumnTypesOption[]; @@ -116,20 +124,24 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef) collations: [], }); - const isEditing = (record: IColumnItemNew) => record.key === editingKey; + const isEditing = (record: IColumnItemNew) => record.key === editingData?.key; const edit = (record: IColumnItemNew) => { if (record.key) { form.setFieldsValue({ ...record }); - setEditingKey(record.key); - + setEditingData(record); // 根据当前字段类型,设置编辑配置 + console.log(databaseSupportField.columnTypes, record.columnType); databaseSupportField.columnTypes.forEach((i) => { if (i.typeName === record.columnType) { setEditingConfig({ ...i, editKey: record.key!, }); + console.log({ + ...i, + editKey: record.key!, + }); } }); } @@ -197,19 +209,19 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef) width: '40px', align: 'center', }, - { - title: 'O T', - dataIndex: 'editStatus', - width: '60px', - align: 'center', - render: (text: EditColumnOperationType) => { - return text === EditColumnOperationType.Add ? ( - - ) : ( - - ); - }, - }, + // { + // title: 'O T', + // dataIndex: 'editStatus', + // width: '60px', + // align: 'center', + // render: (text: EditColumnOperationType) => { + // return text === EditColumnOperationType.Add ? ( + // + // ) : ( + // + // ); + // }, + // }, { title: i18n('editTable.label.columnName'), dataIndex: 'name', @@ -221,9 +233,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef) ) : ( -
edit(record)}> - {text} -
+
{text}
); }, }, @@ -240,7 +250,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef) ) : ( -
edit(record)}> - {text} -
+
{text}
); }, }, @@ -319,7 +325,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef) } const newData = dataSource.map((item) => { - if (item.key === editingKey) { + if (item.key === editingData?.key) { // 判断当前数据是新增的数据还是编辑后的数据 let editStatus = item.editStatus; if (editStatus !== EditColumnOperationType.Add) { @@ -345,7 +351,6 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef) return item; }); setDataSource(newData); - console.log(field); }; const addData = () => { @@ -357,10 +362,13 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef) }; const deleteData = () => { - setDataSource( - dataSource.map((i) => { - if (i.key === editingKey) { - setEditingKey(null); + let list: any = []; + if (editingData?.editStatus === EditColumnOperationType.Add) { + list = dataSource.filter((i) => i.key !== editingData?.key); + } else { + list = dataSource.map((i) => { + if (i.key === editingData?.key) { + setEditingData(null); setEditingConfig(null); return { ...i, @@ -368,12 +376,13 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef) }; } return i; - }), - ); + }); + } + setDataSource(list); }; const moveData = (action: 'up' | 'down') => { - const index = dataSource.findIndex((i) => i.key === editingKey); + const index = dataSource.findIndex((i) => i.key === editingData?.key); if (index === -1) { return; } @@ -425,8 +434,8 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef) ) ); }; + const onRow = (record: any) => { + return { + onClick: () => { + if (editingData?.key !== record.key) { + edit(record); + } + }, + }; + }; + return (
@@ -473,6 +492,7 @@ const ColumnList = forwardRef((props: IProps, ref: ForwardedRef) row: Row, }, }} + onRow={onRow} pagination={false} rowKey="key" columns={columns as any} diff --git a/chat2db-client/src/blocks/DatabaseTableEditor/IndexList/index.tsx b/chat2db-client/src/blocks/DatabaseTableEditor/IndexList/index.tsx index 24b87c1cf..bba39e8e7 100644 --- a/chat2db-client/src/blocks/DatabaseTableEditor/IndexList/index.tsx +++ b/chat2db-client/src/blocks/DatabaseTableEditor/IndexList/index.tsx @@ -7,6 +7,7 @@ import React, { useRef, useMemo, useEffect, + useCallback, } from 'react'; import styles from './index.less'; import classnames from 'classnames'; @@ -49,20 +50,49 @@ interface RowProps extends React.HTMLAttributes { 'data-row-key': string; } +const Row = ({ children, ...props }: RowProps) => { + const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({ + id: props['data-row-key'], + }); + + const style: React.CSSProperties = { + ...props.style, + transform: CSS.Transform.toString(transform && { ...transform, scaleY: 1 }), + transition, + ...(isDragging ? { position: 'relative', zIndex: 9999 } : {}), + }; + + return ( + + {React.Children.map(children, (child) => { + if ((child as React.ReactElement).key === 'sort') { + return React.cloneElement(child as React.ReactElement, { + children: ( + + ), + }); + } + return child; + })} + + ); +}; + const IndexList = forwardRef((props: IProps, ref: ForwardedRef) => { const { tableDetails } = useContext(Context); const [dataSource, setDataSource] = useState([createInitialData()]); const [form] = Form.useForm(); - const [editingKey, setEditingKey] = useState(null); + const [editingData, setEditingData] = useState(null); const [includeColModalOpen, setIncludeColModalOpen] = useState(false); const includeColRef = useRef(null); - const isEditing = (record: IIndexItem) => record.key === editingKey; + const isEditing = (record: IIndexItem) => record.key === editingData?.key; const edit = (record: IIndexItem) => { - console.log(record); form.setFieldsValue({ ...record }); - setEditingKey(record.key || null); + if (record.key !== editingData?.key) { + setEditingData(record || null); + } }; useEffect(() => { @@ -83,11 +113,11 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef) = }; const deleteData = () => { - setDataSource(dataSource.filter((i) => i.key !== editingKey)); + setDataSource(dataSource.filter((i) => i.key !== editingData?.key)); setDataSource( dataSource.map((i) => { - if (i.key === editingKey) { - setEditingKey(null); + if (i.key === editingData?.key) { + setEditingData(null); // setEditingConfig(null); return { ...i, @@ -107,7 +137,7 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef) = value = value ? 1 : 0; } const newData = dataSource.map((item) => { - if (item.key === editingKey) { + if (item.key === editingData?.key) { let editStatus = item.editStatus; if (editStatus !== EditColumnOperationType.Add) { editStatus = EditColumnOperationType.Modify; @@ -133,38 +163,6 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef) = } }; - const Row = ({ children, ...rowProps }: RowProps) => { - const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({ - id: rowProps['data-row-key'], - }); - - const style: React.CSSProperties = { - ...rowProps.style, - transform: CSS.Transform.toString(transform && { ...transform, scaleY: 1 }), - transition, - ...(isDragging ? { position: 'relative', zIndex: 9999 } : {}), - }; - - return ( - - {React.Children.map(children, (child) => { - if ((child as React.ReactElement).key === 'sort') { - return React.cloneElement(child as React.ReactElement, { - children: ( - - ), - }); - } - return child; - })} - - ); - }; - function getIndexListInfo(): IIndexListInfo { return dataSource.map((i) => { return lodash.omit(i, 'key'); @@ -181,14 +179,14 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef) = width: '40px', align: 'center', }, - { - title: i18n('editTable.label.index'), - width: '70px', - align: 'center', - render: (text: string, record: IIndexItem) => { - return dataSource.findIndex((i) => i.key === record.key) + 1; - }, - }, + // { + // title: i18n('editTable.label.index'), + // width: '70px', + // align: 'center', + // render: (text: string, record: IIndexItem) => { + // return dataSource.findIndex((i) => i.key === record.key) + 1; + // }, + // }, { title: i18n('editTable.label.indexName'), dataIndex: 'name', @@ -200,9 +198,7 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef) = ) : ( -
edit(record)}> - {text} -
+
{text}
); }, }, @@ -223,9 +219,7 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef) = ) : ( -
edit(record)}> - {text} -
+
{text}
); }, }, @@ -251,9 +245,7 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef) = {text}
) : ( -
edit(record)}> - {text} -
+
{text}
); }, }, @@ -279,8 +271,7 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef) = setDataSource( dataSource.map((i) => { const columnList = includeColRef.current?.getIncludeColInfo(); - console.log(columnList); - if (i.key === editingKey && columnList) { + if (i.key === editingData?.key && columnList) { i.columnList = columnList; } return i; @@ -290,15 +281,25 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef) = setIncludeColModalOpen(false); }; + const onRow = (record: any) => { + return { + onClick: () => { + if (editingData?.key !== record.key) { + edit(record); + } + }, + }; + }; + const indexIncludedColumnList: IIndexIncludeColumnItem[] = useMemo(() => { let list: IIndexIncludeColumnItem[] = []; dataSource.forEach((i) => { - if (i.key === editingKey) { + if (i.key === editingData?.key) { list = i.columnList || []; } }); return list; - }, [editingKey]); + }, [editingData?.key]); return (
@@ -318,6 +319,7 @@ const IndexList = forwardRef((props: IProps, ref: ForwardedRef) = row: Row, }, }} + onRow={onRow} pagination={false} rowKey="key" columns={columns as any} diff --git a/chat2db-client/src/components/CustomSelect/index.tsx b/chat2db-client/src/components/CustomSelect/index.tsx index 5e8e2dba1..4363e1095 100644 --- a/chat2db-client/src/components/CustomSelect/index.tsx +++ b/chat2db-client/src/components/CustomSelect/index.tsx @@ -16,7 +16,8 @@ interface IProps { const CustomSelect = memo((props: IProps) => { const { options, onChange, value } = props; const [customOptions, setCustomOptions] = useState([]); - const [customValue, setCustomValue] = useState(); + const [customValue, setCustomValue] = useState(''); + const [curSearch, setCurSearch] = useState(null); useEffect(() => { setCustomOptions([...options, { label: '', value: null }]); @@ -40,22 +41,30 @@ const CustomSelect = memo((props: IProps) => { }; const onSearch = (v: string) => { - customOptions[customOptions.length - 1].label = v; - customOptions[customOptions.length - 1].value = v; - setCustomOptions([...customOptions]); + setCurSearch(v); }; const customChange = (v: string) => { + setCurSearch(null); setCustomValue(v); onChange?.(v); }; + const onBlur = () => { + if (curSearch) { + onChange?.(curSearch); + } + setCurSearch(null); + }; + return (