From 9906dcb6ce7ffae10871c7c72e948d3919939846 Mon Sep 17 00:00:00 2001 From: Maksim Efremov Date: Mon, 16 Dec 2024 14:14:38 +0300 Subject: [PATCH] chore(ACL): extract 'isGranted' method [YTFRONT-4560] --- packages/ui/src/ui/containers/ACL/ACL.tsx | 4 ++-- packages/ui/src/ui/utils/acl/index.ts | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/ui/src/ui/containers/ACL/ACL.tsx b/packages/ui/src/ui/containers/ACL/ACL.tsx index 24359a01c..9c09fd828 100644 --- a/packages/ui/src/ui/containers/ACL/ACL.tsx +++ b/packages/ui/src/ui/containers/ACL/ACL.tsx @@ -35,7 +35,7 @@ import {ObjectPermissionRowWithExpand, PreparedApprover} from '../../store/selec import {SegmentControl, SegmentControlItem} from '../../components/SegmentControl/SegmentControl'; import WithStickyToolbar from '../../components/WithStickyToolbar/WithStickyToolbar'; -import {PreparedRole} from '../../utils/acl'; +import {PreparedRole, isGranted} from '../../utils/acl'; import {AclModeControl} from './AclModeControl'; import {ExpandButton} from '../../components/ExpandButton'; import {AclColumnsCell} from './AclColumnsCell'; @@ -601,7 +601,7 @@ class ACL extends Component { UIFactory.getAclPermissionsSettings()[idmKind]; function toSegmentItem(name: string, role?: boolean | PreparedRole, invert?: boolean) { - const value = 'boolean' === typeof role ? role : role?.state === 'granted'; + const value = isGranted(role); return { name, value: invert ? !value : value, diff --git a/packages/ui/src/ui/utils/acl/index.ts b/packages/ui/src/ui/utils/acl/index.ts index 2e7cfa5d5..bc1835a0a 100644 --- a/packages/ui/src/ui/utils/acl/index.ts +++ b/packages/ui/src/ui/utils/acl/index.ts @@ -165,3 +165,7 @@ export function convertFromUIPermission(permission: YTPermissionTypeUI): { } return {permission}; } + +export function isGranted(role: boolean | PreparedRole | undefined) { + return 'boolean' === typeof role ? role : role?.state === 'granted'; +}