@pagamio/frontend-commons-lib 0.8.355 → 0.8.356

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.
@@ -138,6 +138,12 @@ function buildQueryParams(config, pagination, sorting, filtering) {
138
138
  }
139
139
  return params;
140
140
  }
141
+ // Backend caps `limit` at 200 (PaginationDto `@Max(200)`, anti-DoS). Export-all
142
+ // pages through at this max so the whole dataset reaches the client in the
143
+ // fewest round-trips the contract allows. Driven through the hook's own param
144
+ // builder — never a hardcoded `limit` in a consumer `queryFn` (see backend
145
+ // pagination convention).
146
+ const MAX_EXPORT_PAGE_SIZE = 200;
141
147
  function clientFilter(items, filters) {
142
148
  return items.filter((item) => Object.entries(filters).every(([key, value]) => key === 'search' || !value || value === 'all' || item[key]?.toString() === value));
143
149
  }
@@ -264,6 +270,49 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
264
270
  queryClient.invalidateQueries({ queryKey });
265
271
  }
266
272
  }, [isServerMode, queryKey, queryClient]);
273
+ // ── Export-all: fetch every server row, not just the current page ──
274
+ // Pages through the same `queryFn` at the backend's max `limit`, preserving
275
+ // the user's current sort/filters/search so the export matches what they see.
276
+ // Returns the full flattened dataset for the client-side export utils.
277
+ const fetchAllPages = useCallback(async () => {
278
+ if (!isServerMode || !queryFn) {
279
+ // Client-mode tables already hold the whole filtered/sorted set.
280
+ return processedData;
281
+ }
282
+ const buildPageParams = (page) => buildQueryParams(queryParamConfig, { mode: paginationConfig.mode, page, size: MAX_EXPORT_PAGE_SIZE }, { mode: sortingConfig.mode, sortConfig }, { mode: filteringConfig.mode, searchMode, filters: appliedFilters });
283
+ // Always start from the first page (index 0) regardless of where the user
284
+ // is paged to. The first response also gives us the true total, so we
285
+ // derive the page count from it rather than the possibly-stale live view.
286
+ const firstRaw = await queryFn(buildPageParams(0));
287
+ const first = processResponse(firstRaw, responseMapping);
288
+ const all = [...first.data];
289
+ const total = first.total || serverTotal;
290
+ const totalPages = Math.max(1, Math.ceil(total / MAX_EXPORT_PAGE_SIZE));
291
+ // Pages are zero/one-based per the consumer's `queryParamConfig.transform`;
292
+ // `buildQueryParams` already applies that transform, so we just feed it the
293
+ // hook's internal zero-based index and let the config bump it.
294
+ for (let page = 1; page < totalPages; page++) {
295
+ const raw = await queryFn(buildPageParams(page));
296
+ const { data: pageData } = processResponse(raw, responseMapping);
297
+ if (pageData.length === 0)
298
+ break; // defensive: stop if a page comes back empty
299
+ all.push(...pageData);
300
+ }
301
+ return all;
302
+ }, [
303
+ isServerMode,
304
+ queryFn,
305
+ processedData,
306
+ queryParamConfig,
307
+ paginationConfig.mode,
308
+ sortingConfig.mode,
309
+ sortConfig,
310
+ filteringConfig.mode,
311
+ searchMode,
312
+ appliedFilters,
313
+ responseMapping,
314
+ serverTotal,
315
+ ]);
267
316
  // ── Search handler (for <input> onChange) ────────────────────────
268
317
  const handleSearchChange = useCallback((e) => {
269
318
  setSearchQuery(e.target.value);
@@ -307,6 +356,18 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
307
356
  ...toolbar,
308
357
  onClearFilters: clearFilters,
309
358
  showClearFilters: toolbar.showClearFilters ?? true,
359
+ // Auto-wire export-all for server-paginated tables. Providing
360
+ // `fetchAllData` makes PagamioTable surface the "Export all data"
361
+ // checkbox; checking it pages through the full dataset. A consumer
362
+ // can still override with its own `fetchAllData` (e.g. a dedicated
363
+ // export endpoint).
364
+ ...(toolbar.export?.enabled &&
365
+ isServerMode && {
366
+ export: {
367
+ ...toolbar.export,
368
+ fetchAllData: toolbar.export.fetchAllData ?? fetchAllPages,
369
+ },
370
+ }),
310
371
  },
311
372
  }),
312
373
  ...(onRowClick && { onRowClick }),
@@ -336,6 +397,8 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
336
397
  searchPlaceholder,
337
398
  toolbar,
338
399
  clearFilters,
400
+ isServerMode,
401
+ fetchAllPages,
339
402
  onRowClick,
340
403
  rowClassName,
341
404
  expandable,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pagamio/frontend-commons-lib",
3
3
  "description": "Pagamio library for Frontend reusable components like the form engine and table container",
4
- "version": "0.8.355",
4
+ "version": "0.8.356",
5
5
  "publishConfig": {
6
6
  "access": "public",
7
7
  "provenance": false