@visns-studio/visns-components 1.5.4 → 1.5.5

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.
@@ -480,70 +480,90 @@ const DataGrid = forwardRef(
480
480
 
481
481
  const renderSetting = (s, d) => {
482
482
  let iconStyle = {};
483
+ let allow = true;
483
484
 
484
485
  if (s.active) {
485
486
  if (
486
487
  d.hasOwnProperty(s.active.id) &&
487
- !s.active.hasOwnProperty("type") &&
488
- d[s.active.id] === s.active.value
488
+ (!s.active.hasOwnProperty("type") ||
489
+ d[s.active.id] === s.active.value)
490
+ ) {
491
+ iconStyle = {
492
+ color: s.active.colour,
493
+ };
494
+ } else if (
495
+ s.active.type === "greater" &&
496
+ d[s.active.id] > s.active.value
497
+ ) {
498
+ iconStyle = {
499
+ color: s.active.colour,
500
+ };
501
+ } else if (
502
+ s.active.type === "not null" &&
503
+ d[s.active.id] !== null
489
504
  ) {
490
505
  iconStyle = {
491
506
  color: s.active.colour,
492
507
  };
493
- } else if (s.active.hasOwnProperty("type")) {
494
- switch (s.active.type) {
495
- case "greater":
496
- if (d[s.active.id] > s.active.value) {
497
- iconStyle = {
498
- color: s.active.colour,
499
- };
500
- }
501
- break;
502
- case "not null":
503
- if (d[s.active.id] !== null) {
504
- iconStyle = {
505
- color: s.active.colour,
506
- };
507
- }
508
- break;
509
- default:
510
- break;
511
- }
512
508
  }
513
509
  }
514
510
 
515
- const getIconComponent = (IconComponent) => (
516
- <IconComponent
517
- data-tooltip-id="system-tooltip"
518
- data-tooltip-content={
519
- iconStyle && iconStyle.color ? s.active.title : s.title
520
- }
521
- strokeWidth={2}
522
- size={18}
523
- className="tdaction"
524
- style={iconStyle}
525
- />
526
- );
511
+ const handleIconClick = (e) => {
512
+ e.preventDefault();
513
+ e.stopPropagation();
514
+ handleSettingClick(s, d);
515
+ };
527
516
 
528
- switch (s.id) {
529
- case "archive":
530
- return getIconComponent(ShippingBoxV1);
531
- case "complete":
532
- return getIconComponent(Check);
533
- case "copy":
534
- return getIconComponent(Copy);
535
- case "delete":
536
- return getIconComponent(Backspace);
537
- case "family":
538
- return getIconComponent(Network);
539
- case "primary":
540
- return getIconComponent(Ribbon);
541
- case "ssa":
542
- return getIconComponent(Clock);
543
- case "update":
544
- return getIconComponent(Edit);
545
- default:
546
- return null;
517
+ const tooltipContent =
518
+ iconStyle && iconStyle.color ? s.active.title : s.title;
519
+
520
+ if (s.hide && s.hide.id && s.hide.value > 0) {
521
+ if (
522
+ d.hasOwnProperty(s.hide.id) &&
523
+ d[s.hide.id] === s.hide.value
524
+ ) {
525
+ allow = false;
526
+ }
527
+ }
528
+
529
+ if (allow) {
530
+ switch (s.id) {
531
+ case "archive":
532
+ return getIconComponent(ShippingBoxV1);
533
+ case "complete":
534
+ return getIconComponent(Check);
535
+ case "copy":
536
+ return getIconComponent(Copy);
537
+ case "delete":
538
+ return getIconComponent(Backspace);
539
+ case "family":
540
+ return getIconComponent(Network);
541
+ case "primary":
542
+ return getIconComponent(Ribbon);
543
+ case "ssa":
544
+ return getIconComponent(Clock);
545
+ case "update":
546
+ return getIconComponent(Edit);
547
+ default:
548
+ return null;
549
+ }
550
+ } else {
551
+ return null;
552
+ }
553
+
554
+ function getIconComponent(IconComponent) {
555
+ return (
556
+ <span key={`setting-${s.id}`} onClick={handleIconClick}>
557
+ <IconComponent
558
+ data-tooltip-id="system-tooltip"
559
+ data-tooltip-content={tooltipContent}
560
+ strokeWidth={2}
561
+ size={18}
562
+ className="tdaction"
563
+ style={iconStyle}
564
+ />
565
+ </span>
566
+ );
547
567
  }
548
568
  };
549
569
 
@@ -1342,18 +1362,9 @@ const DataGrid = forwardRef(
1342
1362
  render: ({ data }) => {
1343
1363
  return (
1344
1364
  <div className="tdactions">
1345
- {settings.map((setting) => (
1346
- <span
1347
- key={`setting-${setting.id}`}
1348
- onClick={(e) => {
1349
- e.preventDefault();
1350
- e.stopPropagation();
1351
- handleSettingClick(setting, data);
1352
- }}
1353
- >
1354
- {renderSetting(setting, data)}
1355
- </span>
1356
- ))}
1365
+ {settings.map((setting) =>
1366
+ renderSetting(setting, data)
1367
+ )}
1357
1368
  </div>
1358
1369
  );
1359
1370
  },
@@ -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
@@ -35,7 +35,7 @@
35
35
  "react-dom": "^17.0.1"
36
36
  },
37
37
  "name": "@visns-studio/visns-components",
38
- "version": "1.5.4",
38
+ "version": "1.5.5",
39
39
  "description": "Various packages to assist in the development of our Custom Applications.",
40
40
  "main": "index.js",
41
41
  "devDependencies": {},