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, Thead,
Tr, Tr,
} from "@patternfly/react-table"; } from "@patternfly/react-table";
import type { KeyValueType } from "../../../components/attribute-form/attribute-convert";
import { AddValidatorRoleDialog } from "./AddValidatorRoleDialog"; import { AddValidatorRoleDialog } from "./AddValidatorRoleDialog";
import { Validator, validators as allValidator } from "./Validators"; import { Validator, validators as allValidator } from "./Validators";
import useToggle from "../../../utils/useToggle"; import useToggle from "../../../utils/useToggle";
export type AddValidatorDialogProps = { export type AddValidatorDialogProps = {
selectedValidators: KeyValueType[];
toggleDialog: () => void; toggleDialog: () => void;
onConfirm: (newValidator: Validator) => void; onConfirm: (newValidator: Validator) => void;
}; };
export const AddValidatorDialog = ({ export const AddValidatorDialog = ({
selectedValidators,
toggleDialog, toggleDialog,
onConfirm, onConfirm,
}: AddValidatorDialogProps) => { }: AddValidatorDialogProps) => {
const { t } = useTranslation("realm-settings"); const { t } = useTranslation("realm-settings");
const [selectedValidator, setSelectedValidator] = useState<Validator>(); 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(); const [addValidatorRoleModalOpen, toggleModal] = useToggle();
return ( return (

View file

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