import { useState } from "react"; import { Button, Label, Modal, ModalVariant } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; import { useFetch, useAdminClient } from "../context/auth/AdminClient"; import type RoleRepresentation from "@keycloak/keycloak-admin-client/lib/defs/roleRepresentation"; import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; import { KeycloakSpinner } from "../components/keycloak-spinner/KeycloakSpinner"; import type ClientProfileRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientProfileRepresentation"; type ClientProfile = ClientProfileRepresentation & { global: boolean; }; const AliasRenderer = ({ name, global }: ClientProfile) => { const { t } = useTranslation("roles"); return ( <> {name}{" "} {global && } ); }; export type AddClientProfileModalProps = { open: boolean; toggleDialog: () => void; onConfirm: (newReps: RoleRepresentation[]) => void; allProfiles: string[]; }; export const AddClientProfileModal = (props: AddClientProfileModalProps) => { const { t } = useTranslation("roles"); const { adminClient } = useAdminClient(); const [selectedRows, setSelectedRows] = useState([]); const [tableProfiles, setTableProfiles] = useState(); useFetch( () => adminClient.clientPolicies.listProfiles({ includeGlobalProfiles: true, }), (allProfiles) => { const globalProfiles = allProfiles.globalProfiles?.map( (globalProfiles) => ({ ...globalProfiles, global: true, }) ); const profiles = allProfiles.profiles?.map((profiles) => ({ ...profiles, global: false, })); setTableProfiles([...(globalProfiles ?? []), ...(profiles ?? [])]); }, [] ); const loader = async () => tableProfiles?.filter((item) => !props.allProfiles.includes(item.name!)) ?? []; if (!tableProfiles) { return ; } return ( { props.toggleDialog(); props.onConfirm(selectedRows); }} > {t("common:add")} , , ]} > { setSelectedRows([...rows]); }} columns={[ { name: "name", displayKey: "realm-settings:clientProfileName", cellRenderer: AliasRenderer, }, { name: "description", displayKey: "common:description", }, ]} emptyState={ } /> ); };