Skip to content
Merged
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
25 changes: 24 additions & 1 deletion datajunction-ui/src/app/pages/AddEditNodePage/FormikSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,33 @@ export const FormikSelect = ({
}
};

// Convert Formik field value to React Select format
const getSelectValue = () => {
if (!field.value) {
return isMulti ? [] : null;
}

if (isMulti) {
// For multi-select, map array of values to option objects
return Array.isArray(field.value)
? field.value.map(
val =>
selectOptions.find(opt => opt.value === val) || {
value: val,
label: val,
},
)
: [];
} else {
// For single-select, find the matching option
return selectOptions.find(opt => opt.value === field.value) || null;
}
};

return (
<Select
className={className}
defaultValue={defaultValue}
value={getSelectValue()}
options={selectOptions}
name={field.name}
placeholder={placeholder}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('FormikSelect', () => {

const singleSelect = () => {
const utils = render(
<Formik initialValues={{ selectedOption: '' }} onSubmit={jest.fn()}>
<Formik initialValues={{ namespace: '' }} onSubmit={jest.fn()}>
<Form>
<FormikSelect
selectOptions={namespaces}
Expand All @@ -38,7 +38,7 @@ describe('FormikSelect', () => {

const multiSelect = () => {
const utils = render(
<Formik initialValues={{ selectedOption: '' }} onSubmit={jest.fn()}>
<Formik initialValues={{ namespace: [] }} onSubmit={jest.fn()}>
<Form>
<FormikSelect
selectOptions={namespaces}
Expand All @@ -61,15 +61,15 @@ describe('FormikSelect', () => {
};
};

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

it('renders the multi-select component with provided options', () => {
it('renders the multi-select component with provided options', async () => {
multiSelect();
userEvent.click(screen.getByRole('combobox')); // to open the dropdown
await userEvent.click(screen.getByRole('combobox')); // to open the dropdown
expect(screen.getByText('basic.one')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default function EditColumnPopover({ column, node, options, onSubmit }) {
initialValues={{
column: column.name,
node: node.name,
attributes: [],
attributes: column.attributes.map(attr => attr.attribute_type.name),
}}
onSubmit={saveAttributes}
>
Expand Down
Loading