@visns-studio/visns-components 6.1.6 → 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.
|
|
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": [
|
|
@@ -250,6 +250,13 @@ const loadData = async (
|
|
|
250
250
|
const ROW_HEIGHT = 34;
|
|
251
251
|
const GRID_CHROME = ROW_HEIGHT * 2 + 60; // header + filter row + footer
|
|
252
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Column types whose renderer names the grid column `${type}.${id}` instead of
|
|
255
|
+
* the plain field path. Their filter entries must use the same name, otherwise
|
|
256
|
+
* the grid cannot pair the filter with its column and no editor is rendered.
|
|
257
|
+
*/
|
|
258
|
+
const TYPE_PREFIXED_FILTER_NAMES = ['age', 'coding'];
|
|
259
|
+
|
|
253
260
|
function fitToRows(dataCount, windowHeight) {
|
|
254
261
|
const roomy = Math.max(windowHeight * 0.7, 550);
|
|
255
262
|
|
|
@@ -3655,6 +3662,7 @@ const DataGrid = forwardRef(
|
|
|
3655
3662
|
column,
|
|
3656
3663
|
commonProps,
|
|
3657
3664
|
filterEditor,
|
|
3665
|
+
filterEditorProps,
|
|
3658
3666
|
});
|
|
3659
3667
|
case 'arrayCount':
|
|
3660
3668
|
return renderArrayCountColumn({
|
|
@@ -3672,6 +3680,8 @@ const DataGrid = forwardRef(
|
|
|
3672
3680
|
return renderCodingColumn({
|
|
3673
3681
|
column,
|
|
3674
3682
|
commonProps,
|
|
3683
|
+
filterEditor,
|
|
3684
|
+
filterEditorProps,
|
|
3675
3685
|
handleCoding,
|
|
3676
3686
|
});
|
|
3677
3687
|
case 'colour':
|
|
@@ -4285,21 +4295,31 @@ const DataGrid = forwardRef(
|
|
|
4285
4295
|
let filterName = '';
|
|
4286
4296
|
|
|
4287
4297
|
if (Array.isArray(column.id)) {
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4298
|
+
// The age/coding renderers name their column
|
|
4299
|
+
// `${type}.${id}` with the array stringified,
|
|
4300
|
+
// so the filter has to be named the same way or
|
|
4301
|
+
// the grid never matches it to the column.
|
|
4302
|
+
if (TYPE_PREFIXED_FILTER_NAMES.includes(column.type)) {
|
|
4303
|
+
filterName = `${column.type}.${column.id}`;
|
|
4304
|
+
} else {
|
|
4305
|
+
filterName = column.id.reduce(
|
|
4306
|
+
(acc, id) => acc + `${id}.`,
|
|
4307
|
+
''
|
|
4308
|
+
);
|
|
4292
4309
|
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4310
|
+
if (
|
|
4311
|
+
column.type === 'dropdown' &&
|
|
4312
|
+
filterName.endsWith('.')
|
|
4313
|
+
) {
|
|
4314
|
+
filterName = filterName.slice(0, -1);
|
|
4315
|
+
}
|
|
4298
4316
|
}
|
|
4299
4317
|
} else {
|
|
4300
4318
|
switch (column.type) {
|
|
4301
4319
|
case 'address':
|
|
4302
4320
|
case 'boolean':
|
|
4321
|
+
case 'age':
|
|
4322
|
+
case 'coding':
|
|
4303
4323
|
filterName = `${column.type}.${column.id}`;
|
|
4304
4324
|
break;
|
|
4305
4325
|
default:
|
|
@@ -4308,7 +4328,10 @@ const DataGrid = forwardRef(
|
|
|
4308
4328
|
}
|
|
4309
4329
|
}
|
|
4310
4330
|
|
|
4311
|
-
if (
|
|
4331
|
+
if (
|
|
4332
|
+
column.nameFrom &&
|
|
4333
|
+
!TYPE_PREFIXED_FILTER_NAMES.includes(column.type)
|
|
4334
|
+
) {
|
|
4312
4335
|
filterName += column.nameFrom;
|
|
4313
4336
|
}
|
|
4314
4337
|
|
|
@@ -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
|
|
|
@@ -1641,11 +1641,17 @@ export const renderPlaceholderColumn = ({ column, commonProps }) => {
|
|
|
1641
1641
|
};
|
|
1642
1642
|
|
|
1643
1643
|
// Age Column Renderer
|
|
1644
|
-
export const renderAgeColumn = ({
|
|
1644
|
+
export const renderAgeColumn = ({
|
|
1645
|
+
column,
|
|
1646
|
+
commonProps,
|
|
1647
|
+
filterEditor,
|
|
1648
|
+
filterEditorProps,
|
|
1649
|
+
}) => {
|
|
1645
1650
|
return {
|
|
1646
1651
|
...commonProps,
|
|
1647
1652
|
type: 'number',
|
|
1648
1653
|
filterEditor: filterEditor,
|
|
1654
|
+
filterEditorProps: filterEditorProps,
|
|
1649
1655
|
name: `${column.type}.${column.id}`,
|
|
1650
1656
|
render: ({ data }) => {
|
|
1651
1657
|
const value = column.id.reduce((acc, id) => {
|
|
@@ -1675,9 +1681,19 @@ export const renderAgeColumn = ({ column, commonProps, filterEditor }) => {
|
|
|
1675
1681
|
};
|
|
1676
1682
|
|
|
1677
1683
|
// Coding Column Renderer
|
|
1678
|
-
export const renderCodingColumn = ({
|
|
1684
|
+
export const renderCodingColumn = ({
|
|
1685
|
+
column,
|
|
1686
|
+
commonProps,
|
|
1687
|
+
filterEditor,
|
|
1688
|
+
filterEditorProps,
|
|
1689
|
+
handleCoding,
|
|
1690
|
+
}) => {
|
|
1679
1691
|
return {
|
|
1680
1692
|
...commonProps,
|
|
1693
|
+
// A coding column is a composite of several icon fields, so it cannot
|
|
1694
|
+
// be sorted — but it can be filtered when the config declares one.
|
|
1695
|
+
filterEditor: filterEditor,
|
|
1696
|
+
filterEditorProps: filterEditorProps,
|
|
1681
1697
|
name: `${column.type}.${column.id}`,
|
|
1682
1698
|
sortable: false,
|
|
1683
1699
|
render: ({ data }) => {
|