import React, { useMemo, useState } from "react"; import { AlertVariant, Button, ButtonVariant, Label, PageSection, ToolbarItem, } from "@patternfly/react-core"; import { Divider, Flex, FlexItem, Radio, Title } from "@patternfly/react-core"; import { CodeEditor, Language } from "@patternfly/react-code-editor"; import { KeycloakDataTable } from "../components/table-toolbar/KeycloakDataTable"; import { ListEmptyState } from "../components/list-empty-state/ListEmptyState"; import { useTranslation } from "react-i18next"; import { useAdminClient } from "../context/auth/AdminClient"; import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog"; import { useRealm } from "../context/realm-context/RealmContext"; import { useAlerts } from "../components/alert/Alerts"; import { Link } from "react-router-dom"; import "./RealmSettingsSection.css"; import type ClientPolicyExecutorRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientPolicyExecutorRepresentation"; import { toNewClientProfile } from "./routes/NewClientProfile"; type ClientProfile = { description?: string; executors?: ClientPolicyExecutorRepresentation[]; name?: string; global: boolean; }; export const ProfilesTab = () => { const { t } = useTranslation("realm-settings"); const adminClient = useAdminClient(); const { realm } = useRealm(); const { addAlert, addError } = useAlerts(); const [profiles, setProfiles] = useState(); const [show, setShow] = useState(false); const loader = async () => { const allProfiles = await adminClient.clientPolicies.listProfiles({ realm, includeGlobalProfiles: true, }); const globalProfiles = allProfiles.globalProfiles?.map( (globalProfiles) => ({ ...globalProfiles, global: true, }) ); const profiles = allProfiles.profiles?.map((profiles) => ({ ...profiles, global: false, })); const allClientProfiles = globalProfiles?.concat(profiles ?? []); setProfiles(allClientProfiles); return allClientProfiles ?? []; }; const code = useMemo(() => JSON.stringify(profiles, null, 2), [profiles]); const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({ titleKey: t("deleteClientProfileConfirmTitle"), messageKey: t("deleteClientProfileConfirm"), continueButtonLabel: t("delete"), continueButtonVariant: ButtonVariant.danger, onConfirm: async () => { try { // delete client profile here addAlert(t("deleteClientSuccess"), AlertVariant.success); } catch (error) { addError(t("deleteClientError"), error); } }, }); const cellFormatter = (row: ClientProfile) => ( {row.name} {""} {row.global && } ); return ( <> {t("profilesConfigType")} setShow(false)} label={t("profilesConfigTypes.formView")} id="formView-radioBtn" className="kc-form-radio-btn pf-u-mr-sm pf-u-ml-sm" /> setShow(true)} label={t("profilesConfigTypes.jsonEditor")} id="jsonEditor-radioBtn" className="kc-editor-radio-btn" /> {!show ? ( } isRowDisabled={(value) => value.global === true} actions={[ { title: t("common:delete"), onRowClick: () => { toggleDeleteDialog(); }, }, ]} columns={[ { name: "name", displayKey: t("clientProfileName"), cellRenderer: cellFormatter, }, { name: "description", displayKey: t("clientProfileDescription"), }, ]} emptyState={ } /> ) : ( <>
)} ); };