2022-01-21 14:10:36 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import {
|
|
|
|
Modal,
|
|
|
|
ModalVariant,
|
|
|
|
TextContent,
|
|
|
|
Text,
|
|
|
|
TextVariants,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
import {
|
|
|
|
TableComposable,
|
|
|
|
Tbody,
|
|
|
|
Td,
|
|
|
|
Th,
|
|
|
|
Thead,
|
|
|
|
Tr,
|
|
|
|
} from "@patternfly/react-table";
|
|
|
|
|
|
|
|
import type PolicyProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/policyProviderRepresentation";
|
2022-05-23 08:52:06 +00:00
|
|
|
import { isValidComponentType } from "./policy/PolicyDetails";
|
2022-10-17 13:09:50 +00:00
|
|
|
import { useMemo } from "react";
|
|
|
|
import useLocaleSort, { mapByKey } from "../../utils/useLocaleSort";
|
2022-01-21 14:10:36 +00:00
|
|
|
|
|
|
|
type NewPolicyDialogProps = {
|
|
|
|
policyProviders?: PolicyProviderRepresentation[];
|
|
|
|
toggleDialog: () => void;
|
|
|
|
onSelect: (provider: PolicyProviderRepresentation) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const NewPolicyDialog = ({
|
|
|
|
policyProviders,
|
|
|
|
onSelect,
|
|
|
|
toggleDialog,
|
|
|
|
}: NewPolicyDialogProps) => {
|
|
|
|
const { t } = useTranslation("clients");
|
2022-10-17 13:09:50 +00:00
|
|
|
const localeSort = useLocaleSort();
|
|
|
|
|
|
|
|
const sortedPolicies = useMemo(
|
|
|
|
() =>
|
|
|
|
policyProviders ? localeSort(policyProviders, mapByKey("name")) : [],
|
|
|
|
[policyProviders]
|
|
|
|
);
|
2022-01-21 14:10:36 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
aria-labelledby={t("addPredefinedMappers")}
|
|
|
|
variant={ModalVariant.medium}
|
|
|
|
header={
|
|
|
|
<TextContent>
|
|
|
|
<Text component={TextVariants.h1}>{t("chooseAPolicyType")}</Text>
|
|
|
|
<Text>{t("chooseAPolicyTypeInstructions")}</Text>
|
|
|
|
</TextContent>
|
|
|
|
}
|
|
|
|
isOpen
|
|
|
|
onClose={toggleDialog}
|
|
|
|
>
|
|
|
|
<TableComposable aria-label={t("policies")} variant="compact">
|
|
|
|
<Thead>
|
|
|
|
<Tr>
|
|
|
|
<Th>{t("common:name")}</Th>
|
|
|
|
<Th>{t("common:description")}</Th>
|
|
|
|
</Tr>
|
|
|
|
</Thead>
|
|
|
|
<Tbody>
|
2022-10-17 13:09:50 +00:00
|
|
|
{sortedPolicies.map((provider) => (
|
2022-01-21 14:10:36 +00:00
|
|
|
<Tr
|
|
|
|
key={provider.type}
|
|
|
|
data-testid={provider.type}
|
|
|
|
onRowClick={() => onSelect(provider)}
|
|
|
|
isHoverable
|
|
|
|
>
|
|
|
|
<Td>{provider.name}</Td>
|
2022-05-23 08:52:06 +00:00
|
|
|
<Td>
|
|
|
|
{isValidComponentType(provider.type!) &&
|
|
|
|
t(`policyProvider.${provider.type}`)}
|
|
|
|
</Td>
|
2022-01-21 14:10:36 +00:00
|
|
|
</Tr>
|
|
|
|
))}
|
|
|
|
</Tbody>
|
|
|
|
</TableComposable>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|