@monolith-forensics/monolith-ui 1.3.21 → 1.3.22

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.
@@ -332,45 +332,99 @@ const TableProvider = (_a) => {
332
332
  var _a;
333
333
  return (((_a = columnState.find((col) => col.dataField === dataField)) === null || _a === void 0 ? void 0 : _a.visible) || true);
334
334
  };
335
+ const saveSelectionState = (selectionState) => {
336
+ if (stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled) {
337
+ if ((stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.type) === "localStorage") {
338
+ StateStorage.setSelectionState(stateStorage.key, selectionState);
339
+ }
340
+ }
341
+ };
335
342
  const selectRow = (row) => {
343
+ var _a;
336
344
  const key = !!props.keyField ? row[props.keyField] : row.__key;
337
345
  const keyField = !!props.keyField ? props.keyField : "__key";
346
+ const newSelectionState = {
347
+ selectedRowKeys,
348
+ excludedRowKeys,
349
+ selectionStatus,
350
+ };
338
351
  if (props.data.length === selectedRowKeys.length + 1) {
339
- setSelectionStatus(SelectionStatus.All);
352
+ newSelectionState.selectionStatus = SelectionStatus.All;
340
353
  }
341
354
  else {
342
- setSelectionStatus(SelectionStatus.SomeIncluded);
355
+ newSelectionState.selectionStatus = SelectionStatus.SomeIncluded;
343
356
  }
344
- setSelectedRowKeys((prevSelectedRowKeys) => {
345
- return [...prevSelectedRowKeys, key];
346
- });
347
- setExcludedRowKeys((prev) => prev.filter((k) => k !== key));
357
+ newSelectionState.selectedRowKeys = [
358
+ ...newSelectionState.selectedRowKeys,
359
+ key,
360
+ ];
361
+ newSelectionState.excludedRowKeys =
362
+ newSelectionState.excludedRowKeys.filter((k) => k !== key);
363
+ setSelectionStatus(newSelectionState.selectionStatus);
364
+ setSelectedRowKeys(newSelectionState.selectedRowKeys);
365
+ setExcludedRowKeys(newSelectionState.excludedRowKeys);
366
+ (_a = props.onSelectionChange) === null || _a === void 0 ? void 0 : _a.call(props, newSelectionState);
367
+ saveSelectionState(newSelectionState);
348
368
  };
349
369
  const deselectRow = (row) => {
370
+ var _a;
350
371
  const key = !!props.keyField ? props.keyField : "__key";
372
+ const newSelectionState = {
373
+ selectedRowKeys,
374
+ excludedRowKeys,
375
+ selectionStatus,
376
+ };
351
377
  if (selectionStatus === SelectionStatus.All ||
352
378
  selectionStatus === SelectionStatus.SomeExcluded) {
353
- setSelectionStatus(SelectionStatus.SomeExcluded);
354
- setExcludedRowKeys((prev) => [...prev, row[key]]);
379
+ newSelectionState.selectionStatus = SelectionStatus.SomeExcluded;
380
+ newSelectionState.excludedRowKeys = [
381
+ ...newSelectionState.excludedRowKeys,
382
+ row[key],
383
+ ];
355
384
  }
356
385
  if (selectedRowKeys.length === 1) {
357
- setSelectionStatus(SelectionStatus.None);
386
+ newSelectionState.selectionStatus = SelectionStatus.None;
358
387
  }
359
- setSelectedRowKeys((prevSelectedRowKeys) => {
360
- return prevSelectedRowKeys.filter((k) => k !== row[key]);
361
- });
388
+ newSelectionState.selectedRowKeys =
389
+ newSelectionState.selectedRowKeys.filter((k) => k !== row[key]);
390
+ setSelectionStatus(newSelectionState.selectionStatus);
391
+ setSelectedRowKeys(newSelectionState.selectedRowKeys);
392
+ setExcludedRowKeys(newSelectionState.excludedRowKeys);
393
+ (_a = props.onSelectionChange) === null || _a === void 0 ? void 0 : _a.call(props, newSelectionState);
394
+ saveSelectionState(newSelectionState);
362
395
  };
363
396
  const selectAllRows = () => {
364
- var _a;
397
+ var _a, _b;
365
398
  const keys = ((_a = props.data) === null || _a === void 0 ? void 0 : _a.map((row) => !!props.keyField ? row[props.keyField] : row.__key)) || [];
366
- setSelectedRowKeys(keys);
367
- setSelectionStatus(SelectionStatus.All);
368
- setExcludedRowKeys([]);
399
+ const newSelectionState = {
400
+ selectedRowKeys,
401
+ excludedRowKeys,
402
+ selectionStatus,
403
+ };
404
+ newSelectionState.selectedRowKeys = keys;
405
+ newSelectionState.excludedRowKeys = [];
406
+ newSelectionState.selectionStatus = SelectionStatus.All;
407
+ setSelectionStatus(newSelectionState.selectionStatus);
408
+ setSelectedRowKeys(newSelectionState.selectedRowKeys);
409
+ setExcludedRowKeys(newSelectionState.excludedRowKeys);
410
+ (_b = props.onSelectionChange) === null || _b === void 0 ? void 0 : _b.call(props, newSelectionState);
411
+ saveSelectionState(newSelectionState);
369
412
  };
370
413
  const clearSelections = () => {
371
- setSelectedRowKeys([]);
372
- setSelectionStatus(SelectionStatus.None);
373
- setExcludedRowKeys([]);
414
+ var _a;
415
+ const newSelectionState = {
416
+ selectedRowKeys,
417
+ excludedRowKeys,
418
+ selectionStatus,
419
+ };
420
+ newSelectionState.selectedRowKeys = [];
421
+ newSelectionState.excludedRowKeys = [];
422
+ newSelectionState.selectionStatus = SelectionStatus.None;
423
+ setSelectionStatus(newSelectionState.selectionStatus);
424
+ setSelectedRowKeys(newSelectionState.selectedRowKeys);
425
+ setExcludedRowKeys(newSelectionState.excludedRowKeys);
426
+ (_a = props.onSelectionChange) === null || _a === void 0 ? void 0 : _a.call(props, newSelectionState);
427
+ saveSelectionState(newSelectionState);
374
428
  };
375
429
  const getSelectedRows = () => {
376
430
  return props.data.filter((row) => {
@@ -436,31 +490,6 @@ const TableProvider = (_a) => {
436
490
  };
437
491
  }
438
492
  }, [columnState]);
439
- useEffect(() => {
440
- var _a;
441
- (_a = props === null || props === void 0 ? void 0 : props.onSelectionChange) === null || _a === void 0 ? void 0 : _a.call(props, {
442
- selectedRowKeys,
443
- excludedRowKeys,
444
- selectionStatus,
445
- });
446
- if (stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled) {
447
- if ((stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.type) === "localStorage") {
448
- StateStorage.setSelectionState(stateStorage.key, {
449
- selectedRowKeys,
450
- excludedRowKeys,
451
- selectionStatus,
452
- });
453
- }
454
- }
455
- }, [
456
- selectedRowKeys,
457
- selectionStatus,
458
- excludedRowKeys,
459
- props === null || props === void 0 ? void 0 : props.onSelectionChange,
460
- stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled,
461
- stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.type,
462
- stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.key,
463
- ]);
464
493
  useEffect(() => {
465
494
  var _a, _b;
466
495
  if (stateStorage === null || stateStorage === void 0 ? void 0 : stateStorage.enabled) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monolith-forensics/monolith-ui",
3
- "version": "1.3.21",
3
+ "version": "1.3.22",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Matt Danner (Monolith Forensics LLC)",