|
| 1 | +import React from "react"; |
| 2 | +import { Box, Typography, Chip, Paper, Grid, Tooltip } from "@mui/material"; |
| 3 | +import { |
| 4 | + CheckCircle, |
| 5 | + Cancel, |
| 6 | + Warning, |
| 7 | + Security, |
| 8 | + Info, |
| 9 | +} from "@mui/icons-material"; |
| 10 | + |
| 11 | +/** |
| 12 | + * Visual Role Overview Component |
| 13 | + * Displays all roles in a grid with visual status indicators |
| 14 | + */ |
| 15 | +export const CippRoleOverview = ({ roles = [], onRoleClick }) => { |
| 16 | + if (!roles || roles.length === 0) return null; |
| 17 | + |
| 18 | + const getRoleStatus = (role) => { |
| 19 | + if (role.isUserHasAccess) { |
| 20 | + return { |
| 21 | + icon: <CheckCircle />, |
| 22 | + color: "success", |
| 23 | + label: "Has Access", |
| 24 | + bgColor: "success.light", |
| 25 | + }; |
| 26 | + } else if (role.isAssigned) { |
| 27 | + return { |
| 28 | + icon: <Warning />, |
| 29 | + color: "warning", |
| 30 | + label: "Assigned but No Access", |
| 31 | + bgColor: "warning.light", |
| 32 | + }; |
| 33 | + } else if (role.roleExistsInRelationship) { |
| 34 | + return { |
| 35 | + icon: <Info />, |
| 36 | + color: "info", |
| 37 | + label: "In Relationship but Not Assigned", |
| 38 | + bgColor: "info.light", |
| 39 | + }; |
| 40 | + } else { |
| 41 | + return { |
| 42 | + icon: <Cancel />, |
| 43 | + color: "default", |
| 44 | + label: "Not In Any Relationship", |
| 45 | + bgColor: "grey.200", |
| 46 | + }; |
| 47 | + } |
| 48 | + }; |
| 49 | + |
| 50 | + return ( |
| 51 | + <Grid container spacing={2}> |
| 52 | + {roles.map((role) => { |
| 53 | + const status = getRoleStatus(role); |
| 54 | + return ( |
| 55 | + <Grid item xs={12} sm={6} md={4} key={role.roleId}> |
| 56 | + <Tooltip title={role.roleDescription || role.roleName} arrow> |
| 57 | + <Paper |
| 58 | + elevation={2} |
| 59 | + sx={{ |
| 60 | + p: 2, |
| 61 | + height: "100%", |
| 62 | + cursor: onRoleClick ? "pointer" : "default", |
| 63 | + backgroundColor: status.bgColor, |
| 64 | + border: 2, |
| 65 | + borderColor: `${status.color}.main`, |
| 66 | + transition: "all 0.2s", |
| 67 | + "&:hover": onRoleClick |
| 68 | + ? { |
| 69 | + elevation: 4, |
| 70 | + transform: "translateY(-2px)", |
| 71 | + } |
| 72 | + : {}, |
| 73 | + }} |
| 74 | + onClick={() => onRoleClick && onRoleClick(role)} |
| 75 | + > |
| 76 | + <Box sx={{ display: "flex", alignItems: "flex-start", gap: 1 }}> |
| 77 | + <Box |
| 78 | + sx={{ |
| 79 | + color: `${status.color}.main`, |
| 80 | + display: "flex", |
| 81 | + alignItems: "center", |
| 82 | + }} |
| 83 | + > |
| 84 | + <Security /> |
| 85 | + </Box> |
| 86 | + <Box sx={{ flex: 1, minWidth: 0 }}> |
| 87 | + <Typography |
| 88 | + variant="subtitle2" |
| 89 | + sx={{ |
| 90 | + fontWeight: "bold", |
| 91 | + mb: 0.5, |
| 92 | + overflow: "hidden", |
| 93 | + textOverflow: "ellipsis", |
| 94 | + whiteSpace: "nowrap", |
| 95 | + }} |
| 96 | + > |
| 97 | + {role.roleName} |
| 98 | + </Typography> |
| 99 | + <Chip |
| 100 | + icon={status.icon} |
| 101 | + label={status.label} |
| 102 | + color={status.color} |
| 103 | + size="small" |
| 104 | + sx={{ fontSize: "0.7rem" }} |
| 105 | + /> |
| 106 | + {role.accessPaths && role.accessPaths.length > 0 && ( |
| 107 | + <Typography variant="caption" color="text.secondary" sx={{ display: "block", mt: 0.5 }}> |
| 108 | + {role.accessPaths.length} access path{role.accessPaths.length !== 1 ? "s" : ""} |
| 109 | + </Typography> |
| 110 | + )} |
| 111 | + {role.relationshipsWithRole && role.relationshipsWithRole.length > 0 && ( |
| 112 | + <Typography variant="caption" color="text.secondary" sx={{ display: "block", mt: 0.5 }}> |
| 113 | + {role.relationshipsWithRole.length} group{role.relationshipsWithRole.length !== 1 ? "s" : ""} |
| 114 | + </Typography> |
| 115 | + )} |
| 116 | + </Box> |
| 117 | + </Box> |
| 118 | + </Paper> |
| 119 | + </Tooltip> |
| 120 | + </Grid> |
| 121 | + ); |
| 122 | + })} |
| 123 | + </Grid> |
| 124 | + ); |
| 125 | +}; |
0 commit comments