import React, { useState } from "react"; import { useHistory, useRouteMatch } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { Button, ButtonVariant, PageSection } from "@patternfly/react-core"; import { cellWidth } from "@patternfly/react-table"; import type { KeyMetadataRepresentation } from "keycloak-admin/lib/defs/keyMetadataRepresentation"; import type ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation"; import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import { emptyFormatter } from "../util"; import { useAdminClient } from "../context/auth/AdminClient"; import { useRealm } from "../context/realm-context/RealmContext"; import "./RealmSettingsSection.css"; type KeyData = KeyMetadataRepresentation & { provider?: string; }; type KeysListTabProps = { realmComponents: ComponentRepresentation[]; }; export const KeysListTab = ({ realmComponents }: KeysListTabProps) => { const { t } = useTranslation("roles"); const history = useHistory(); const { url } = useRouteMatch(); const [publicKey, setPublicKey] = useState(""); const [certificate, setCertificate] = useState(""); const adminClient = useAdminClient(); const { realm: realmName } = useRealm(); const loader = async () => { const keysMetaData = await adminClient.realms.getKeys({ realm: realmName, }); const keys = keysMetaData.keys; return keys?.map((key) => { const provider = realmComponents.find( (component: ComponentRepresentation) => component.id === key.providerId ); return { ...key, provider: provider?.name } as KeyData; })!; }; const [togglePublicKeyDialog, PublicKeyDialog] = useConfirmDialog({ titleKey: t("realm-settings:publicKeys").slice(0, -1), messageKey: publicKey, continueButtonLabel: "common:close", continueButtonVariant: ButtonVariant.primary, onConfirm: async () => {}, }); const [toggleCertificateDialog, CertificateDialog] = useConfirmDialog({ titleKey: t("realm-settings:certificate"), messageKey: certificate, continueButtonLabel: "common:close", continueButtonVariant: ButtonVariant.primary, onConfirm: async () => {}, }); const goToCreate = () => history.push(`${url}/add-role`); const ProviderRenderer = ({ provider }: KeyData) => { return <>{provider}; }; const ButtonRenderer = ({ type, publicKey, certificate }: KeyData) => { if (type === "EC") { return ( <> ); } else if (type === "RSA") { return ( <>
); } }; return ( <> } /> ); };