Merge pull request #1781 from bluewave-labs/fix/fe/sidebar-selection
fix: sidebar selection
This commit is contained in:
1 file changed
+217
-212
@@ -183,7 +183,7 @@ function Sidebar() {
|
|||||||
This is the top lever for styles
|
This is the top lever for styles
|
||||||
*/
|
*/
|
||||||
sx={{
|
sx={{
|
||||||
position: 'relative',
|
position: "relative",
|
||||||
border: 1,
|
border: 1,
|
||||||
borderColor: theme.palette.primary.lowContrast,
|
borderColor: theme.palette.primary.lowContrast,
|
||||||
borderRadius: theme.shape.borderRadius,
|
borderRadius: theme.shape.borderRadius,
|
||||||
@@ -304,86 +304,55 @@ function Sidebar() {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
|
||||||
flexGrow: 1,
|
|
||||||
overflow: 'auto',
|
|
||||||
overflowX: 'hidden',
|
|
||||||
'&::-webkit-scrollbar': {
|
|
||||||
width: theme.spacing(2),
|
|
||||||
},
|
|
||||||
'&::-webkit-scrollbar-thumb': {
|
|
||||||
backgroundColor: theme.palette.primary.lowContrast,
|
|
||||||
borderRadius: theme.spacing(4),
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<List
|
|
||||||
component="nav"
|
|
||||||
aria-labelledby="nested-menu-subheader"
|
|
||||||
disablePadding
|
|
||||||
subheader={
|
|
||||||
<ListSubheader
|
|
||||||
component="div"
|
|
||||||
id="nested-menu-subheader"
|
|
||||||
sx={{
|
|
||||||
py: theme.spacing(4),
|
|
||||||
/* TODO px should be centralized in container */
|
|
||||||
px: collapsed ? theme.spacing(2) : theme.spacing(4),
|
|
||||||
backgroundColor: "transparent",
|
|
||||||
position: "static",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Menu
|
|
||||||
</ListSubheader>
|
|
||||||
}
|
|
||||||
sx={{
|
sx={{
|
||||||
px: theme.spacing(6),
|
flexGrow: 1,
|
||||||
height: "100%",
|
overflow: "auto",
|
||||||
/* overflow: "hidden", */
|
overflowX: "hidden",
|
||||||
|
"&::-webkit-scrollbar": {
|
||||||
|
width: theme.spacing(2),
|
||||||
|
},
|
||||||
|
"&::-webkit-scrollbar-thumb": {
|
||||||
|
backgroundColor: theme.palette.primary.lowContrast,
|
||||||
|
borderRadius: theme.spacing(4),
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{menu.map((item) => {
|
<List
|
||||||
if (item.path === "distributed-uptime" && distributedUptimeEnabled === false) {
|
component="nav"
|
||||||
return null;
|
aria-labelledby="nested-menu-subheader"
|
||||||
}
|
disablePadding
|
||||||
return item.path ? (
|
subheader={
|
||||||
/* If item has a path */
|
<ListSubheader
|
||||||
<Tooltip
|
component="div"
|
||||||
key={item.path}
|
id="nested-menu-subheader"
|
||||||
placement="right"
|
sx={{
|
||||||
title={collapsed ? item.name : ""}
|
py: theme.spacing(4),
|
||||||
slotProps={{
|
/* TODO px should be centralized in container */
|
||||||
popper: {
|
px: collapsed ? theme.spacing(2) : theme.spacing(4),
|
||||||
modifiers: [
|
backgroundColor: "transparent",
|
||||||
{
|
position: "static",
|
||||||
name: "offset",
|
|
||||||
options: {
|
|
||||||
offset: [0, -16],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
disableInteractive
|
|
||||||
>
|
>
|
||||||
<ListItemButton
|
Menu
|
||||||
className={location.pathname === `/${item.path}` ? "selected-path" : ""}
|
</ListSubheader>
|
||||||
onClick={() => navigate(`/${item.path}`)}
|
}
|
||||||
sx={{
|
sx={{
|
||||||
height: "37px",
|
px: theme.spacing(6),
|
||||||
gap: theme.spacing(4),
|
height: "100%",
|
||||||
borderRadius: theme.shape.borderRadius,
|
/* overflow: "hidden", */
|
||||||
px: theme.spacing(4),
|
}}
|
||||||
}}
|
>
|
||||||
>
|
{menu.map((item) => {
|
||||||
<ListItemIcon sx={{ minWidth: 0 }}>{item.icon}</ListItemIcon>
|
if (
|
||||||
<ListItemText>{item.name}</ListItemText>
|
item.path === "distributed-uptime" &&
|
||||||
</ListItemButton>
|
distributedUptimeEnabled === false
|
||||||
</Tooltip>
|
) {
|
||||||
) : collapsed ? (
|
return null;
|
||||||
/* TODO Do we ever get here? If item does not have a path and collapsed state is true */
|
}
|
||||||
<React.Fragment key={item.name}>
|
return item.path ? (
|
||||||
|
/* If item has a path */
|
||||||
<Tooltip
|
<Tooltip
|
||||||
|
key={item.path}
|
||||||
placement="right"
|
placement="right"
|
||||||
title={collapsed ? item.name : ""}
|
title={collapsed ? item.name : ""}
|
||||||
slotProps={{
|
slotProps={{
|
||||||
@@ -402,11 +371,11 @@ function Sidebar() {
|
|||||||
>
|
>
|
||||||
<ListItemButton
|
<ListItemButton
|
||||||
className={
|
className={
|
||||||
Boolean(anchorEl) && popup === item.name ? "selected-path" : ""
|
location.pathname.startsWith(`/${item.path}`) ? "selected-path" : ""
|
||||||
}
|
}
|
||||||
onClick={(event) => openPopup(event, item.name)}
|
onClick={() => navigate(`/${item.path}`)}
|
||||||
sx={{
|
sx={{
|
||||||
position: "relative",
|
height: "37px",
|
||||||
gap: theme.spacing(4),
|
gap: theme.spacing(4),
|
||||||
borderRadius: theme.shape.borderRadius,
|
borderRadius: theme.shape.borderRadius,
|
||||||
px: theme.spacing(4),
|
px: theme.spacing(4),
|
||||||
@@ -416,104 +385,68 @@ function Sidebar() {
|
|||||||
<ListItemText>{item.name}</ListItemText>
|
<ListItemText>{item.name}</ListItemText>
|
||||||
</ListItemButton>
|
</ListItemButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Menu
|
) : collapsed ? (
|
||||||
className="sidebar-popup"
|
/* TODO Do we ever get here? If item does not have a path and collapsed state is true */
|
||||||
anchorEl={anchorEl}
|
<React.Fragment key={item.name}>
|
||||||
open={Boolean(anchorEl) && popup === item.name}
|
<Tooltip
|
||||||
onClose={closePopup}
|
placement="right"
|
||||||
disableScrollLock
|
title={collapsed ? item.name : ""}
|
||||||
anchorOrigin={{
|
slotProps={{
|
||||||
vertical: "top",
|
popper: {
|
||||||
horizontal: "right",
|
modifiers: [
|
||||||
}}
|
{
|
||||||
slotProps={{
|
name: "offset",
|
||||||
paper: {
|
options: {
|
||||||
sx: {
|
offset: [0, -16],
|
||||||
mt: theme.spacing(-2),
|
|
||||||
ml: theme.spacing(1),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
MenuListProps={{ sx: { px: 1, py: 2 } }}
|
|
||||||
sx={{
|
|
||||||
ml: theme.spacing(8),
|
|
||||||
/* TODO what is this selection? */
|
|
||||||
"& .selected-path": {
|
|
||||||
backgroundColor: theme.palette.tertiary.main,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{item.nested.map((child) => {
|
|
||||||
if (
|
|
||||||
child.name === "Team" &&
|
|
||||||
authState.user?.role &&
|
|
||||||
!authState.user.role.includes("superadmin")
|
|
||||||
) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<MenuItem
|
|
||||||
className={
|
|
||||||
location.pathname.includes(child.path) ? "selected-path" : ""
|
|
||||||
}
|
|
||||||
key={child.path}
|
|
||||||
onClick={() => {
|
|
||||||
const url = URL_MAP[child.path];
|
|
||||||
if (url) {
|
|
||||||
window.open(url, "_blank", "noreferrer");
|
|
||||||
} else {
|
|
||||||
navigate(`/${child.path}`);
|
|
||||||
}
|
|
||||||
closePopup();
|
|
||||||
}}
|
|
||||||
sx={{
|
|
||||||
gap: theme.spacing(4),
|
|
||||||
opacity: 0.9,
|
|
||||||
/* TODO this has no effect? */
|
|
||||||
"& svg": {
|
|
||||||
"& path": {
|
|
||||||
stroke: theme.palette.primary.contrastTextTertiary,
|
|
||||||
strokeWidth: 1.1,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}}
|
],
|
||||||
>
|
},
|
||||||
{child.icon}
|
}}
|
||||||
{child.name}
|
disableInteractive
|
||||||
</MenuItem>
|
>
|
||||||
);
|
<ListItemButton
|
||||||
})}
|
className={
|
||||||
</Menu>
|
Boolean(anchorEl) && popup === item.name ? "selected-path" : ""
|
||||||
</React.Fragment>
|
}
|
||||||
) : (
|
onClick={(event) => openPopup(event, item.name)}
|
||||||
/* TODO Do we ever get here? If item does not have a path and collapsed state is false */
|
sx={{
|
||||||
<React.Fragment key={item.name}>
|
position: "relative",
|
||||||
<ListItemButton
|
gap: theme.spacing(4),
|
||||||
onClick={() =>
|
borderRadius: theme.shape.borderRadius,
|
||||||
setOpen((prev) => ({
|
px: theme.spacing(4),
|
||||||
...Object.fromEntries(Object.keys(prev).map((key) => [key, false])),
|
}}
|
||||||
[item.name]: !prev[item.name],
|
>
|
||||||
}))
|
<ListItemIcon sx={{ minWidth: 0 }}>{item.icon}</ListItemIcon>
|
||||||
}
|
<ListItemText>{item.name}</ListItemText>
|
||||||
sx={{
|
</ListItemButton>
|
||||||
gap: theme.spacing(4),
|
</Tooltip>
|
||||||
borderRadius: theme.shape.borderRadius,
|
<Menu
|
||||||
px: theme.spacing(4),
|
className="sidebar-popup"
|
||||||
}}
|
anchorEl={anchorEl}
|
||||||
>
|
open={Boolean(anchorEl) && popup === item.name}
|
||||||
<ListItemIcon sx={{ minWidth: 0 }}>{item.icon}</ListItemIcon>
|
onClose={closePopup}
|
||||||
<ListItemText>{item.name}</ListItemText>
|
disableScrollLock
|
||||||
{open[`${item.name}`] ? <ArrowUp /> : <ArrowDown />}
|
anchorOrigin={{
|
||||||
</ListItemButton>
|
vertical: "top",
|
||||||
<Collapse
|
horizontal: "right",
|
||||||
in={open[`${item.name}`]}
|
}}
|
||||||
timeout="auto"
|
slotProps={{
|
||||||
>
|
paper: {
|
||||||
<List
|
sx: {
|
||||||
component="div"
|
mt: theme.spacing(-2),
|
||||||
disablePadding
|
ml: theme.spacing(1),
|
||||||
sx={{ pl: theme.spacing(12) }}
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
MenuListProps={{ sx: { px: 1, py: 2 } }}
|
||||||
|
sx={{
|
||||||
|
ml: theme.spacing(8),
|
||||||
|
/* TODO what is this selection? */
|
||||||
|
"& .selected-path": {
|
||||||
|
backgroundColor: theme.palette.tertiary.main,
|
||||||
|
},
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{item.nested.map((child) => {
|
{item.nested.map((child) => {
|
||||||
if (
|
if (
|
||||||
@@ -525,7 +458,7 @@ function Sidebar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListItemButton
|
<MenuItem
|
||||||
className={
|
className={
|
||||||
location.pathname.includes(child.path) ? "selected-path" : ""
|
location.pathname.includes(child.path) ? "selected-path" : ""
|
||||||
}
|
}
|
||||||
@@ -537,51 +470,123 @@ function Sidebar() {
|
|||||||
} else {
|
} else {
|
||||||
navigate(`/${child.path}`);
|
navigate(`/${child.path}`);
|
||||||
}
|
}
|
||||||
|
closePopup();
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
gap: theme.spacing(4),
|
gap: theme.spacing(4),
|
||||||
borderRadius: theme.shape.borderRadius,
|
opacity: 0.9,
|
||||||
pl: theme.spacing(4),
|
/* TODO this has no effect? */
|
||||||
"&::before": {
|
"& svg": {
|
||||||
content: `""`,
|
"& path": {
|
||||||
position: "absolute",
|
stroke: theme.palette.primary.contrastTextTertiary,
|
||||||
top: 0,
|
strokeWidth: 1.1,
|
||||||
left: "-7px",
|
},
|
||||||
height: "100%",
|
|
||||||
borderLeft: 1,
|
|
||||||
borderLeftColor: theme.palette.primary.lowContrast,
|
|
||||||
},
|
|
||||||
"&:last-child::before": {
|
|
||||||
height: "50%",
|
|
||||||
},
|
|
||||||
"&::after": {
|
|
||||||
content: `""`,
|
|
||||||
position: "absolute",
|
|
||||||
top: "45%",
|
|
||||||
left: "-8px",
|
|
||||||
height: "3px",
|
|
||||||
width: "3px",
|
|
||||||
borderRadius: "50%",
|
|
||||||
backgroundColor: theme.palette.primary.lowContrast,
|
|
||||||
},
|
|
||||||
"&.selected-path::after": {
|
|
||||||
/* TODO what is this selector doing? */
|
|
||||||
backgroundColor: theme.palette.primary.contrastTextTertiary,
|
|
||||||
transform: "scale(1.2)",
|
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ListItemIcon sx={{ minWidth: 0 }}>{child.icon}</ListItemIcon>
|
{child.icon}
|
||||||
<ListItemText>{child.name}</ListItemText>
|
{child.name}
|
||||||
</ListItemButton>
|
</MenuItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</List>
|
</Menu>
|
||||||
</Collapse>
|
</React.Fragment>
|
||||||
</React.Fragment>
|
) : (
|
||||||
);
|
/* TODO Do we ever get here? If item does not have a path and collapsed state is false */
|
||||||
})}
|
<React.Fragment key={item.name}>
|
||||||
</List>
|
<ListItemButton
|
||||||
|
onClick={() =>
|
||||||
|
setOpen((prev) => ({
|
||||||
|
...Object.fromEntries(Object.keys(prev).map((key) => [key, false])),
|
||||||
|
[item.name]: !prev[item.name],
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
sx={{
|
||||||
|
gap: theme.spacing(4),
|
||||||
|
borderRadius: theme.shape.borderRadius,
|
||||||
|
px: theme.spacing(4),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ListItemIcon sx={{ minWidth: 0 }}>{item.icon}</ListItemIcon>
|
||||||
|
<ListItemText>{item.name}</ListItemText>
|
||||||
|
{open[`${item.name}`] ? <ArrowUp /> : <ArrowDown />}
|
||||||
|
</ListItemButton>
|
||||||
|
<Collapse
|
||||||
|
in={open[`${item.name}`]}
|
||||||
|
timeout="auto"
|
||||||
|
>
|
||||||
|
<List
|
||||||
|
component="div"
|
||||||
|
disablePadding
|
||||||
|
sx={{ pl: theme.spacing(12) }}
|
||||||
|
>
|
||||||
|
{item.nested.map((child) => {
|
||||||
|
if (
|
||||||
|
child.name === "Team" &&
|
||||||
|
authState.user?.role &&
|
||||||
|
!authState.user.role.includes("superadmin")
|
||||||
|
) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ListItemButton
|
||||||
|
className={
|
||||||
|
location.pathname.includes(child.path) ? "selected-path" : ""
|
||||||
|
}
|
||||||
|
key={child.path}
|
||||||
|
onClick={() => {
|
||||||
|
const url = URL_MAP[child.path];
|
||||||
|
if (url) {
|
||||||
|
window.open(url, "_blank", "noreferrer");
|
||||||
|
} else {
|
||||||
|
navigate(`/${child.path}`);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
sx={{
|
||||||
|
gap: theme.spacing(4),
|
||||||
|
borderRadius: theme.shape.borderRadius,
|
||||||
|
pl: theme.spacing(4),
|
||||||
|
"&::before": {
|
||||||
|
content: `""`,
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
left: "-7px",
|
||||||
|
height: "100%",
|
||||||
|
borderLeft: 1,
|
||||||
|
borderLeftColor: theme.palette.primary.lowContrast,
|
||||||
|
},
|
||||||
|
"&:last-child::before": {
|
||||||
|
height: "50%",
|
||||||
|
},
|
||||||
|
"&::after": {
|
||||||
|
content: `""`,
|
||||||
|
position: "absolute",
|
||||||
|
top: "45%",
|
||||||
|
left: "-8px",
|
||||||
|
height: "3px",
|
||||||
|
width: "3px",
|
||||||
|
borderRadius: "50%",
|
||||||
|
backgroundColor: theme.palette.primary.lowContrast,
|
||||||
|
},
|
||||||
|
"&.selected-path::after": {
|
||||||
|
/* TODO what is this selector doing? */
|
||||||
|
backgroundColor: theme.palette.primary.contrastTextTertiary,
|
||||||
|
transform: "scale(1.2)",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ListItemIcon sx={{ minWidth: 0 }}>{child.icon}</ListItemIcon>
|
||||||
|
<ListItemText>{child.name}</ListItemText>
|
||||||
|
</ListItemButton>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</List>
|
||||||
|
</Collapse>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</List>
|
||||||
</Box>
|
</Box>
|
||||||
<Divider sx={{ mt: "auto", borderColor: theme.palette.primary.lowContrast }} />
|
<Divider sx={{ mt: "auto", borderColor: theme.palette.primary.lowContrast }} />
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user