Skip to content

Commit

Permalink
Merge pull request #82 from warjiang/fix/i18n-breadcrumb
Browse files Browse the repository at this point in the history
fix: new method for generate breadcrumbs
  • Loading branch information
karmada-bot authored Aug 12, 2024
2 parents 650ef60 + 3a4711a commit c686b70
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions ui/apps/dashboard/src/components/panel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FC, ReactNode, useMemo } from 'react';
import { useMatches } from 'react-router-dom';
import { Breadcrumb } from 'antd';
import { IRouteObjectHandle } from '@/routes/route.tsx';
import { getRoutes, IRouteObjectHandle } from '@/routes/route.tsx';
import * as React from 'react';

interface IPanelProps {
Expand All @@ -21,15 +21,29 @@ const Panel: FC<IPanelProps> = (props) => {
const matches = useMatches();
const breadcrumbs = useMemo(() => {
if (!matches || matches.length === 0) return [] as MenuItem[];
return matches
.filter((m) => Boolean(m.handle))
.map((m) => {
const { isPage, sidebarName } = m.handle as IRouteObjectHandle;
const pathname = m.pathname;
return {
title: isPage && pathname ? <a>{sidebarName}</a> : sidebarName,
};
}) as MenuItem[];
const filteredMatches = matches.filter((m) => Boolean(m.handle));
let idx = 0;
let ptr = getRoutes()[0];
const menuItems: MenuItem[] = [];
while (idx < filteredMatches.length) {
const { isPage, sidebarKey: _sideBarKey } = filteredMatches[idx]
.handle as IRouteObjectHandle;
for (let i = 0; ptr.children && i < ptr.children.length; i++) {
if (ptr.children[i].handle?.sidebarKey === _sideBarKey) {
menuItems.push({
title:
isPage && filteredMatches[idx].pathname ? (
<a>{ptr.children[i].handle?.sidebarName}</a>
) : (
ptr.children[i].handle?.sidebarName
),
});
ptr = ptr.children[i];
}
}
idx++;
}
return menuItems;
}, [matches]);
return (
<div className="w-full h-full px-[30px] py-[20px] box-border bg-[#FAFBFC]">
Expand Down

0 comments on commit c686b70

Please sign in to comment.