@@ -8,9 +8,10 @@ import { useLocation } from 'react-router-dom';
88import TeamTable from './components/TeamTable' ;
99import AuthZLayout from '../components/AuthZLayout' ;
1010import RoleCard from '../components/RoleCard' ;
11+ import PermissionTable from '../components/PermissionTable' ;
1112import { useLibraryAuthZ } from './context' ;
1213import { AddNewTeamMemberTrigger } from './components/AddNewTeamMemberModal' ;
13- import { buildPermissionsByRoleMatrix } from './utils' ;
14+ import { buildPermissionMatrixByResource , buildPermissionMatrixByRole } from './utils' ;
1415
1516import messages from './messages' ;
1617
@@ -23,12 +24,18 @@ const LibrariesTeamManager = () => {
2324 const { data : library } = useLibrary ( libraryId ) ;
2425 const rootBradecrumb = intl . formatMessage ( messages [ 'library.authz.breadcrumb.root' ] ) || '' ;
2526 const pageTitle = intl . formatMessage ( messages [ 'library.authz.manage.page.title' ] ) ;
26- const libraryRoles = useMemo ( ( ) => roles . map ( role => ( {
27- ...role ,
28- permissions : buildPermissionsByRoleMatrix ( {
29- rolePermissions : role . permissions , permissions, resources, intl,
30- } ) ,
31- } ) ) , [ roles , permissions , resources , intl ] ) ;
27+
28+ const [ libraryPermissionsByRole , libraryPermissionsByResource ] = useMemo ( ( ) => {
29+ if ( ! roles && ! permissions && ! resources ) { return [ null , null ] ; }
30+ const permissionsByRole = buildPermissionMatrixByRole ( {
31+ roles, permissions, resources, intl,
32+ } ) ;
33+ const permissionsByResource = buildPermissionMatrixByResource ( {
34+ roles, permissions, resources, intl,
35+ } ) ;
36+
37+ return [ permissionsByRole , permissionsByResource ] ;
38+ } , [ roles , permissions , resources , intl ] ) ;
3239
3340 return (
3441 < div className = "authz-libraries" >
@@ -54,20 +61,23 @@ const LibrariesTeamManager = () => {
5461 </ Tab >
5562 < Tab eventKey = "roles" title = { intl . formatMessage ( messages [ 'library.authz.tabs.roles' ] ) } >
5663 < Container className = "p-5" >
57- { ! libraryRoles ? < Skeleton count = { 2 } height = { 200 } /> : null }
58- { libraryRoles && libraryRoles . map ( role => (
59- < RoleCard
60- key = { `${ role . role } -description` }
61- title = { role . name }
62- userCounter = { role . userCount }
63- description = { role . description }
64- permissions = { role . permissions as any [ ] }
65- />
66- ) ) }
64+ { ! libraryPermissionsByRole ? < Skeleton count = { 2 } height = { 200 } />
65+ : libraryPermissionsByRole . map ( role => (
66+ < RoleCard
67+ key = { `${ role . role } -description` }
68+ title = { role . name }
69+ userCounter = { role . userCount }
70+ description = { role . description }
71+ permissionsByResource = { role . resources as any [ ] }
72+ />
73+ ) ) }
6774 </ Container >
6875 </ Tab >
6976 < Tab id = "libraries-permissions-tab" eventKey = "permissions" title = { intl . formatMessage ( messages [ 'library.authz.tabs.permissions' ] ) } >
70- Permissions tab.
77+ < Container className = "p-5 container-mw-lg" >
78+ { ! libraryPermissionsByResource ? < Skeleton count = { 2 } height = { 200 } />
79+ : < PermissionTable permissionsTable = { libraryPermissionsByResource } roles = { roles } /> }
80+ </ Container >
7181 </ Tab >
7282 </ Tabs >
7383 </ AuthZLayout >
0 commit comments