UNPKG

@keycloakify/keycloak-admin-ui

Version:
29 lines 2.59 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { Checkbox, FormGroup, Grid, GridItem } from "@patternfly/react-core"; import { Controller, useFormContext } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { FormAccess } from "../../../components/form/FormAccess"; import { HelpItem } from "../../../ui-shared"; import "../../realm-settings-section.css"; const Permissions = ({ name }) => { const { t } = useTranslation(); const { control } = useFormContext(); return (_jsx(Grid, { children: _jsx(Controller, { name: `permissions.${name}`, control: control, defaultValue: [], render: ({ field }) => (_jsxs(_Fragment, { children: [_jsx(GridItem, { lg: 4, sm: 6, children: _jsx(Checkbox, { id: `user-${name}`, label: t("user"), value: "user", "data-testid": `user-${name}`, isChecked: field.value.includes("user"), onChange: () => { const option = "user"; const changedValue = field.value.includes(option) ? field.value.filter((item) => item !== option) : [...field.value, option]; field.onChange(changedValue); } }) }), _jsx(GridItem, { lg: 8, sm: 6, children: _jsx(Checkbox, { id: `admin-${name}`, label: t("admin"), value: "admin", "data-testid": `admin-${name}`, isChecked: field.value.includes("admin"), onChange: () => { const option = "admin"; const changedValue = field.value.includes(option) ? field.value.filter((item) => item !== option) : [...field.value, option]; field.onChange(changedValue); } }) })] })) }) })); }; export const AttributePermission = () => { const { t } = useTranslation(); return (_jsxs(FormAccess, { role: "manage-realm", isHorizontal: true, children: [_jsx(FormGroup, { hasNoPaddingTop: true, label: t("whoCanEdit"), labelIcon: _jsx(HelpItem, { helpText: t("whoCanEditHelp"), fieldLabelId: "whoCanEdit" }), fieldId: "kc-who-can-edit", children: _jsx(Permissions, { name: "edit" }) }), _jsx(FormGroup, { hasNoPaddingTop: true, label: t("whoCanView"), labelIcon: _jsx(HelpItem, { helpText: t("whoCanViewHelp"), fieldLabelId: "whoCanView" }), fieldId: "kc-who-can-view", children: _jsx(Permissions, { name: "view" }) })] })); }; //# sourceMappingURL=AttributePermission.js.map