Remove picked validators from list (#2405)

This commit is contained in:
Erik Jan de Wit 2022-04-07 16:35:17 +02:00 committed by GitHub
parent 36cf7022f5
commit 2d1baed0e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 12 deletions

View file

@ -10,7 +10,7 @@ import {
Tr, Tr,
} from "@patternfly/react-table"; } from "@patternfly/react-table";
import { AddValidatorRoleDialog } from "./AddValidatorRoleDialog"; import { AddValidatorRoleDialog } from "./AddValidatorRoleDialog";
import { Validator, validators } 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 = {
@ -24,13 +24,19 @@ export const AddValidatorDialog = ({
}: 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 [addValidatorRoleModalOpen, toggleModal] = useToggle(); const [addValidatorRoleModalOpen, toggleModal] = useToggle();
return ( return (
<> <>
{addValidatorRoleModalOpen && ( {addValidatorRoleModalOpen && (
<AddValidatorRoleDialog <AddValidatorRoleDialog
onConfirm={(newValidator) => onConfirm(newValidator)} onConfirm={(newValidator) => {
onConfirm(newValidator);
setValidators(
validators.filter(({ name }) => name !== newValidator.name)
);
}}
open={addValidatorRoleModalOpen} open={addValidatorRoleModalOpen}
toggleDialog={toggleModal} toggleDialog={toggleModal}
selected={selectedValidator!} selected={selectedValidator!}

View file

@ -23,16 +23,8 @@ export const AddValidatorRoleDialog = ({
const { handleSubmit } = form; const { handleSubmit } = form;
const selectedRoleValidator = selected; const selectedRoleValidator = selected;
const save = () => { const save = (newValidator: Validator) => {
const formValues = form.getValues(); onConfirm({ ...newValidator, name: selected.name });
formValues.name = selectedRoleValidator.name;
const newValidator = {
name: formValues.name,
config: formValues.config ?? [],
};
onConfirm(newValidator);
toggleDialog(); toggleDialog();
}; };