@pagamio/frontend-commons-lib 0.8.327 → 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;
|
|
@@ -17,4 +17,4 @@ export declare const pagamioMapping: ResponseMapping;
|
|
|
17
17
|
* The hook tracks `page` zero-indexed internally; we bump on the way out.
|
|
18
18
|
*/
|
|
19
19
|
export declare const pagamioQueryConfig: QueryParamConfig;
|
|
20
|
-
export declare const usePagamioTable: <T extends BaseEntity>({ queryKey, queryFn, enabled: queryEnabled, staleTime, gcTime, data: clientData, columns, defaultFilters, responseMapping, queryParamConfig, pagination: paginationConfig, filtering: filteringConfig, sorting: sortingConfig, toolbar, searchPlaceholder, onRowClick, rowClassName, expandable, renderDetailPanel, }: UsePagamioTableConfig<T>) => UsePagamioTableReturn<T>;
|
|
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 ────────────────────────────────────────────────
|
|
@@ -154,7 +154,7 @@ function clientSort(items, sortConfig) {
|
|
|
154
154
|
return sorted;
|
|
155
155
|
}
|
|
156
156
|
// ─── Hook ────────────────────────────────────────────────────────────
|
|
157
|
-
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, }) => {
|
|
158
158
|
// ── Local state ──────────────────────────────────────────────────
|
|
159
159
|
const [currentPage, setCurrentPage] = useState(paginationConfig.pageIndex ?? 0);
|
|
160
160
|
const [pageSize, setPageSize] = useState(paginationConfig.pageSize ?? 10);
|
|
@@ -179,12 +179,13 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
179
179
|
]);
|
|
180
180
|
// ── TanStack Query — replaces manual fetch + AbortController ─────
|
|
181
181
|
const fullQueryKey = useMemo(() => (queryKey ? [...queryKey, queryParams] : ['pagamio-table-noop']), [queryKey, queryParams]);
|
|
182
|
-
const { data: rawResponse, isLoading: queryLoading, error: queryError, } = useQuery({
|
|
182
|
+
const { data: rawResponse, isLoading: queryLoading, isFetching: queryFetching, error: queryError, } = useQuery({
|
|
183
183
|
queryKey: fullQueryKey,
|
|
184
184
|
queryFn: () => queryFn(queryParams),
|
|
185
185
|
enabled: isServerMode && queryEnabled,
|
|
186
186
|
staleTime,
|
|
187
187
|
gcTime,
|
|
188
|
+
placeholderData: keepPrev ? keepPreviousData : undefined,
|
|
188
189
|
});
|
|
189
190
|
// ── Process server response ──────────────────────────────────────
|
|
190
191
|
const { serverData, serverTotal } = useMemo(() => {
|
|
@@ -217,6 +218,7 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
217
218
|
return processedData;
|
|
218
219
|
}, [processedData, currentPage, pageSize, paginationConfig.mode, paginationConfig.enabled]);
|
|
219
220
|
const isLoading = isServerMode ? queryLoading : false;
|
|
221
|
+
const isFetching = isServerMode ? queryFetching : false;
|
|
220
222
|
const error = queryError ? queryError.message : null;
|
|
221
223
|
// ── Actions ──────────────────────────────────────────────────────
|
|
222
224
|
const handleFilterChange = useCallback((key, value) => {
|
|
@@ -255,6 +257,7 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
255
257
|
columns,
|
|
256
258
|
data: paginatedData,
|
|
257
259
|
isLoading,
|
|
260
|
+
isFetching,
|
|
258
261
|
rowCount: totalItems,
|
|
259
262
|
...(paginationConfig.enabled && {
|
|
260
263
|
pagination: {
|
|
@@ -298,6 +301,7 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
298
301
|
columns,
|
|
299
302
|
paginatedData,
|
|
300
303
|
isLoading,
|
|
304
|
+
isFetching,
|
|
301
305
|
totalItems,
|
|
302
306
|
paginationConfig.enabled,
|
|
303
307
|
currentPage,
|
|
@@ -326,6 +330,7 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
326
330
|
data: paginatedData,
|
|
327
331
|
totalItems,
|
|
328
332
|
isLoading,
|
|
333
|
+
isFetching,
|
|
329
334
|
error,
|
|
330
335
|
currentPage,
|
|
331
336
|
pageSize,
|
|
@@ -347,6 +352,7 @@ export const usePagamioTable = ({ queryKey, queryFn, enabled: queryEnabled = tru
|
|
|
347
352
|
paginatedData,
|
|
348
353
|
totalItems,
|
|
349
354
|
isLoading,
|
|
355
|
+
isFetching,
|
|
350
356
|
error,
|
|
351
357
|
currentPage,
|
|
352
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
|