@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 +1 -1
- package/src/components/TableFilter.jsx +59 -45
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.
|
|
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
|
-
//
|
|
410
|
-
//
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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
|
-
|
|
445
|
-
|
|
445
|
+
// Remove any existing filters that might conflict
|
|
446
|
+
w = w.filter((item) => item.id !== filterId);
|
|
446
447
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
-
|
|
458
|
-
...
|
|
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 (
|
|
481
|
-
|
|
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
|
|