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"; import { isValidComponentType } from "./policy/PolicyDetails"; import { useMemo } from "react"; import useLocaleSort, { mapByKey } from "../../utils/useLocaleSort"; type NewPolicyDialogProps = { policyProviders?: PolicyProviderRepresentation[]; toggleDialog: () => void; onSelect: (provider: PolicyProviderRepresentation) => void; }; export const NewPolicyDialog = ({ policyProviders, onSelect, toggleDialog, }: NewPolicyDialogProps) => { const { t } = useTranslation("clients"); const localeSort = useLocaleSort(); const sortedPolicies = useMemo( () => policyProviders ? localeSort(policyProviders, mapByKey("name")) : [], [policyProviders] ); return ( {t("chooseAPolicyType")} {t("chooseAPolicyTypeInstructions")} } isOpen onClose={toggleDialog} > {t("common:name")} {t("common:description")} {sortedPolicies.map((provider) => ( onSelect(provider)} isHoverable > {provider.name} {isValidComponentType(provider.type!) && t(`policyProvider.${provider.type}`)} ))} ); };