import React from "react"; import { useNavigate } from "react-router-dom"; import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import NavigateNextIcon from "@mui/icons-material/NavigateNext"; import { AppBar, AppBarProps, Breadcrumbs, IconButton, Link, Stack, Toolbar, Typography, } from "@mui/material"; import { useI18n } from "../../contexts/I18nContext"; import { RouteInfo, useRouter } from "../../contexts/RouterContext"; import { useUser } from "../../contexts/UserContext"; import { hasAccess } from "../../util/has_access"; import ActionMenu from "../ActionMenu"; import { usePage } from "../Page"; export interface TitleBarProps extends React.PropsWithChildren> { back?: boolean | number | string | RouteInfo; title?: React.ReactNode; } export const TitleBar: React.FC = ({ back = false, title, children, ...props }) => { const { t } = useI18n(); const { navigate, getCurrent, routes } = useRouter(); const routerNavigate = useNavigate(); const page = usePage(); const { user } = useUser(); if (typeof back === "boolean" && back) back = -1; const { route: currentRoute } = getCurrent()!; const breadcrumbRoutes = routes.filter( (route) => route.id !== currentRoute.id && route.action === "list" && currentRoute.path.startsWith(route.path), ); return ( *": { width: "100%" }, }} variant="dense" > {back ? ( navigate(back as string | number | RouteInfo)} > ) : null} {title ? ( {title} ) : null} } sx={{ fontSize: "0.8rem", ".MuiBreadcrumbs-separator": { mx: 0.5 }, a: { cursor: "pointer" }, }} > routerNavigate("/", { replace: true })} > {t("Home")} {breadcrumbRoutes.map((route) => ( navigate(route)} > {route.title} ))} {children} {page?.contrib.filter( (operation) => operation.component?.variant === "action" && hasAccess(user, operation.component.permission, operation.component.group), ).length > 0 && ( )} ); };