2021-03-05 10:18:47 +00:00
|
|
|
import React, { isValidElement } from "react";
|
2020-10-01 14:25:29 +00:00
|
|
|
import { Link } from "react-router-dom";
|
2021-03-05 10:18:47 +00:00
|
|
|
import useBreadcrumbs, { BreadcrumbData } from "use-react-router-breadcrumbs";
|
2020-10-01 14:25:29 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2021-03-05 10:18:47 +00:00
|
|
|
import _ from "lodash";
|
2020-11-05 14:40:00 +00:00
|
|
|
import { Breadcrumb, BreadcrumbItem } from "@patternfly/react-core";
|
2020-10-01 14:25:29 +00:00
|
|
|
|
2021-01-05 19:49:33 +00:00
|
|
|
import { useRealm } from "../../context/realm-context/RealmContext";
|
2020-10-01 14:25:29 +00:00
|
|
|
import { routes } from "../../route-config";
|
2021-01-12 14:00:44 +00:00
|
|
|
import { GroupBreadCrumbs } from "./GroupBreadCrumbs";
|
2020-10-01 14:25:29 +00:00
|
|
|
|
|
|
|
export const PageBreadCrumbs = () => {
|
|
|
|
const { t } = useTranslation();
|
2021-01-05 19:49:33 +00:00
|
|
|
const { realm } = useRealm();
|
2021-03-05 10:18:47 +00:00
|
|
|
const elementText = (crumb: BreadcrumbData) =>
|
|
|
|
isValidElement(crumb.breadcrumb) && crumb.breadcrumb.props.children;
|
|
|
|
|
|
|
|
const crumbs = _.uniqBy(
|
|
|
|
useBreadcrumbs(routes(t), {
|
|
|
|
excludePaths: ["/", `/${realm}`],
|
|
|
|
}),
|
|
|
|
elementText
|
|
|
|
);
|
2020-10-01 14:25:29 +00:00
|
|
|
return (
|
2020-11-05 14:40:00 +00:00
|
|
|
<>
|
|
|
|
{crumbs.length > 1 && (
|
|
|
|
<Breadcrumb>
|
|
|
|
{crumbs.map(({ match, breadcrumb: crumb }, i) => (
|
|
|
|
<BreadcrumbItem key={i} isActive={crumbs.length - 1 === i}>
|
|
|
|
{crumbs.length - 1 !== i && <Link to={match.url}>{crumb}</Link>}
|
|
|
|
{crumbs.length - 1 === i && <>{crumb}</>}
|
|
|
|
</BreadcrumbItem>
|
|
|
|
))}
|
|
|
|
</Breadcrumb>
|
|
|
|
)}
|
2021-01-12 14:00:44 +00:00
|
|
|
<GroupBreadCrumbs />
|
2020-11-05 14:40:00 +00:00
|
|
|
</>
|
2020-10-01 14:25:29 +00:00
|
|
|
);
|
|
|
|
};
|