@visns-studio/visns-components 1.5.3 → 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
  },
@@ -1,230 +1,288 @@
1
1
  import React, { useEffect, useState } from "react";
2
- import { Link, useLocation } from "react-router-dom";
2
+ import { Link, useLocation, useNavigate } from "react-router-dom";
3
3
  import {
4
- ArrowCycle,
5
- BookClose,
6
- Bug,
7
- Calendar,
8
- Clipboard,
9
- DoubleSword,
10
- Draft,
11
- Grid,
12
- LightBulb,
13
- PeopleGroup,
14
- Person,
15
- SettingsVertical,
16
- SignOut,
17
- Shield,
18
- Ticket,
4
+ ArrowCycle,
5
+ BookClose,
6
+ Bug,
7
+ Calendar,
8
+ Clipboard,
9
+ DoubleSword,
10
+ Draft,
11
+ Grid,
12
+ LightBulb,
13
+ PeopleGroup,
14
+ Person,
15
+ SettingsVertical,
16
+ SignOut,
17
+ Shield,
18
+ Ticket,
19
19
  } from "akar-icons";
20
20
 
21
21
  import CustomFetch from "./visns-fetch";
22
22
  import Notification from "./visns-notification";
23
23
 
24
24
  function Navigation({ logo, logout, navConfig, setSystemAuth, userProfile }) {
25
- const location = useLocation();
26
- const currentPage = location.pathname.substr(1) || "dashboard";
27
- const [navData, setNavData] = useState(navConfig);
28
- const [isScrolled, setIsScrolled] = useState(false);
29
- const appNavClasses = `app-nav ${isScrolled ? "navscrolled" : ""}`;
30
-
31
- const handleLogout = () => {
32
- CustomFetch("/logout", "GET", {}, () => {
33
- setSystemAuth(false);
34
- navigate("/login");
35
- });
36
- };
37
-
38
- const renderSetting = (n) => {
39
- const iconComponents = {
40
- bug: Bug,
41
- calendar: Calendar,
42
- person: Person,
43
- shield: Shield,
44
- signOut: SignOut,
45
- };
46
-
47
- if (n.id === "notifications") {
48
- return (
49
- <li>
50
- <Notification setSystemAuth={setSystemAuth} />
51
- </li>
52
- );
53
- } else if (n.id === "logout") {
54
- const IconComponent = iconComponents[n.icon];
55
- return (
56
- <li>
57
- <button
58
- title={n.label}
59
- data-tooltip-id="system-tooltip"
60
- data-tooltip-content={n.label}
61
- onClick={handleLogout}
62
- >
63
- <IconComponent size={19} strokeWidth={2} />
64
- </button>
65
- </li>
66
- );
67
- } else {
68
- const IconComponent = iconComponents[n.icon];
69
-
70
- return (
71
- <li>
72
- <Link
73
- to={n.url}
74
- data-tooltip-id="system-tooltip"
75
- data-tooltip-content={n.label}
76
- className="tooltip"
77
- target={n.target ? n.target : "_self"}
78
- >
79
- <IconComponent size={19} strokeWidth={2} />
80
- </Link>
81
- </li>
82
- );
83
- }
84
- };
85
-
86
- const renderNav = (n) => {
87
- const iconComponents = {
88
- arrowCycle: ArrowCycle,
89
- bookClose: BookClose,
90
- calendar: Calendar,
91
- clipboard: Clipboard,
92
- doubleSword: DoubleSword,
93
- draft: Draft,
94
- grid: Grid,
95
- lightBulb: LightBulb,
96
- peopleGroup: PeopleGroup,
97
- settingsVertical: SettingsVertical,
98
- ticket: Ticket,
99
- };
100
-
101
- const IconComponent = iconComponents[n.icon];
102
-
103
- const renderChildren = () => {
104
- if (n.children && n.children.length > 0) {
105
- return (
106
- <ul>
107
- {n.children.map((child, childKey) => (
108
- <li
109
- className="sub-nav-item"
110
- key={`nav-child-${childKey}`}
111
- >
112
- <Link to={child.url} title={child.label}>
113
- {child.label}
114
- </Link>
115
- </li>
116
- ))}
117
- </ul>
118
- );
119
- }
120
- return null;
121
- };
122
-
123
- return (
124
- <li className={n.class}>
125
- {n.url ? (
126
- <Link to={n.url}>
127
- <IconComponent strokeWidth={2} size={18} />
128
- {n.label}
129
- </Link>
130
- ) : (
131
- <span title={n.label}>
132
- <IconComponent strokeWidth={2} size={18} />
133
- {n.label}
134
- </span>
135
- )}
136
- {renderChildren()}
137
- </li>
138
- );
139
- };
140
-
141
- useEffect(() => {
142
- const permissions = userProfile.roles[0].permissions;
143
-
144
- setNavData((prevNavData) => {
145
- const updatePermissions = (nav) => {
146
- const matchingPermission = permissions.find(
147
- (permission) => permission.name === nav.permissionKey
148
- );
149
-
150
- if (matchingPermission) {
151
- return {
152
- ...nav,
153
- permission: true,
154
- };
155
- }
156
-
157
- return nav;
158
- };
159
-
160
- const updatedNavigations =
161
- prevNavData.navigations.map(updatePermissions);
162
- const updatedSettings = prevNavData.settings.map(updatePermissions);
163
-
164
- return {
165
- ...prevNavData,
166
- navigations: updatedNavigations,
167
- settings: updatedSettings,
168
- };
169
- });
170
- }, [userProfile]);
171
-
172
- useEffect(() => {
173
- setNavData((prevNavData) => ({
174
- ...prevNavData,
175
- navigations: prevNavData.navigations.map((nav) =>
176
- nav.id === currentPage
177
- ? { ...nav, class: "nav-item active" }
178
- : { ...nav, class: "nav-item" }
179
- ),
180
- }));
181
- }, [currentPage]);
182
-
183
- useEffect(() => {
184
- function handleScroll() {
185
- setIsScrolled(window.scrollY > 0);
186
- }
187
-
188
- window.addEventListener("scroll", handleScroll);
189
- return () => {
190
- window.removeEventListener("scroll", handleScroll);
191
- };
192
- }, []);
193
-
194
- return (
195
- <header className="header">
196
- <div className="hwrap">
197
- <div className="logo">
198
- <Link to="/">
199
- <img src={logo} alt="Visns Studio CRM" />
200
- </Link>
201
- </div>
202
- <div className="navwrap">
203
- <ul className={appNavClasses}>
204
- {navData.navigations.map((nav, navKey) =>
205
- nav.permission === true ||
206
- nav.permissionKey === "" ? (
207
- <React.Fragment key={`nav-item-${navKey}`}>
208
- {renderNav(nav)}
209
- </React.Fragment>
210
- ) : null
211
- )}
212
- </ul>
213
- </div>
214
- <div className="hactions">
215
- <ul>
216
- {navData.settings.map((setting, settingKey) =>
217
- setting.permission === true ? (
218
- <React.Fragment key={`setting-${settingKey}`}>
219
- {renderSetting(setting)}
220
- </React.Fragment>
221
- ) : null
222
- )}
223
- </ul>
224
- </div>
225
- </div>
226
- </header>
227
- );
25
+ const location = useLocation();
26
+ const navigate = useNavigate();
27
+ const currentPage = location.pathname.substr(1) || "dashboard";
28
+ const [navData, setNavData] = useState(navConfig);
29
+ const [isScrolled, setIsScrolled] = useState(false);
30
+ const appNavClasses = `app-nav ${isScrolled ? "navscrolled" : ""}`;
31
+
32
+ const handleLogout = () => {
33
+ CustomFetch("/logout", "GET", {}, () => {
34
+ setSystemAuth(false);
35
+ navigate("/login");
36
+ });
37
+ };
38
+
39
+ const renderSetting = (n) => {
40
+ const iconComponents = {
41
+ bug: Bug,
42
+ calendar: Calendar,
43
+ person: Person,
44
+ shield: Shield,
45
+ signOut: SignOut,
46
+ };
47
+
48
+ if (n.id === "notifications") {
49
+ return (
50
+ <li>
51
+ <Notification setSystemAuth={setSystemAuth} />
52
+ </li>
53
+ );
54
+ } else if (n.id === "logout") {
55
+ const IconComponent = iconComponents[n.icon];
56
+ return (
57
+ <li>
58
+ <button
59
+ title={n.label}
60
+ data-tooltip-id="system-tooltip"
61
+ data-tooltip-content={n.label}
62
+ onClick={handleLogout}
63
+ >
64
+ <IconComponent size={19} strokeWidth={2} />
65
+ </button>
66
+ </li>
67
+ );
68
+ } else {
69
+ const IconComponent = iconComponents[n.icon];
70
+
71
+ return (
72
+ <li>
73
+ <Link
74
+ to={n.url}
75
+ data-tooltip-id="system-tooltip"
76
+ data-tooltip-content={n.label}
77
+ className="tooltip"
78
+ target={n.target ? n.target : "_self"}
79
+ >
80
+ <IconComponent size={19} strokeWidth={2} />
81
+ </Link>
82
+ </li>
83
+ );
84
+ }
85
+ };
86
+
87
+ const renderNav = (n) => {
88
+ const iconComponents = {
89
+ arrowCycle: ArrowCycle,
90
+ bookClose: BookClose,
91
+ calendar: Calendar,
92
+ clipboard: Clipboard,
93
+ doubleSword: DoubleSword,
94
+ draft: Draft,
95
+ grid: Grid,
96
+ lightBulb: LightBulb,
97
+ peopleGroup: PeopleGroup,
98
+ settingsVertical: SettingsVertical,
99
+ ticket: Ticket,
100
+ };
101
+
102
+ const IconComponent = iconComponents[n.icon];
103
+
104
+ const renderChildren = () => {
105
+ if (n.children && n.children.length > 0) {
106
+ return (
107
+ <ul>
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
+ )}
124
+ </ul>
125
+ );
126
+ }
127
+ return null;
128
+ };
129
+
130
+ return (
131
+ <li className={n.class}>
132
+ {n.url ? (
133
+ <Link to={n.url}>
134
+ <IconComponent strokeWidth={2} size={18} />
135
+ {n.label}
136
+ </Link>
137
+ ) : (
138
+ <span title={n.label}>
139
+ <IconComponent strokeWidth={2} size={18} />
140
+ {n.label}
141
+ </span>
142
+ )}
143
+ {renderChildren()}
144
+ </li>
145
+ );
146
+ };
147
+
148
+ useEffect(() => {
149
+ const permissions = userProfile.roles[0].permissions.map(
150
+ (permission) => permission.name
151
+ );
152
+
153
+ setNavData((prevNavData) => {
154
+ const updatePermissions = (nav) => {
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
+ );
184
+
185
+ return {
186
+ ...nav,
187
+ permission: matchingPermission,
188
+ };
189
+ }
190
+
191
+ return {
192
+ ...nav,
193
+ permission: true,
194
+ };
195
+ };
196
+
197
+ const updatedNavigations = prevNavData.navigations
198
+ .map(updatePermissions)
199
+ .filter(Boolean);
200
+ const updatedSettings = prevNavData.settings
201
+ .map(updatePermissions)
202
+ .filter(Boolean);
203
+
204
+ return {
205
+ ...prevNavData,
206
+ navigations: updatedNavigations,
207
+ settings: updatedSettings,
208
+ };
209
+ });
210
+ }, [userProfile]);
211
+
212
+ useEffect(() => {
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
+ });
239
+ }, [currentPage]);
240
+
241
+ useEffect(() => {
242
+ function handleScroll() {
243
+ setIsScrolled(window.scrollY > 0);
244
+ }
245
+
246
+ window.addEventListener("scroll", handleScroll);
247
+ return () => {
248
+ window.removeEventListener("scroll", handleScroll);
249
+ };
250
+ }, []);
251
+
252
+ return (
253
+ <header className="header">
254
+ <div className="hwrap">
255
+ <div className="logo">
256
+ <Link to="/">
257
+ <img src={logo} alt="Visns Studio CRM" />
258
+ </Link>
259
+ </div>
260
+ <div className="navwrap">
261
+ <ul className={appNavClasses}>
262
+ {navData.navigations.map((nav, navKey) =>
263
+ nav.permission === true ||
264
+ nav.permissionKey === "" ? (
265
+ <React.Fragment key={`nav-item-${navKey}`}>
266
+ {renderNav(nav)}
267
+ </React.Fragment>
268
+ ) : null
269
+ )}
270
+ </ul>
271
+ </div>
272
+ <div className="hactions">
273
+ <ul>
274
+ {navData.settings.map((setting, settingKey) =>
275
+ setting.permission === true ? (
276
+ <React.Fragment key={`setting-${settingKey}`}>
277
+ {renderSetting(setting)}
278
+ </React.Fragment>
279
+ ) : null
280
+ )}
281
+ </ul>
282
+ </div>
283
+ </div>
284
+ </header>
285
+ );
228
286
  }
229
287
 
230
288
  export default Navigation;
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.3",
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.5",
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
  }