Skip to content

Commit

Permalink
fix adding dropdown fields to section
Browse files Browse the repository at this point in the history
  • Loading branch information
christianvogt committed Nov 7, 2024
1 parent 7023236 commit f19e0d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const ManageConnectionTypeFieldsTable: React.FC<Props> = ({ fields, onFieldsChan
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);
});
});

0 comments on commit f19e0d1

Please sign in to comment.