fix(menu): подсветка родительского пункта на detail-страницах
Refs EventHub/EventHubFrontAdmin#7 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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={{
|
||||
|
||||
Reference in New Issue
Block a user