UNPKG

@keycloakify/keycloak-admin-ui

Version:
62 lines 3.42 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { KeycloakDataTable, useFetch } from "../ui-shared"; import { Button, Label, Modal, ModalVariant } from "@patternfly/react-core"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useAdminClient } from "../admin-client"; import { KeycloakSpinner } from "../ui-shared"; import { ListEmptyState } from "../ui-shared"; import { translationFormatter } from "../utils/translationFormatter"; const AliasRenderer = ({ name, global }) => { const { t } = useTranslation(); return (_jsxs(_Fragment, { children: [name, " ", global && _jsx(Label, { color: "blue", children: t("global") })] })); }; export const AddClientProfileModal = (props) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const [selectedRows, setSelectedRows] = useState([]); const [tableProfiles, setTableProfiles] = useState(); useFetch(() => adminClient.clientPolicies.listProfiles({ includeGlobalProfiles: true, }), (allProfiles) => { var _a, _b; const globalProfiles = (_a = allProfiles.globalProfiles) === null || _a === void 0 ? void 0 : _a.map((globalProfiles) => ({ ...globalProfiles, global: true, })); const profiles = (_b = allProfiles.profiles) === null || _b === void 0 ? void 0 : _b.map((profiles) => ({ ...profiles, global: false, })); setTableProfiles([...(globalProfiles !== null && globalProfiles !== void 0 ? globalProfiles : []), ...(profiles !== null && profiles !== void 0 ? profiles : [])]); }, []); const loader = async () => { var _a; return (_a = tableProfiles === null || tableProfiles === void 0 ? void 0 : tableProfiles.filter((item) => !props.allProfiles.includes(item.name))) !== null && _a !== void 0 ? _a : []; }; if (!tableProfiles) { return _jsx(KeycloakSpinner, {}); } return (_jsx(Modal, { "data-testid": "addClientProfile", title: t("addClientProfile"), isOpen: props.open, onClose: props.toggleDialog, variant: ModalVariant.large, actions: [ _jsx(Button, { "data-testid": "add-client-profile-button", variant: "primary", isDisabled: !selectedRows.length, onClick: () => { props.toggleDialog(); props.onConfirm(selectedRows); }, children: t("add") }, "add"), _jsx(Button, { variant: "link", onClick: () => { props.toggleDialog(); }, children: t("cancel") }, "cancel"), ], children: _jsx(KeycloakDataTable, { loader: loader, ariaLabelKey: "profilesList", searchPlaceholderKey: "searchProfile", canSelectAll: true, onSelect: (rows) => { setSelectedRows([...rows]); }, columns: [ { name: "name", displayKey: "clientProfileName", cellRenderer: AliasRenderer, }, { name: "description", cellFormatters: [translationFormatter(t)], }, ], emptyState: _jsx(ListEmptyState, { hasIcon: true, message: t("noRoles"), instructions: t("noRolesInstructions"), primaryActionText: t("createRole") }) }) })); }; //# sourceMappingURL=AddClientProfileModal.js.map