Removes the already added validators after closing the dialog (#2435)

This commit is contained in:
Erik Jan de Wit 2022-04-13 15:18:26 +02:00 committed by GitHub
parent 45746e7660
commit 4fc64e6915
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -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<Validator>();
const [validators, setValidators] = useState(allValidator);
const [validators, setValidators] = useState(() =>
allValidator.filter(
({ name }) => !selectedValidators.map(({ key }) => key).includes(name)
)
);
const [addValidatorRoleModalOpen, toggleModal] = useToggle();
return (

View file

@ -66,6 +66,7 @@ export const AttributeValidations = () => {
<>
{addValidatorModalOpen && (
<AddValidatorDialog
selectedValidators={validators}
onConfirm={(newValidator) => {
setValue("validations", [
...validators,