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 type { KeyMetadataRepresentation } from "keycloak-admin/lib/defs/keyMetadataRepresentation"; 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 type ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation"; import "./RealmSettingsSection.css"; import { cellWidth } from "@patternfly/react-table"; type KeyData = KeyMetadataRepresentation & { provider?: string; }; type KeysTabInnerProps = { keys: KeyData[]; }; export const KeysTabInner = ({ keys }: KeysTabInnerProps) => { const { t } = useTranslation("roles"); const history = useHistory(); const { url } = useRouteMatch(); const [key, setKey] = useState(0); const refresh = () => setKey(new Date().getTime()); const [publicKey, setPublicKey] = useState(""); const [certificate, setCertificate] = useState(""); const loader = async () => { return keys; }; React.useEffect(() => { refresh(); }, [keys]); const [togglePublicKeyDialog, PublicKeyDialog] = useConfirmDialog({ titleKey: t("realm-settings:publicKeys").slice(0, -1), messageKey: publicKey, continueButtonLabel: "common:close", continueButtonVariant: ButtonVariant.primary, noCancelButton: true, onConfirm: async () => {}, }); const [toggleCertificateDialog, CertificateDialog] = useConfirmDialog({ titleKey: t("realm-settings:certificate"), messageKey: certificate, continueButtonLabel: "common:close", continueButtonVariant: ButtonVariant.primary, noCancelButton: true, onConfirm: async () => {}, }); const goToCreate = () => history.push(`${url}/add-role`); const ProviderRenderer = ({ provider }: KeyData) => { return <>{provider}>; }; const renderPublicKeyButton = (publicKey: string) => { return ( ); }; const ButtonRenderer = ({ provider, publicKey, certificate }: KeyData) => { if (provider === "ecdsa-generated") { return <>{renderPublicKeyButton(publicKey!)}>; } if (provider === "rsa-generated" || provider === "fallback-RS256") { return ( <>