simplify breadcrumbs

This commit is contained in:
Alex Holliday committed 2026-01-24 20:41:21 +00:00
1 parent 8d6bc7bc0b
commit 794018a6ab
1 file changed
+43 -82
@@ -2,25 +2,21 @@ import MuiBreadcrumbs from "@mui/material/Breadcrumbs";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import { Link, useLocation } from "react-router-dom"; import { Link, useLocation } from "react-router-dom";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import { ChevronRight, Home } from "lucide-react"; import { ChevronRight } from "lucide-react";
import { useTranslation } from "react-i18next";
export const Breadcrumb = ({ breadcrumbOverride }: { breadcrumbOverride?: string[] }) => { const isId = (segment: string): boolean => {
const { t } = useTranslation(); return segment.length === 24 || /^[a-f0-9-]{36}$/.test(segment);
};
export const Breadcrumb = () => {
const theme = useTheme(); const theme = useTheme();
const location = useLocation(); const location = useLocation();
// Don't show breadcrumb on dashboard const segments = location.pathname.split("/").filter((x) => x);
if (location.pathname === "/" || location.pathname === "/uptime") {
return null;
}
const pathnames = breadcrumbOverride || location.pathname.split("/").filter((x) => x); // Build simplified breadcrumb: "uptime" or "uptime / details"
const basePage = segments[0] || "home";
// Don't show if only one level (e.g., /uptime) const hasDetailsPage = segments.length > 1 && isId(segments[1]);
if (pathnames.length === 0) {
return null;
}
return ( return (
<MuiBreadcrumbs <MuiBreadcrumbs
@@ -38,80 +34,45 @@ export const Breadcrumb = ({ breadcrumbOverride }: { breadcrumbOverride?: string
}, },
}} }}
> >
<Link {hasDetailsPage ? (
to="/uptime" <Link
style={{ to={`/${basePage}`}
display: "flex", style={{ textDecoration: "none" }}
alignItems: "center", >
gap: theme.spacing(2), <Typography
textDecoration: "none", sx={{
color: theme.palette.text.secondary, fontSize: "14px",
}} color: theme.palette.text.secondary,
> "&:hover": {
<Home color: theme.palette.primary.main,
size={16} },
strokeWidth={1.5} }}
/> >
{basePage.charAt(0).toUpperCase() + basePage.slice(1)}
</Typography>
</Link>
) : (
<Typography <Typography
sx={{ sx={{
fontSize: "14px", fontSize: "14px",
color: theme.palette.text.secondary, fontWeight: 600,
"&:hover": { color: theme.palette.primary.main,
color: theme.palette.primary.main,
},
}} }}
> >
Home {basePage.charAt(0).toUpperCase() + basePage.slice(1)}
</Typography> </Typography>
</Link> )}
{pathnames.map((value, index) => { {hasDetailsPage && (
const last = index === pathnames.length - 1; <Typography
const to = `/${pathnames.slice(0, index + 1).join("/")}`; sx={{
fontSize: "14px",
let displayName = ""; fontWeight: 600,
color: theme.palette.primary.main,
// Paths that are IDs should be detail pages }}
if (value.length === 24 || value.match(/^[a-f0-9-]{36}$/)) { >
displayName = "Details"; Details
} else { </Typography>
displayName = )}
t(`common.breadcrumbs.${value}`) ||
value.charAt(0).toUpperCase() + value.slice(1);
}
return last ? (
<Typography
key={to}
sx={{
fontSize: "14px",
fontWeight: 600,
color: theme.palette.primary.main,
}}
>
{displayName}
</Typography>
) : (
<Link
key={to}
to={to}
style={{
textDecoration: "none",
}}
>
<Typography
sx={{
fontSize: "14px",
color: theme.palette.text.secondary,
"&:hover": {
color: theme.palette.primary.main,
},
}}
>
{displayName}
</Typography>
</Link>
);
})}
</MuiBreadcrumbs> </MuiBreadcrumbs>
); );
}; };