@snowpact/react-tanstack-query-table 1.5.1 → 1.5.3
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 +18 -22
- package/dist/index.cjs +12 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +26 -17
- package/dist/index.js +1423 -1403
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -18,12 +18,12 @@ 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>({ item, actions, onAction }: ActionCellProps<T>): JSX.Element;
|
|
21
|
+
declare function ActionCellInner<T, K>({ item, actions, onAction }: ActionCellProps<T, K>): JSX.Element;
|
|
22
22
|
|
|
23
|
-
declare interface ActionCellProps<T> {
|
|
23
|
+
declare interface ActionCellProps<T, K> {
|
|
24
24
|
item: T;
|
|
25
|
-
actions: TableAction<T>[];
|
|
26
|
-
onAction: (action: TableAction<T>, item: T) => void;
|
|
25
|
+
actions: TableAction<T, K>[];
|
|
26
|
+
onAction: (action: TableAction<T, K>, item: T) => void;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export declare type BaseAction = {
|
|
@@ -39,10 +39,10 @@ export declare type BaseAction = {
|
|
|
39
39
|
/**
|
|
40
40
|
* Base props shared between SnowClientDataTable and SnowServerDataTable
|
|
41
41
|
*/
|
|
42
|
-
export declare interface BaseSnowTableProps<T extends Record<string, unknown
|
|
42
|
+
export declare interface BaseSnowTableProps<T extends Record<string, unknown>, K = unknown> extends DataTableUIOptions<T> {
|
|
43
43
|
queryKey: string[];
|
|
44
44
|
columnConfig: SnowColumnConfig<T>[];
|
|
45
|
-
actions?: TableAction<T>[];
|
|
45
|
+
actions?: TableAction<T, K>[];
|
|
46
46
|
filters?: FilterConfig<T>[];
|
|
47
47
|
prefilters?: PreFilter[];
|
|
48
48
|
defaultSortBy?: string;
|
|
@@ -167,6 +167,15 @@ declare interface DropdownStyles {
|
|
|
167
167
|
separator: string;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
export declare type EndpointAction<T, K> = BaseAction & {
|
|
171
|
+
type: 'endpoint';
|
|
172
|
+
endpoint: (item: T) => Promise<K>;
|
|
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;
|
|
177
|
+
};
|
|
178
|
+
|
|
170
179
|
export declare type ErrorResponse = {
|
|
171
180
|
message: string;
|
|
172
181
|
status: number;
|
|
@@ -324,12 +333,12 @@ export declare interface SingleFilterDropdownProps<T extends object> {
|
|
|
324
333
|
onFilterChange: (key: keyof T, selectedValues: string[]) => void;
|
|
325
334
|
}
|
|
326
335
|
|
|
327
|
-
export declare const SnowClientDataTable: <T extends Record<string, unknown
|
|
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;
|
|
328
337
|
|
|
329
338
|
/**
|
|
330
339
|
* Props for SnowClientDataTable component (client-side filtering/sorting)
|
|
331
340
|
*/
|
|
332
|
-
export declare interface SnowClientDataTableProps<T extends Record<string, unknown
|
|
341
|
+
export declare interface SnowClientDataTableProps<T extends Record<string, unknown>, K = unknown> extends BaseSnowTableProps<T, K> {
|
|
333
342
|
fetchAllItemsEndpoint: () => Promise<T[]>;
|
|
334
343
|
/** Optional function to filter items based on active prefilter */
|
|
335
344
|
prefilterFn?: (item: T, prefilterId: string) => boolean;
|
|
@@ -345,12 +354,12 @@ export declare type SnowColumnConfig<T extends object> = {
|
|
|
345
354
|
meta?: ColumnMeta<T, unknown>;
|
|
346
355
|
};
|
|
347
356
|
|
|
348
|
-
export declare const SnowServerDataTable: <T extends Record<string, unknown
|
|
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;
|
|
349
358
|
|
|
350
359
|
/**
|
|
351
360
|
* Props for SnowServerDataTable component (server-side pagination/filtering/sorting)
|
|
352
361
|
*/
|
|
353
|
-
export declare interface SnowServerDataTableProps<T extends Record<string, unknown
|
|
362
|
+
export declare interface SnowServerDataTableProps<T extends Record<string, unknown>, K = unknown> extends BaseSnowTableProps<T, K> {
|
|
354
363
|
fetchServerEndpoint: (params: ServerFetchParams) => Promise<ServerPaginatedResponse<T>>;
|
|
355
364
|
filters?: FilterConfig<Record<string, unknown>>[];
|
|
356
365
|
}
|
|
@@ -378,7 +387,7 @@ declare interface StateStyles {
|
|
|
378
387
|
focus: string;
|
|
379
388
|
}
|
|
380
389
|
|
|
381
|
-
export declare type TableAction<T> = ClickAction<T> | LinkAction<T> | ((item: T) => ClickAction<T>) | ((item: T) => LinkAction<T>);
|
|
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>);
|
|
382
391
|
|
|
383
392
|
declare interface TabsStyles {
|
|
384
393
|
list: string;
|
|
@@ -392,13 +401,13 @@ declare interface TabsStyles {
|
|
|
392
401
|
* Extracts the common logic for:
|
|
393
402
|
* - Transforming SnowColumnConfig into TanStack Table ColumnDef
|
|
394
403
|
* - Adding action column with ActionCell
|
|
395
|
-
* - Handling action execution (click
|
|
404
|
+
* - Handling action execution (click, link, endpoint)
|
|
396
405
|
*/
|
|
397
|
-
export declare const useSnowColumns: <T extends Record<string, unknown
|
|
406
|
+
export declare const useSnowColumns: <T extends Record<string, unknown>, K>({ columnConfig, actions, filters, mode, }: UseSnowColumnsOptions<T, K>) => UseSnowColumnsReturn<T, K>;
|
|
398
407
|
|
|
399
|
-
export declare interface UseSnowColumnsOptions<T extends Record<string, unknown
|
|
408
|
+
export declare interface UseSnowColumnsOptions<T extends Record<string, unknown>, K> {
|
|
400
409
|
columnConfig: SnowColumnConfig<T>[];
|
|
401
|
-
actions?: TableAction<T>[];
|
|
410
|
+
actions?: TableAction<T, K>[];
|
|
402
411
|
filters?: FilterConfig<T>[];
|
|
403
412
|
/**
|
|
404
413
|
* Mode determines how global filter behaves:
|
|
@@ -408,9 +417,9 @@ export declare interface UseSnowColumnsOptions<T extends Record<string, unknown>
|
|
|
408
417
|
mode: 'client' | 'server';
|
|
409
418
|
}
|
|
410
419
|
|
|
411
|
-
export declare interface UseSnowColumnsReturn<T extends Record<string, unknown
|
|
420
|
+
export declare interface UseSnowColumnsReturn<T extends Record<string, unknown>, K> {
|
|
412
421
|
columns: ColumnDef<T, unknown>[];
|
|
413
|
-
handleAction: (action: TableAction<T>, item: T) => void
|
|
422
|
+
handleAction: (action: TableAction<T, K>, item: T) => Promise<void>;
|
|
414
423
|
}
|
|
415
424
|
|
|
416
425
|
export declare const useTableStatePersist: ({ enabled, defaultPrefilter, defaultPageSize, defaultSortBy, defaultSortOrder, }: UseTableStatePersistOptions) => {
|