@buerokratt-ria/menu 0.1.7 → 0.1.8

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