Skip to content

Commit 4ab561b

Browse files
committed
custom role tweaks
1 parent b1b8ebe commit 4ab561b

File tree

1 file changed

+76
-54
lines changed

1 file changed

+76
-54
lines changed

src/components/CippSettings/CippCustomRoles.jsx

Lines changed: 76 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
AccordionDetails,
1111
Stack,
1212
SvgIcon,
13+
Skeleton,
1314
} from "@mui/material";
1415

1516
import Grid from "@mui/material/Grid2";
@@ -23,6 +24,7 @@ import { useForm, useWatch } from "react-hook-form";
2324
import { InformationCircleIcon, TrashIcon } from "@heroicons/react/24/outline";
2425
import { CippApiDialog } from "../CippComponents/CippApiDialog";
2526
import { useDialog } from "../../hooks/use-dialog";
27+
import { CippApiResults } from "../CippComponents/CippApiResults";
2628

2729
export const CippCustomRoles = () => {
2830
const updatePermissions = ApiPostCall({
@@ -46,7 +48,11 @@ export const CippCustomRoles = () => {
4648
const setDefaults = useWatch({ control: formControl.control, name: "Defaults" });
4749
const selectedPermissions = useWatch({ control: formControl.control, name: "Permissions" });
4850

49-
const { data: apiPermissions = [] } = ApiGetCall({
51+
const {
52+
data: apiPermissions = [],
53+
isFetching: apiPermissionFetching,
54+
isSuccess: apiPermissionSuccess,
55+
} = ApiGetCall({
5056
url: "/api/ExecAPIPermissionList",
5157
queryKey: "apiPermissions",
5258
});
@@ -259,8 +265,8 @@ export const CippCustomRoles = () => {
259265

260266
return (
261267
<>
262-
<Stack spacing={3} xl={8} md={12} direction="row">
263-
<Box>
268+
<Stack spacing={3} direction="row">
269+
<Box width={"80%"}>
264270
<Stack spacing={1} sx={{ mb: 3 }}>
265271
<CippFormComponent
266272
type="autoComplete"
@@ -310,62 +316,77 @@ export const CippCustomRoles = () => {
310316
/>
311317
</Box>
312318

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 && (
345320
<>
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)
353358
.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+
)}
364385
</>
365-
</Box>
386+
)}
366387
</Box>
367388

368-
<Box xl={4} md={12}>
389+
<Box xl={3} md={12} width="30%">
369390
{selectedRole && selectedTenant?.length > 0 && (
370391
<>
371392
<h5>Allowed Tenants</h5>
@@ -424,6 +445,7 @@ export const CippCustomRoles = () => {
424445
formControl={formControl}
425446
relatedQueryKeys={"customRoleList"}
426447
/>
448+
<CippApiResults apiObject={updatePermissions} />
427449
<Stack direction="row" spacing={2} justifyContent="flex-end">
428450
{currentRole && (
429451
<Button

0 commit comments

Comments
 (0)