Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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: false
},
{ ...DEFAULT_COLUMNS[1], type: 'INT', isPrimaryKey: false }
]);
expect(closeModal).toHaveBeenCalled();
});
Expand Down Expand Up @@ -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: false },
{ ...duplicateColumns[1], title: 'col2_fixed', type: 'INT', isPrimaryKey: false }
]);
});
});
Expand Down Expand Up @@ -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: false
},
{ ...columnsWithEmpty[1], type: 'INT', comment: 'comment2', isPrimaryKey: false }
]);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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';
Expand All @@ -39,6 +39,7 @@ interface EditableRow extends Required<BaseColumnProperties> {
type: string;
sample: string;
comment: string;
isPrimaryKey: boolean;
}

interface EditColumnsModalProps {
Expand Down Expand Up @@ -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 || false
}))
);
}, [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 () => {
Expand All @@ -210,13 +221,26 @@ const EditColumnsModal = ({
...columns[row.key],
title: row.title.trim(),
type: row.type,
comment: row.comment
comment: row.comment,
isPrimaryKey: row.isPrimaryKey
}));
setColumns(updatedColumns);
closeModal();
};

const modalColumns = [
{
title: t('P Key'),
dataIndex: 'isPrimaryKey',
className: 'hue-importer-edit-columns-modal__primary-key',
render: (isPrimaryKey: boolean, _: EditableRow, rowIndex: number) => (
<Checkbox
checked={isPrimaryKey}
onChange={() => handleChange(rowIndex, 'isPrimaryKey', true)}
aria-label={t('Set as primary key')}
/>
)
},
{
title: t('Title'),
dataIndex: 'title',
Expand Down
1 change: 1 addition & 0 deletions desktop/core/src/desktop/js/apps/newimporter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface FileMetaData {
export interface BaseColumnProperties {
type?: string;
comment?: string;
isPrimaryKey?: boolean;
}

export interface FilePreviewTableColumn extends BaseColumnProperties {
Expand Down