@pagamio/frontend-commons-lib 0.8.326 → 0.8.328
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,3 +1,3 @@
|
|
|
1
1
|
import type { PagamioTableProps } from './types';
|
|
2
|
-
declare const PagamioTable: <T extends Record<string, any>>({ columns, data, isLoading, rowCount, sorting, pagination, filtering, search, onRowClick, rowClassName, expandable, renderDetailPanel, toolbar, toolbarMode, enableColumnResizing, enableColumnPinning, enableColumnOrdering, enableColumnFilters, enableHiding, enableRowSelection, enableRowActions, enableRowVirtualization, enableGrouping, enableEditing, enableDensityToggle, enableFullScreenToggle, enableClickToCopy, enableRowNumbers, enableMultiSort, enableStickyHeader, enableStickyFooter, editDisplayMode, onEditingRowSave, onEditingRowCancel, renderRowActions, renderRowActionMenuItems, positionActionsColumn, renderTopToolbarCustomActions, renderBottomToolbarCustomActions, layoutMode, defaultColumn, mantineTableOptions, }: PagamioTableProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
declare const PagamioTable: <T extends Record<string, any>>({ columns, data, isLoading, isFetching, rowCount, sorting, pagination, filtering, search, onRowClick, rowClassName, expandable, renderDetailPanel, toolbar, toolbarMode, enableColumnResizing, enableColumnPinning, enableColumnOrdering, enableColumnFilters, enableHiding, enableRowSelection, enableRowActions, enableRowVirtualization, enableGrouping, enableEditing, enableDensityToggle, enableFullScreenToggle, enableClickToCopy, enableRowNumbers, enableMultiSort, enableStickyHeader, enableStickyFooter, editDisplayMode, onEditingRowSave, onEditingRowCancel, renderRowActions, renderRowActionMenuItems, positionActionsColumn, renderTopToolbarCustomActions, renderBottomToolbarCustomActions, layoutMode, defaultColumn, mantineTableOptions, }: PagamioTableProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default PagamioTable;
|
|
@@ -101,7 +101,7 @@ function CustomToolbar({ filters, appliedFilters, onFilterChange, onApply, onCle
|
|
|
101
101
|
(typeof addButton === 'boolean' ? (_jsx(IconButton, { onClick: onAdd ?? (() => { }), icon: HiPlusSm, label: "add-new-entry", className: cn('items-center text-nowrap', isNarrow ? 'w-full' : undefined), children: addText ?? 'Add New Entry' })) : (addButton))] }) }));
|
|
102
102
|
}
|
|
103
103
|
// ─── PagamioTable Component ──────────────────────────────────────────
|
|
104
|
-
const PagamioTable = ({ columns, data, isLoading = false, rowCount, sorting, pagination, filtering, search, onRowClick, rowClassName, expandable = false, renderDetailPanel, toolbar, toolbarMode = 'custom', enableColumnResizing, enableColumnPinning, enableColumnOrdering, enableColumnFilters, enableHiding, enableRowSelection, enableRowActions, enableRowVirtualization, enableGrouping, enableEditing, enableDensityToggle, enableFullScreenToggle, enableClickToCopy, enableRowNumbers, enableMultiSort, enableStickyHeader, enableStickyFooter, editDisplayMode, onEditingRowSave, onEditingRowCancel, renderRowActions, renderRowActionMenuItems, positionActionsColumn, renderTopToolbarCustomActions, renderBottomToolbarCustomActions, layoutMode, defaultColumn, mantineTableOptions, }) => {
|
|
104
|
+
const PagamioTable = ({ columns, data, isLoading = false, isFetching = false, rowCount, sorting, pagination, filtering, search, onRowClick, rowClassName, expandable = false, renderDetailPanel, toolbar, toolbarMode = 'custom', enableColumnResizing, enableColumnPinning, enableColumnOrdering, enableColumnFilters, enableHiding, enableRowSelection, enableRowActions, enableRowVirtualization, enableGrouping, enableEditing, enableDensityToggle, enableFullScreenToggle, enableClickToCopy, enableRowNumbers, enableMultiSort, enableStickyHeader, enableStickyFooter, editDisplayMode, onEditingRowSave, onEditingRowCancel, renderRowActions, renderRowActionMenuItems, positionActionsColumn, renderTopToolbarCustomActions, renderBottomToolbarCustomActions, layoutMode, defaultColumn, mantineTableOptions, }) => {
|
|
105
105
|
const [expanded, setExpanded] = useState({});
|
|
106
106
|
const tableRef = useRef(null);
|
|
107
107
|
// ── Internal max-height ─────────────────────────────────────────────
|
|
@@ -233,6 +233,7 @@ const PagamioTable = ({ columns, data, isLoading = false, rowCount, sorting, pag
|
|
|
233
233
|
// State
|
|
234
234
|
state: {
|
|
235
235
|
isLoading,
|
|
236
|
+
showProgressBars: isFetching,
|
|
236
237
|
pagination: paginationState,
|
|
237
238
|
sorting: sortingState,
|
|
238
239
|
expanded,
|
|
@@ -103,6 +103,13 @@ export interface PagamioTableProps<T extends Record<string, any>> {
|
|
|
103
103
|
columns: CoreTableColumnDef<T>[];
|
|
104
104
|
data: T[];
|
|
105
105
|
isLoading?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Background-refetch indicator (e.g. paginating with `keepPreviousData`).
|
|
108
|
+
* When true, MRT shows a top progress bar without replacing rows with
|
|
109
|
+
* skeletons. `isLoading` should remain reserved for the first-load case
|
|
110
|
+
* where there are no rows yet.
|
|
111
|
+
*/
|
|
112
|
+
isFetching?: boolean;
|
|
106
113
|
rowCount?: number;
|
|
107
114
|
sorting?: {
|
|
108
115
|
sortConfig: SortConfig;
|
|
@@ -170,6 +177,12 @@ export interface UsePagamioTableConfig<T extends BaseEntity> {
|
|
|
170
177
|
enabled?: boolean;
|
|
171
178
|
staleTime?: number;
|
|
172
179
|
gcTime?: number;
|
|
180
|
+
/**
|
|
181
|
+
* Keep the previous page's rows visible while the next page fetches
|
|
182
|
+
* (TanStack `placeholderData: keepPreviousData`). Defaults to true so
|
|
183
|
+
* pagination/sort/filter no longer flash an empty table.
|
|
184
|
+
*/
|
|
185
|
+
keepPreviousData?: boolean;
|
|
173
186
|
data?: T[];
|
|
174
187
|
columns: CoreTableColumnDef<T>[];
|
|
175
188
|
defaultFilters?: Record<string, string>;
|
|
@@ -202,6 +215,7 @@ export interface UsePagamioTableReturn<T extends BaseEntity> {
|
|
|
202
215
|
data: T[];
|
|
203
216
|
totalItems: number;
|
|
204
217
|
isLoading: boolean;
|
|
218
|
+
isFetching: boolean;
|
|
205
219
|
error: string | null;
|
|
206
220
|
currentPage: number;
|
|
207
221
|
pageSize: number;
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
-
import type { ResponseMapping } from '../../api';
|
|
1
|
+
import type { QueryParamConfig, ResponseMapping } from '../../api';
|
|
2
2
|
import type { BaseEntity, UsePagamioTableConfig, UsePagamioTableReturn } from '../../pagamio-table/data-table/types';
|
|
3
3
|
export declare const springBootMapping: ResponseMapping;
|
|
4
4
|
export declare const arrayResponseMapping: ResponseMapping;
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Response mapping for Pagamio NestJS backends (commerce-os-core,
|
|
7
|
+
* nestjs-api-commons). Matches `PaginatedResponseDto<T>`:
|
|
8
|
+
* { data: T[], meta: { page, limit, total, totalPages, hasNextPage, hasPreviousPage } }
|
|
9
|
+
*
|
|
10
|
+
* Pair with `pagamioQueryConfig` so request params line up too.
|
|
11
|
+
*/
|
|
12
|
+
export declare const pagamioMapping: ResponseMapping;
|
|
13
|
+
/**
|
|
14
|
+
* Query-param config for Pagamio NestJS backends. Matches `PaginationDto`:
|
|
15
|
+
* page (1-based), limit, search, sortBy, sortOrder ('asc'|'desc')
|
|
16
|
+
*
|
|
17
|
+
* The hook tracks `page` zero-indexed internally; we bump on the way out.
|
|
18
|
+
*/
|
|
19
|
+
export declare const pagamioQueryConfig: QueryParamConfig;
|
|
20
|
+
export declare const usePagamioTable: <T extends BaseEntity>({ queryKey, queryFn, enabled: queryEnabled, staleTime, gcTime, keepPreviousData: keepPrev, data: clientData, columns, defaultFilters, responseMapping, queryParamConfig, pagination: paginationConfig, filtering: filteringConfig, sorting: sortingConfig, toolbar, searchPlaceholder, onRowClick, rowClassName, expandable, renderDetailPanel, }: UsePagamioTableConfig<T>) => UsePagamioTableReturn<T>;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Returns `tableProps` (spread-ready for <PagamioTable {...tableProps} />)
|
|
11
11
|
* plus direct state/action access for custom logic.
|
|
12
12
|
*/
|
|
13
|
-
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
|
13
|
+
import { keepPreviousData, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
14
14
|
import { useCallback, useMemo, useState } from 'react';
|
|
15
15
|
import { getNestedValue } from '../utils';
|
|
16
16
|
// ─── Default Mappings ────────────────────────────────────────────────
|
|
@@ -30,6 +30,37 @@ export const arrayResponseMapping = {
|
|
|
30
30
|
pageSize: '',
|
|
31
31
|
defaultValues: { data: [], total: 0, page: 0, pageSize: 10 },
|
|
32
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Response mapping for Pagamio NestJS backends (commerce-os-core,
|
|
35
|
+
* nestjs-api-commons). Matches `PaginatedResponseDto<T>`:
|
|
36
|
+
* { data: T[], meta: { page, limit, total, totalPages, hasNextPage, hasPreviousPage } }
|
|
37
|
+
*
|
|
38
|
+
* Pair with `pagamioQueryConfig` so request params line up too.
|
|
39
|
+
*/
|
|
40
|
+
export const pagamioMapping = {
|
|
41
|
+
responseType: 'default',
|
|
42
|
+
data: 'data',
|
|
43
|
+
total: 'meta.total',
|
|
44
|
+
page: 'meta.page',
|
|
45
|
+
pageSize: 'meta.limit',
|
|
46
|
+
defaultValues: { data: [], total: 0, page: 1, pageSize: 10 },
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Query-param config for Pagamio NestJS backends. Matches `PaginationDto`:
|
|
50
|
+
* page (1-based), limit, search, sortBy, sortOrder ('asc'|'desc')
|
|
51
|
+
*
|
|
52
|
+
* The hook tracks `page` zero-indexed internally; we bump on the way out.
|
|
53
|
+
*/
|
|
54
|
+
export const pagamioQueryConfig = {
|
|
55
|
+
pagination: {
|
|
56
|
+
transform: (page, size) => ({
|
|
57
|
+
page: (page + 1).toString(),
|
|
58
|
+
limit: size.toString(),
|
|
59
|
+
}),
|
|
60
|
+
},
|
|
61
|
+
sorting: { sortByParam: 'sortBy', sortDirParam: 'sortOrder' },
|
|
62
|
+
filtering: { searchParam: 'search', filterFormat: 'flat' },
|
|
63
|
+
};
|
|
33
64
|
const defaultQueryConfig = {
|
|
34
65
|
pagination: {
|
|
35
66
|
transform: (page, size) => ({ page: page.toString(), size: size.toString() }),
|
|
@@ -123,7 +154,7 @@ function clientSort(items, sortConfig) {
|
|
|
123
154
|
return sorted;
|
|
124
155
|
}
|
|
125
156
|
// ─── Hook ────────────────────────────────────────────────────────────
|
|
126
|
-
export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = true, staleTime, gcTime, data: clientData, columns, defaultFilters = {}, responseMapping = springBootMapping, queryParamConfig = defaultQueryConfig, pagination: paginationConfig = { enabled: true, mode: 'client' }, filtering: filteringConfig = { enabled: true, mode: 'client', searchMode: 'server' }, sorting: sortingConfig = { enabled: true, mode: 'client' }, toolbar, searchPlaceholder, onRowClick, rowClassName, expandable, renderDetailPanel, }) => {
|
|
157
|
+
export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = true, staleTime, gcTime, keepPreviousData: keepPrev = true, data: clientData, columns, defaultFilters = {}, responseMapping = springBootMapping, queryParamConfig = defaultQueryConfig, pagination: paginationConfig = { enabled: true, mode: 'client' }, filtering: filteringConfig = { enabled: true, mode: 'client', searchMode: 'server' }, sorting: sortingConfig = { enabled: true, mode: 'client' }, toolbar, searchPlaceholder, onRowClick, rowClassName, expandable, renderDetailPanel, }) => {
|
|
127
158
|
// ── Local state ──────────────────────────────────────────────────
|
|
128
159
|
const [currentPage, setCurrentPage] = useState(paginationConfig.pageIndex ?? 0);
|
|
129
160
|
const [pageSize, setPageSize] = useState(paginationConfig.pageSize ?? 10);
|
|
@@ -148,12 +179,13 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
148
179
|
]);
|
|
149
180
|
// ── TanStack Query — replaces manual fetch + AbortController ─────
|
|
150
181
|
const fullQueryKey = useMemo(() => (queryKey ? [...queryKey, queryParams] : ['pagamio-table-noop']), [queryKey, queryParams]);
|
|
151
|
-
const { data: rawResponse, isLoading: queryLoading, error: queryError, } = useQuery({
|
|
182
|
+
const { data: rawResponse, isLoading: queryLoading, isFetching: queryFetching, error: queryError, } = useQuery({
|
|
152
183
|
queryKey: fullQueryKey,
|
|
153
184
|
queryFn: () => queryFn(queryParams),
|
|
154
185
|
enabled: isServerMode && queryEnabled,
|
|
155
186
|
staleTime,
|
|
156
187
|
gcTime,
|
|
188
|
+
placeholderData: keepPrev ? keepPreviousData : undefined,
|
|
157
189
|
});
|
|
158
190
|
// ── Process server response ──────────────────────────────────────
|
|
159
191
|
const { serverData, serverTotal } = useMemo(() => {
|
|
@@ -186,6 +218,7 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
186
218
|
return processedData;
|
|
187
219
|
}, [processedData, currentPage, pageSize, paginationConfig.mode, paginationConfig.enabled]);
|
|
188
220
|
const isLoading = isServerMode ? queryLoading : false;
|
|
221
|
+
const isFetching = isServerMode ? queryFetching : false;
|
|
189
222
|
const error = queryError ? queryError.message : null;
|
|
190
223
|
// ── Actions ──────────────────────────────────────────────────────
|
|
191
224
|
const handleFilterChange = useCallback((key, value) => {
|
|
@@ -224,6 +257,7 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
224
257
|
columns,
|
|
225
258
|
data: paginatedData,
|
|
226
259
|
isLoading,
|
|
260
|
+
isFetching,
|
|
227
261
|
rowCount: totalItems,
|
|
228
262
|
...(paginationConfig.enabled && {
|
|
229
263
|
pagination: {
|
|
@@ -267,6 +301,7 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
267
301
|
columns,
|
|
268
302
|
paginatedData,
|
|
269
303
|
isLoading,
|
|
304
|
+
isFetching,
|
|
270
305
|
totalItems,
|
|
271
306
|
paginationConfig.enabled,
|
|
272
307
|
currentPage,
|
|
@@ -295,6 +330,7 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
295
330
|
data: paginatedData,
|
|
296
331
|
totalItems,
|
|
297
332
|
isLoading,
|
|
333
|
+
isFetching,
|
|
298
334
|
error,
|
|
299
335
|
currentPage,
|
|
300
336
|
pageSize,
|
|
@@ -316,6 +352,7 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
316
352
|
paginatedData,
|
|
317
353
|
totalItems,
|
|
318
354
|
isLoading,
|
|
355
|
+
isFetching,
|
|
319
356
|
error,
|
|
320
357
|
currentPage,
|
|
321
358
|
pageSize,
|
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.
|
|
4
|
+
"version": "0.8.328",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
7
7
|
"provenance": false
|