@@ -20,6 +20,7 @@ import {
2020 TableContainer ,
2121 TableHead ,
2222 TableRow ,
23+ Tooltip ,
2324 Typography ,
2425 Avatar ,
2526} from '@wso2/oxygen-ui'
@@ -79,6 +80,26 @@ function formatResourcesForModal(resources: unknown): string {
7980 }
8081}
8182
83+ function isEmptyAuthorizationResources ( resources : unknown ) : boolean {
84+ if ( resources == null ) {
85+ return true
86+ }
87+
88+ if ( typeof resources === 'string' ) {
89+ return resources . trim ( ) . length === 0
90+ }
91+
92+ if ( Array . isArray ( resources ) ) {
93+ return resources . length === 0
94+ }
95+
96+ if ( typeof resources === 'object' ) {
97+ return Object . keys ( resources as Record < string , unknown > ) . length === 0
98+ }
99+
100+ return false
101+ }
102+
82103function ConsentDetailsPage ( ) : React . JSX . Element {
83104 const { t } = useTranslation ( 'common' )
84105 const { id } = useParams < { id : string } > ( )
@@ -451,51 +472,67 @@ function ConsentDetailsPage(): React.JSX.Element {
451472 </ TableRow >
452473 </ TableHead >
453474 < TableBody >
454- { ( detail . authorizations ?? [ ] ) . map ( ( authorization ) => (
455- < TableRow key = { authorization . id } >
456- < TableCell >
457- < Stack direction = "row" spacing = { 1 } alignItems = "center" >
458- < Avatar sx = { { width : 24 , height : 24 , fontSize : '0.75rem' } } >
459- { ( authorization . userId ?? 'U' ) . charAt ( 0 ) . toUpperCase ( ) }
460- </ Avatar >
461- < Typography variant = "body2" > { authorization . userId ?? '-' } </ Typography >
462- </ Stack >
463- </ TableCell >
464- < TableCell >
465- < Chip
466- label = { t (
467- `consentRegistry.status.${ getConsentStatusLabelKey (
468- authorization . status ,
469- 'authorization' ,
470- ) } `,
471- ) }
472- color = { getConsentStatusChipColor ( authorization . status ) }
473- size = "small"
474- variant = "outlined"
475- />
476- </ TableCell >
477- < TableCell >
478- < Typography variant = "body2" >
479- { formatEpochSeconds ( authorization . updatedTime ) }
480- </ Typography >
481- </ TableCell >
482- < TableCell >
483- < Button
484- size = "small"
485- variant = "contained"
486- color = "secondary"
487- startIcon = { < Eye size = { 14 } /> }
488- disabled = { ! authorization . resources }
489- onClick = { ( ) => {
490- setSelectedResourcesJson ( formatResourcesForModal ( authorization . resources ) )
491- setResourcesModalOpen ( true )
492- } }
493- >
494- { t ( 'consentRegistry.details.actions.viewResources' , 'View Resources' ) }
495- </ Button >
496- </ TableCell >
497- </ TableRow >
498- ) ) }
475+ { ( detail . authorizations ?? [ ] ) . map ( ( authorization ) => {
476+ const resourcesEmpty = isEmptyAuthorizationResources ( authorization . resources )
477+
478+ return (
479+ < TableRow key = { authorization . id } >
480+ < TableCell >
481+ < Stack direction = "row" spacing = { 1 } alignItems = "center" >
482+ < Avatar sx = { { width : 24 , height : 24 , fontSize : '0.75rem' } } >
483+ { ( authorization . userId ?? 'U' ) . charAt ( 0 ) . toUpperCase ( ) }
484+ </ Avatar >
485+ < Typography variant = "body2" > { authorization . userId ?? '-' } </ Typography >
486+ </ Stack >
487+ </ TableCell >
488+ < TableCell >
489+ < Chip
490+ label = { t (
491+ `consentRegistry.status.${ getConsentStatusLabelKey (
492+ authorization . status ,
493+ 'authorization' ,
494+ ) } `,
495+ ) }
496+ color = { getConsentStatusChipColor ( authorization . status ) }
497+ size = "small"
498+ variant = "outlined"
499+ />
500+ </ TableCell >
501+ < TableCell >
502+ < Typography variant = "body2" >
503+ { formatEpochSeconds ( authorization . updatedTime ) }
504+ </ Typography >
505+ </ TableCell >
506+ < TableCell >
507+ < Tooltip
508+ title = { t (
509+ 'consentRegistry.details.actions.noResourcesTooltip' ,
510+ 'No resources available' ,
511+ ) }
512+ disableHoverListener = { ! resourcesEmpty }
513+ >
514+ < span >
515+ < Button
516+ size = "small"
517+ variant = "contained"
518+ color = "secondary"
519+ startIcon = { < Eye size = { 14 } /> }
520+ disabled = { resourcesEmpty }
521+ onClick = { ( ) => {
522+ setSelectedResourcesJson (
523+ formatResourcesForModal ( authorization . resources ) ,
524+ )
525+ setResourcesModalOpen ( true )
526+ } }
527+ >
528+ { t ( 'consentRegistry.details.actions.viewResources' , 'View Resources' ) }
529+ </ Button >
530+ </ span >
531+ </ Tooltip >
532+ </ TableCell >
533+ </ TableRow >
534+ )
535+ } ) }
499536 </ TableBody >
500537 </ Table >
501538 </ TableContainer >
0 commit comments