keycloak-scim/src/components/bread-crumb/PageBreadCrumbs.tsx
Erik Jan de Wit b14027ccb7
Use realm name in urls (#265)
* remove circular dependency on realm context

* added realm as a param of the url

* updated links to include realm

* null !== undefined

* set realm if realm in url

* fixed breadcrumb type

* fixed tests

* addressed pr review comments
2021-01-05 14:49:33 -05:00

30 lines
982 B
TypeScript

import React from "react";
import { Link } from "react-router-dom";
import useBreadcrumbs from "use-react-router-breadcrumbs";
import { useTranslation } from "react-i18next";
import { Breadcrumb, BreadcrumbItem } from "@patternfly/react-core";
import { useRealm } from "../../context/realm-context/RealmContext";
import { routes } from "../../route-config";
export const PageBreadCrumbs = () => {
const { t } = useTranslation();
const { realm } = useRealm();
const crumbs = useBreadcrumbs(routes(t), {
excludePaths: ["/", `/${realm}`],
});
return (
<>
{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>
)}
</>
);
};