@visns-studio/visns-components 1.2.1 → 1.2.3
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/components/crm/visns-data-grid.jsx +887 -823
- package/components/crm/visns-table-filter.jsx +40 -14
- package/package.json +51 -51
|
@@ -9,14 +9,14 @@ import ReactDataGrid from "@inovua/reactdatagrid-community";
|
|
|
9
9
|
import { confirmAlert } from "react-confirm-alert";
|
|
10
10
|
import { toast } from "react-toastify";
|
|
11
11
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
Backspace,
|
|
13
|
+
Check,
|
|
14
|
+
Clock,
|
|
15
|
+
CloudDownload,
|
|
16
|
+
Copy,
|
|
17
|
+
Edit,
|
|
18
|
+
Ribbon,
|
|
19
|
+
Search,
|
|
20
20
|
} from "akar-icons";
|
|
21
21
|
|
|
22
22
|
import "@inovua/reactdatagrid-community/index.css";
|
|
@@ -26,825 +26,889 @@ import CustomFetch from "./visns-fetch";
|
|
|
26
26
|
import Form from "./visns-form";
|
|
27
27
|
|
|
28
28
|
const loadData = async (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
{ skip, limit, sortInfo, currentData, filterValue, groupBy },
|
|
30
|
+
search,
|
|
31
|
+
ajaxSetting
|
|
32
32
|
) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
33
|
+
const url = ajaxSetting.url;
|
|
34
|
+
|
|
35
|
+
let page = Math.floor(skip / limit) + 1;
|
|
36
|
+
let params = { page, sortInfo, take: limit, search: search };
|
|
37
|
+
|
|
38
|
+
if (sortInfo) {
|
|
39
|
+
params.sortBy = sortInfo.name;
|
|
40
|
+
params.sort = sortInfo.dir === 1 ? "asc" : "desc";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (ajaxSetting && ajaxSetting.where) {
|
|
44
|
+
params.where = ajaxSetting.where;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
const response = await axios.post(url, params);
|
|
49
|
+
const { data, total } = response.data;
|
|
50
|
+
return { data, count: total };
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error("Error fetching data:", error);
|
|
53
|
+
return { data: [], count: 0 };
|
|
54
|
+
}
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
const DataGrid = (props) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
58
|
+
const {
|
|
59
|
+
ajaxSetting,
|
|
60
|
+
form,
|
|
61
|
+
columns,
|
|
62
|
+
settings,
|
|
63
|
+
style,
|
|
64
|
+
tableFilters,
|
|
65
|
+
historySearch,
|
|
66
|
+
historyUrl,
|
|
67
|
+
} = props;
|
|
68
|
+
const navigate = useNavigate();
|
|
69
|
+
|
|
70
|
+
/** Modal States */
|
|
71
|
+
const [formData, setFormData] = useState(form);
|
|
72
|
+
const [formType, setFormType] = useState("");
|
|
73
|
+
const [formId, setFormId] = useState(0);
|
|
74
|
+
const [modalShow, setModalShow] = useState(false);
|
|
75
|
+
|
|
76
|
+
/** Modal Functions */
|
|
77
|
+
const childDropdownCallback = (data) => {
|
|
78
|
+
let _form = { ...formData };
|
|
79
|
+
|
|
80
|
+
if (formData.fields.length > 0) {
|
|
81
|
+
formData.fields.forEach((a, b) => {
|
|
82
|
+
if (a.id === data.id) {
|
|
83
|
+
_form.fields[b].options = data.data;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
setFormData(_form);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const modalOpen = (formType, formId) => {
|
|
92
|
+
setModalShow(true);
|
|
93
|
+
setFormType(formType);
|
|
94
|
+
setFormId(formId);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const modalClose = () => {
|
|
98
|
+
setModalShow(false);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** Table States */
|
|
102
|
+
const [dataReload, setDataReload] = useState(0);
|
|
103
|
+
const [dSearch, setDSearch] = useState("");
|
|
104
|
+
const data = useCallback(
|
|
105
|
+
(params) => loadData(params, dSearch, ajaxSetting),
|
|
106
|
+
[ajaxSetting, dataReload, dSearch]
|
|
107
|
+
);
|
|
108
|
+
const [gridColumns, setGridColumns] = useState([]);
|
|
109
|
+
const limit = ajaxSetting.take || 10;
|
|
110
|
+
const [search, setSearch] = useState("");
|
|
111
|
+
const sortInfo =
|
|
112
|
+
ajaxSetting.sortBy && ajaxSetting.sort
|
|
113
|
+
? {
|
|
114
|
+
name: ajaxSetting.sortBy,
|
|
115
|
+
dir: ajaxSetting.sort === "asc" ? 1 : -1,
|
|
116
|
+
}
|
|
117
|
+
: null;
|
|
118
|
+
|
|
119
|
+
/** Table Functions */
|
|
120
|
+
const handleChangeSearch = (e) => {
|
|
121
|
+
const { value } = e.target;
|
|
122
|
+
setSearch(value);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const handleSettingClick = (s, d) => {
|
|
126
|
+
switch (s.id) {
|
|
127
|
+
case "update":
|
|
128
|
+
modalOpen("update", d.id);
|
|
129
|
+
break;
|
|
130
|
+
case "delete":
|
|
131
|
+
confirmAlert({
|
|
132
|
+
title: "Delete Item",
|
|
133
|
+
message: `Are you sure you want to delete ${
|
|
134
|
+
d.name ? d.name : d.label ? d.label : "this item"
|
|
135
|
+
}?`,
|
|
136
|
+
buttons: [
|
|
137
|
+
{
|
|
138
|
+
label: "Yes",
|
|
139
|
+
onClick: () =>
|
|
140
|
+
CustomFetch(
|
|
141
|
+
form.url + "/" + d[form.primaryKey],
|
|
142
|
+
"DELETE",
|
|
143
|
+
{},
|
|
144
|
+
(result) => {
|
|
145
|
+
if (result.error === "") {
|
|
146
|
+
const min = 0;
|
|
147
|
+
const max = 999999999;
|
|
148
|
+
const randomNumber = Math.floor(
|
|
149
|
+
Math.random() *
|
|
150
|
+
(max - min + 1) +
|
|
151
|
+
min
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
setDataReload(randomNumber);
|
|
155
|
+
|
|
156
|
+
toast.success(
|
|
157
|
+
`The selected item has been deleted.`
|
|
158
|
+
);
|
|
159
|
+
} else {
|
|
160
|
+
toast.error(String(result.error));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
),
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
label: "No",
|
|
167
|
+
onClick: () => close(),
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
});
|
|
171
|
+
break;
|
|
172
|
+
default:
|
|
173
|
+
confirmAlert({
|
|
174
|
+
title: s.title,
|
|
175
|
+
message: "",
|
|
176
|
+
buttons: [
|
|
177
|
+
{
|
|
178
|
+
label: "Yes",
|
|
179
|
+
onClick: () =>
|
|
180
|
+
CustomFetch(
|
|
181
|
+
s.url + "/" + d[form.primaryKey],
|
|
182
|
+
s.method,
|
|
183
|
+
{},
|
|
184
|
+
function (result) {
|
|
185
|
+
if (result.error === "") {
|
|
186
|
+
const min = 0;
|
|
187
|
+
const max = 999999999;
|
|
188
|
+
const randomNumber = Math.floor(
|
|
189
|
+
Math.random() *
|
|
190
|
+
(max - min + 1) +
|
|
191
|
+
min
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
setDataReload(randomNumber);
|
|
195
|
+
|
|
196
|
+
toast.success(String(s.title));
|
|
197
|
+
} else {
|
|
198
|
+
toast.error(String(result.error));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
),
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
label: "No",
|
|
205
|
+
onClick: () => close(),
|
|
206
|
+
},
|
|
207
|
+
],
|
|
208
|
+
});
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
const handleReload = () => {
|
|
214
|
+
setDataReload(dataReload + 1);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const onRowClick = useCallback((rowProps, event) => {
|
|
218
|
+
const cellElement = event.target.closest(".InovuaReactDataGrid__cell");
|
|
219
|
+
const columnIndex = Array.from(cellElement.parentNode.children).indexOf(
|
|
220
|
+
cellElement
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
if (columnIndex === rowProps.columns.length - 1) {
|
|
224
|
+
} else {
|
|
225
|
+
if (
|
|
226
|
+
rowProps.columns[columnIndex].link &&
|
|
227
|
+
rowProps.columns[columnIndex].link.url
|
|
228
|
+
) {
|
|
229
|
+
if (rowProps.columns[columnIndex].link.folder) {
|
|
230
|
+
window.location.href =
|
|
231
|
+
rowProps.columns[columnIndex].link.url +
|
|
232
|
+
rowProps.data[rowProps.columns[columnIndex].link.key] +
|
|
233
|
+
"/" +
|
|
234
|
+
rowProps.columns[columnIndex].link.folder;
|
|
235
|
+
} else {
|
|
236
|
+
navigate(
|
|
237
|
+
`${rowProps.columns[columnIndex].link.url}${
|
|
238
|
+
rowProps.data[
|
|
239
|
+
rowProps.columns[columnIndex].link.key
|
|
240
|
+
]
|
|
241
|
+
}`
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
modalOpen("update", rowProps.data[form.primaryKey]);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}, []);
|
|
249
|
+
|
|
250
|
+
const onRenderRow = useCallback((rowProps) => {
|
|
251
|
+
// save the original handlers to be called later
|
|
252
|
+
const { onClick } = rowProps;
|
|
253
|
+
|
|
254
|
+
rowProps.onClick = (event) => {
|
|
255
|
+
onRowClick(rowProps, event);
|
|
256
|
+
if (onClick) {
|
|
257
|
+
onClick(event);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}, []);
|
|
261
|
+
|
|
262
|
+
/** Table Hooks */
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
const delayedSetDSearch = debounce(() => {
|
|
265
|
+
setDSearch(search);
|
|
266
|
+
}, 300); // Adjust the delay (in milliseconds) according to your needs
|
|
267
|
+
|
|
268
|
+
delayedSetDSearch();
|
|
269
|
+
|
|
270
|
+
return delayedSetDSearch.cancel; // Cleanup the debounce timer on unmount
|
|
271
|
+
}, [search, setDSearch]);
|
|
272
|
+
|
|
273
|
+
const renderSetting = (s, d) => {
|
|
274
|
+
let iconStyle = {};
|
|
275
|
+
|
|
276
|
+
if (s.active) {
|
|
277
|
+
if (
|
|
278
|
+
d.hasOwnProperty(s.active.id) &&
|
|
279
|
+
!s.active.hasOwnProperty("type") &&
|
|
280
|
+
d[s.active.id] === s.active.value
|
|
281
|
+
) {
|
|
282
|
+
iconStyle = {
|
|
283
|
+
color: s.active.colour,
|
|
284
|
+
};
|
|
285
|
+
} else if (s.active.hasOwnProperty("type")) {
|
|
286
|
+
switch (s.active.type) {
|
|
287
|
+
case "greater":
|
|
288
|
+
if (d[s.active.id] > s.active.value) {
|
|
289
|
+
iconStyle = {
|
|
290
|
+
color: s.active.colour,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
break;
|
|
294
|
+
case "not null":
|
|
295
|
+
if (d[s.active.id] !== null) {
|
|
296
|
+
iconStyle = {
|
|
297
|
+
color: s.active.colour,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
break;
|
|
301
|
+
default:
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const getIconComponent = (IconComponent) => (
|
|
308
|
+
<IconComponent
|
|
309
|
+
data-tooltip-id="system-tooltip"
|
|
310
|
+
data-tooltip-content={
|
|
311
|
+
iconStyle && iconStyle.color ? s.active.title : s.title
|
|
312
|
+
}
|
|
313
|
+
strokeWidth={2}
|
|
314
|
+
size={18}
|
|
315
|
+
className="tdaction"
|
|
316
|
+
style={iconStyle}
|
|
317
|
+
/>
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
switch (s.id) {
|
|
321
|
+
case "complete":
|
|
322
|
+
return getIconComponent(Check);
|
|
323
|
+
case "copy":
|
|
324
|
+
return getIconComponent(Copy);
|
|
325
|
+
case "delete":
|
|
326
|
+
return getIconComponent(Backspace);
|
|
327
|
+
case "primary":
|
|
328
|
+
return getIconComponent(Ribbon);
|
|
329
|
+
case "ssa":
|
|
330
|
+
return getIconComponent(Clock);
|
|
331
|
+
case "update":
|
|
332
|
+
return getIconComponent(Edit);
|
|
333
|
+
default:
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
const renderColumnContextMenu = useCallback((menuProps, { cellProps }) => {
|
|
339
|
+
const filteredItems = menuProps.items
|
|
340
|
+
.map((item, key) => {
|
|
341
|
+
if (key >= 6 && key <= 9) {
|
|
342
|
+
return null; // Skip items with keys 6-9 [lock columns setting]
|
|
343
|
+
}
|
|
344
|
+
return item;
|
|
345
|
+
})
|
|
346
|
+
.filter(Boolean); // Filter out any null items
|
|
347
|
+
|
|
348
|
+
menuProps.items = filteredItems;
|
|
349
|
+
}, []);
|
|
350
|
+
|
|
351
|
+
useEffect(() => {
|
|
352
|
+
const renderColumn = (column) => {
|
|
353
|
+
switch (column.type) {
|
|
354
|
+
case "created_by":
|
|
355
|
+
return {
|
|
356
|
+
name: "audits.name",
|
|
357
|
+
header: column.label,
|
|
358
|
+
defaultFlex: 1,
|
|
359
|
+
link: column.link ? column.link : {},
|
|
360
|
+
minWidth:
|
|
361
|
+
column.minWidth && column.minWidth > 0
|
|
362
|
+
? column.minWidth
|
|
363
|
+
: undefined,
|
|
364
|
+
maxWidth:
|
|
365
|
+
column.maxWidth && column.maxWidth > 0
|
|
366
|
+
? column.maxWidth
|
|
367
|
+
: undefined,
|
|
368
|
+
render: ({ data }) => {
|
|
369
|
+
if (
|
|
370
|
+
data.audits[0] &&
|
|
371
|
+
data.audits[0].user &&
|
|
372
|
+
data.audits[0].user.name
|
|
373
|
+
) {
|
|
374
|
+
let value = data.audits[0].user.name;
|
|
375
|
+
|
|
376
|
+
return <span>{value}</span>;
|
|
377
|
+
} else {
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
case "currency":
|
|
383
|
+
return {
|
|
384
|
+
name: column.id,
|
|
385
|
+
header: column.label,
|
|
386
|
+
defaultFlex: 1,
|
|
387
|
+
minWidth:
|
|
388
|
+
column.minWidth && column.minWidth > 0
|
|
389
|
+
? column.minWidth
|
|
390
|
+
: undefined,
|
|
391
|
+
maxWidth:
|
|
392
|
+
column.maxWidth && column.maxWidth > 0
|
|
393
|
+
? column.maxWidth
|
|
394
|
+
: undefined,
|
|
395
|
+
link: column.link ? column.link : {},
|
|
396
|
+
render: ({ data }) => {
|
|
397
|
+
if (data) {
|
|
398
|
+
data = numeral(data[column.id]).format(
|
|
399
|
+
"$0,0.00"
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
return <span>{data}</span>;
|
|
403
|
+
} else {
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
case "date":
|
|
409
|
+
return {
|
|
410
|
+
name: column.id,
|
|
411
|
+
header: column.label,
|
|
412
|
+
defaultFlex: 1,
|
|
413
|
+
minWidth:
|
|
414
|
+
column.minWidth && column.minWidth > 0
|
|
415
|
+
? column.minWidth
|
|
416
|
+
: undefined,
|
|
417
|
+
maxWidth:
|
|
418
|
+
column.maxWidth && column.maxWidth > 0
|
|
419
|
+
? column.maxWidth
|
|
420
|
+
: undefined,
|
|
421
|
+
link: column.link ? column.link : {},
|
|
422
|
+
render: ({ data }) => {
|
|
423
|
+
if (data && data[column.id]) {
|
|
424
|
+
data = moment(data[column.id]).format(
|
|
425
|
+
column.format ? column.format : "DD-MM-YYYY"
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
return <span>{data}</span>;
|
|
429
|
+
} else {
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
},
|
|
433
|
+
};
|
|
434
|
+
case "datetime":
|
|
435
|
+
return {
|
|
436
|
+
name: column.id,
|
|
437
|
+
header: column.label,
|
|
438
|
+
defaultFlex: 1,
|
|
439
|
+
minWidth:
|
|
440
|
+
column.minWidth && column.minWidth > 0
|
|
441
|
+
? column.minWidth
|
|
442
|
+
: undefined,
|
|
443
|
+
maxWidth:
|
|
444
|
+
column.maxWidth && column.maxWidth > 0
|
|
445
|
+
? column.maxWidth
|
|
446
|
+
: undefined,
|
|
447
|
+
link: column.link ? column.link : {},
|
|
448
|
+
render: ({ data }) => {
|
|
449
|
+
if (data && data[column.id]) {
|
|
450
|
+
data = moment(data[column.id]).format(
|
|
451
|
+
column.format
|
|
452
|
+
? column.format
|
|
453
|
+
: "DD-MM-YYYY hh:mm A"
|
|
454
|
+
);
|
|
455
|
+
|
|
456
|
+
return <span>{data}</span>;
|
|
457
|
+
} else {
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
};
|
|
462
|
+
case "file":
|
|
463
|
+
return {
|
|
464
|
+
name: column.id,
|
|
465
|
+
header: column.label,
|
|
466
|
+
defaultFlex: 1,
|
|
467
|
+
minWidth:
|
|
468
|
+
column.minWidth && column.minWidth > 0
|
|
469
|
+
? column.minWidth
|
|
470
|
+
: undefined,
|
|
471
|
+
maxWidth:
|
|
472
|
+
column.maxWidth && column.maxWidth > 0
|
|
473
|
+
? column.maxWidth
|
|
474
|
+
: undefined,
|
|
475
|
+
link: column.link ? column.link : {},
|
|
476
|
+
render: ({ data }) => {
|
|
477
|
+
if (data) {
|
|
478
|
+
return (
|
|
479
|
+
<span>
|
|
480
|
+
<CloudDownload
|
|
481
|
+
data-tooltip-id="system-tooltip"
|
|
482
|
+
data-tooltip-content="Download File"
|
|
483
|
+
strokeWidth={2}
|
|
484
|
+
size={18}
|
|
485
|
+
className="tdaction"
|
|
486
|
+
/>
|
|
487
|
+
</span>
|
|
488
|
+
);
|
|
489
|
+
} else {
|
|
490
|
+
return null;
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
};
|
|
494
|
+
case "icons":
|
|
495
|
+
return {
|
|
496
|
+
name: column.id,
|
|
497
|
+
header: column.label,
|
|
498
|
+
defaultFlex: 1,
|
|
499
|
+
minWidth:
|
|
500
|
+
column.minWidth && column.minWidth > 0
|
|
501
|
+
? column.minWidth
|
|
502
|
+
: undefined,
|
|
503
|
+
maxWidth:
|
|
504
|
+
column.maxWidth && column.maxWidth > 0
|
|
505
|
+
? column.maxWidth
|
|
506
|
+
: undefined,
|
|
507
|
+
link: column.link ? column.link : {},
|
|
508
|
+
render: ({ data }) => {
|
|
509
|
+
let icons = [];
|
|
510
|
+
|
|
511
|
+
if (column.icons && column.icons.length > 0) {
|
|
512
|
+
column.icons.forEach((icon) => {
|
|
513
|
+
icons.push(
|
|
514
|
+
<img
|
|
515
|
+
src={icon.url}
|
|
516
|
+
alt={icon.name}
|
|
517
|
+
data-tooltip-id="system-tooltip"
|
|
518
|
+
data-tooltip-content={icon.name}
|
|
519
|
+
/>
|
|
520
|
+
);
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return <span>{icons}</span>;
|
|
525
|
+
},
|
|
526
|
+
};
|
|
527
|
+
case "json":
|
|
528
|
+
return {
|
|
529
|
+
name: column.id,
|
|
530
|
+
header: column.label,
|
|
531
|
+
defaultFlex: 1,
|
|
532
|
+
minWidth:
|
|
533
|
+
column.minWidth && column.minWidth > 0
|
|
534
|
+
? column.minWidth
|
|
535
|
+
: undefined,
|
|
536
|
+
maxWidth:
|
|
537
|
+
column.maxWidth && column.maxWidth > 0
|
|
538
|
+
? column.maxWidth
|
|
539
|
+
: undefined,
|
|
540
|
+
link: column.link ? column.link : {},
|
|
541
|
+
render: ({ data }) => {
|
|
542
|
+
if (
|
|
543
|
+
data &&
|
|
544
|
+
data[column.id] &&
|
|
545
|
+
data[column.id][column.jsonData]
|
|
546
|
+
) {
|
|
547
|
+
data = data[column.id][column.jsonData];
|
|
548
|
+
|
|
549
|
+
return <span>{data}</span>;
|
|
550
|
+
} else {
|
|
551
|
+
return null;
|
|
552
|
+
}
|
|
553
|
+
},
|
|
554
|
+
};
|
|
555
|
+
case "number":
|
|
556
|
+
return {
|
|
557
|
+
name: column.id,
|
|
558
|
+
header: column.label,
|
|
559
|
+
defaultFlex: 1,
|
|
560
|
+
minWidth:
|
|
561
|
+
column.minWidth && column.minWidth > 0
|
|
562
|
+
? column.minWidth
|
|
563
|
+
: undefined,
|
|
564
|
+
maxWidth:
|
|
565
|
+
column.maxWidth && column.maxWidth > 0
|
|
566
|
+
? column.maxWidth
|
|
567
|
+
: undefined,
|
|
568
|
+
link: column.link ? column.link : {},
|
|
569
|
+
type: "number",
|
|
570
|
+
};
|
|
571
|
+
case "option":
|
|
572
|
+
return {
|
|
573
|
+
name: column.id,
|
|
574
|
+
header: column.label,
|
|
575
|
+
defaultFlex: 1,
|
|
576
|
+
minWidth:
|
|
577
|
+
column.minWidth && column.minWidth > 0
|
|
578
|
+
? column.minWidth
|
|
579
|
+
: undefined,
|
|
580
|
+
maxWidth:
|
|
581
|
+
column.maxWidth && column.maxWidth > 0
|
|
582
|
+
? column.maxWidth
|
|
583
|
+
: undefined,
|
|
584
|
+
link: column.link ? column.link : {},
|
|
585
|
+
render: ({ data }) => {
|
|
586
|
+
if (
|
|
587
|
+
data &&
|
|
588
|
+
column.options &&
|
|
589
|
+
column.options[data[column.id]]
|
|
590
|
+
) {
|
|
591
|
+
data = column.options[data[column.id]];
|
|
592
|
+
|
|
593
|
+
return <span>{data}</span>;
|
|
594
|
+
} else {
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
},
|
|
598
|
+
};
|
|
599
|
+
case "placeholder":
|
|
600
|
+
return {
|
|
601
|
+
name: column.id,
|
|
602
|
+
header: column.label,
|
|
603
|
+
defaultFlex: 1,
|
|
604
|
+
minWidth:
|
|
605
|
+
column.minWidth && column.minWidth > 0
|
|
606
|
+
? column.minWidth
|
|
607
|
+
: undefined,
|
|
608
|
+
maxWidth:
|
|
609
|
+
column.maxWidth && column.maxWidth > 0
|
|
610
|
+
? column.maxWidth
|
|
611
|
+
: undefined,
|
|
612
|
+
link: column.link ? column.link : {},
|
|
613
|
+
render: ({ data }) => {
|
|
614
|
+
return <span>{column.placeholder}</span>;
|
|
615
|
+
},
|
|
616
|
+
};
|
|
617
|
+
case "relation":
|
|
618
|
+
let relationName = column.id.reduce(
|
|
619
|
+
(acc, id) => acc + `${id}.`,
|
|
620
|
+
""
|
|
621
|
+
);
|
|
622
|
+
relationName += column.nameFrom;
|
|
623
|
+
|
|
624
|
+
return {
|
|
625
|
+
name: relationName,
|
|
626
|
+
header: column.label,
|
|
627
|
+
defaultFlex: 1,
|
|
628
|
+
minWidth:
|
|
629
|
+
column.minWidth && column.minWidth > 0
|
|
630
|
+
? column.minWidth
|
|
631
|
+
: undefined,
|
|
632
|
+
maxWidth:
|
|
633
|
+
column.maxWidth && column.maxWidth > 0
|
|
634
|
+
? column.maxWidth
|
|
635
|
+
: undefined,
|
|
636
|
+
link: column.link ? column.link : {},
|
|
637
|
+
render: ({ data }) => {
|
|
638
|
+
let value = column.id.reduce((acc, id) => {
|
|
639
|
+
if (acc === "") {
|
|
640
|
+
return data[id];
|
|
641
|
+
} else {
|
|
642
|
+
return acc[id];
|
|
643
|
+
}
|
|
644
|
+
}, "");
|
|
645
|
+
|
|
646
|
+
if (value) {
|
|
647
|
+
if (Array.isArray(column.nameFrom)) {
|
|
648
|
+
value = column.nameFrom
|
|
649
|
+
.map((nf) => value[nf])
|
|
650
|
+
.join(" ");
|
|
651
|
+
} else {
|
|
652
|
+
value = value[column.nameFrom];
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
if (
|
|
656
|
+
column.placeholder &&
|
|
657
|
+
column.placeholder !== ""
|
|
658
|
+
) {
|
|
659
|
+
return <span>{column.placeholder}</span>;
|
|
660
|
+
} else {
|
|
661
|
+
return <span>{value}</span>;
|
|
662
|
+
}
|
|
663
|
+
} else {
|
|
664
|
+
return null;
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
};
|
|
668
|
+
case "relationArray":
|
|
669
|
+
const relationArrayName =
|
|
670
|
+
column.id.reduce((acc, id) => acc + `${id}.`, "") +
|
|
671
|
+
column.nameFrom;
|
|
672
|
+
|
|
673
|
+
return {
|
|
674
|
+
name: relationArrayName,
|
|
675
|
+
header: column.label,
|
|
676
|
+
defaultFlex: 1,
|
|
677
|
+
minWidth:
|
|
678
|
+
column.minWidth && column.minWidth > 0
|
|
679
|
+
? column.minWidth
|
|
680
|
+
: undefined,
|
|
681
|
+
maxWidth:
|
|
682
|
+
column.maxWidth && column.maxWidth > 0
|
|
683
|
+
? column.maxWidth
|
|
684
|
+
: undefined,
|
|
685
|
+
link: column.link ? column.link : {},
|
|
686
|
+
render: ({ data }) => {
|
|
687
|
+
const relationValue = column.id.reduce(
|
|
688
|
+
(acc, id) => (acc === "" ? data[id] : acc[id]),
|
|
689
|
+
""
|
|
690
|
+
);
|
|
691
|
+
|
|
692
|
+
if (relationValue && Array.isArray(relationValue)) {
|
|
693
|
+
const value = relationValue
|
|
694
|
+
.map((rv) => rv[column.nameFrom])
|
|
695
|
+
.join(", ");
|
|
696
|
+
return <span>{value}</span>;
|
|
697
|
+
} else {
|
|
698
|
+
return null;
|
|
699
|
+
}
|
|
700
|
+
},
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
case "stage":
|
|
704
|
+
return {
|
|
705
|
+
name: column.id,
|
|
706
|
+
header: column.label,
|
|
707
|
+
defaultFlex: 1,
|
|
708
|
+
minWidth:
|
|
709
|
+
column.minWidth && column.minWidth > 0
|
|
710
|
+
? column.minWidth
|
|
711
|
+
: undefined,
|
|
712
|
+
maxWidth:
|
|
713
|
+
column.maxWidth && column.maxWidth > 0
|
|
714
|
+
? column.maxWidth
|
|
715
|
+
: undefined,
|
|
716
|
+
link: column.link ? column.link : {},
|
|
717
|
+
render: ({ data }) => {
|
|
718
|
+
let stage = "";
|
|
719
|
+
|
|
720
|
+
column.keyIds.forEach((a, b) => {
|
|
721
|
+
if (data[a] === 1) {
|
|
722
|
+
stage = column.valueIds[b];
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
return <span>{stage}</span>;
|
|
727
|
+
},
|
|
728
|
+
};
|
|
729
|
+
case "time":
|
|
730
|
+
return {
|
|
731
|
+
name: column.id,
|
|
732
|
+
header: column.label,
|
|
733
|
+
defaultFlex: 1,
|
|
734
|
+
minWidth:
|
|
735
|
+
column.minWidth && column.minWidth > 0
|
|
736
|
+
? column.minWidth
|
|
737
|
+
: undefined,
|
|
738
|
+
maxWidth:
|
|
739
|
+
column.maxWidth && column.maxWidth > 0
|
|
740
|
+
? column.maxWidth
|
|
741
|
+
: undefined,
|
|
742
|
+
link: column.link ? column.link : {},
|
|
743
|
+
render: ({ data }) => {
|
|
744
|
+
if (data && data[column.id]) {
|
|
745
|
+
data = moment(data[column.id]).format(
|
|
746
|
+
column.format ? column.format : "hh:mm A"
|
|
747
|
+
);
|
|
748
|
+
|
|
749
|
+
return <span>{data}</span>;
|
|
750
|
+
} else {
|
|
751
|
+
return null;
|
|
752
|
+
}
|
|
753
|
+
},
|
|
754
|
+
};
|
|
755
|
+
case "url":
|
|
756
|
+
return {
|
|
757
|
+
name: column.id,
|
|
758
|
+
header: column.label,
|
|
759
|
+
defaultFlex: 1,
|
|
760
|
+
minWidth:
|
|
761
|
+
column.minWidth && column.minWidth > 0
|
|
762
|
+
? column.minWidth
|
|
763
|
+
: undefined,
|
|
764
|
+
maxWidth:
|
|
765
|
+
column.maxWidth && column.maxWidth > 0
|
|
766
|
+
? column.maxWidth
|
|
767
|
+
: undefined,
|
|
768
|
+
link: column.link ? column.link : {},
|
|
769
|
+
render: ({ data }) => {
|
|
770
|
+
if (data) {
|
|
771
|
+
return (
|
|
772
|
+
<span>
|
|
773
|
+
<a href={data} target="_blank">
|
|
774
|
+
Link
|
|
775
|
+
</a>
|
|
776
|
+
</span>
|
|
777
|
+
);
|
|
778
|
+
} else {
|
|
779
|
+
return null;
|
|
780
|
+
}
|
|
781
|
+
},
|
|
782
|
+
};
|
|
783
|
+
default:
|
|
784
|
+
return {
|
|
785
|
+
name: column.id,
|
|
786
|
+
header: column.label,
|
|
787
|
+
defaultFlex: 1,
|
|
788
|
+
minWidth:
|
|
789
|
+
column.minWidth && column.minWidth > 0
|
|
790
|
+
? column.minWidth
|
|
791
|
+
: undefined,
|
|
792
|
+
maxWidth:
|
|
793
|
+
column.maxWidth && column.maxWidth > 0
|
|
794
|
+
? column.maxWidth
|
|
795
|
+
: undefined,
|
|
796
|
+
link: column.link ? column.link : {},
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
const newColumns = columns.map(renderColumn);
|
|
802
|
+
|
|
803
|
+
if (settings.length > 0) {
|
|
804
|
+
newColumns.push({
|
|
805
|
+
name: "setting",
|
|
806
|
+
header: "Action",
|
|
807
|
+
defaultWidth: 100,
|
|
808
|
+
textAlign: "center",
|
|
809
|
+
render: ({ data }) => {
|
|
810
|
+
return (
|
|
811
|
+
<div className="tdactions">
|
|
812
|
+
{settings.map((setting) => (
|
|
813
|
+
<span
|
|
814
|
+
key={`setting-${setting.id}`}
|
|
815
|
+
onClick={(e) => {
|
|
816
|
+
e.preventDefault();
|
|
817
|
+
e.stopPropagation();
|
|
818
|
+
handleSettingClick(setting, data);
|
|
819
|
+
}}
|
|
820
|
+
>
|
|
821
|
+
{renderSetting(setting, data)}
|
|
822
|
+
</span>
|
|
823
|
+
))}
|
|
824
|
+
</div>
|
|
825
|
+
);
|
|
826
|
+
},
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
setGridColumns(newColumns);
|
|
831
|
+
}, [columns]);
|
|
832
|
+
|
|
833
|
+
// Data Grid Styling
|
|
834
|
+
const [windowHeight, setWindowHeight] = useState(window.innerHeight);
|
|
835
|
+
const gridStyle = {
|
|
836
|
+
minHeight: windowHeight * 0.6 > 550 ? windowHeight * 0.6 : 550,
|
|
837
|
+
};
|
|
838
|
+
const headerProps = {
|
|
839
|
+
style: style ? style : {},
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
useEffect(() => {
|
|
843
|
+
const handleResize = () => {
|
|
844
|
+
setWindowHeight(window.innerHeight);
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
window.addEventListener("resize", handleResize);
|
|
848
|
+
|
|
849
|
+
// Clean up the event listener
|
|
850
|
+
return () => {
|
|
851
|
+
window.removeEventListener("resize", handleResize);
|
|
852
|
+
};
|
|
853
|
+
}, []);
|
|
854
|
+
|
|
855
|
+
return (
|
|
856
|
+
<>
|
|
857
|
+
<div className="filterInput--alt">
|
|
858
|
+
<div className="icon-search">
|
|
859
|
+
<Search strokeWidth={2} size={18} />
|
|
860
|
+
</div>
|
|
861
|
+
<input
|
|
862
|
+
type="text"
|
|
863
|
+
placeholder="Search"
|
|
864
|
+
value={search}
|
|
865
|
+
onChange={handleChangeSearch}
|
|
866
|
+
/>
|
|
867
|
+
</div>
|
|
868
|
+
<div className="filterAction--alt">
|
|
869
|
+
<button
|
|
870
|
+
className="btn"
|
|
871
|
+
onClick={() => {
|
|
872
|
+
modalOpen("create", 0);
|
|
873
|
+
}}
|
|
874
|
+
>
|
|
875
|
+
<div className="icon-plus"></div> Create
|
|
876
|
+
</button>
|
|
877
|
+
</div>
|
|
878
|
+
<ReactDataGrid
|
|
879
|
+
columns={gridColumns}
|
|
880
|
+
dataSource={data}
|
|
881
|
+
defaultLimit={limit}
|
|
882
|
+
defaultSortInfo={sortInfo}
|
|
883
|
+
enableColumnAutosize={false}
|
|
884
|
+
headerProps={headerProps}
|
|
885
|
+
idProperty={`visns-datagrid-${ajaxSetting.url.replace(
|
|
886
|
+
/\//g,
|
|
887
|
+
"-"
|
|
888
|
+
)}`}
|
|
889
|
+
style={gridStyle}
|
|
890
|
+
onRenderRow={onRenderRow}
|
|
891
|
+
pagination
|
|
892
|
+
renderColumnContextMenu={renderColumnContextMenu}
|
|
893
|
+
showZebraRows={true}
|
|
894
|
+
/>
|
|
895
|
+
<Popup
|
|
896
|
+
open={modalShow}
|
|
897
|
+
onClose={modalClose}
|
|
898
|
+
closeOnDocumentClick={false}
|
|
899
|
+
>
|
|
900
|
+
<Form
|
|
901
|
+
closeModal={modalClose}
|
|
902
|
+
fetchTable={handleReload}
|
|
903
|
+
formSettings={formData}
|
|
904
|
+
formType={formType}
|
|
905
|
+
updateForm={setFormData}
|
|
906
|
+
columnId={formId}
|
|
907
|
+
childDropdownCallback={childDropdownCallback}
|
|
908
|
+
/>
|
|
909
|
+
</Popup>
|
|
910
|
+
</>
|
|
911
|
+
);
|
|
848
912
|
};
|
|
849
913
|
|
|
850
914
|
export default DataGrid;
|