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

ui/taxonomy: CustomSelect isClearable - handle empty string selection #1712

Merged
merged 3 commits into from
Nov 10, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The types of changes are:
* Removed local storage parsing that is redundant with redux-persist. [#1678](https://github.com/ethyca/fides/pull/1678)
* Show a helpful error message if Docker daemon is not running during "fides deploy" [#1694](https://github.com/ethyca/fides/pull/1694)
* Allow users to query their own permissions, including root user. [#1698](https://github.com/ethyca/fides/pull/1698)
* Single-select taxonomy fields legal basis and special category can be cleared. [#1712](https://github.com/ethyca/fides/pull/1712)

### Security

Expand Down
9 changes: 6 additions & 3 deletions clients/admin-ui/cypress/e2e/taxonomy.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,15 @@ describe("Taxonomy management page", () => {
"https://example.org/legitimate_interest_assessment"
);

// trigger a PUT
cy.getByTestId("input-legitimate_interest_impact_assessment")
.clear()
.type("foo");
// Test clearable single-select.
cy.getByTestId("input-legal_basis").within(() => {
cy.get('[aria-label="Clear selected options"]').click();
});
cy.getByTestId("input-special_category").click().type("{backspace}{esc}");
// trigger a PUT
cy.getByTestId("submit-btn").click();
cy.wait("@putDataUse").then((interception) => {
const { body } = interception.request;
Expand All @@ -237,8 +242,6 @@ describe("Taxonomy management page", () => {
description:
"Provide, give, or make available the product, service, application or system.",
is_default: true,
legal_basis: "Legitimate Interests",
special_category: "Vital Interests",
recipients: ["marketing team", "dog shelter"],
legitimate_interest: true,
legitimate_interest_impact_assessment: "foo",
Expand Down
2 changes: 2 additions & 0 deletions clients/admin-ui/src/features/common/form/inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ export const CustomSelect = ({
onChange={(newValue) => {
if (newValue) {
field.onChange(props.name)(newValue.value);
} else if (isClearable) {
field.onChange(props.name)("");
}
}}
name={props.name}
Expand Down
10 changes: 10 additions & 0 deletions clients/admin-ui/src/features/taxonomy/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ export const useDataUse = (): TaxonomyHookData<DataUse> => {
legitimate_interest: !!(
formValues.legitimate_interest?.toString() === "true"
),
legal_basis:
formValues.legal_basis?.toString() === ""
? undefined
: formValues.legal_basis,
special_category:
formValues.special_category?.toString() === ""
? undefined
: formValues.special_category,
});

const [handleDelete] = useDeleteDataUseMutation();
Expand Down Expand Up @@ -156,11 +164,13 @@ export const useDataUse = (): TaxonomyHookData<DataUse> => {
name="legal_basis"
label={labels.legal_basis}
options={legalBases}
isClearable
/>
<CustomSelect
name="special_category"
label={labels.special_category}
options={specialCategories}
isClearable
/>
<CustomCreatableMultiSelect
name="recipients"
Expand Down