@dooherceg/material-react-table 3.2.8 → 3.2.9

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/dist/index.js CHANGED
@@ -794,9 +794,16 @@ const DeleteRowAction = ({ onDeleteConfirm, table, deleteConfirmation, }) => {
794
794
  };
795
795
  const handleConfirmDelete = () => __awaiter(void 0, void 0, void 0, function* () {
796
796
  setDeleting(true);
797
- yield onDeleteConfirm();
798
- setDeleting(false);
799
- setOpen(false);
797
+ try {
798
+ yield onDeleteConfirm();
799
+ setOpen(false);
800
+ }
801
+ catch (error) {
802
+ console.error('[MRT] Error while deleting row(s):', error);
803
+ }
804
+ finally {
805
+ setDeleting(false);
806
+ }
800
807
  });
801
808
  const handleClose = () => __awaiter(void 0, void 0, void 0, function* () {
802
809
  setOpen(false);
@@ -837,16 +844,15 @@ const createDeleteAction = (_a = {}) => {
837
844
  return executeDelete({ table, rowsToDelete: [row] });
838
845
  };
839
846
  // Wraps row context into a zero-argument callback expected by row action UI.
847
+ // Must return the promise (not fire-and-forget it) so callers like DeleteRowAction
848
+ // can `await` it and keep the confirmation modal open until delete actually finishes.
840
849
  const createRowDeleteExecutor = (context) => {
841
- return () => {
842
- void handleSingleRowDelete(context);
843
- };
850
+ return () => handleSingleRowDelete(context);
844
851
  };
845
852
  // Wraps toolbar context into a zero-argument callback expected by toolbar action UI.
853
+ // Same reasoning as createRowDeleteExecutor — the returned promise must propagate.
846
854
  const createToolbarDeleteExecutor = (context) => {
847
- return () => {
848
- void handleMultipleRowDelete(context);
849
- };
855
+ return () => handleMultipleRowDelete(context);
850
856
  };
851
857
  // Uses custom row renderer when provided; otherwise renders default delete action UI.
852
858
  const renderRowAction = (context) => {
@@ -2630,6 +2636,11 @@ const useMRT_Effects = (table) => {
2630
2636
  }, [density]);
2631
2637
  };
2632
2638
 
2639
+ // Keeps the local rows array from growing past the current page size. New rows are
2640
+ // inserted at the front, so overflow is trimmed off the tail (the oldest existing
2641
+ // rows), since the local state is expected to be reconciled with the source of
2642
+ // truth on the next fetch.
2643
+ const capRowsToPageSize = (rows, pageSize) => pageSize && rows.length > pageSize ? rows.slice(0, pageSize) : rows;
2633
2644
  const normalizeRowInput = (rowInput) => (Array.isArray(rowInput) ? rowInput : [rowInput]);
2634
2645
  const getResolvedRowId = (row, index, parentRow, getRowId) => {
2635
2646
  const customRowId = getRowId === null || getRowId === void 0 ? void 0 : getRowId(row, index, parentRow);
@@ -2640,7 +2651,7 @@ const getResolvedRowId = (row, index, parentRow, getRowId) => {
2640
2651
  return String(row.id);
2641
2652
  return undefined;
2642
2653
  };
2643
- const handleAddRow = ({ setRowsState, }) => {
2654
+ const handleAddRow = ({ pageSize, setRowsState, }) => {
2644
2655
  return (rowInput) => {
2645
2656
  const rowsToAdd = normalizeRowInput(rowInput);
2646
2657
  const hasValidRowIds = rowsToAdd.every((row, index) => {
@@ -2650,7 +2661,7 @@ const handleAddRow = ({ setRowsState, }) => {
2650
2661
  if (!hasValidRowIds) {
2651
2662
  throw new Error('Each row must have a valid `id` property or a `getRowId` function must be provided to generate unique IDs.');
2652
2663
  }
2653
- setRowsState((previousRows) => [...previousRows, ...rowsToAdd]);
2664
+ setRowsState((previousRows) => capRowsToPageSize([...rowsToAdd, ...previousRows], pageSize));
2654
2665
  };
2655
2666
  };
2656
2667
  const handleUpdateRow = ({ getRowId, setRowsState, }) => {
@@ -2680,7 +2691,7 @@ const handleSetRows = ({ setRowsState, }) => {
2680
2691
  setRowsState(normalizeRowInput(rowInput));
2681
2692
  };
2682
2693
  };
2683
- const handleUpsertRow = ({ getRowId, setRowsState, }) => {
2694
+ const handleUpsertRow = ({ getRowId, pageSize, setRowsState, }) => {
2684
2695
  return (rowInput) => {
2685
2696
  const rowsToUpsert = normalizeRowInput(rowInput);
2686
2697
  setRowsState((previousRows) => {
@@ -2694,19 +2705,17 @@ const handleUpsertRow = ({ getRowId, setRowsState, }) => {
2694
2705
  indexByRowId.set(rowId, index);
2695
2706
  }
2696
2707
  });
2708
+ const rowsToInsert = [];
2697
2709
  rowsToUpsert.forEach((row, index) => {
2698
2710
  const rowId = getResolvedRowId(row, index, undefined, getRowId);
2699
2711
  const existingIndex = rowId !== undefined ? indexByRowId.get(rowId) : undefined;
2700
2712
  if (existingIndex === undefined) {
2701
- if (rowId !== undefined) {
2702
- indexByRowId.set(rowId, nextRows.length);
2703
- }
2704
- nextRows.push(row);
2713
+ rowsToInsert.push(row);
2705
2714
  return;
2706
2715
  }
2707
2716
  nextRows[existingIndex] = row;
2708
2717
  });
2709
- return nextRows;
2718
+ return capRowsToPageSize([...rowsToInsert, ...nextRows], pageSize);
2710
2719
  });
2711
2720
  };
2712
2721
  };
@@ -3136,6 +3145,7 @@ const useMRT_TableInstance = (definedTableOptions) => {
3136
3145
  table.addRow = handleAddRow({
3137
3146
  setRowsState,
3138
3147
  getRowId: resolveRowId,
3148
+ pageSize: statefulTableOptions.state.pagination.pageSize,
3139
3149
  });
3140
3150
  table.updateRow = handleUpdateRow({
3141
3151
  setRowsState,
@@ -3148,6 +3158,7 @@ const useMRT_TableInstance = (definedTableOptions) => {
3148
3158
  table.upsertRow = handleUpsertRow({
3149
3159
  setRowsState,
3150
3160
  getRowId: resolveRowId,
3161
+ pageSize: statefulTableOptions.state.pagination.pageSize,
3151
3162
  });
3152
3163
  table.removeRow = handleRemoveRow({
3153
3164
  setRowsState,