@eml-payments/ui-kit 0.1.56 → 0.1.57

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.
@@ -1,9 +1,13 @@
1
- import { useEffect, useState } from 'react';
1
+ import { useEffect, useMemo, useState } from 'react';
2
2
  import { useReactTable, getCoreRowModel, getSortedRowModel, getPaginationRowModel, getGroupedRowModel, getExpandedRowModel, } from '@tanstack/react-table';
3
3
  import { applyFlexSizes, getCheckboxSelectionColumn } from '../table.helpers';
4
4
  import { usePaginationController } from './usePaginationController';
5
5
  export function useTableController({ data, columns, checkboxSelection, checkboxPosition = 'start', paginationMode = 'client', sorting, onSortingChange, onSelectionChange, enableRowSelection, rowsPerPage = 10, isMultiRowSelection = true, selectedRowIds, rowIdKey = 'id', totalServerRows, onRefetch, showHeader = true, grouping, }) {
6
6
  const safeData = Array.isArray(data) ? data : [];
7
+ const stableGrouping = useMemo(() => grouping !== null && grouping !== void 0 ? grouping : [], [grouping]);
8
+ const columnVisibility = useMemo(() => {
9
+ return Object.fromEntries(stableGrouping.map((columnId) => [columnId, false]));
10
+ }, [stableGrouping]);
7
11
  const [tableColumns, setTableColumns] = useState(() => applyFlexSizes(columns !== null && columns !== void 0 ? columns : []));
8
12
  const [internalSorting, setInternalSorting] = useState(sorting !== null && sorting !== void 0 ? sorting : []);
9
13
  const [internalRowSelection, setInternalRowSelection] = useState(() => {
@@ -25,8 +29,8 @@ export function useTableController({ data, columns, checkboxSelection, checkboxP
25
29
  pagination: { pageSize, pageIndex },
26
30
  sorting: sorting !== null && sorting !== void 0 ? sorting : internalSorting,
27
31
  rowSelection: internalRowSelection,
28
- grouping: grouping !== null && grouping !== void 0 ? grouping : [],
29
- columnVisibility: Object.fromEntries((grouping !== null && grouping !== void 0 ? grouping : []).map((columnId) => [columnId, false])),
32
+ grouping: stableGrouping,
33
+ columnVisibility,
30
34
  },
31
35
  getSortedRowModel: getSortedRowModel(),
32
36
  getCoreRowModel: getCoreRowModel(),
@@ -61,9 +65,11 @@ export function useTableController({ data, columns, checkboxSelection, checkboxP
61
65
  paginationMode,
62
66
  onRefetch,
63
67
  });
68
+ const selectionColumn = useMemo(() => {
69
+ return checkboxSelection ? getCheckboxSelectionColumn(table) : null;
70
+ }, [checkboxSelection, table]);
64
71
  useEffect(() => {
65
72
  const normalized = applyFlexSizes(columns !== null && columns !== void 0 ? columns : []);
66
- const selectionColumn = checkboxSelection ? getCheckboxSelectionColumn(table) : null;
67
73
  let finalColumns;
68
74
  if (checkboxSelection && selectionColumn) {
69
75
  if (checkboxPosition === 'start') {
@@ -80,7 +86,7 @@ export function useTableController({ data, columns, checkboxSelection, checkboxP
80
86
  finalColumns = normalized;
81
87
  }
82
88
  setTableColumns(finalColumns);
83
- }, [columns, checkboxSelection, checkboxPosition, table]);
89
+ }, [columns, checkboxSelection, checkboxPosition]);
84
90
  return {
85
91
  table,
86
92
  setPageSize,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eml-payments/ui-kit",
3
- "version": "0.1.56",
3
+ "version": "0.1.57",
4
4
  "private": false,
5
5
  "description": "ARLO UIKit",
6
6
  "homepage": "https://github.com/EML-Payments/arlo.npm.uikit#readme",