Skip to content

Commit 2359a0e

Browse files
authored
Fix required dimensions component to read/write formik state properly (#1783)
* Fix required dimensions component to read/write formik state properly * Fix lint * Fix tests
1 parent bcae6fc commit 2359a0e

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

datajunction-ui/src/app/pages/AddEditNodePage/FormikSelect.jsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,33 @@ export const FormikSelect = ({
3939
}
4040
};
4141

42+
// Convert Formik field value to React Select format
43+
const getSelectValue = () => {
44+
if (!field.value) {
45+
return isMulti ? [] : null;
46+
}
47+
48+
if (isMulti) {
49+
// For multi-select, map array of values to option objects
50+
return Array.isArray(field.value)
51+
? field.value.map(
52+
val =>
53+
selectOptions.find(opt => opt.value === val) || {
54+
value: val,
55+
label: val,
56+
},
57+
)
58+
: [];
59+
} else {
60+
// For single-select, find the matching option
61+
return selectOptions.find(opt => opt.value === field.value) || null;
62+
}
63+
};
64+
4265
return (
4366
<Select
4467
className={className}
45-
defaultValue={defaultValue}
68+
value={getSelectValue()}
4669
options={selectOptions}
4770
name={field.name}
4871
placeholder={placeholder}

datajunction-ui/src/app/pages/AddEditNodePage/__tests__/FormikSelect.test.jsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('FormikSelect', () => {
1414

1515
const singleSelect = () => {
1616
const utils = render(
17-
<Formik initialValues={{ selectedOption: '' }} onSubmit={jest.fn()}>
17+
<Formik initialValues={{ namespace: '' }} onSubmit={jest.fn()}>
1818
<Form>
1919
<FormikSelect
2020
selectOptions={namespaces}
@@ -38,7 +38,7 @@ describe('FormikSelect', () => {
3838

3939
const multiSelect = () => {
4040
const utils = render(
41-
<Formik initialValues={{ selectedOption: '' }} onSubmit={jest.fn()}>
41+
<Formik initialValues={{ namespace: [] }} onSubmit={jest.fn()}>
4242
<Form>
4343
<FormikSelect
4444
selectOptions={namespaces}
@@ -61,15 +61,15 @@ describe('FormikSelect', () => {
6161
};
6262
};
6363

64-
it('renders the single select component with provided options', () => {
64+
it('renders the single select component with provided options', async () => {
6565
singleSelect();
66-
userEvent.click(screen.getByRole('combobox')); // to open the dropdown
66+
await userEvent.click(screen.getByRole('combobox')); // to open the dropdown
6767
expect(screen.getByText('basic.one')).toBeInTheDocument();
6868
});
6969

70-
it('renders the multi-select component with provided options', () => {
70+
it('renders the multi-select component with provided options', async () => {
7171
multiSelect();
72-
userEvent.click(screen.getByRole('combobox')); // to open the dropdown
72+
await userEvent.click(screen.getByRole('combobox')); // to open the dropdown
7373
expect(screen.getByText('basic.one')).toBeInTheDocument();
7474
});
7575
});

datajunction-ui/src/app/pages/NodePage/EditColumnPopover.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default function EditColumnPopover({ column, node, options, onSubmit }) {
6363
initialValues={{
6464
column: column.name,
6565
node: node.name,
66-
attributes: [],
66+
attributes: column.attributes.map(attr => attr.attribute_type.name),
6767
}}
6868
onSubmit={saveAttributes}
6969
>

0 commit comments

Comments
 (0)