@visns-studio/visns-components 5.7.13 → 5.7.15

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/package.json CHANGED
@@ -82,7 +82,7 @@
82
82
  "react-dom": "^17.0.0 || ^18.0.0"
83
83
  },
84
84
  "name": "@visns-studio/visns-components",
85
- "version": "5.7.13",
85
+ "version": "5.7.15",
86
86
  "description": "Various packages to assist in the development of our Custom Applications.",
87
87
  "main": "src/index.js",
88
88
  "files": [
@@ -515,66 +515,27 @@ const DataGrid = forwardRef(
515
515
  (typeof param.selected === 'object' &&
516
516
  Object.keys(param.selected).length > 0)
517
517
  ) {
518
- // Show confirmation dialog for selection
519
- const selectedCount =
520
- param.selected === true ? param.data.length : 1;
521
- const itemText = selectedCount === 1 ? 'item' : 'items';
522
-
523
- confirmDialog({
524
- title: 'Selection Confirmation',
525
- message: `You have selected ${selectedCount} ${itemText}. Do you want to proceed with this selection?`,
526
- data:
527
- param.selected === true
528
- ? param.data
529
- : param.selected, // Pass the selected data
530
- buttons: [
531
- {
532
- label: 'Yes',
533
- onClick: () => {
534
- // Process the selection as before
535
- if (param.selected === true) {
536
- const s = {};
537
- param.data.forEach((obj) => {
538
- s[obj.id] = obj;
539
- });
540
- setSelected(s);
541
- } else if (
542
- typeof param.selected === 'object'
543
- ) {
544
- const selectedKey = Object.keys(
545
- param.selected
546
- )[0];
547
- const isSelectedAlready =
548
- selected.hasOwnProperty(
549
- selectedKey
550
- );
551
-
552
- if (isSelectedAlready) {
553
- setSelected({});
554
- } else {
555
- setSelected((prevSelected) => ({
556
- ...prevSelected,
557
- [selectedKey]:
558
- param.selected[selectedKey],
559
- }));
560
- }
561
- }
562
-
563
- // Show a success message
564
- toast.success(
565
- `Selection of ${selectedCount} ${itemText} confirmed`
566
- );
567
- },
568
- },
569
- {
570
- label: 'No',
571
- onClick: () => {
572
- // Clear selection if user cancels
573
- setSelected({});
574
- },
575
- },
576
- ],
577
- });
518
+ // Process the selection directly without confirmation
519
+ if (param.selected === true) {
520
+ const s = {};
521
+ param.data.forEach((obj) => {
522
+ s[obj.id] = obj;
523
+ });
524
+ setSelected(s);
525
+ } else if (typeof param.selected === 'object') {
526
+ const selectedKey = Object.keys(param.selected)[0];
527
+ const isSelectedAlready =
528
+ selected.hasOwnProperty(selectedKey);
529
+
530
+ if (isSelectedAlready) {
531
+ setSelected({});
532
+ } else {
533
+ setSelected((prevSelected) => ({
534
+ ...prevSelected,
535
+ [selectedKey]: param.selected[selectedKey],
536
+ }));
537
+ }
538
+ }
578
539
  } else {
579
540
  // Handle deselection directly without confirmation
580
541
  setSelected(param.selected);
@@ -45,6 +45,8 @@ function useConfig(setting, tabs, filters, setRowsSelected, tableSetting) {
45
45
  style: setting.style || {},
46
46
  tableSetting,
47
47
  type: setting.type ? setting.type : 'table',
48
+ // Make sure to include functions if they exist in the setting
49
+ functions: setting.functions || {},
48
50
  };
49
51
 
50
52
  setConfig(newConfig);
@@ -135,6 +137,11 @@ function useConfig(setting, tabs, filters, setRowsSelected, tableSetting) {
135
137
  type: activeTabConfig.type
136
138
  ? activeTabConfig.type
137
139
  : 'table',
140
+ tableSetting:
141
+ activeTabConfig.tableSetting || tableSetting,
142
+ // Preserve functions from the tab config, falling back to the original config functions
143
+ functions:
144
+ activeTabConfig.functions || config.functions || {},
138
145
  };
139
146
 
140
147
  setConfig(updatedConfig);
@@ -156,6 +163,8 @@ function useConfig(setting, tabs, filters, setRowsSelected, tableSetting) {
156
163
  style: config.style || setting.style || {},
157
164
  tableSetting,
158
165
  type: setting.type ? setting.type : 'table',
166
+ // Preserve functions from the original config or setting
167
+ functions: config.functions || setting.functions || {},
159
168
  };
160
169
 
161
170
  // Add the filter for the active child
@@ -353,12 +362,32 @@ function GenericIndex({
353
362
  rowsSelectedRef.current = rowsSelected;
354
363
  }, [rowsSelected]);
355
364
 
356
- const handleCustomAction = async () => {
365
+ // Helper function to get function config from any of the three possible locations
366
+ const getFunctionConfig = useCallback(
367
+ (functionName) => {
368
+ // Check in priority order:
369
+ // 1. First check if it exists directly in setting.functions
370
+ if (setting?.functions?.[functionName]) {
371
+ return setting.functions[functionName];
372
+ }
373
+ // 2. Then check if it exists in config.form.functions
374
+ if (config?.form?.functions?.[functionName]) {
375
+ return config.form.functions[functionName];
376
+ }
377
+ // 3. Finally check if it exists in config.functions
378
+ if (config?.functions?.[functionName]) {
379
+ return config.functions[functionName];
380
+ }
381
+ // Return null if not found in any location
382
+ return null;
383
+ },
384
+ [setting, config]
385
+ );
386
+
387
+ const handleCustomAction = useCallback(async () => {
357
388
  try {
358
- // Get the custom action configuration
359
- const customActionConfig = setting?.functions?.customAction
360
- ? setting.functions.customAction
361
- : config.form.functions.customAction;
389
+ // Get the custom action configuration using our helper
390
+ const customActionConfig = getFunctionConfig('customAction');
362
391
 
363
392
  if (customActionConfig) {
364
393
  // Implementation will be added when needed
@@ -368,14 +397,18 @@ function GenericIndex({
368
397
  console.error(err);
369
398
  toast.error('An error occurred while performing the custom action');
370
399
  }
371
- };
400
+ }, [getFunctionConfig]);
372
401
 
373
402
  const handleCheckboxUpdate = useCallback(async () => {
374
403
  try {
375
- const { data, method, message, url } = setting?.functions
376
- ?.checkboxUpdate
377
- ? setting.functions.checkboxUpdate
378
- : config.form.functions.checkboxUpdate;
404
+ const checkboxUpdateConfig = getFunctionConfig('checkboxUpdate');
405
+
406
+ if (!checkboxUpdateConfig) {
407
+ console.error('checkboxUpdate configuration not found');
408
+ return;
409
+ }
410
+
411
+ const { data, method, message, url } = checkboxUpdateConfig;
379
412
 
380
413
  if (!Object.keys(rowsSelectedRef.current).length) {
381
414
  toast.warning(message.warning);
@@ -408,18 +441,18 @@ function GenericIndex({
408
441
  } catch (error) {
409
442
  console.error(error);
410
443
  }
411
- }, [
412
- setting?.functions?.checkboxUpdate,
413
- config.form?.functions?.checkboxUpdate,
414
- tableData,
415
- ]);
444
+ }, [getFunctionConfig, tableData]);
416
445
 
417
- const handleCheckboxDelete = async () => {
446
+ const handleCheckboxDelete = useCallback(async () => {
418
447
  try {
419
- const { data, method, message, url } = setting?.functions
420
- ?.checkboxDelete
421
- ? setting.functions.checkboxDelete
422
- : config.form?.functions?.checkboxDelete;
448
+ const checkboxDeleteConfig = getFunctionConfig('checkboxDelete');
449
+
450
+ if (!checkboxDeleteConfig) {
451
+ console.error('checkboxDelete configuration not found');
452
+ return;
453
+ }
454
+
455
+ const { data, method, message, url } = checkboxDeleteConfig;
423
456
 
424
457
  if (!Object.keys(rowsSelectedRef.current).length) {
425
458
  toast.warning(message.warning);
@@ -458,7 +491,7 @@ function GenericIndex({
458
491
  'An error occurred while processing the delete request'
459
492
  );
460
493
  }
461
- };
494
+ }, [getFunctionConfig, tableData]);
462
495
 
463
496
  const handleExport = async (e) => {
464
497
  try {
@@ -684,48 +717,31 @@ function GenericIndex({
684
717
  <Outlet />
685
718
 
686
719
  <div className={styles.polActions}>
687
- {setting.functions?.checkboxUpdate && (
720
+ {/* Render Update button if checkboxUpdate function is configured in any location */}
721
+ {getFunctionConfig('checkboxUpdate') && (
688
722
  <button
689
723
  className={styles.btn}
690
724
  onClick={handleCheckboxUpdate}
691
725
  >
692
- {setting.functions.checkboxUpdate.label || 'Update'}
693
- </button>
694
- )}
695
- {config?.form?.functions?.checkboxUpdate && (
696
- <button
697
- className={styles.btn}
698
- onClick={handleCheckboxUpdate}
699
- >
700
- {config.form.functions.checkboxUpdate.label || 'Update'}
726
+ {getFunctionConfig('checkboxUpdate').label || 'Update'}
701
727
  </button>
702
728
  )}
703
729
 
704
- {setting.functions?.checkboxDelete && (
730
+ {/* Render Delete button if checkboxDelete function is configured in any location */}
731
+ {getFunctionConfig('checkboxDelete') && (
705
732
  <button
706
733
  className={styles.btn}
707
734
  onClick={handleCheckboxDelete}
708
735
  >
709
- {setting.functions.checkboxDelete.label || 'Delete'}
710
- </button>
711
- )}
712
- {config?.form?.functions?.checkboxDelete && (
713
- <button
714
- className={styles.btn}
715
- onClick={handleCheckboxDelete}
716
- >
717
- {config.form.functions.checkboxDelete.label || 'Delete'}
736
+ {getFunctionConfig('checkboxDelete').label || 'Delete'}
718
737
  </button>
719
738
  )}
720
739
 
721
- {setting.functions?.customAction && (
722
- <button className={styles.btn} onClick={handleCustomAction}>
723
- {setting.functions.customAction.label || 'Delete'}
724
- </button>
725
- )}
726
- {config?.form?.functions?.customAction && (
740
+ {/* Render Custom Action button if customAction function is configured in any location */}
741
+ {getFunctionConfig('customAction') && (
727
742
  <button className={styles.btn} onClick={handleCustomAction}>
728
- {config.form.functions.customAction.label || 'Delete'}
743
+ {getFunctionConfig('customAction').label ||
744
+ 'Custom Action'}
729
745
  </button>
730
746
  )}
731
747