@@ -29,6 +29,7 @@ import Typography from '@material-ui/core/Typography';
29
29
import { Client , Configuration , LoggedUser , Pool , Session , SessionConfiguration , SessionUpdateConfiguration , Template , User , UserConfiguration , UserUpdateConfiguration } from '@substrate/playground-client' ;
30
30
import { CenteredContainer , ErrorSnackbar , LoadingPanel } from '../components' ;
31
31
import { useInterval } from '../hooks' ;
32
+ import { canCustomizeDuration , canCustomizePoolAffinity , hasAdminEditRights , hasAdminReadRights } from '../utils' ;
32
33
import { DialogActions , DialogContentText , MenuItem } from '@material-ui/core' ;
33
34
import { Autocomplete } from '@material-ui/lab' ;
34
35
@@ -38,12 +39,12 @@ const useStyles = makeStyles({
38
39
} ,
39
40
} ) ;
40
41
41
- function NoResourcesContainer ( { label, action } : { label : string , action ?: ( ) => void } ) : JSX . Element {
42
+ function NoResourcesContainer ( { user , label, action } : { user : LoggedUser , label : string , action ?: ( ) => void } ) : JSX . Element {
42
43
return (
43
44
< Container >
44
45
< Typography variant = "h6" >
45
46
{ label }
46
- { action &&
47
+ { ( action && hasAdminEditRights ( user ) ) &&
47
48
< Tooltip title = "Create" >
48
49
< IconButton aria-label = "create" onClick = { action } >
49
50
< AddIcon />
@@ -77,18 +78,6 @@ function Resources<T>( { children, label, callback }: { children: (resources: Re
77
78
}
78
79
}
79
80
80
- function paritytechMember ( user : LoggedUser ) : boolean {
81
- return user . organizations . indexOf ( 'paritytech' ) != - 1 ;
82
- }
83
-
84
- function canCustomizeDuration ( user : LoggedUser ) : boolean {
85
- return user . admin || user . canCustomizeDuration || paritytechMember ( user ) ;
86
- }
87
-
88
- function canCustomizePoolAffinity ( user : LoggedUser ) : boolean {
89
- return user . admin || user . canCustomizePoolAffinity || paritytechMember ( user ) ;
90
- }
91
-
92
81
export function canCustomize ( user : LoggedUser ) : boolean {
93
82
return canCustomizeDuration ( user ) || canCustomizePoolAffinity ( user ) ;
94
83
}
@@ -327,7 +316,7 @@ function Sessions({ client, conf, user }: { client: Client, conf: Configuration,
327
316
{ Object . keys ( resources ) . length > 0
328
317
?
329
318
< >
330
- < EnhancedTableToolbar label = "Sessions" selected = { selected } onCreate = { ( ) => setShowCreationDialog ( true ) } onUpdate = { ( ) => setShowUpdateDialog ( true ) } onDelete = { ( ) => onDelete ( setSessions ) } />
319
+ < EnhancedTableToolbar user = { user } label = "Sessions" selected = { selected } onCreate = { ( ) => setShowCreationDialog ( true ) } onUpdate = { ( ) => setShowUpdateDialog ( true ) } onDelete = { ( ) => onDelete ( setSessions ) } />
331
320
< TableContainer component = { Paper } >
332
321
< Table className = { classes . table } aria-label = "simple table" >
333
322
< TableHead >
@@ -374,7 +363,7 @@ function Sessions({ client, conf, user }: { client: Client, conf: Configuration,
374
363
</ Table >
375
364
</ TableContainer >
376
365
</ >
377
- : < NoResourcesContainer label = { ` No sessions` } action = { ( ) => setShowCreationDialog ( true ) } /> }
366
+ : < NoResourcesContainer user = { user } label = " No sessions" action = { ( ) => setShowCreationDialog ( true ) } /> }
378
367
{ errorMessage &&
379
368
< ErrorSnackbar open = { true } message = { errorMessage } onClose = { ( ) => setErrorMessage ( null ) } /> }
380
369
< SessionCreationDialog allowUserSelection = { true } client = { client } conf = { conf } sessions = { resources } user = { user } users = { users } templates = { templates } show = { showCreationDialog } onCreate = { ( conf , id ) => onCreate ( conf , id , setSessions ) } onHide = { ( ) => setShowCreationDialog ( false ) } />
@@ -386,14 +375,14 @@ function Sessions({ client, conf, user }: { client: Client, conf: Configuration,
386
375
) ;
387
376
}
388
377
389
- function Templates ( { client } : { client : Client } ) : JSX . Element {
378
+ function Templates ( { client, user } : { client : Client , user : LoggedUser } ) : JSX . Element {
390
379
const classes = useStyles ( ) ;
391
380
392
381
return (
393
382
< Resources < Template > label = "Templates" callback = { async ( ) => ( await client . get ( ) ) . templates } >
394
383
{ ( resources : Record < string , Template > ) => (
395
384
< >
396
- < EnhancedTableToolbar label = "Templates" />
385
+ < EnhancedTableToolbar user = { user } label = "Templates" />
397
386
< TableContainer component = { Paper } >
398
387
< Table className = { classes . table } aria-label = "simple table" >
399
388
< TableHead >
@@ -474,20 +463,10 @@ function DeleteConfirmationDialog({open, onClose, onConfirmation}: {open: boolea
474
463
) ;
475
464
}
476
465
477
- function EnhancedTableToolbar ( { label , selected = null , onCreate, onUpdate, onDelete } : { label : string , selected ?: string | null , onCreate ?: ( ) => void , onUpdate ?: ( ) => void , onDelete ?: ( ) => void } ) : JSX . Element {
466
+ function EditToolbar ( { selected, onCreate, onUpdate, onDelete } : { selected ?: string | null , onCreate ?: ( ) => void , onUpdate ?: ( ) => void , onDelete ?: ( ) => void } ) : JSX . Element {
478
467
const [ open , setOpen ] = React . useState ( false ) ;
479
- const classes = useToolbarStyles ( ) ;
480
- return (
481
- < >
482
- < Toolbar
483
- className = { clsx ( classes . root , {
484
- [ classes . highlight ] : selected != null ,
485
- } ) }
486
- >
487
- < Typography className = { classes . title } variant = "h6" id = "tableTitle" component = "div" >
488
- { label }
489
- </ Typography >
490
- { selected ?
468
+ if ( selected ) {
469
+ return (
491
470
< >
492
471
{ onUpdate &&
493
472
< Tooltip title = "Update" >
@@ -503,15 +482,35 @@ function EnhancedTableToolbar({ label, selected = null, onCreate, onUpdate, onDe
503
482
</ Tooltip > }
504
483
< DeleteConfirmationDialog open = { open } onClose = { ( ) => setOpen ( false ) } onConfirmation = { onDelete } />
505
484
</ >
506
- : < >
485
+ ) ;
486
+ } else {
487
+ return (
488
+ < >
507
489
{ onCreate &&
508
490
< Tooltip title = "Create" >
509
491
< IconButton aria-label = "create" onClick = { onCreate } >
510
492
< AddIcon />
511
493
</ IconButton >
512
494
</ Tooltip > }
513
495
</ >
514
- }
496
+ ) ;
497
+ }
498
+ }
499
+
500
+ function EnhancedTableToolbar ( { user, label, selected = null , onCreate, onUpdate, onDelete } : { user : LoggedUser , label : string , selected ?: string | null , onCreate ?: ( ) => void , onUpdate ?: ( ) => void , onDelete ?: ( ) => void } ) : JSX . Element {
501
+ const classes = useToolbarStyles ( ) ;
502
+ return (
503
+ < >
504
+ < Toolbar
505
+ className = { clsx ( classes . root , {
506
+ [ classes . highlight ] : selected != null ,
507
+ } ) }
508
+ >
509
+ < Typography className = { classes . title } variant = "h6" id = "tableTitle" component = "div" >
510
+ { label }
511
+ </ Typography >
512
+ { hasAdminEditRights ( user ) &&
513
+ < EditToolbar selected = { selected } onCreate = { onCreate } onUpdate = { onUpdate } onDelete = { onDelete } /> }
515
514
</ Toolbar >
516
515
</ >
517
516
) ;
@@ -747,7 +746,7 @@ function Users({ client, user, conf }: { client: Client, user: LoggedUser, conf:
747
746
< Resources < User > label = "Users" callback = { async ( ) => await client . listUsers ( ) } >
748
747
{ ( resources : Record < string , User > , setUsers : Dispatch < SetStateAction < Record < string , User > | null > > ) => (
749
748
< >
750
- < EnhancedTableToolbar label = "Users" selected = { selected } onCreate = { ( ) => setShowCreationDialog ( true ) } onUpdate = { ( ) => setShowUpdateDialog ( true ) } onDelete = { ( ) => onDelete ( setUsers ) } />
749
+ < EnhancedTableToolbar user = { user } label = "Users" selected = { selected } onCreate = { ( ) => setShowCreationDialog ( true ) } onUpdate = { ( ) => setShowUpdateDialog ( true ) } onDelete = { ( ) => onDelete ( setUsers ) } />
751
750
< TableContainer component = { Paper } >
752
751
< Table className = { classes . table } aria-label = "simple table" >
753
752
< TableHead >
@@ -839,14 +838,14 @@ function DetailsPanel({ conf }: { conf: Configuration }): JSX.Element {
839
838
) ;
840
839
}
841
840
842
- function Pools ( { client } : { client : Client } ) : JSX . Element {
841
+ function Pools ( { client, user } : { client : Client , user : LoggedUser } ) : JSX . Element {
843
842
const classes = useStyles ( ) ;
844
843
845
844
return (
846
845
< Resources < Pool > label = "Pools" callback = { async ( ) => await client . listPools ( ) } >
847
846
{ ( resources : Record < string , Pool > ) => (
848
847
< >
849
- < EnhancedTableToolbar label = "Pools" />
848
+ < EnhancedTableToolbar user = { user } label = "Pools" />
850
849
< TableContainer component = { Paper } >
851
850
< Table className = { classes . table } aria-label = "simple table" >
852
851
< TableHead >
@@ -894,12 +893,12 @@ export function AdminPanel({ client, user, conf }: { client: Client, user: Logge
894
893
{ value == 0
895
894
? < DetailsPanel conf = { conf } />
896
895
: value == 1
897
- ? < Templates client = { client } />
896
+ ? < Templates client = { client } user = { user } />
898
897
: value == 2
899
898
? < Users client = { client } user = { user } conf = { conf } />
900
899
: value == 3
901
900
? < Sessions client = { client } conf = { conf } user = { user } />
902
- : < Pools client = { client } /> }
901
+ : < Pools client = { client } user = { user } /> }
903
902
</ Paper >
904
903
</ CenteredContainer >
905
904
) ;
0 commit comments