Skip to content

Commit d072502

Browse files
committed
fix: permissioned tabs menus
1 parent b02b80b commit d072502

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

  • src/components/pageLayout/PageLayoutWithTabs

src/components/pageLayout/PageLayoutWithTabs/TabMenu.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import React, { useState, useEffect } from 'react';
1+
import React, { useState, useEffect, useContext } from 'react';
22
import { useHistory } from 'react-router-dom';
33
import { useTranslation } from 'react-i18next';
4+
import _ from 'lodash';
45

6+
import { CommonStateContext } from '@/App';
57
import { getStorageKey } from '@/components/SideMenu/utils';
68
import { MenuMatchResult } from '@/components/SideMenu/types';
79

@@ -12,9 +14,15 @@ interface TabMenuProps {
1214
onTabChange?: (key: string) => void;
1315
}
1416

17+
const calcUrlPath = (url: string) => {
18+
const urlPath = url.split('?')[0];
19+
return urlPath;
20+
};
21+
1522
export const TabMenu: React.FC<TabMenuProps> = ({ currentMenu, onTabChange }) => {
1623
const history = useHistory();
1724
const { t } = useTranslation('sideMenu');
25+
const { perms } = useContext(CommonStateContext);
1826
const [activeTab, setActiveTab] = useState('');
1927

2028
useEffect(() => {
@@ -27,9 +35,13 @@ export const TabMenu: React.FC<TabMenuProps> = ({ currentMenu, onTabChange }) =>
2735
return null;
2836
}
2937

38+
const permissionedMenus = _.filter(currentMenu.parentItem.children, (item) => {
39+
return _.includes(perms, calcUrlPath(item.key));
40+
});
41+
3042
return (
3143
<div className='flex items-center gap-0 h-[50px] -mt-[10px] -mb-[10px] border-b border-fc-200'>
32-
{currentMenu.parentItem.children.map((item) => (
44+
{_.map(permissionedMenus, (item) => (
3345
<div
3446
key={item.key}
3547
className={`relative px-5 h-full header-tab-menu flex items-center cursor-pointer text-sm transition-colors duration-300 ${

0 commit comments

Comments
 (0)