2023-01-16 07:42:11 +00:00
|
|
|
import ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentRepresentation";
|
|
|
|
import ComponentTypeRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentTypeRepresentation";
|
2022-11-16 14:19:09 +00:00
|
|
|
import {
|
|
|
|
Modal,
|
|
|
|
ModalVariant,
|
|
|
|
Text,
|
|
|
|
TextVariants,
|
|
|
|
} from "@patternfly/react-core";
|
2022-03-16 09:32:23 +00:00
|
|
|
import {
|
|
|
|
TableComposable,
|
|
|
|
Tbody,
|
|
|
|
Td,
|
|
|
|
Th,
|
|
|
|
Thead,
|
|
|
|
Tr,
|
|
|
|
} from "@patternfly/react-table";
|
2023-01-16 07:42:11 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2022-04-13 13:18:26 +00:00
|
|
|
|
2023-01-16 07:42:11 +00:00
|
|
|
import { useServerInfo } from "../../../context/server-info/ServerInfoProvider";
|
|
|
|
import useToggle from "../../../utils/useToggle";
|
2022-11-16 14:19:09 +00:00
|
|
|
import type { IndexedValidations } from "../../NewAttributeSettings";
|
2022-03-16 09:32:23 +00:00
|
|
|
import { AddValidatorRoleDialog } from "./AddValidatorRoleDialog";
|
|
|
|
|
|
|
|
export type AddValidatorDialogProps = {
|
2022-11-16 14:19:09 +00:00
|
|
|
selectedValidators: IndexedValidations[];
|
2022-03-16 09:32:23 +00:00
|
|
|
toggleDialog: () => void;
|
2023-01-07 19:14:16 +00:00
|
|
|
onConfirm: (newValidator: ComponentRepresentation) => void;
|
2022-03-16 09:32:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const AddValidatorDialog = ({
|
2022-04-13 13:18:26 +00:00
|
|
|
selectedValidators,
|
2022-03-16 09:32:23 +00:00
|
|
|
toggleDialog,
|
|
|
|
onConfirm,
|
|
|
|
}: AddValidatorDialogProps) => {
|
|
|
|
const { t } = useTranslation("realm-settings");
|
2022-11-17 16:14:47 +00:00
|
|
|
const [selectedValidator, setSelectedValidator] =
|
|
|
|
useState<ComponentTypeRepresentation>();
|
|
|
|
const allValidator: ComponentTypeRepresentation[] =
|
|
|
|
useServerInfo().componentTypes?.["org.keycloak.validate.Validator"] || [];
|
|
|
|
const [validators, setValidators] = useState(
|
2022-04-13 13:18:26 +00:00
|
|
|
allValidator.filter(
|
2022-11-17 16:14:47 +00:00
|
|
|
({ id }) => !selectedValidators.map(({ key }) => key).includes(id)
|
2022-04-13 13:18:26 +00:00
|
|
|
)
|
|
|
|
);
|
2022-03-16 09:32:23 +00:00
|
|
|
const [addValidatorRoleModalOpen, toggleModal] = useToggle();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{addValidatorRoleModalOpen && (
|
|
|
|
<AddValidatorRoleDialog
|
2022-04-07 14:35:17 +00:00
|
|
|
onConfirm={(newValidator) => {
|
|
|
|
onConfirm(newValidator);
|
|
|
|
setValidators(
|
2022-11-17 16:14:47 +00:00
|
|
|
validators.filter(({ id }) => id !== newValidator.id)
|
2022-04-07 14:35:17 +00:00
|
|
|
);
|
|
|
|
}}
|
2022-03-16 09:32:23 +00:00
|
|
|
open={addValidatorRoleModalOpen}
|
|
|
|
toggleDialog={toggleModal}
|
|
|
|
selected={selectedValidator!}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<Modal
|
|
|
|
variant={ModalVariant.small}
|
|
|
|
title={t("addValidator")}
|
|
|
|
isOpen
|
|
|
|
onClose={toggleDialog}
|
|
|
|
>
|
2022-11-16 14:19:09 +00:00
|
|
|
{validators.length !== 0 ? (
|
2023-03-02 12:25:35 +00:00
|
|
|
<TableComposable variant="compact">
|
2022-11-16 14:19:09 +00:00
|
|
|
<Thead>
|
|
|
|
<Tr>
|
2023-03-02 12:25:35 +00:00
|
|
|
<Th width={30}>{t("validatorDialogColNames.colName")}</Th>
|
|
|
|
<Th width={70} modifier="fitContent">
|
|
|
|
{t("validatorDialogColNames.colDescription")}
|
|
|
|
</Th>
|
2022-03-16 09:32:23 +00:00
|
|
|
</Tr>
|
2022-11-16 14:19:09 +00:00
|
|
|
</Thead>
|
|
|
|
<Tbody>
|
2023-01-07 19:14:16 +00:00
|
|
|
{validators.map((validator) => (
|
2022-11-16 14:19:09 +00:00
|
|
|
<Tr
|
2022-11-17 16:14:47 +00:00
|
|
|
key={validator.id}
|
2022-11-16 14:19:09 +00:00
|
|
|
onRowClick={() => {
|
|
|
|
setSelectedValidator(validator);
|
|
|
|
toggleModal();
|
|
|
|
}}
|
|
|
|
isHoverable
|
|
|
|
>
|
|
|
|
<Td dataLabel={t("validatorDialogColNames.colName")}>
|
2022-11-17 16:14:47 +00:00
|
|
|
{validator.id}
|
2022-11-16 14:19:09 +00:00
|
|
|
</Td>
|
|
|
|
<Td dataLabel={t("validatorDialogColNames.colDescription")}>
|
2022-11-17 16:14:47 +00:00
|
|
|
{validator.helpText}
|
2022-11-16 14:19:09 +00:00
|
|
|
</Td>
|
|
|
|
</Tr>
|
|
|
|
))}
|
|
|
|
</Tbody>
|
|
|
|
</TableComposable>
|
|
|
|
) : (
|
|
|
|
<Text className="kc-emptyValidators" component={TextVariants.h6}>
|
|
|
|
{t("realm-settings:emptyValidators")}
|
|
|
|
</Text>
|
|
|
|
)}
|
2022-03-16 09:32:23 +00:00
|
|
|
</Modal>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|