Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix adding dropdown fields to section #3448

Merged
merged 1 commit into from
Nov 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
onAddField={() => {
const nextSectionIndex = index + findSectionFields(index, fields).length;
if (nextSectionIndex >= 0) {
setModalField({ index: nextSectionIndex });
setModalField({ index: nextSectionIndex + 1 });

Check warning on line 122 in frontend/src/pages/connectionTypes/manage/ManageConnectionTypeFieldsTable.tsx

View check run for this annotation

Codecov / codecov/patch

frontend/src/pages/connectionTypes/manage/ManageConnectionTypeFieldsTable.tsx#L122

Added line #L122 was not covered by tests
} else {
setModalField({});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ const DropdownAdvancedPropertiesForm: React.FC<AdvancedFieldProps<DropdownField>
// filter out empty rows for validation (they will be removed on save)
const itemsWithoutEmptyRows =
properties.items?.filter((item) => item.label || item.value) ?? [];
const duplicateLabels = itemsWithoutEmptyRows.find((item1, index1) =>
properties.items?.find((item2, index2) => item1.label === item2.label && index1 !== index2),
const duplicateLabels = itemsWithoutEmptyRows.some(
(item1, index1) =>
item1.label &&
itemsWithoutEmptyRows.some(
(item2, index2) => item1.label === item2.label && index1 !== index2,
),
);
const duplicateValues = itemsWithoutEmptyRows.find((item1, index1) =>
properties.items?.find((item2, index2) => item1.value === item2.value && index1 !== index2),
const duplicateValues = itemsWithoutEmptyRows.some((item1, index1) =>
itemsWithoutEmptyRows.some(
(item2, index2) => item1.value === item2.value && index1 !== index2,
),
);
const noMissingValues = itemsWithoutEmptyRows.every((item) => item.value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,24 @@ describe('DropdownFieldAdvancedPropertiesForm', () => {
expect(screen.getByText('a already exists.')).toBeVisible();
expect(screen.getByText('b already exists.')).toBeVisible();
});

it('should validate to true with empty rows', async () => {
render(
<DropdownAdvancedPropertiesForm
properties={{
variant: 'single',
items: [
{ label: '', value: 'v1' },
{ label: '', value: '' },
{ label: '', value: 'v2' },
],
}}
field={field}
onChange={onChange}
onValidate={onValidate}
/>,
);

expect(onValidate).toHaveBeenCalledWith(true);
});
});
Loading