@buerokratt-ria/menu 0.1.8 → 0.1.10
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 +12 -0
- package/buerokratt-ria-menu-0.1.10.tgz +0 -0
- package/package.json +1 -1
- package/src/menu/components/icons/icon/icon.tsx +4 -3
- package/src/menu/components/icons/icon.scss +5 -0
- package/src/menu/constants.ts +3 -0
- package/src/menu/data/menu-structure.json +2 -0
- package/src/menu/index.tsx +63 -45
- package/src/menu/main-navigation.scss +23 -3
- package/buerokratt-ria-menu-0.1.8.tgz +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,10 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
All changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.1.10] - 30-05-2024
|
|
6
|
+
|
|
7
|
+
- Hide some menu items from production
|
|
8
|
+
|
|
9
|
+
## [0.1.9] - 28-04-2024
|
|
10
|
+
|
|
11
|
+
- Merge previous code
|
|
12
|
+
|
|
5
13
|
## [0.1.8] - 28-04-2024
|
|
6
14
|
|
|
7
15
|
- Hide some menu items
|
|
8
16
|
|
|
17
|
+
## [0.1.7] - 27-05-2024
|
|
18
|
+
|
|
19
|
+
- Fix close menu button
|
|
20
|
+
|
|
9
21
|
## [0.1.6] - 25-04-2024
|
|
10
22
|
|
|
11
23
|
- Updated api call addresses
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -12,12 +12,13 @@ import '../icon.scss';
|
|
|
12
12
|
type IconProps = StyleHTMLAttributes<CSSProperties> & {
|
|
13
13
|
label?: string | null;
|
|
14
14
|
icon: ReactNode;
|
|
15
|
-
size?: 'small' | 'medium';
|
|
15
|
+
size?: 'small' | 'medium' | 'large';
|
|
16
|
+
className?: string;
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
const IconComponent = forwardRef<HTMLSpanElement, IconProps>(
|
|
19
|
-
({ label, icon, size = 'small', ...rest }, ref) => {
|
|
20
|
-
const iconClasses = clsx('icon', `icon--${size}
|
|
20
|
+
({ label, icon, className, size = 'small', ...rest }, ref) => {
|
|
21
|
+
const iconClasses = clsx('icon', `icon--${size}`, className);
|
|
21
22
|
|
|
22
23
|
return (
|
|
23
24
|
<AccessibleIcon.Root label={label ?? ''}>
|
|
@@ -226,6 +226,7 @@
|
|
|
226
226
|
},
|
|
227
227
|
{
|
|
228
228
|
"id": "services",
|
|
229
|
+
"hiddenMode": "production",
|
|
229
230
|
"label": {
|
|
230
231
|
"et": "Teenused",
|
|
231
232
|
"en": "Services"
|
|
@@ -332,6 +333,7 @@
|
|
|
332
333
|
},
|
|
333
334
|
{
|
|
334
335
|
"id": "monitoring",
|
|
336
|
+
"hiddenMode": "production",
|
|
335
337
|
"label": {
|
|
336
338
|
"et": "Seire",
|
|
337
339
|
"en": "Monitoring"
|
package/src/menu/index.tsx
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import React, {FC, MouseEvent, useState} from 'react';
|
|
2
|
-
|
|
3
|
-
import {NavLink, useLocation} from 'react-router-dom';
|
|
1
|
+
import React, { FC, MouseEvent, useState } from 'react';
|
|
2
|
+
import { NavLink } from 'react-router-dom';
|
|
4
3
|
import clsx from 'clsx';
|
|
5
|
-
import {
|
|
6
|
-
|
|
4
|
+
import {
|
|
5
|
+
MdOutlineForum,
|
|
6
|
+
MdOutlineAdb,
|
|
7
|
+
MdOutlineEqualizer,
|
|
8
|
+
MdKeyboardArrowDown,
|
|
9
|
+
MdMiscellaneousServices,
|
|
10
|
+
MdSettings,
|
|
11
|
+
MdOutlineMonitorWeight,
|
|
12
|
+
MdKeyboardArrowRight,
|
|
13
|
+
MdKeyboardArrowLeft,
|
|
14
|
+
} from 'react-icons/md';
|
|
15
|
+
import Icon from './components/icons/icon/icon';
|
|
7
16
|
import './main-navigation.scss';
|
|
8
17
|
import { useQuery } from '@tanstack/react-query';
|
|
9
|
-
import {useTranslation} from "react-i18next";
|
|
18
|
+
import { useTranslation } from "react-i18next";
|
|
10
19
|
import menuStructure from './data/menu-structure.json';
|
|
20
|
+
import { isHiddenFeaturesEnabled } from './constants';
|
|
11
21
|
|
|
12
22
|
interface MenuItem {
|
|
13
23
|
id?: string;
|
|
@@ -16,6 +26,7 @@ interface MenuItem {
|
|
|
16
26
|
target?: '_blank' | '_self';
|
|
17
27
|
children?: MenuItem[];
|
|
18
28
|
hidden?: boolean;
|
|
29
|
+
hiddenMode?: 'production' | 'development' | 'staging' | 'testing';
|
|
19
30
|
}
|
|
20
31
|
|
|
21
32
|
interface TranslatedLabel {
|
|
@@ -30,42 +41,41 @@ const MainNavigation: FC<{items: MenuItem[], serviceId: string[]}> = ( {items, s
|
|
|
30
41
|
const { t, i18n } = useTranslation();
|
|
31
42
|
const currentlySelectedLanguage = i18n.language;
|
|
32
43
|
const [menuItems, setMenuItems] = useState<MenuItem[]>([]);
|
|
44
|
+
|
|
33
45
|
const menuData = [
|
|
34
46
|
{
|
|
35
47
|
id: 'conversations',
|
|
36
|
-
icon: <MdOutlineForum />,
|
|
48
|
+
icon: <MdOutlineForum className='menu-item-icon' />,
|
|
37
49
|
url: import.meta.env.REACT_APP_CONVERSATIONS_BASE_URL,
|
|
38
50
|
},
|
|
39
51
|
{
|
|
40
52
|
id: 'training',
|
|
41
|
-
icon: <MdOutlineAdb />,
|
|
53
|
+
icon: <MdOutlineAdb className='menu-item-icon' />,
|
|
42
54
|
url: import.meta.env.REACT_APP_TRAINING_BASE_URL,
|
|
43
55
|
},
|
|
44
56
|
{
|
|
45
57
|
id: 'analytics',
|
|
46
|
-
icon: <MdOutlineEqualizer />,
|
|
58
|
+
icon: <MdOutlineEqualizer className='menu-item-icon' />,
|
|
47
59
|
url: import.meta.env.REACT_APP_ANALYTICS_BASE_URL,
|
|
48
60
|
},
|
|
49
61
|
{
|
|
50
62
|
id: "services",
|
|
51
|
-
icon: <MdMiscellaneousServices />,
|
|
63
|
+
icon: <MdMiscellaneousServices className='menu-item-icon' />,
|
|
52
64
|
url: import.meta.env.REACT_APP_SERVICES_BASE_URL,
|
|
53
65
|
},
|
|
54
66
|
{
|
|
55
67
|
id: 'settings',
|
|
56
|
-
icon: <MdSettings />,
|
|
68
|
+
icon: <MdSettings className='menu-item-icon' />,
|
|
57
69
|
url: import.meta.env.REACT_APP_SETTINGS_BASE_URL,
|
|
58
70
|
},
|
|
59
71
|
{
|
|
60
72
|
id: 'monitoring',
|
|
61
|
-
icon: <MdOutlineMonitorWeight />,
|
|
73
|
+
icon: <MdOutlineMonitorWeight className='menu-item-icon' />,
|
|
62
74
|
url: import.meta.env.REACT_APP_MONITORING_BASE_URL,
|
|
63
75
|
},
|
|
64
76
|
];
|
|
65
77
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const { data } = useQuery({
|
|
78
|
+
useQuery({
|
|
69
79
|
queryKey: ['accounts/user-role', 'prod'],
|
|
70
80
|
onSuccess: (res: any) => {
|
|
71
81
|
const filteredItems =
|
|
@@ -89,69 +99,77 @@ const MainNavigation: FC<{items: MenuItem[], serviceId: string[]}> = ( {items, s
|
|
|
89
99
|
},
|
|
90
100
|
});
|
|
91
101
|
|
|
92
|
-
const location = useLocation();
|
|
93
102
|
const [navCollapsed, setNavCollapsed] = useState(false);
|
|
94
103
|
|
|
95
104
|
const handleNavToggle = (event: MouseEvent) => {
|
|
105
|
+
setNavCollapsed(false);
|
|
96
106
|
const isExpanded = event.currentTarget.getAttribute('aria-expanded') === 'true';
|
|
97
107
|
event.currentTarget.setAttribute('aria-expanded', isExpanded ? 'false' : 'true');
|
|
98
108
|
};
|
|
99
109
|
|
|
100
110
|
const renderMenuTree = (menuItems: MenuItem[]) => {
|
|
101
|
-
return menuItems
|
|
111
|
+
return menuItems
|
|
112
|
+
.filter(x => !x.hidden)
|
|
113
|
+
.filter(x => isHiddenFeaturesEnabled || x.hiddenMode !== "production")
|
|
114
|
+
.map((menuItem) => (
|
|
102
115
|
<li key={menuItem.label[currentlySelectedLanguage]}>
|
|
103
116
|
{!!menuItem.children ? (
|
|
104
117
|
<>
|
|
105
118
|
<button
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
119
|
+
className={clsx('nav__toggle', { 'nav__toggle--icon': !!menuItem.id })}
|
|
120
|
+
aria-expanded={menuItem.path && (isSameRoot(menuItem)) ? 'true' : 'false'}
|
|
121
|
+
onClick={handleNavToggle}
|
|
109
122
|
>
|
|
110
|
-
{
|
|
111
|
-
|
|
123
|
+
{menuItem.id && (
|
|
124
|
+
<Icon icon={menuData.find(dataItem => dataItem.id === menuItem.id)?.icon} size='large' />
|
|
112
125
|
)}
|
|
113
|
-
|
|
114
|
-
<
|
|
115
|
-
<Icon icon={<MdKeyboardArrowDown />} />
|
|
126
|
+
<span className='menu-item-title'>{menuItem.label[currentlySelectedLanguage]}</span>
|
|
127
|
+
<Icon icon={<MdKeyboardArrowDown />} className='menu-item-arrow' />
|
|
116
128
|
</button>
|
|
117
129
|
<ul className='nav__submenu'>
|
|
118
130
|
{renderMenuTree(menuItem.children.map((item) => ({id: menuItem.id, ...item})))}
|
|
119
131
|
</ul>
|
|
120
132
|
</>
|
|
121
133
|
) : (
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
134
|
+
serviceId.includes(menuItem.id)
|
|
135
|
+
? <NavLink to={menuItem.path || '#'}>
|
|
136
|
+
{menuItem.label[currentlySelectedLanguage]}
|
|
137
|
+
</NavLink>
|
|
138
|
+
: <a href={menuData.find(dataItem => dataItem.id === menuItem.id)?.url + menuItem.path}>
|
|
139
|
+
{menuItem.label[currentlySelectedLanguage]}
|
|
140
|
+
</a>
|
|
127
141
|
)}
|
|
128
|
-
</li>
|
|
142
|
+
</li>
|
|
143
|
+
),
|
|
129
144
|
);
|
|
130
145
|
};
|
|
131
146
|
|
|
132
147
|
const base = window.location.pathname.split("/")[1];
|
|
133
148
|
const currentService = base === 'chat' ? serviceId : [base];
|
|
134
149
|
const isSameRoot = (menuItem) => {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
result = menuItem.children.some((item: MenuItem) => item.path?.includes("/" + window.location.pathname.split("/")[2]));
|
|
150
|
+
if(currentService.includes(menuItem.id)) {
|
|
151
|
+
return menuItem.children.some((item: MenuItem) => item.path?.includes("/" + window.location.pathname.split("/")[2]));
|
|
138
152
|
}
|
|
139
|
-
return
|
|
153
|
+
return false;
|
|
140
154
|
}
|
|
141
155
|
|
|
142
156
|
if (!menuItems) return null;
|
|
143
157
|
|
|
144
158
|
return (
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
</
|
|
153
|
-
</
|
|
159
|
+
<nav className={clsx('nav', { 'collapsed': navCollapsed })}>
|
|
160
|
+
<button className='nav__menu-toggle close-button-item' onClick={() => setNavCollapsed(!navCollapsed)}>
|
|
161
|
+
{
|
|
162
|
+
navCollapsed
|
|
163
|
+
? <Icon icon={<MdKeyboardArrowRight className='menu-item-icon' />} size='large' />
|
|
164
|
+
: <Icon icon={<MdKeyboardArrowLeft className='menu-item-icon' />} size='large' />
|
|
165
|
+
}
|
|
166
|
+
<span className='menu-item-title'>{t('mainMenu.closeMenu')}</span>
|
|
167
|
+
</button>
|
|
168
|
+
<ul className='nav__menu'>
|
|
169
|
+
{renderMenuTree(menuItems)}
|
|
170
|
+
</ul>
|
|
171
|
+
</nav>
|
|
154
172
|
);
|
|
155
173
|
};
|
|
156
174
|
|
|
157
|
-
export default MainNavigation;
|
|
175
|
+
export default MainNavigation;
|
|
@@ -57,9 +57,6 @@
|
|
|
57
57
|
&.active {
|
|
58
58
|
font-weight: 700;
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
&:focus {
|
|
62
|
-
}
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
&__toggle {
|
|
@@ -117,3 +114,26 @@
|
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
}
|
|
117
|
+
|
|
118
|
+
.collapsed {
|
|
119
|
+
width: 64px;
|
|
120
|
+
|
|
121
|
+
.menu-item-arrow,
|
|
122
|
+
.menu-item-title {
|
|
123
|
+
display: none !important;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.menu-item-icon {
|
|
127
|
+
height: 24px;
|
|
128
|
+
width: 24px;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.close-button-item,
|
|
132
|
+
button.nav__toggle {
|
|
133
|
+
justify-content: center;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.nav__submenu {
|
|
137
|
+
display: none !important;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
Binary file
|