Skip to content

Commit

Permalink
fix: fix role permission grid (#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbllmnn authored Oct 21, 2024
1 parent a118a38 commit ba0a7fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import {
useTranslation
} from 'react-i18next';

import BaseEntity from '@terrestris/shogun-util/dist/model/BaseEntity';
import PermissionCollectionType from '@terrestris/shogun-util/dist/model/enum/PermissionCollectionType';
import Group from '@terrestris/shogun-util/dist/model/Group';
import GroupInstancePermission from '@terrestris/shogun-util/dist/model/security/GroupInstancePermission';
import GenericEntityService from '@terrestris/shogun-util/dist/service/GenericEntityService';
import { PageOpts } from '@terrestris/shogun-util/dist/service/GenericService';

import useSHOGunAPIClient from '../../../../Hooks/useSHOGunAPIClient';
Expand All @@ -32,7 +30,10 @@ const GroupPermissionGrid: React.FC<GroupPermissionGridProps> = ({
const client = useSHOGunAPIClient();

const service = useCallback(() => {
return (client?.[entityType] as () => GenericEntityService<BaseEntity>)();
// for unknown reasons, just calling the function here will result in 'this'
// not being defined in the function, so 'apply' is used to set 'this' correctly
// @ts-expect-error
return client?.[entityType].apply(client);
}, [client, entityType]);

const getGroupInstancePermissions = async (id: number) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import {
useTranslation
} from 'react-i18next';

import BaseEntity from '@terrestris/shogun-util/dist/model/BaseEntity';
import PermissionCollectionType from '@terrestris/shogun-util/dist/model/enum/PermissionCollectionType';
import Role from '@terrestris/shogun-util/dist/model/Role';
import RoleInstancePermission from '@terrestris/shogun-util/dist/model/security/RoleInstancePermission';
import GenericEntityService from '@terrestris/shogun-util/dist/service/GenericEntityService';
import { PageOpts } from '@terrestris/shogun-util/dist/service/GenericService';

import useSHOGunAPIClient from '../../../../Hooks/useSHOGunAPIClient';
Expand All @@ -40,7 +38,10 @@ const RolePermissionGrid: React.FC<RolePermissionGridProps> = ({
const client = useSHOGunAPIClient();

const service = useMemo(() => {
return (client?.[entityType] as () => GenericEntityService<BaseEntity>)();
// for unknown reasons, just calling the function here will result in 'this'
// not being defined in the function, so 'apply' is used to set 'this' correctly
// @ts-expect-error
return client?.[entityType].apply(client);
}, [client, entityType]);

const getRoleInstancePermissions = async (id: number) => {
Expand Down

0 comments on commit ba0a7fb

Please sign in to comment.