11import { useMemo } from 'react' ;
22import { useIntl } from '@edx/frontend-platform/i18n' ;
33import { Person } from '@openedx/paragon/icons' ;
4- import { useValidateUserPermissionsNonSuspense } from '@src/data/hooks' ;
5- import {
6- CONTENT_COURSE_PERMISSIONS , CONTENT_LIBRARY_PERMISSIONS , VIEW_TEAM_PERMISSIONS ,
7- } from '@src/authz-module/roles-permissions' ;
4+ import { useViewTeamPermissions } from '@src/authz-module/hooks/useViewTeamPermissions' ;
85import { CONTEXT_TYPES } from '@src/authz-module/constants' ;
96import MultipleChoiceFilter from './MultipleChoiceFilter' ;
107import { MultipleChoiceFilterProps } from './types' ;
@@ -16,24 +13,16 @@ const RolesFilter = ({
1613 filterButtonText, filterValue, setFilter, disabled,
1714} : RolesFilterProps ) => {
1815 const intl = useIntl ( ) ;
19- const { data : permissions } = useValidateUserPermissionsNonSuspense ( VIEW_TEAM_PERMISSIONS ) ;
16+ const { isCourseViewAllowed , isLibraryViewAllowed , isLoading } = useViewTeamPermissions ( ) ;
2017
21- // Only show role groups for the domains the user can view. Global roles stay
22- // hidden until a platform-wide permission is available to gate them on.
23- const allowedContexts = useMemo ( ( ) => {
24- const contexts = new Set < string > ( ) ;
25- permissions ?. forEach ( ( p ) => {
26- if ( ! p . allowed ) { return ; }
27- if ( p . action === CONTENT_LIBRARY_PERMISSIONS . VIEW_LIBRARY_TEAM ) { contexts . add ( CONTEXT_TYPES . LIBRARY ) ; }
28- if ( p . action === CONTENT_COURSE_PERMISSIONS . VIEW_COURSE_TEAM ) { contexts . add ( CONTEXT_TYPES . COURSE ) ; }
18+ const rolesOptions = useMemo ( ( ) => {
19+ if ( isLoading ) { return [ ] ; }
20+ return getRolesFiltersOptions ( intl ) . filter ( ( option ) => {
21+ if ( option . contextType === CONTEXT_TYPES . COURSE ) { return isCourseViewAllowed ; }
22+ if ( option . contextType === CONTEXT_TYPES . LIBRARY ) { return isLibraryViewAllowed ; }
23+ return false ;
2924 } ) ;
30- return contexts ;
31- } , [ permissions ] ) ;
32-
33- const rolesOptions = useMemo (
34- ( ) => getRolesFiltersOptions ( intl ) . filter ( ( option ) => allowedContexts . has ( option . contextType ) ) ,
35- [ intl , allowedContexts ] ,
36- ) ;
25+ } , [ intl , isCourseViewAllowed , isLibraryViewAllowed , isLoading ] ) ;
3726 return (
3827 < MultipleChoiceFilter
3928 filterButtonText = { filterButtonText }
0 commit comments