diff --git a/react/src/components/MainLayout/MainLayout.tsx b/react/src/components/MainLayout/MainLayout.tsx index c161e72b2..ed3764631 100644 --- a/react/src/components/MainLayout/MainLayout.tsx +++ b/react/src/components/MainLayout/MainLayout.tsx @@ -9,6 +9,7 @@ import ForceTOTPChecker from '../ForceTOTPChecker'; import NetworkStatusBanner from '../NetworkStatusBanner'; import PasswordChangeRequestAlert from '../PasswordChangeRequestAlert'; import { DRAWER_WIDTH } from '../WEBUINotificationDrawer'; +import WebUIBreadcrumb from '../WebUIBreadcrumb'; import WebUIHeader from './WebUIHeader'; import WebUISider from './WebUISider'; import { App, Layout, theme } from 'antd'; @@ -177,33 +178,6 @@ function MainLayout() { /> - {/* */} - - {/* TODO: Breadcrumb */} - {/* {location.pathname.split("/").length > 3 && ( - { - return { - key: match.id, - href: - _.last(matches) === match - ? undefined - : // @ts-ignore - match?.handle?.altPath || match.pathname, - //@ts-ignore - title: match?.handle?.title, - onClick: - _.last(matches) === match - ? undefined - : (e) => { - e.preventDefault(); - // @ts-ignore - navigate(match?.handle?.altPath || match.pathname); - }, - }; - })} - /> - )} */} + {/* To match paddig to 16 (2+14) */} diff --git a/react/src/components/WebUIBreadcrumb.tsx b/react/src/components/WebUIBreadcrumb.tsx new file mode 100644 index 000000000..b086e1e01 --- /dev/null +++ b/react/src/components/WebUIBreadcrumb.tsx @@ -0,0 +1,98 @@ +import Flex, { FlexProps } from './Flex'; +import WebUILink from './WebUILink'; +import { Breadcrumb, theme } from 'antd'; +import _ from 'lodash'; +import React from 'react'; +import { useTranslation } from 'react-i18next'; +import { useMatches } from 'react-router-dom'; + +interface WebUIBreadcrumbProps extends FlexProps {} +const WebUIBreadcrumb: React.FC = (props) => { + // const location = useLocation(); + const matches = useMatches(); + // matches[0].handle. + + const { token } = theme.useToken(); + + const { t } = useTranslation(); + return ( + + { + return ( + // @ts-ignore + !_.isEmpty(match?.handle?.labelKey) || + // @ts-ignore + !_.isEmpty(match?.handle?.title) + ); + }) + .map((match, index) => { + return { + key: match.id, + href: + _.last(matches) === match + ? undefined + : // @ts-ignore + match?.handle?.altPath || match.pathname, + //@ts-ignore + title: match?.handle?.title || t(match?.handle?.labelKey), + // onClick: + // _.last(matches) === match + // ? undefined + // : (e: any) => { + // e.preventDefault(); + // // @ts-ignore + // navigate(match?.handle?.altPath || match.pathname); + // }, + }; + }) + .value(), + { + // Add dummy tail to add a `/` at the end of the breadcrumb + key: 'dummy_tail', + title: ' ', + }, + ]} + itemRender={(currentRoute, params, items, paths) => { + const isLast = + currentRoute?.key === items[items.length - 2]?.key || + currentRoute?.key === 'dummy_tail'; + return isLast || !currentRoute.href ? ( + {currentRoute.title} + ) : ( + + {currentRoute.title} + + ); + }} + /> + + ); +}; + +export default WebUIBreadcrumb;