Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Global breadcrumb #2847

Open
wants to merge 1 commit into
base: feature/webui-link-and-navigate-component
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 8 additions & 27 deletions react/src/components/MainLayout/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -177,33 +178,6 @@ function MainLayout() {
/>
</div>
</Suspense>
{/* <Flex direction="column"> */}

{/* TODO: Breadcrumb */}
{/* {location.pathname.split("/").length > 3 && (
<Breadcrumb
items={matches.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,
onClick:
_.last(matches) === match
? undefined
: (e) => {
e.preventDefault();
// @ts-ignore
navigate(match?.handle?.altPath || match.pathname);
},
};
})}
/>
)} */}
<Suspense>
<PasswordChangeRequestAlert
showIcon
Expand All @@ -217,6 +191,13 @@ function MainLayout() {
<ForceTOTPChecker />
ironAiken2 marked this conversation as resolved.
Show resolved Hide resolved
</Suspense>
<Suspense>
<WebUIBreadcrumb
style={{
marginBottom: token.marginMD,
marginLeft: token.paddingContentHorizontalLG * -1,
marginRight: token.paddingContentHorizontalLG * -1,
}}
/>
<Outlet />
</Suspense>
{/* To match paddig to 16 (2+14) */}
Expand Down
99 changes: 99 additions & 0 deletions react/src/components/WebUIBreadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
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<WebUIBreadcrumbProps> = (props) => {
// const location = useLocation();
const matches = useMatches();
// matches[0].handle.

const { token } = theme.useToken();

const { t } = useTranslation();
return (
<Flex
direction="column"
justify="center"
align="stretch"
{...props}
style={_.merge(
{
height: 40,
paddingLeft: token.paddingContentHorizontalLG,
borderBottom: `1px solid ${token.colorBorder}`,
} as React.CSSProperties,
props.style,
)}
>
<Breadcrumb
style={{
fontSize: token.fontSizeSM,
// lineHeight: he,
}}
items={[
..._.chain(matches)
.filter((match) => {
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 ? (
<span>{currentRoute.title}</span>
) : (
<WebUILink
to={currentRoute.href}
style={{
margin: 0,
padding: 0,
height: 'unset'
}}
>
{currentRoute.title}
</WebUILink>
);
}}
/>
</Flex>
);
};

export default WebUIBreadcrumb;
Loading