import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { DescriptionList, DescriptionListGroup, DescriptionListTerm, DescriptionListDescription, } from "@patternfly/react-core"; import type ResourceServerRepresentation from "@keycloak/keycloak-admin-client/lib/defs/resourceServerRepresentation"; import { KeycloakSpinner } from "../../components/keycloak-spinner/KeycloakSpinner"; import { useAdminClient, useFetch } from "../../context/auth/AdminClient"; import "./detail-cell.css"; type Scope = { id: string; name: string }[]; type DetailCellProps = { id: string; clientId: string; uris?: string[]; }; export const DetailCell = ({ id, clientId, uris }: DetailCellProps) => { const { t } = useTranslation("clients"); const adminClient = useAdminClient(); const [scope, setScope] = useState(); const [permissions, setPermissions] = useState(); useFetch( () => Promise.all([ adminClient.clients.listScopesByResource({ id: clientId, resourceName: id, }), adminClient.clients.listPermissionsByResource({ id: clientId, resourceId: id, }), ]), ([scopes, permissions]) => { setScope(scopes); setPermissions(permissions); }, [] ); if (!permissions || !scope) { return ; } return ( {t("uris")} {uris?.map((uri) => ( {uri} ))} {uris?.length === 0 && {t("common:none")}} {t("scopes")} {scope.map((scope) => ( {scope.name} ))} {scope.length === 0 && {t("common:none")}} {t("associatedPermissions")} {permissions.map((permission) => ( {permission.name} ))} {permissions.length === 0 && {t("common:none")}} ); };