@visns-studio/visns-components 6.1.7 → 6.1.8

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
@@ -91,7 +91,7 @@
91
91
  "react-dom": "^17.0.0 || ^18.0.0"
92
92
  },
93
93
  "name": "@visns-studio/visns-components",
94
- "version": "6.1.7",
94
+ "version": "6.1.8",
95
95
  "description": "Various packages to assist in the development of our Custom Applications.",
96
96
  "main": "src/index.js",
97
97
  "files": [
@@ -390,6 +390,7 @@ function TableFilter({
390
390
 
391
391
  // Calculate the updated settings
392
392
  let updatedSettings = null;
393
+ let applySettingsUpdate = null;
393
394
 
394
395
  if (setSettings) {
395
396
  // For child items, non-parent items, or parent items with a value property
@@ -406,66 +407,73 @@ function TableFilter({
406
407
  const filterId = id;
407
408
  const filterValue = value || '';
408
409
 
409
- // Start with the current settings
410
- // Check if _currentValue exists (React state setter) or use the object directly
411
- updatedSettings = setSettings._currentValue
412
- ? { ...setSettings._currentValue }
413
- : { ...setSettings };
414
-
415
- if (updatedSettings.ajaxSetting) {
416
- // First, remove any existing filters that might conflict
417
- let _where = updatedSettings.ajaxSetting.where
418
- ? [...updatedSettings.ajaxSetting.where].filter(
419
- (item) => {
410
+ // Merge this filter into a settings object, supporting both
411
+ // ajaxSetting.where and a top-level where. Written as a pure
412
+ // function of the base settings so it can run either against
413
+ // the `settings` prop or inside a functional state update —
414
+ // a state setter carries no readable current value.
415
+ const mergeFilterIntoSettings = (base) => {
416
+ let updated = base ? { ...base } : {};
417
+
418
+ if (updated.ajaxSetting) {
419
+ // First, remove any existing filters that might conflict
420
+ let _where = updated.ajaxSetting.where
421
+ ? [...updated.ajaxSetting.where].filter((item) => {
420
422
  // Keep items that don't match this filter ID
421
423
  return item.id !== filterId;
422
- }
423
- )
424
- : [];
424
+ })
425
+ : [];
425
426
 
426
- // Add the new filter only if both filterId and filterValue have values
427
- if (filterId && filterValue !== '') {
428
- _where.push({ id: filterId, value: filterValue });
427
+ // Add the new filter only if both filterId and filterValue have values
428
+ if (filterId && filterValue !== '') {
429
+ _where.push({ id: filterId, value: filterValue });
430
+ }
431
+
432
+ return {
433
+ ...updated,
434
+ ajaxSetting: {
435
+ ...updated.ajaxSetting,
436
+ where: _where,
437
+ },
438
+ };
429
439
  }
430
440
 
431
- updatedSettings = {
432
- ...updatedSettings,
433
- ajaxSetting: {
434
- ...updatedSettings.ajaxSetting,
435
- where: _where,
436
- },
437
- };
438
- } else if (updatedSettings.where) {
439
- // Handle the case where we're using 'where' directly instead of ajaxSetting.where
440
- let w = updatedSettings.where
441
- ? [...updatedSettings.where]
442
- : [];
441
+ if (updated.where) {
442
+ // Handle the case where we're using 'where' directly instead of ajaxSetting.where
443
+ let w = [...updated.where];
443
444
 
444
- // Remove any existing filters that might conflict
445
- w = w.filter((item) => item.id !== filterId);
445
+ // Remove any existing filters that might conflict
446
+ w = w.filter((item) => item.id !== filterId);
446
447
 
447
- // Add the new filter only if both filterId and filterValue have values
448
- if (filterId && filterValue !== '') {
449
- w.push({ id: filterId, value: filterValue });
448
+ // Add the new filter only if both filterId and filterValue have values
449
+ if (filterId && filterValue !== '') {
450
+ w.push({ id: filterId, value: filterValue });
451
+ }
452
+
453
+ return { ...updated, where: w };
450
454
  }
451
455
 
452
- updatedSettings = { ...updatedSettings, where: w };
453
- } else {
454
456
  // If neither ajaxSetting.where nor where exists, create a new ajaxSetting
455
457
  // Only apply the filter if both filterId and filterValue have values
456
458
  if (filterId && filterValue !== '') {
457
- updatedSettings = {
458
- ...settings,
459
+ return {
460
+ ...updated,
459
461
  ajaxSetting: {
460
- ...(settings.ajaxSetting || {}),
461
462
  where: [{ id: filterId, value: filterValue }],
462
463
  },
463
464
  };
464
- } else {
465
- // If either filterId or filterValue is empty, just copy the existing settings
466
- updatedSettings = { ...settings };
467
465
  }
468
- }
466
+
467
+ return updated;
468
+ };
469
+
470
+ applySettingsUpdate = mergeFilterIntoSettings;
471
+ // With a settings prop we can compute the result now (also
472
+ // feeds onFilterChange); without one the update happens as a
473
+ // functional setState below.
474
+ updatedSettings = settings
475
+ ? mergeFilterIntoSettings(settings)
476
+ : null;
469
477
  }
470
478
  }
471
479
 
@@ -477,8 +485,14 @@ function TableFilter({
477
485
  setFilters(updatedFilters);
478
486
 
479
487
  // Update the settings if needed
480
- if (updatedSettings && setSettings) {
481
- setSettings(updatedSettings);
488
+ if (setSettings && applySettingsUpdate) {
489
+ if (updatedSettings) {
490
+ setSettings(updatedSettings);
491
+ } else {
492
+ // No settings prop to read from — merge against the
493
+ // live state via a functional update instead.
494
+ setSettings((prev) => applySettingsUpdate(prev));
495
+ }
482
496
  }
483
497
  }
484
498