From 717dc54b652c023a168a9eaf681f63e03dd2511e Mon Sep 17 00:00:00 2001 From: Ananya_Agarwal Date: Mon, 6 Oct 2025 11:36:29 +0530 Subject: [PATCH 1/7] [ui-importer] Add Primary key column in bulk column modal --- .../EditColumnsModal/EditColumnsModal.scss | 9 +++++ .../EditColumnsModal/EditColumnsModal.tsx | 39 +++++++++++++++---- .../src/desktop/js/apps/newimporter/types.ts | 1 + hue | 1 + 4 files changed, 43 insertions(+), 7 deletions(-) create mode 160000 hue diff --git a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss index 247f47a64dc..ac45acfeecd 100644 --- a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss +++ b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss @@ -38,4 +38,13 @@ color: vars.$fluidx-gray-500; font-style: italic; } + + &__primary-key { + text-align: center; + white-space: nowrap; + + .ant-radio-wrapper { + margin: 0; + } + } } diff --git a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx index 0ceb124ec49..80faa49e1a6 100644 --- a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx +++ b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx @@ -20,7 +20,7 @@ import Modal from 'cuix/dist/components/Modal'; import Table from 'cuix/dist/components/Table'; import Input from 'cuix/dist/components/Input'; import Select from 'cuix/dist/components/Select'; -import { Alert } from 'antd'; +import { Alert, Radio } from 'antd'; import { SQL_TYPE_MAPPING_API_URL } from '../../../admin/Components/utils'; import useLoadData from '../../../../utils/hooks/useLoadData/useLoadData'; import LoadingErrorWrapper from '../../../../reactComponents/LoadingErrorWrapper/LoadingErrorWrapper'; @@ -39,6 +39,7 @@ interface EditableRow extends Required { type: string; sample: string; comment: string; + isPrimaryKey: boolean; } interface EditColumnsModalProps { @@ -190,15 +191,25 @@ const EditColumnsModal = ({ title: col.title, type: (col.type || 'string').toUpperCase(), sample: sample && sample[col.dataIndex] !== undefined ? String(sample[col.dataIndex]) : '', - comment: col.comment || '' + comment: col.comment || '', + isPrimaryKey: col.isPrimaryKey || (idx === 0 && !columns.some(c => c.isPrimaryKey)) })) ); }, [columns, sample]); - const handleChange = (rowIndex: number, field: keyof EditableRow, value: string) => { - setEditableRows(rows => - rows.map((row, i) => (i === rowIndex ? { ...row, [field]: value } : row)) - ); + const handleChange = (rowIndex: number, field: keyof EditableRow, value: string | boolean) => { + if (field === 'isPrimaryKey' && value === true) { + setEditableRows(rows => + rows.map((row, i) => ({ + ...row, + isPrimaryKey: i === rowIndex ? true : false + })) + ); + } else { + setEditableRows(rows => + rows.map((row, i) => (i === rowIndex ? { ...row, [field]: value } : row)) + ); + } }; const handleDone = async () => { @@ -210,7 +221,8 @@ const EditColumnsModal = ({ ...columns[row.key], title: row.title.trim(), type: row.type, - comment: row.comment + comment: row.comment, + isPrimaryKey: row.isPrimaryKey })); setColumns(updatedColumns); closeModal(); @@ -232,6 +244,19 @@ const EditColumnsModal = ({ /> ) }, + { + title: t('Primary Key'), + dataIndex: 'isPrimaryKey', + width: 100, + className: 'hue-importer-edit-columns-modal__primary-key', + render: (isPrimaryKey: boolean, _: EditableRow, rowIndex: number) => ( + handleChange(rowIndex, 'isPrimaryKey', true)} + aria-label={t('Set as primary key')} + /> + ) + }, { title: t('Type'), dataIndex: 'type', diff --git a/desktop/core/src/desktop/js/apps/newimporter/types.ts b/desktop/core/src/desktop/js/apps/newimporter/types.ts index 7fa9c902ec7..6cd536c8351 100644 --- a/desktop/core/src/desktop/js/apps/newimporter/types.ts +++ b/desktop/core/src/desktop/js/apps/newimporter/types.ts @@ -69,6 +69,7 @@ export interface FileMetaData { export interface BaseColumnProperties { type?: string; comment?: string; + isPrimaryKey?: boolean; } export interface FilePreviewTableColumn extends BaseColumnProperties { diff --git a/hue b/hue new file mode 160000 index 00000000000..0f40586408c --- /dev/null +++ b/hue @@ -0,0 +1 @@ +Subproject commit 0f40586408cac04e111e76b9f973caf6d3ad5d20 From d118c2cb40745859a7774e1af79d9e5f2966457b Mon Sep 17 00:00:00 2001 From: Ananya_Agarwal Date: Mon, 6 Oct 2025 11:41:14 +0530 Subject: [PATCH 2/7] Making the headings in the modal centre align --- .../FilePreviewTab/EditColumnsModal/EditColumnsModal.scss | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss index ac45acfeecd..8018a70257b 100644 --- a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss +++ b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss @@ -21,6 +21,10 @@ width: 800px; } + .ant-table-thead > tr > th { + text-align: center; + } + &__input-title { width: 100px; } @@ -42,9 +46,5 @@ &__primary-key { text-align: center; white-space: nowrap; - - .ant-radio-wrapper { - margin: 0; - } } } From 7b415110d0edfc3bb10fd6325d2c52baa5d40b1e Mon Sep 17 00:00:00 2001 From: Ananya_Agarwal Date: Mon, 6 Oct 2025 11:50:07 +0530 Subject: [PATCH 3/7] Updated the unit tests after adding the pKey --- .../EditColumnsModal.test.tsx | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.test.tsx b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.test.tsx index 3b0e0447c92..57f5b985420 100644 --- a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.test.tsx +++ b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.test.tsx @@ -159,8 +159,14 @@ describe('EditColumnsModal', () => { await waitFor(() => { expect(setColumns).toHaveBeenCalledWith([ - { ...DEFAULT_COLUMNS[0], title: 'newCol1', type: 'STRING', comment: 'new comment' }, - { ...DEFAULT_COLUMNS[1], type: 'INT' } + { + ...DEFAULT_COLUMNS[0], + title: 'newCol1', + type: 'STRING', + comment: 'new comment', + isPrimaryKey: true + }, + { ...DEFAULT_COLUMNS[1], type: 'INT', isPrimaryKey: false } ]); expect(closeModal).toHaveBeenCalled(); }); @@ -263,8 +269,8 @@ describe('EditColumnsModal', () => { await waitFor(() => { expect(setColumns).toHaveBeenCalledWith([ - { ...duplicateColumns[0], title: 'col1', type: 'STRING' }, - { ...duplicateColumns[1], title: 'col2_fixed', type: 'INT' } + { ...duplicateColumns[0], title: 'col1', type: 'STRING', isPrimaryKey: true }, + { ...duplicateColumns[1], title: 'col2_fixed', type: 'INT', isPrimaryKey: false } ]); }); }); @@ -312,8 +318,14 @@ describe('EditColumnsModal', () => { await waitFor(() => { expect(setColumns).toHaveBeenCalledWith([ - { ...columnsWithEmpty[0], title: 'fixed_name', type: 'STRING' }, - { ...columnsWithEmpty[1], type: 'INT' } + { + ...columnsWithEmpty[0], + title: 'fixed_name', + type: 'STRING', + comment: 'comment1', + isPrimaryKey: true + }, + { ...columnsWithEmpty[1], type: 'INT', comment: 'comment2', isPrimaryKey: false } ]); }); }); From 304b578d72b29dae3a38582c4b9d2131d77bc69f Mon Sep 17 00:00:00 2001 From: Ananya_Agarwal Date: Tue, 7 Oct 2025 15:44:59 +0530 Subject: [PATCH 4/7] nits --- .../EditColumnsModal/EditColumnsModal.scss | 8 ------ .../EditColumnsModal/EditColumnsModal.tsx | 27 +++++++++---------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss index 8018a70257b..6fe814dbe50 100644 --- a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss +++ b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss @@ -21,10 +21,6 @@ width: 800px; } - .ant-table-thead > tr > th { - text-align: center; - } - &__input-title { width: 100px; } @@ -43,8 +39,4 @@ font-style: italic; } - &__primary-key { - text-align: center; - white-space: nowrap; - } } diff --git a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx index 80faa49e1a6..84e9b91f13d 100644 --- a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx +++ b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx @@ -20,7 +20,7 @@ import Modal from 'cuix/dist/components/Modal'; import Table from 'cuix/dist/components/Table'; import Input from 'cuix/dist/components/Input'; import Select from 'cuix/dist/components/Select'; -import { Alert, Radio } from 'antd'; +import { Alert, Checkbox } from 'antd'; import { SQL_TYPE_MAPPING_API_URL } from '../../../admin/Components/utils'; import useLoadData from '../../../../utils/hooks/useLoadData/useLoadData'; import LoadingErrorWrapper from '../../../../reactComponents/LoadingErrorWrapper/LoadingErrorWrapper'; @@ -229,6 +229,18 @@ const EditColumnsModal = ({ }; const modalColumns = [ + { + title: t('P Key'), + dataIndex: 'isPrimaryKey', + className: 'hue-importer-edit-columns-modal__primary-key', + render: (isPrimaryKey: boolean, _: EditableRow, rowIndex: number) => ( + handleChange(rowIndex, 'isPrimaryKey', true)} + aria-label={t('Set as primary key')} + /> + ) + }, { title: t('Title'), dataIndex: 'title', @@ -244,19 +256,6 @@ const EditColumnsModal = ({ /> ) }, - { - title: t('Primary Key'), - dataIndex: 'isPrimaryKey', - width: 100, - className: 'hue-importer-edit-columns-modal__primary-key', - render: (isPrimaryKey: boolean, _: EditableRow, rowIndex: number) => ( - handleChange(rowIndex, 'isPrimaryKey', true)} - aria-label={t('Set as primary key')} - /> - ) - }, { title: t('Type'), dataIndex: 'type', From 35365d8ce7ea8b1e18ba8a0779861651fb21991e Mon Sep 17 00:00:00 2001 From: Ananya_Agarwal Date: Tue, 7 Oct 2025 15:52:32 +0530 Subject: [PATCH 5/7] Remove accidentally added hue submodule --- hue | 1 - 1 file changed, 1 deletion(-) delete mode 160000 hue diff --git a/hue b/hue deleted file mode 160000 index 0f40586408c..00000000000 --- a/hue +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0f40586408cac04e111e76b9f973caf6d3ad5d20 From 3e109fe549286e0585458a54a1620ce308572927 Mon Sep 17 00:00:00 2001 From: Ananya_Agarwal Date: Tue, 7 Oct 2025 15:59:42 +0530 Subject: [PATCH 6/7] Removing the condition make first key as p Key --- .../EditColumnsModal/EditColumnsModal.test.tsx | 6 +++--- .../FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.test.tsx b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.test.tsx index 57f5b985420..576379c0257 100644 --- a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.test.tsx +++ b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.test.tsx @@ -164,7 +164,7 @@ describe('EditColumnsModal', () => { title: 'newCol1', type: 'STRING', comment: 'new comment', - isPrimaryKey: true + isPrimaryKey: false }, { ...DEFAULT_COLUMNS[1], type: 'INT', isPrimaryKey: false } ]); @@ -269,7 +269,7 @@ describe('EditColumnsModal', () => { await waitFor(() => { expect(setColumns).toHaveBeenCalledWith([ - { ...duplicateColumns[0], title: 'col1', type: 'STRING', isPrimaryKey: true }, + { ...duplicateColumns[0], title: 'col1', type: 'STRING', isPrimaryKey: false }, { ...duplicateColumns[1], title: 'col2_fixed', type: 'INT', isPrimaryKey: false } ]); }); @@ -323,7 +323,7 @@ describe('EditColumnsModal', () => { title: 'fixed_name', type: 'STRING', comment: 'comment1', - isPrimaryKey: true + isPrimaryKey: false }, { ...columnsWithEmpty[1], type: 'INT', comment: 'comment2', isPrimaryKey: false } ]); diff --git a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx index 84e9b91f13d..ee2d2a290e8 100644 --- a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx +++ b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.tsx @@ -192,7 +192,7 @@ const EditColumnsModal = ({ type: (col.type || 'string').toUpperCase(), sample: sample && sample[col.dataIndex] !== undefined ? String(sample[col.dataIndex]) : '', comment: col.comment || '', - isPrimaryKey: col.isPrimaryKey || (idx === 0 && !columns.some(c => c.isPrimaryKey)) + isPrimaryKey: col.isPrimaryKey || false })) ); }, [columns, sample]); From f7965d7342b5e380bc539729f955afd786a582c4 Mon Sep 17 00:00:00 2001 From: Ananya_Agarwal Date: Tue, 7 Oct 2025 16:02:33 +0530 Subject: [PATCH 7/7] nits --- .../FilePreviewTab/EditColumnsModal/EditColumnsModal.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss index 6fe814dbe50..247f47a64dc 100644 --- a/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss +++ b/desktop/core/src/desktop/js/apps/newimporter/FilePreviewTab/EditColumnsModal/EditColumnsModal.scss @@ -38,5 +38,4 @@ color: vars.$fluidx-gray-500; font-style: italic; } - }