@eml-payments/ui-kit 1.1.2 → 1.1.3

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.
@@ -30,4 +30,5 @@ export declare const WithHiddenHeader: Story;
30
30
  export declare const GroupedByDate: Story;
31
31
  export declare const WithSearch: Story;
32
32
  export declare const ServerSideSearch: Story;
33
- export declare const WithQueryParams: StoryObj<TableStoryArgs>;
33
+ export declare const ClientPaginationWithQueryParams: StoryObj;
34
+ export declare const ServerPaginationWithQueryParams: StoryObj;
@@ -279,12 +279,27 @@ export const ServerSideSearch = {
279
279
  return (_jsxs("div", { className: "space-y-4", children: [_jsx("div", { style: { width: '300px' }, children: _jsx(SearchInput, { onSearch: (q) => setQuery(q), onClear: () => setQuery(''), placeholder: "Search users..." }) }), _jsx(Table, { id: "server-search-table", data: data, columns: columns, paginationMode: "server", totalServerRows: 100, onRefetch: fetchData, isLoading: isLoading, isSearchActive: query.trim().length >= 3 })] }));
280
280
  },
281
281
  };
282
- export const WithQueryParams = {
282
+ export const ClientPaginationWithQueryParams = {
283
+ args: {
284
+ initialPageNo: 2,
285
+ initialPageSize: 5,
286
+ },
287
+ render: () => (_jsxs(_Fragment, { children: [_jsx(CurrentUrl, {}), _jsx(Table, { id: "client-pagination-table", data: data, columns: columns, paginationMode: "client", showHeader: true })] })),
288
+ };
289
+ export const ServerPaginationWithQueryParams = {
283
290
  args: {
284
291
  initialPageNo: 2,
285
292
  initialPageSize: 5,
286
293
  },
287
294
  render: () => {
288
- return (_jsxs(_Fragment, { children: [_jsx(CurrentUrl, {}), _jsx(Table, { id: "url-sync-table", data: data, columns: columns, paginationMode: "client", showHeader: true })] }));
295
+ const [data, setData] = useState([]);
296
+ const [isLoading, setIsLoading] = useState(false);
297
+ const fetchData = useCallback(async (pageIndex, pageSize) => {
298
+ setIsLoading(true);
299
+ const results = await fetchServerData(pageIndex, pageSize);
300
+ setData(results);
301
+ setIsLoading(false);
302
+ }, []);
303
+ return (_jsxs(_Fragment, { children: [_jsx(CurrentUrl, {}), _jsx(Table, { id: "server-pagination-table", data: data, columns: columns, paginationMode: "server", totalServerRows: 100, onRefetch: fetchData, isLoading: isLoading, showHeader: true })] }));
289
304
  },
290
305
  };
@@ -4,7 +4,6 @@ import { applyFlexSizes, getCheckboxSelectionColumn } from '../table.helpers';
4
4
  import { usePaginationController } from './usePaginationController';
5
5
  import { useUrlPaginationSync } from './useUrlPaginationSync';
6
6
  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, queryParamKeys, }) {
7
- var _a;
8
7
  const safeData = Array.isArray(data) ? data : [];
9
8
  const stableGrouping = useMemo(() => grouping !== null && grouping !== void 0 ? grouping : [], [grouping]);
10
9
  const columnVisibility = useMemo(() => {
@@ -22,16 +21,8 @@ export function useTableController({ data, columns, checkboxSelection, checkboxP
22
21
  return {};
23
22
  });
24
23
  const { pageIndex, setPageIndex, pageSize, setPageSize } = useUrlPaginationSync(rowsPerPage, queryParamKeys);
25
- const paginatedData = useMemo(() => {
26
- if (paginationMode === 'server') {
27
- return safeData;
28
- }
29
- const start = pageIndex * pageSize;
30
- const end = start + pageSize;
31
- return safeData.slice(start, end);
32
- }, [safeData, pageIndex, pageSize, paginationMode]);
33
24
  const table = useReactTable({
34
- data: paginatedData,
25
+ data: safeData,
35
26
  columns: tableColumns,
36
27
  getRowId: (row) => String(row[rowIdKey]),
37
28
  state: {
@@ -43,12 +34,12 @@ export function useTableController({ data, columns, checkboxSelection, checkboxP
43
34
  },
44
35
  getSortedRowModel: getSortedRowModel(),
45
36
  getCoreRowModel: getCoreRowModel(),
46
- getPaginationRowModel: paginationMode !== 'server' ? getPaginationRowModel() : undefined,
47
- manualPagination: true,
37
+ getPaginationRowModel: paginationMode === 'client' ? getPaginationRowModel() : undefined,
38
+ manualPagination: paginationMode === 'server',
48
39
  autoResetPageIndex: false,
49
40
  pageCount: paginationMode === 'server'
50
41
  ? Math.ceil((totalServerRows !== null && totalServerRows !== void 0 ? totalServerRows : 0) / pageSize)
51
- : Math.ceil(((_a = safeData === null || safeData === void 0 ? void 0 : safeData.length) !== null && _a !== void 0 ? _a : 0) / pageSize),
42
+ : undefined,
52
43
  onPaginationChange: (updater) => {
53
44
  const next = typeof updater === 'function' ? updater({ pageIndex, pageSize }) : updater;
54
45
  setPageIndex(next.pageIndex);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eml-payments/ui-kit",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "private": false,
5
5
  "description": "ARLO UIKit",
6
6
  "homepage": "https://github.com/EML-Payments/arlo.npm.uikit#readme",