UNPKG

@keycloakify/keycloak-admin-ui

Version:
69 lines 3.62 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { KeycloakDataTable, ListEmptyState, useAlerts, useFetch, } from "../../../ui-shared"; import { AlertVariant, Button, ButtonVariant, ToolbarItem, } from "@patternfly/react-core"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Link, useNavigate, useParams } from "react-router-dom"; import { useAdminClient } from "../../../admin-client"; import { useConfirmDialog } from "../../../components/confirm-dialog/ConfirmDialog"; import useLocaleSort, { mapByKey } from "../../../utils/useLocaleSort"; const MapperLink = ({ toDetail, ...mapper }) => (_jsx(Link, { to: toDetail(mapper.id), children: mapper.name })); export const LdapMapperList = ({ toCreate, toDetail }) => { const { adminClient } = useAdminClient(); const navigate = useNavigate(); const { t } = useTranslation(); const { addAlert, addError } = useAlerts(); const [key, setKey] = useState(0); const refresh = () => setKey(key + 1); const [mappers, setMappers] = useState([]); const localeSort = useLocaleSort(); const { id } = useParams(); const [selectedMapper, setSelectedMapper] = useState(); useFetch(() => adminClient.components.find({ parent: id, type: "org.keycloak.storage.ldap.mappers.LDAPStorageMapper", }), (mapper) => { setMappers(localeSort(mapper.map((mapper) => ({ ...mapper, name: mapper.name, type: mapper.providerId, })), mapByKey("name"))); }, [key]); const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({ titleKey: t("deleteMappingTitle", { mapperId: selectedMapper === null || selectedMapper === void 0 ? void 0 : selectedMapper.id }), messageKey: "deleteMappingConfirm", continueButtonLabel: "delete", continueButtonVariant: ButtonVariant.danger, onConfirm: async () => { try { await adminClient.components.del({ id: selectedMapper.id, }); refresh(); addAlert(t("mappingDeletedSuccess"), AlertVariant.success); setSelectedMapper(undefined); } catch (error) { addError("mappingDeletedError", error); } }, }); return (_jsxs(_Fragment, { children: [_jsx(DeleteConfirm, {}), _jsx(KeycloakDataTable, { loader: mappers, ariaLabelKey: "ldapMappersList", searchPlaceholderKey: "searchForMapper", toolbarItem: _jsx(ToolbarItem, { children: _jsx(Button, { "data-testid": "add-mapper-btn", variant: "primary", component: (props) => _jsx(Link, { ...props, to: toCreate }), children: t("addMapper") }) }), actions: [ { title: t("delete"), onRowClick: (mapper) => { setSelectedMapper(mapper); toggleDeleteDialog(); }, }, ], columns: [ { name: "name", cellRenderer: (row) => _jsx(MapperLink, { ...row, toDetail: toDetail }), }, { name: "type", }, ], emptyState: _jsx(ListEmptyState, { message: t("emptyMappers"), instructions: t("emptyMappersInstructions"), primaryActionText: t("emptyPrimaryAction"), onPrimaryAction: () => navigate(toCreate) }) }, key)] })); }; //# sourceMappingURL=LdapMapperList.js.map