Removes the already added validators after closing the dialog (#2435)
This commit is contained in:
parent
45746e7660
commit
4fc64e6915
2 changed files with 10 additions and 1 deletions
|
@ -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 (
|
||||||
|
|
|
@ -66,6 +66,7 @@ export const AttributeValidations = () => {
|
||||||
<>
|
<>
|
||||||
{addValidatorModalOpen && (
|
{addValidatorModalOpen && (
|
||||||
<AddValidatorDialog
|
<AddValidatorDialog
|
||||||
|
selectedValidators={validators}
|
||||||
onConfirm={(newValidator) => {
|
onConfirm={(newValidator) => {
|
||||||
setValue("validations", [
|
setValue("validations", [
|
||||||
...validators,
|
...validators,
|
||||||
|
|
Loading…
Reference in a new issue