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 { 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); }, [] ); return ( {uris?.length !== 0 && ( {t("uris")} {uris?.map((uri) => ( {uri} ))} )} {scope?.length !== 0 && ( {t("scopes")} {scope?.map((scope) => ( {scope.name} ))} )} {permissions?.length !== 0 && ( {t("associatedPermissions")} {permissions?.map((permission) => ( {permission.name} ))} )} ); };