From 4fc64e6915529ea56cb490792299c84a45945587 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 13 Apr 2022 15:18:26 +0200 Subject: [PATCH] Removes the already added validators after closing the dialog (#2435) --- .../user-profile/attribute/AddValidatorDialog.tsx | 10 +++++++++- .../user-profile/attribute/AttributeValidations.tsx | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/realm-settings/user-profile/attribute/AddValidatorDialog.tsx b/src/realm-settings/user-profile/attribute/AddValidatorDialog.tsx index e1681d3cf0..3e7fdd81fc 100644 --- a/src/realm-settings/user-profile/attribute/AddValidatorDialog.tsx +++ b/src/realm-settings/user-profile/attribute/AddValidatorDialog.tsx @@ -9,22 +9,30 @@ import { Thead, Tr, } from "@patternfly/react-table"; + +import type { KeyValueType } from "../../../components/attribute-form/attribute-convert"; import { AddValidatorRoleDialog } from "./AddValidatorRoleDialog"; import { Validator, validators as allValidator } from "./Validators"; import useToggle from "../../../utils/useToggle"; export type AddValidatorDialogProps = { + selectedValidators: KeyValueType[]; toggleDialog: () => void; onConfirm: (newValidator: Validator) => void; }; export const AddValidatorDialog = ({ + selectedValidators, toggleDialog, onConfirm, }: AddValidatorDialogProps) => { const { t } = useTranslation("realm-settings"); const [selectedValidator, setSelectedValidator] = useState(); - const [validators, setValidators] = useState(allValidator); + const [validators, setValidators] = useState(() => + allValidator.filter( + ({ name }) => !selectedValidators.map(({ key }) => key).includes(name) + ) + ); const [addValidatorRoleModalOpen, toggleModal] = useToggle(); return ( diff --git a/src/realm-settings/user-profile/attribute/AttributeValidations.tsx b/src/realm-settings/user-profile/attribute/AttributeValidations.tsx index 49178bde3f..7899993127 100644 --- a/src/realm-settings/user-profile/attribute/AttributeValidations.tsx +++ b/src/realm-settings/user-profile/attribute/AttributeValidations.tsx @@ -66,6 +66,7 @@ export const AttributeValidations = () => { <> {addValidatorModalOpen && ( { setValue("validations", [ ...validators,