@@ -10,6 +10,7 @@ import {
10
10
AccordionDetails ,
11
11
Stack ,
12
12
SvgIcon ,
13
+ Skeleton ,
13
14
} from "@mui/material" ;
14
15
15
16
import Grid from "@mui/material/Grid2" ;
@@ -23,6 +24,7 @@ import { useForm, useWatch } from "react-hook-form";
23
24
import { InformationCircleIcon , TrashIcon } from "@heroicons/react/24/outline" ;
24
25
import { CippApiDialog } from "../CippComponents/CippApiDialog" ;
25
26
import { useDialog } from "../../hooks/use-dialog" ;
27
+ import { CippApiResults } from "../CippComponents/CippApiResults" ;
26
28
27
29
export const CippCustomRoles = ( ) => {
28
30
const updatePermissions = ApiPostCall ( {
@@ -46,7 +48,11 @@ export const CippCustomRoles = () => {
46
48
const setDefaults = useWatch ( { control : formControl . control , name : "Defaults" } ) ;
47
49
const selectedPermissions = useWatch ( { control : formControl . control , name : "Permissions" } ) ;
48
50
49
- const { data : apiPermissions = [ ] } = ApiGetCall ( {
51
+ const {
52
+ data : apiPermissions = [ ] ,
53
+ isFetching : apiPermissionFetching ,
54
+ isSuccess : apiPermissionSuccess ,
55
+ } = ApiGetCall ( {
50
56
url : "/api/ExecAPIPermissionList" ,
51
57
queryKey : "apiPermissions" ,
52
58
} ) ;
@@ -259,8 +265,8 @@ export const CippCustomRoles = () => {
259
265
260
266
return (
261
267
< >
262
- < Stack spacing = { 3 } xl = { 8 } md = { 12 } direction = "row" >
263
- < Box >
268
+ < Stack spacing = { 3 } direction = "row" >
269
+ < Box width = { "80%" } >
264
270
< Stack spacing = { 1 } sx = { { mb : 3 } } >
265
271
< CippFormComponent
266
272
type = "autoComplete"
@@ -310,62 +316,77 @@ export const CippCustomRoles = () => {
310
316
/>
311
317
</ Box >
312
318
313
- < Typography variant = "h5" > API Permissions</ Typography >
314
- < Stack
315
- direction = "row"
316
- display = "flex"
317
- alignItems = "center"
318
- justifyContent = { "space-between" }
319
- width = { "100%" }
320
- sx = { { my : 2 } }
321
- >
322
- < Typography variant = "body2" > Set All Permissions</ Typography >
323
-
324
- < Box sx = { { pr : 5 } } >
325
- < CippFormComponent
326
- type = "radio"
327
- name = "Defaults"
328
- options = { [
329
- {
330
- label : "None" ,
331
- value : "None" ,
332
- } ,
333
- { label : "Read" , value : "Read" } ,
334
- {
335
- label : "Read / Write" ,
336
- value : "ReadWrite" ,
337
- } ,
338
- ] }
339
- formControl = { formControl }
340
- row = { true }
341
- />
342
- </ Box >
343
- </ Stack >
344
- < Box >
319
+ { currentRole && (
345
320
< >
346
- { Object . keys ( apiPermissions )
347
- . sort ( )
348
- . map ( ( cat , catIndex ) => (
349
- < Accordion variant = "outlined" key = { `accordion-item-${ catIndex } ` } >
350
- < AccordionSummary expandIcon = { < ExpandMoreIcon /> } > { cat } </ AccordionSummary >
351
- < AccordionDetails >
352
- { Object . keys ( apiPermissions [ cat ] )
321
+ { apiPermissionFetching && < Skeleton height = { 500 } /> }
322
+ { apiPermissionSuccess && (
323
+ < >
324
+ < Typography variant = "h5" > API Permissions</ Typography >
325
+ < Stack
326
+ direction = "row"
327
+ display = "flex"
328
+ alignItems = "center"
329
+ justifyContent = { "space-between" }
330
+ width = { "100%" }
331
+ sx = { { my : 2 } }
332
+ >
333
+ < Typography variant = "body2" > Set All Permissions</ Typography >
334
+
335
+ < Box sx = { { pr : 5 } } >
336
+ < CippFormComponent
337
+ type = "radio"
338
+ name = "Defaults"
339
+ options = { [
340
+ {
341
+ label : "None" ,
342
+ value : "None" ,
343
+ } ,
344
+ { label : "Read" , value : "Read" } ,
345
+ {
346
+ label : "Read / Write" ,
347
+ value : "ReadWrite" ,
348
+ } ,
349
+ ] }
350
+ formControl = { formControl }
351
+ row = { true }
352
+ />
353
+ </ Box >
354
+ </ Stack >
355
+ < Box >
356
+ < >
357
+ { Object . keys ( apiPermissions )
353
358
. sort ( )
354
- . map ( ( obj , index ) => {
355
- return (
356
- < Grid container key = { `row-${ catIndex } -${ index } ` } className = "mb-3" >
357
- < ApiPermissionRow obj = { obj } cat = { cat } />
358
- </ Grid >
359
- ) ;
360
- } ) }
361
- </ AccordionDetails >
362
- </ Accordion >
363
- ) ) }
359
+ . map ( ( cat , catIndex ) => (
360
+ < Accordion variant = "outlined" key = { `accordion-item-${ catIndex } ` } >
361
+ < AccordionSummary expandIcon = { < ExpandMoreIcon /> } >
362
+ { cat }
363
+ </ AccordionSummary >
364
+ < AccordionDetails >
365
+ { Object . keys ( apiPermissions [ cat ] )
366
+ . sort ( )
367
+ . map ( ( obj , index ) => {
368
+ return (
369
+ < Grid
370
+ container
371
+ key = { `row-${ catIndex } -${ index } ` }
372
+ className = "mb-3"
373
+ >
374
+ < ApiPermissionRow obj = { obj } cat = { cat } />
375
+ </ Grid >
376
+ ) ;
377
+ } ) }
378
+ </ AccordionDetails >
379
+ </ Accordion >
380
+ ) ) }
381
+ </ >
382
+ </ Box >
383
+ </ >
384
+ ) }
364
385
</ >
365
- </ Box >
386
+ ) }
366
387
</ Box >
367
388
368
- < Box xl = { 4 } md = { 12 } >
389
+ < Box xl = { 3 } md = { 12 } width = "30%" >
369
390
{ selectedRole && selectedTenant ?. length > 0 && (
370
391
< >
371
392
< h5 > Allowed Tenants</ h5 >
@@ -424,6 +445,7 @@ export const CippCustomRoles = () => {
424
445
formControl = { formControl }
425
446
relatedQueryKeys = { "customRoleList" }
426
447
/>
448
+ < CippApiResults apiObject = { updatePermissions } />
427
449
< Stack direction = "row" spacing = { 2 } justifyContent = "flex-end" >
428
450
{ currentRole && (
429
451
< Button
0 commit comments