fix(menu): подсветка родительского пункта на detail-страницах

Refs EventHub/EventHubFrontAdmin#7

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-13 17:06:59 +03:00
parent 7a2467370a
commit 9deaa34a6e
2 changed files with 17 additions and 2 deletions
+15
View File
@@ -52,3 +52,18 @@ export function filterMenuByRole<T extends { roles?: AdminRole[] }>(
): T[] {
return items.filter((item) => !item.roles || (role && item.roles.includes(role as AdminRole)));
}
/** Ключ пункта меню для detail-маршрутов (/users/:id → /users). */
export function getMenuSelectedKey(pathname: string): string {
if (MENU_ITEMS.some((item) => item.key === pathname)) {
return pathname;
}
const segment = pathname.split('/').filter(Boolean)[0];
if (segment) {
const parent = `/${segment}`;
if (MENU_ITEMS.some((item) => item.key === parent)) {
return parent;
}
}
return pathname;
}
+2 -2
View File
@@ -23,7 +23,7 @@ import {
CloudServerOutlined,
} from '@ant-design/icons';
import dayjs from 'dayjs';
import { MENU_ITEMS, filterMenuByRole } from '../config/adminAccess';
import { MENU_ITEMS, filterMenuByRole, getMenuSelectedKey } from '../config/adminAccess';
const { Header, Sider, Content } = Layout;
const { Text } = Typography;
@@ -174,7 +174,7 @@ const AdminLayout: React.FC = () => {
<Menu
theme="dark"
mode="inline"
selectedKeys={[location.pathname]}
selectedKeys={[getMenuSelectedKey(location.pathname)]}
items={filteredMenu}
onClick={({ key }) => navigate(key)}
style={{