@visns-studio/visns-components 1.5.4 → 1.5.6

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.
@@ -105,16 +105,22 @@ function Navigation({ logo, logout, navConfig, setSystemAuth, userProfile }) {
105
105
  if (n.children && n.children.length > 0) {
106
106
  return (
107
107
  <ul>
108
- {n.children.map((child, childKey) => (
109
- <li
110
- className="sub-nav-item"
111
- key={`nav-child-${childKey}`}
112
- >
113
- <Link to={child.url} title={child.label}>
114
- {child.label}
115
- </Link>
116
- </li>
117
- ))}
108
+ {n.children.map(
109
+ (child, childKey) =>
110
+ child.permission === true && (
111
+ <li
112
+ className="sub-nav-item"
113
+ key={`nav-child-${childKey}`}
114
+ >
115
+ <Link
116
+ to={child.url}
117
+ title={child.label}
118
+ >
119
+ {child.label}
120
+ </Link>
121
+ </li>
122
+ )
123
+ )}
118
124
  </ul>
119
125
  );
120
126
  }
@@ -140,27 +146,60 @@ function Navigation({ logo, logout, navConfig, setSystemAuth, userProfile }) {
140
146
  };
141
147
 
142
148
  useEffect(() => {
143
- const permissions = userProfile.roles[0].permissions;
149
+ const permissions = userProfile.roles[0].permissions.map(
150
+ (permission) => permission.name
151
+ );
144
152
 
145
153
  setNavData((prevNavData) => {
146
154
  const updatePermissions = (nav) => {
147
- const matchingPermission = permissions.find(
148
- (permission) => permission.name === nav.permissionKey
149
- );
155
+ if (nav.children && nav.children.length > 0) {
156
+ const updatedChildren = nav.children
157
+ .map(updatePermissions)
158
+ .filter(Boolean);
159
+ const childPermission = updatedChildren.length > 0;
160
+
161
+ if (nav.permissionKey) {
162
+ const matchingPermission = permissions.includes(
163
+ nav.permissionKey
164
+ );
165
+
166
+ return {
167
+ ...nav,
168
+ permission: matchingPermission,
169
+ children: updatedChildren,
170
+ };
171
+ } else {
172
+ return {
173
+ ...nav,
174
+ permission: childPermission,
175
+ children: updatedChildren,
176
+ };
177
+ }
178
+ }
179
+
180
+ if (nav.permissionKey) {
181
+ const matchingPermission = permissions.includes(
182
+ nav.permissionKey
183
+ );
150
184
 
151
- if (matchingPermission) {
152
185
  return {
153
186
  ...nav,
154
- permission: true,
187
+ permission: matchingPermission,
155
188
  };
156
189
  }
157
190
 
158
- return nav;
191
+ return {
192
+ ...nav,
193
+ permission: true,
194
+ };
159
195
  };
160
196
 
161
- const updatedNavigations =
162
- prevNavData.navigations.map(updatePermissions);
163
- const updatedSettings = prevNavData.settings.map(updatePermissions);
197
+ const updatedNavigations = prevNavData.navigations
198
+ .map(updatePermissions)
199
+ .filter(Boolean);
200
+ const updatedSettings = prevNavData.settings
201
+ .map(updatePermissions)
202
+ .filter(Boolean);
164
203
 
165
204
  return {
166
205
  ...prevNavData,
@@ -171,14 +210,32 @@ function Navigation({ logo, logout, navConfig, setSystemAuth, userProfile }) {
171
210
  }, [userProfile]);
172
211
 
173
212
  useEffect(() => {
174
- setNavData((prevNavData) => ({
175
- ...prevNavData,
176
- navigations: prevNavData.navigations.map((nav) =>
177
- nav.id === currentPage
178
- ? { ...nav, class: "nav-item active" }
179
- : { ...nav, class: "nav-item" }
180
- ),
181
- }));
213
+ setNavData((prevNavData) => {
214
+ const updateNavItems = (nav) => {
215
+ const cleanUrl = (url) => {
216
+ return url && url.startsWith("/") ? url.substr(1) : url;
217
+ };
218
+
219
+ const currentUrl = cleanUrl(currentPage);
220
+
221
+ if (
222
+ cleanUrl(nav.url) === currentUrl ||
223
+ (nav.children &&
224
+ nav.children.some(
225
+ (child) => cleanUrl(child.url) === currentUrl
226
+ ))
227
+ ) {
228
+ return { ...nav, class: "nav-item active" };
229
+ } else {
230
+ return { ...nav, class: "nav-item" };
231
+ }
232
+ };
233
+
234
+ return {
235
+ ...prevNavData,
236
+ navigations: prevNavData.navigations.map(updateNavItems),
237
+ };
238
+ });
182
239
  }, [currentPage]);
183
240
 
184
241
  useEffect(() => {
package/package.json CHANGED
@@ -1,55 +1,55 @@
1
1
  {
2
- "dependencies": {
3
- "@inovua/reactdatagrid-community": "^5.9.4",
4
- "@inovua/reactdatagrid-enterprise": "^5.9.4",
5
- "akar-icons": "^1.9.28",
6
- "awesome-debounce-promise": "^2.1.0",
7
- "axios": "^1.4.0",
8
- "framer-motion": "^10.12.16",
9
- "html-react-parser": "^4.0.0",
10
- "lodash": "^4.17.21",
11
- "moment": "^2.29.4",
12
- "numeral": "^2.0.6",
13
- "quill-image-uploader": "^1.3.0",
14
- "react-confirm-alert": "^3.0.6",
15
- "react-datepicker": "^4.14.0",
16
- "react-dropzone": "^14.2.3",
17
- "react-number-format": "^5.2.2",
18
- "react-promise-tracker": "^2.1.1",
19
- "react-quill": "^2.0.0",
20
- "react-select": "^5.7.3",
21
- "react-slugify": "^3.0.2",
22
- "react-sortable-hoc": "^2.0.0",
23
- "react-toastify": "^9.1.3",
24
- "react-toggle": "^4.1.3",
25
- "react-tooltip": "^5.14.0",
26
- "react-window": "^1.8.9",
27
- "reactjs-popup": "^2.0.5"
28
- },
29
- "devDependecies": {
30
- "react": "^18.2.0",
31
- "react-dom": "^18.2.0"
32
- },
33
- "peerDependencies": {
34
- "react": "^17.0.1",
35
- "react-dom": "^17.0.1"
36
- },
37
- "name": "@visns-studio/visns-components",
38
- "version": "1.5.4",
39
- "description": "Various packages to assist in the development of our Custom Applications.",
40
- "main": "index.js",
41
- "devDependencies": {},
42
- "scripts": {
43
- "test": "echo \"Error: no test specified\" && exit 1"
44
- },
45
- "repository": {
46
- "type": "git",
47
- "url": "git+https://github.com/visnsstudio/visns-components.git"
48
- },
49
- "author": "Visns Studio",
50
- "license": "ISC",
51
- "bugs": {
52
- "url": "https://github.com/visnsstudio/visns-components/issues"
53
- },
54
- "homepage": "https://github.com/visnsstudio/visns-components#readme"
2
+ "dependencies": {
3
+ "@inovua/reactdatagrid-community": "^5.9.4",
4
+ "@inovua/reactdatagrid-enterprise": "^5.9.4",
5
+ "akar-icons": "^1.9.28",
6
+ "awesome-debounce-promise": "^2.1.0",
7
+ "axios": "^1.4.0",
8
+ "framer-motion": "^10.12.16",
9
+ "html-react-parser": "^4.0.0",
10
+ "lodash": "^4.17.21",
11
+ "moment": "^2.29.4",
12
+ "numeral": "^2.0.6",
13
+ "quill-image-uploader": "^1.3.0",
14
+ "react-confirm-alert": "^3.0.6",
15
+ "react-datepicker": "^4.14.0",
16
+ "react-dropzone": "^14.2.3",
17
+ "react-number-format": "^5.2.2",
18
+ "react-promise-tracker": "^2.1.1",
19
+ "react-quill": "^2.0.0",
20
+ "react-select": "^5.7.3",
21
+ "react-slugify": "^3.0.2",
22
+ "react-sortable-hoc": "^2.0.0",
23
+ "react-toastify": "^9.1.3",
24
+ "react-toggle": "^4.1.3",
25
+ "react-tooltip": "^5.14.0",
26
+ "react-window": "^1.8.9",
27
+ "reactjs-popup": "^2.0.5"
28
+ },
29
+ "devDependecies": {
30
+ "react": "^18.2.0",
31
+ "react-dom": "^18.2.0"
32
+ },
33
+ "peerDependencies": {
34
+ "react": "^17.0.1",
35
+ "react-dom": "^17.0.1"
36
+ },
37
+ "name": "@visns-studio/visns-components",
38
+ "version": "1.5.6",
39
+ "description": "Various packages to assist in the development of our Custom Applications.",
40
+ "main": "index.js",
41
+ "devDependencies": {},
42
+ "scripts": {
43
+ "test": "echo \"Error: no test specified\" && exit 1"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "git+https://github.com/visnsstudio/visns-components.git"
48
+ },
49
+ "author": "Visns Studio",
50
+ "license": "ISC",
51
+ "bugs": {
52
+ "url": "https://github.com/visnsstudio/visns-components/issues"
53
+ },
54
+ "homepage": "https://github.com/visnsstudio/visns-components#readme"
55
55
  }