@buerokratt-ria/menu 0.0.3 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -2,14 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
-
## [0.
|
|
5
|
+
## [0.1.2] - 01-02-2024
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- Added new element in menu /pending
|
|
8
8
|
|
|
9
|
-
## [0.
|
|
9
|
+
## [0.1.1] - 28-12-2023
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
|
|
13
|
-
## [0.0.1] - 07-12-2023
|
|
14
|
-
|
|
15
|
-
- Initial package structure for menu.
|
|
11
|
+
- Initial package structure for menu for ruuter v2.
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buerokratt-ria/menu",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Generic MainNavigation component that would be injected as dependency.",
|
|
5
|
-
"main": "index.
|
|
5
|
+
"main": "index.js",
|
|
6
6
|
"scripts": {},
|
|
7
7
|
"author": "ExiRain",
|
|
8
8
|
"license": "ISC",
|
package/src/menu/index.tsx
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import React, {FC, MouseEvent,
|
|
1
|
+
import React, {FC, MouseEvent, useState} from 'react';
|
|
2
2
|
|
|
3
3
|
import {NavLink, useLocation} from 'react-router-dom';
|
|
4
|
-
import {MdClose, MdKeyboardArrowDown, MdMiscellaneousServices} from 'react-icons/md';
|
|
5
4
|
import clsx from 'clsx';
|
|
6
|
-
import { MdOutlineForum, MdOutlineAdb, MdOutlineEqualizer, MdSettings, MdOutlineMonitorWeight } from 'react-icons/md';
|
|
5
|
+
import { MdOutlineForum, MdOutlineAdb, MdOutlineEqualizer, MdClose, MdKeyboardArrowDown, MdMiscellaneousServices, MdSettings, MdOutlineMonitorWeight } from 'react-icons/md';
|
|
7
6
|
import Icon from './components/icons/icon/icon';
|
|
8
7
|
import './main-navigation.scss';
|
|
9
8
|
import { useQuery } from '@tanstack/react-query';
|
|
@@ -11,15 +10,15 @@ import {useTranslation} from "react-i18next";
|
|
|
11
10
|
import menuStructure from './data/menu-structure.json';
|
|
12
11
|
|
|
13
12
|
interface MenuItem {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
id?: string;
|
|
14
|
+
label: TranslatedLabel;
|
|
15
|
+
path?: string;
|
|
16
|
+
target?: '_blank' | '_self';
|
|
17
|
+
children?: MenuItem[];
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
interface TranslatedLabel {
|
|
22
|
-
|
|
21
|
+
[lang: string] : string;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
const MainNavigation: FC<{items: MenuItem[], serviceId: string[]}> = ( {items, serviceId}) => {
|
|
@@ -66,23 +65,27 @@ const MainNavigation: FC<{items: MenuItem[], serviceId: string[]}> = ( {items, s
|
|
|
66
65
|
let activeMenuId;
|
|
67
66
|
|
|
68
67
|
const { data } = useQuery({
|
|
69
|
-
queryKey: ['
|
|
68
|
+
queryKey: ['account/user-role', 'prod'],
|
|
70
69
|
onSuccess: (res: any) => {
|
|
71
|
-
const filteredItems =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
70
|
+
const filteredItems =
|
|
71
|
+
items.filter((item) => {
|
|
72
|
+
const role = res.response;
|
|
73
|
+
if (role.includes('ROLE_ADMINISTRATOR')) {
|
|
74
|
+
return item.id;
|
|
75
|
+
} else if (role.includes('ROLE_SERVICE_MANAGER')) {
|
|
76
|
+
return item.id != "settings" && item.id != "training";
|
|
77
|
+
} else if (role.includes('ROLE_CUSTOMER_SUPPORT_AGENT')) {
|
|
78
|
+
return item.id != "settings" && item.id != "analytics";
|
|
79
|
+
} else if (role.includes('ROLE_CHATBOT_TRAINER')) {
|
|
80
|
+
return item.id != "settings" && item.id != "conversations";
|
|
81
|
+
} else if (role.includes('ROLE_ANALYST')) {
|
|
82
|
+
return item.id == "analytics" || item.id == "monitoring";
|
|
83
|
+
} else {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}) ?? [];
|
|
87
|
+
setMenuItems(filteredItems);
|
|
88
|
+
},
|
|
86
89
|
});
|
|
87
90
|
|
|
88
91
|
const location = useLocation();
|
|
@@ -95,33 +98,33 @@ const MainNavigation: FC<{items: MenuItem[], serviceId: string[]}> = ( {items, s
|
|
|
95
98
|
|
|
96
99
|
const renderMenuTree = (menuItems: MenuItem[]) => {
|
|
97
100
|
return menuItems.map((menuItem) => (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
101
|
+
<li key={menuItem.label[currentlySelectedLanguage]}>
|
|
102
|
+
{!!menuItem.children ? (
|
|
103
|
+
<>
|
|
104
|
+
<button
|
|
105
|
+
className={clsx('nav__toggle', { 'nav__toggle--icon': !!menuItem.id })}
|
|
106
|
+
aria-expanded={menuItem.path && (isSameRoot(menuItem)) ? 'true' : 'false'}
|
|
107
|
+
onClick={handleNavToggle}
|
|
108
|
+
>
|
|
109
|
+
{ menuItem.id && (
|
|
110
|
+
<Icon icon={menuData.find(dataItem => dataItem.id === menuItem.id)?.icon} />
|
|
111
|
+
)}
|
|
112
|
+
|
|
113
|
+
<span>{menuItem.label[currentlySelectedLanguage]}</span>
|
|
114
|
+
<Icon icon={<MdKeyboardArrowDown />} />
|
|
115
|
+
</button>
|
|
116
|
+
<ul className='nav__submenu'>
|
|
117
|
+
{renderMenuTree(menuItem.children.map((item) => ({id: menuItem.id, ...item})))}
|
|
118
|
+
</ul>
|
|
119
|
+
</>
|
|
120
|
+
) : (
|
|
121
|
+
|
|
122
|
+
(serviceId.includes(menuItem.id)) ?
|
|
123
|
+
<NavLink to={menuItem.path || '#'}>{menuItem.label[currentlySelectedLanguage] }</NavLink> :
|
|
124
|
+
<a href={menuData.find(dataItem => dataItem.id === menuItem.id)?.url + menuItem.path}>{menuItem.label[currentlySelectedLanguage]}</a>
|
|
125
|
+
|
|
126
|
+
)}
|
|
127
|
+
</li>),
|
|
125
128
|
);
|
|
126
129
|
};
|
|
127
130
|
|
|
@@ -138,16 +141,16 @@ const MainNavigation: FC<{items: MenuItem[], serviceId: string[]}> = ( {items, s
|
|
|
138
141
|
if (!menuItems) return null;
|
|
139
142
|
|
|
140
143
|
return (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
144
|
+
<nav className={clsx('nav', { 'nav--collapsed': navCollapsed })}>
|
|
145
|
+
<button className='nav__menu-toggle' onClick={() => setNavCollapsed(!navCollapsed)}>
|
|
146
|
+
<Icon icon={<MdClose />} />
|
|
147
|
+
{t('mainMenu.closeMenu')}
|
|
148
|
+
</button>
|
|
149
|
+
<ul className='nav__menu'>
|
|
150
|
+
{renderMenuTree(menuItems)}
|
|
151
|
+
</ul>
|
|
152
|
+
</nav>
|
|
150
153
|
);
|
|
151
154
|
};
|
|
152
155
|
|
|
153
|
-
export default MainNavigation;
|
|
156
|
+
export default MainNavigation;
|
|
Binary file
|