@snowpact/react-tanstack-query-table 1.5.0 → 1.5.2
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 +25 -33
- package/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -35
- package/dist/index.js +1153 -1165
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -26,11 +26,6 @@ declare interface ActionCellProps<T, K> {
|
|
|
26
26
|
onAction: (action: TableAction<T, K>, 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,17 +34,12 @@ 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>, K> extends DataTableUIOptions<T> {
|
|
42
|
+
export declare interface BaseSnowTableProps<T extends Record<string, unknown>, K = unknown> extends DataTableUIOptions<T> {
|
|
53
43
|
queryKey: string[];
|
|
54
44
|
columnConfig: SnowColumnConfig<T>[];
|
|
55
45
|
actions?: TableAction<T, K>[];
|
|
@@ -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> = {
|
|
@@ -195,8 +170,10 @@ declare interface DropdownStyles {
|
|
|
195
170
|
export declare type EndpointAction<T, K> = BaseAction & {
|
|
196
171
|
type: 'endpoint';
|
|
197
172
|
endpoint: (item: T) => Promise<K>;
|
|
198
|
-
|
|
199
|
-
|
|
173
|
+
/** Optional confirmation - if returns false, endpoint is not called */
|
|
174
|
+
withConfirm?: (item: T) => Promise<boolean> | boolean;
|
|
175
|
+
onSuccess?: (data: K, item: T) => void;
|
|
176
|
+
onError?: (error: ErrorResponse, item: T) => void;
|
|
200
177
|
};
|
|
201
178
|
|
|
202
179
|
export declare type ErrorResponse = {
|
|
@@ -345,7 +322,6 @@ export declare const setupSnowTable: (options: SetupSnowTableOptions) => void;
|
|
|
345
322
|
export declare interface SetupSnowTableOptions {
|
|
346
323
|
t: (key: string) => string;
|
|
347
324
|
LinkComponent: ComponentType<LinkProps>;
|
|
348
|
-
confirm: ConfirmFunction;
|
|
349
325
|
styles?: DeepPartial<SnowTableStyles>;
|
|
350
326
|
}
|
|
351
327
|
|
|
@@ -357,12 +333,12 @@ export declare interface SingleFilterDropdownProps<T extends object> {
|
|
|
357
333
|
onFilterChange: (key: keyof T, selectedValues: string[]) => void;
|
|
358
334
|
}
|
|
359
335
|
|
|
360
|
-
export declare const SnowClientDataTable: <T extends Record<string, unknown>, K>({ queryKey, columnConfig, actions, filters, prefilters, prefilterFn, defaultSortBy, defaultSortOrder, defaultPageSize, persistState, fetchAllItemsEndpoint, ...restProps }: SnowClientDataTableProps<T, K>) => JSX.Element;
|
|
336
|
+
export declare const SnowClientDataTable: <T extends Record<string, unknown>, K = unknown>({ queryKey, columnConfig, actions, filters, prefilters, prefilterFn, defaultSortBy, defaultSortOrder, defaultPageSize, persistState, fetchAllItemsEndpoint, ...restProps }: SnowClientDataTableProps<T, K>) => JSX.Element;
|
|
361
337
|
|
|
362
338
|
/**
|
|
363
339
|
* Props for SnowClientDataTable component (client-side filtering/sorting)
|
|
364
340
|
*/
|
|
365
|
-
export declare interface SnowClientDataTableProps<T extends Record<string, unknown>, K> extends BaseSnowTableProps<T, K> {
|
|
341
|
+
export declare interface SnowClientDataTableProps<T extends Record<string, unknown>, K = unknown> extends BaseSnowTableProps<T, K> {
|
|
366
342
|
fetchAllItemsEndpoint: () => Promise<T[]>;
|
|
367
343
|
/** Optional function to filter items based on active prefilter */
|
|
368
344
|
prefilterFn?: (item: T, prefilterId: string) => boolean;
|
|
@@ -378,12 +354,12 @@ export declare type SnowColumnConfig<T extends object> = {
|
|
|
378
354
|
meta?: ColumnMeta<T, unknown>;
|
|
379
355
|
};
|
|
380
356
|
|
|
381
|
-
export declare const SnowServerDataTable: <T extends Record<string, unknown>, K>({ queryKey, columnConfig, actions, filters, prefilters, defaultSortBy, defaultSortOrder, defaultPageSize, persistState, fetchServerEndpoint, ...restProps }: SnowServerDataTableProps<T, K>) => JSX.Element;
|
|
357
|
+
export declare const SnowServerDataTable: <T extends Record<string, unknown>, K = unknown>({ queryKey, columnConfig, actions, filters, prefilters, defaultSortBy, defaultSortOrder, defaultPageSize, persistState, fetchServerEndpoint, ...restProps }: SnowServerDataTableProps<T, K>) => JSX.Element;
|
|
382
358
|
|
|
383
359
|
/**
|
|
384
360
|
* Props for SnowServerDataTable component (server-side pagination/filtering/sorting)
|
|
385
361
|
*/
|
|
386
|
-
export declare interface SnowServerDataTableProps<T extends Record<string, unknown>, K> extends BaseSnowTableProps<T, K> {
|
|
362
|
+
export declare interface SnowServerDataTableProps<T extends Record<string, unknown>, K = unknown> extends BaseSnowTableProps<T, K> {
|
|
387
363
|
fetchServerEndpoint: (params: ServerFetchParams) => Promise<ServerPaginatedResponse<T>>;
|
|
388
364
|
filters?: FilterConfig<Record<string, unknown>>[];
|
|
389
365
|
}
|
|
@@ -411,7 +387,7 @@ declare interface StateStyles {
|
|
|
411
387
|
focus: string;
|
|
412
388
|
}
|
|
413
389
|
|
|
414
|
-
export declare type TableAction<T, K> =
|
|
390
|
+
export declare type TableAction<T, K = unknown> = ClickAction<T> | LinkAction<T> | EndpointAction<T, K> | ((item: T) => ClickAction<T>) | ((item: T) => LinkAction<T>) | ((item: T) => EndpointAction<T, K>);
|
|
415
391
|
|
|
416
392
|
declare interface TabsStyles {
|
|
417
393
|
list: string;
|
|
@@ -425,7 +401,7 @@ declare interface TabsStyles {
|
|
|
425
401
|
* Extracts the common logic for:
|
|
426
402
|
* - Transforming SnowColumnConfig into TanStack Table ColumnDef
|
|
427
403
|
* - Adding action column with ActionCell
|
|
428
|
-
* - Handling action execution
|
|
404
|
+
* - Handling action execution (click, link, endpoint)
|
|
429
405
|
*/
|
|
430
406
|
export declare const useSnowColumns: <T extends Record<string, unknown>, K>({ columnConfig, actions, filters, mode, }: UseSnowColumnsOptions<T, K>) => UseSnowColumnsReturn<T, K>;
|
|
431
407
|
|