Get labels in breadcrumb from meta-data labels, not path components

This commit is contained in:
2023-05-05 20:24:08 -05:00
parent f1adf3aa5e
commit 8074e0a61d
4 changed files with 48 additions and 9 deletions

View File

@ -60,9 +60,19 @@ export const routeToLabel = (route: string): string =>
function QBreadcrumbs({icon, title, route, light}: Props): JSX.Element
{
const routes: string[] | any = route.slice(0, -1);
const {pageHeader, setPageHeader} = useContext(QContext);
const {pageHeader, pathToLabelMap, branding} = useContext(QContext);
let pageTitle = "ColdTrack Live";
const fullPathToLabel = (fullPath: string, route: string): string =>
{
if(pathToLabelMap && pathToLabelMap[fullPath])
{
return pathToLabelMap[fullPath];
}
return (routeToLabel(route));
}
let pageTitle = branding?.appName ?? "";
const fullRoutes: string[] = [];
let accumulatedPath = "";
for (let i = 0; i < routes.length; i++)
@ -74,7 +84,7 @@ function QBreadcrumbs({icon, title, route, light}: Props): JSX.Element
accumulatedPath = `${accumulatedPath}/${routes[i]}`;
fullRoutes.push(accumulatedPath);
pageTitle = `${routeToLabel(routes[i])} | ${pageTitle}`;
pageTitle = `${fullPathToLabel(accumulatedPath, routes[i])} | ${pageTitle}`;
}
document.title = `${ucFirst(title)} | ${pageTitle}`;
@ -110,7 +120,7 @@ function QBreadcrumbs({icon, title, route, light}: Props): JSX.Element
opacity={light ? 0.8 : 0.5}
sx={{lineHeight: 0}}
>
{routeToLabel(fullRoute.replace(/.*\//, ""))}
{fullPathToLabel(fullRoute, fullRoute.replace(/.*\//, ""))}
</MDTypography>
</Link>
))}