@snowpact/react-tanstack-query-table 1.5.0 → 1.5.1
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.
- package/README.md +33 -37
- package/dist/index.cjs +14 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -50
- package/dist/index.js +1353 -1385
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,19 +18,14 @@ export declare type ActionButtonVariant = 'default' | 'warning' | 'danger' | 'in
|
|
|
18
18
|
|
|
19
19
|
export declare const ActionCell: typeof ActionCellInner;
|
|
20
20
|
|
|
21
|
-
declare function ActionCellInner<T
|
|
21
|
+
declare function ActionCellInner<T>({ item, actions, onAction }: ActionCellProps<T>): JSX.Element;
|
|
22
22
|
|
|
23
|
-
declare interface ActionCellProps<T
|
|
23
|
+
declare interface ActionCellProps<T> {
|
|
24
24
|
item: T;
|
|
25
|
-
actions: TableAction<T
|
|
26
|
-
onAction: (action: TableAction<T
|
|
25
|
+
actions: TableAction<T>[];
|
|
26
|
+
onAction: (action: TableAction<T>, item: T) => void;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
/**
|
|
30
|
-
* Confirm content is always a function receiving { close, confirm } helpers
|
|
31
|
-
*/
|
|
32
|
-
export declare type ActionConfirmContent = (helpers: ConfirmHelpers) => ReactNode;
|
|
33
|
-
|
|
34
29
|
export declare type BaseAction = {
|
|
35
30
|
icon: IconComponent;
|
|
36
31
|
label: string;
|
|
@@ -39,20 +34,15 @@ export declare type BaseAction = {
|
|
|
39
34
|
hidden?: boolean;
|
|
40
35
|
disabled?: boolean;
|
|
41
36
|
showLabel?: boolean;
|
|
42
|
-
confirm?: {
|
|
43
|
-
title: string;
|
|
44
|
-
content: ActionConfirmContent;
|
|
45
|
-
subtitle?: string;
|
|
46
|
-
};
|
|
47
37
|
};
|
|
48
38
|
|
|
49
39
|
/**
|
|
50
40
|
* Base props shared between SnowClientDataTable and SnowServerDataTable
|
|
51
41
|
*/
|
|
52
|
-
export declare interface BaseSnowTableProps<T extends Record<string, unknown
|
|
42
|
+
export declare interface BaseSnowTableProps<T extends Record<string, unknown>> extends DataTableUIOptions<T> {
|
|
53
43
|
queryKey: string[];
|
|
54
44
|
columnConfig: SnowColumnConfig<T>[];
|
|
55
|
-
actions?: TableAction<T
|
|
45
|
+
actions?: TableAction<T>[];
|
|
56
46
|
filters?: FilterConfig<T>[];
|
|
57
47
|
prefilters?: PreFilter[];
|
|
58
48
|
defaultSortBy?: string;
|
|
@@ -91,21 +81,6 @@ export declare type ColumnConfigurationProps<T extends object> = {
|
|
|
91
81
|
table: Table<T>;
|
|
92
82
|
};
|
|
93
83
|
|
|
94
|
-
export declare type ConfirmContent = (helpers: ConfirmHelpers) => ReactNode;
|
|
95
|
-
|
|
96
|
-
export declare type ConfirmFunction = (options: ConfirmOptions) => Promise<boolean>;
|
|
97
|
-
|
|
98
|
-
export declare interface ConfirmHelpers {
|
|
99
|
-
close: () => void;
|
|
100
|
-
confirm: () => void;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
declare interface ConfirmOptions {
|
|
104
|
-
title: string;
|
|
105
|
-
subtitle?: string;
|
|
106
|
-
content: ConfirmContent;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
84
|
export declare function DataTable<Data extends object>({ data, columns, isLoading, isFetching, mode, pagination: externalPagination, onPaginationChange: externalOnPaginationChange, totalCount: externalTotalCount, globalFilter: externalGlobalFilter, onGlobalFilterChange: externalOnGlobalFilterChange, enableGlobalSearch, filters, columnFilters: externalColumnFilters, onColumnFiltersChange: externalOnColumnFiltersChange, prefilters, activePrefilter, onPrefilterChange, sorting: externalSorting, onSortingChange: externalOnSortingChange, enableSorting, columnVisibility: externalColumnVisibility, onColumnVisibilityChange: externalOnColumnVisibilityChange, enableColumnConfiguration, onRowClick, activeRowId, displayTotalNumber, enableElementLabel, enablePagination, paginationSizes, enableResponsive, texts, onResetFilters, }: DataTableProps<Data>): JSX.Element;
|
|
110
85
|
|
|
111
86
|
export declare type DataTableProps<T extends object> = {
|
|
@@ -192,13 +167,6 @@ declare interface DropdownStyles {
|
|
|
192
167
|
separator: string;
|
|
193
168
|
}
|
|
194
169
|
|
|
195
|
-
export declare type EndpointAction<T, K> = BaseAction & {
|
|
196
|
-
type: 'endpoint';
|
|
197
|
-
endpoint: (item: T) => Promise<K>;
|
|
198
|
-
onSuccess?: (data: K, variables: T, context: unknown) => void;
|
|
199
|
-
onError?: (error: ErrorResponse, variables: T, context: unknown) => void;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
170
|
export declare type ErrorResponse = {
|
|
203
171
|
message: string;
|
|
204
172
|
status: number;
|
|
@@ -345,7 +313,6 @@ export declare const setupSnowTable: (options: SetupSnowTableOptions) => void;
|
|
|
345
313
|
export declare interface SetupSnowTableOptions {
|
|
346
314
|
t: (key: string) => string;
|
|
347
315
|
LinkComponent: ComponentType<LinkProps>;
|
|
348
|
-
confirm: ConfirmFunction;
|
|
349
316
|
styles?: DeepPartial<SnowTableStyles>;
|
|
350
317
|
}
|
|
351
318
|
|
|
@@ -357,12 +324,12 @@ export declare interface SingleFilterDropdownProps<T extends object> {
|
|
|
357
324
|
onFilterChange: (key: keyof T, selectedValues: string[]) => void;
|
|
358
325
|
}
|
|
359
326
|
|
|
360
|
-
export declare const SnowClientDataTable: <T extends Record<string, unknown
|
|
327
|
+
export declare const SnowClientDataTable: <T extends Record<string, unknown>>({ queryKey, columnConfig, actions, filters, prefilters, prefilterFn, defaultSortBy, defaultSortOrder, defaultPageSize, persistState, fetchAllItemsEndpoint, ...restProps }: SnowClientDataTableProps<T>) => JSX.Element;
|
|
361
328
|
|
|
362
329
|
/**
|
|
363
330
|
* Props for SnowClientDataTable component (client-side filtering/sorting)
|
|
364
331
|
*/
|
|
365
|
-
export declare interface SnowClientDataTableProps<T extends Record<string, unknown
|
|
332
|
+
export declare interface SnowClientDataTableProps<T extends Record<string, unknown>> extends BaseSnowTableProps<T> {
|
|
366
333
|
fetchAllItemsEndpoint: () => Promise<T[]>;
|
|
367
334
|
/** Optional function to filter items based on active prefilter */
|
|
368
335
|
prefilterFn?: (item: T, prefilterId: string) => boolean;
|
|
@@ -378,12 +345,12 @@ export declare type SnowColumnConfig<T extends object> = {
|
|
|
378
345
|
meta?: ColumnMeta<T, unknown>;
|
|
379
346
|
};
|
|
380
347
|
|
|
381
|
-
export declare const SnowServerDataTable: <T extends Record<string, unknown
|
|
348
|
+
export declare const SnowServerDataTable: <T extends Record<string, unknown>>({ queryKey, columnConfig, actions, filters, prefilters, defaultSortBy, defaultSortOrder, defaultPageSize, persistState, fetchServerEndpoint, ...restProps }: SnowServerDataTableProps<T>) => JSX.Element;
|
|
382
349
|
|
|
383
350
|
/**
|
|
384
351
|
* Props for SnowServerDataTable component (server-side pagination/filtering/sorting)
|
|
385
352
|
*/
|
|
386
|
-
export declare interface SnowServerDataTableProps<T extends Record<string, unknown
|
|
353
|
+
export declare interface SnowServerDataTableProps<T extends Record<string, unknown>> extends BaseSnowTableProps<T> {
|
|
387
354
|
fetchServerEndpoint: (params: ServerFetchParams) => Promise<ServerPaginatedResponse<T>>;
|
|
388
355
|
filters?: FilterConfig<Record<string, unknown>>[];
|
|
389
356
|
}
|
|
@@ -411,7 +378,7 @@ declare interface StateStyles {
|
|
|
411
378
|
focus: string;
|
|
412
379
|
}
|
|
413
380
|
|
|
414
|
-
export declare type TableAction<T
|
|
381
|
+
export declare type TableAction<T> = ClickAction<T> | LinkAction<T> | ((item: T) => ClickAction<T>) | ((item: T) => LinkAction<T>);
|
|
415
382
|
|
|
416
383
|
declare interface TabsStyles {
|
|
417
384
|
list: string;
|
|
@@ -425,13 +392,13 @@ declare interface TabsStyles {
|
|
|
425
392
|
* Extracts the common logic for:
|
|
426
393
|
* - Transforming SnowColumnConfig into TanStack Table ColumnDef
|
|
427
394
|
* - Adding action column with ActionCell
|
|
428
|
-
* - Handling action execution
|
|
395
|
+
* - Handling action execution (click actions)
|
|
429
396
|
*/
|
|
430
|
-
export declare const useSnowColumns: <T extends Record<string, unknown
|
|
397
|
+
export declare const useSnowColumns: <T extends Record<string, unknown>>({ columnConfig, actions, filters, mode, }: UseSnowColumnsOptions<T>) => UseSnowColumnsReturn<T>;
|
|
431
398
|
|
|
432
|
-
export declare interface UseSnowColumnsOptions<T extends Record<string, unknown
|
|
399
|
+
export declare interface UseSnowColumnsOptions<T extends Record<string, unknown>> {
|
|
433
400
|
columnConfig: SnowColumnConfig<T>[];
|
|
434
|
-
actions?: TableAction<T
|
|
401
|
+
actions?: TableAction<T>[];
|
|
435
402
|
filters?: FilterConfig<T>[];
|
|
436
403
|
/**
|
|
437
404
|
* Mode determines how global filter behaves:
|
|
@@ -441,9 +408,9 @@ export declare interface UseSnowColumnsOptions<T extends Record<string, unknown>
|
|
|
441
408
|
mode: 'client' | 'server';
|
|
442
409
|
}
|
|
443
410
|
|
|
444
|
-
export declare interface UseSnowColumnsReturn<T extends Record<string, unknown
|
|
411
|
+
export declare interface UseSnowColumnsReturn<T extends Record<string, unknown>> {
|
|
445
412
|
columns: ColumnDef<T, unknown>[];
|
|
446
|
-
handleAction: (action: TableAction<T
|
|
413
|
+
handleAction: (action: TableAction<T>, item: T) => void;
|
|
447
414
|
}
|
|
448
415
|
|
|
449
416
|
export declare const useTableStatePersist: ({ enabled, defaultPrefilter, defaultPageSize, defaultSortBy, defaultSortOrder, }: UseTableStatePersistOptions) => {
|