2026-01-23 19:58:37 +00:00
|
|
|
import MuiBreadcrumbs from "@mui/material/Breadcrumbs";
|
|
|
|
|
import Typography from "@mui/material/Typography";
|
|
|
|
|
import { Link, useLocation } from "react-router-dom";
|
|
|
|
|
import { useTheme } from "@mui/material/styles";
|
2026-01-24 20:41:21 +00:00
|
|
|
import { ChevronRight } from "lucide-react";
|
2026-01-23 19:58:37 +00:00
|
|
|
|
2026-01-24 20:41:21 +00:00
|
|
|
const isId = (segment: string): boolean => {
|
|
|
|
|
return segment.length === 24 || /^[a-f0-9-]{36}$/.test(segment);
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-29 21:08:26 +00:00
|
|
|
const actionSegments = ["create", "configure"];
|
|
|
|
|
|
2026-01-24 20:41:21 +00:00
|
|
|
export const Breadcrumb = () => {
|
2026-01-23 19:58:37 +00:00
|
|
|
const theme = useTheme();
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
|
2026-01-24 20:41:21 +00:00
|
|
|
const segments = location.pathname.split("/").filter((x) => x);
|
2026-01-23 19:58:37 +00:00
|
|
|
|
2026-01-29 21:08:26 +00:00
|
|
|
// Build simplified breadcrumb: "uptime" or "uptime / details" or "uptime / create"
|
2026-01-24 20:41:21 +00:00
|
|
|
const basePage = segments[0] || "home";
|
2026-01-29 21:08:26 +00:00
|
|
|
|
|
|
|
|
const secondSegment = segments[1];
|
|
|
|
|
const isActionPage = secondSegment && actionSegments.includes(secondSegment); // create/config
|
|
|
|
|
const isDetailsPage = secondSegment && isId(secondSegment); // details
|
|
|
|
|
const hasSubPage = isActionPage || isDetailsPage;
|
|
|
|
|
|
|
|
|
|
const getSubPageLabel = (): string => {
|
|
|
|
|
if (isActionPage) {
|
|
|
|
|
return secondSegment.charAt(0).toUpperCase() + secondSegment.slice(1);
|
|
|
|
|
}
|
|
|
|
|
return "Details";
|
|
|
|
|
};
|
2026-01-23 19:58:37 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<MuiBreadcrumbs
|
|
|
|
|
separator={
|
|
|
|
|
<ChevronRight
|
|
|
|
|
size={16}
|
|
|
|
|
strokeWidth={1.5}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "14px",
|
|
|
|
|
marginBottom: theme.spacing(6),
|
|
|
|
|
"& .MuiBreadcrumbs-separator": {
|
|
|
|
|
color: theme.palette.text.secondary,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-01-29 21:08:26 +00:00
|
|
|
{hasSubPage ? (
|
2026-01-24 20:41:21 +00:00
|
|
|
<Link
|
|
|
|
|
to={`/${basePage}`}
|
|
|
|
|
style={{ textDecoration: "none" }}
|
2026-01-23 19:58:37 +00:00
|
|
|
>
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "14px",
|
2026-01-24 20:41:21 +00:00
|
|
|
color: theme.palette.text.secondary,
|
|
|
|
|
"&:hover": {
|
|
|
|
|
color: theme.palette.primary.main,
|
|
|
|
|
},
|
2026-01-23 19:58:37 +00:00
|
|
|
}}
|
|
|
|
|
>
|
2026-01-24 20:41:21 +00:00
|
|
|
{basePage.charAt(0).toUpperCase() + basePage.slice(1)}
|
2026-01-23 19:58:37 +00:00
|
|
|
</Typography>
|
2026-01-24 20:41:21 +00:00
|
|
|
</Link>
|
|
|
|
|
) : (
|
|
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "14px",
|
|
|
|
|
fontWeight: 600,
|
|
|
|
|
color: theme.palette.primary.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{basePage.charAt(0).toUpperCase() + basePage.slice(1)}
|
|
|
|
|
</Typography>
|
|
|
|
|
)}
|
2026-01-29 21:08:26 +00:00
|
|
|
{hasSubPage && (
|
2026-01-24 20:41:21 +00:00
|
|
|
<Typography
|
|
|
|
|
sx={{
|
|
|
|
|
fontSize: "14px",
|
|
|
|
|
fontWeight: 600,
|
|
|
|
|
color: theme.palette.primary.main,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-01-29 21:08:26 +00:00
|
|
|
{getSubPageLabel()}
|
2026-01-24 20:41:21 +00:00
|
|
|
</Typography>
|
|
|
|
|
)}
|
2026-01-23 19:58:37 +00:00
|
|
|
</MuiBreadcrumbs>
|
|
|
|
|
);
|
|
|
|
|
};
|