@izumisy-tailor/tailor-data-viewer 0.2.0 → 0.2.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 +315 -189
- package/package.json +1 -1
- package/src/component/collection-params/collection-params-provider.tsx +12 -3
- package/src/component/{use-collection-params.test.ts → collection-params/use-collection-params.test.ts} +127 -1
- package/src/component/collection-params/use-collection-params.ts +67 -4
- package/src/component/{use-data-table.test.ts → data-table/use-data-table.test.ts} +2 -2
- package/src/component/field-helpers.test.ts +99 -33
- package/src/component/field-helpers.ts +60 -19
- package/src/component/index.ts +2 -1
- package/src/component/types.ts +47 -15
package/src/component/types.ts
CHANGED
|
@@ -130,6 +130,25 @@ export interface CollectionResult<T> {
|
|
|
130
130
|
pageInfo: PageInfo;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Extract the node type from a cursor connection result.
|
|
135
|
+
*
|
|
136
|
+
* Handles nullable wrappers commonly produced by GraphQL code generators
|
|
137
|
+
* (e.g. gql-tada `ResultOf`).
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* // With gql-tada
|
|
142
|
+
* type OrdersData = ResultOf<typeof GET_ORDERS>;
|
|
143
|
+
* type Order = NodeType<OrdersData["orders"]>;
|
|
144
|
+
*
|
|
145
|
+
* const { field, display } = createColumnHelper<Order>();
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export type NodeType<
|
|
149
|
+
T extends { edges: { node: unknown }[] } | null | undefined,
|
|
150
|
+
> = NonNullable<T>["edges"][number]["node"];
|
|
151
|
+
|
|
133
152
|
// =============================================================================
|
|
134
153
|
// Cell Renderer
|
|
135
154
|
// =============================================================================
|
|
@@ -240,20 +259,33 @@ export type ColumnDefinition<TRow extends Record<string, unknown>> =
|
|
|
240
259
|
|
|
241
260
|
/**
|
|
242
261
|
* Options for `useCollectionParams` hook.
|
|
262
|
+
*
|
|
263
|
+
* @typeParam TFieldName - Union of allowed field name strings (default: `string`).
|
|
243
264
|
*/
|
|
244
|
-
export interface UseCollectionParamsOptions
|
|
265
|
+
export interface UseCollectionParamsOptions<
|
|
266
|
+
TFieldName extends string = string,
|
|
267
|
+
> {
|
|
245
268
|
/** Initial filters to apply */
|
|
246
269
|
initialFilters?: Filter[];
|
|
247
270
|
/** Initial sort states */
|
|
248
|
-
initialSort?:
|
|
271
|
+
initialSort?: { field: TFieldName; direction: "Asc" | "Desc" }[];
|
|
249
272
|
/** Number of items per page (default: 20) */
|
|
250
273
|
pageSize?: number;
|
|
251
274
|
}
|
|
252
275
|
|
|
253
276
|
/**
|
|
254
277
|
* Return type of `useCollectionParams` hook.
|
|
255
|
-
|
|
256
|
-
|
|
278
|
+
*
|
|
279
|
+
* Methods that accept a field name are typed with `TFieldName` so that
|
|
280
|
+
* auto-completion works when a concrete union is supplied.
|
|
281
|
+
*
|
|
282
|
+
* **Note:** Methods use *method syntax* (not property syntax) intentionally
|
|
283
|
+
* so that `UseCollectionParamsReturn<"a" | "b">` remains assignable to
|
|
284
|
+
* `UseCollectionParamsReturn<string>` (bivariant method check).
|
|
285
|
+
*
|
|
286
|
+
* @typeParam TFieldName - Union of allowed field name strings (default: `string`).
|
|
287
|
+
*/
|
|
288
|
+
export interface UseCollectionParamsReturn<TFieldName extends string = string> {
|
|
257
289
|
/** Query variables in Tailor Platform format */
|
|
258
290
|
variables: QueryVariables;
|
|
259
291
|
|
|
@@ -261,25 +293,25 @@ export interface UseCollectionParamsReturn {
|
|
|
261
293
|
/** Current active filters */
|
|
262
294
|
filters: Filter[];
|
|
263
295
|
/** Add or update a filter for a field */
|
|
264
|
-
addFilter
|
|
296
|
+
addFilter(field: TFieldName, value: unknown, operator?: FilterOperator): void;
|
|
265
297
|
/** Replace all filters at once */
|
|
266
|
-
setFilters
|
|
298
|
+
setFilters(filters: Filter[]): void;
|
|
267
299
|
/** Remove filter for a specific field */
|
|
268
|
-
removeFilter
|
|
300
|
+
removeFilter(field: TFieldName): void;
|
|
269
301
|
/** Clear all filters */
|
|
270
|
-
clearFilters
|
|
302
|
+
clearFilters(): void;
|
|
271
303
|
|
|
272
304
|
// Sort operations
|
|
273
305
|
/** Current sort states (supports multi-sort) */
|
|
274
306
|
sortStates: SortState[];
|
|
275
307
|
/** Set sort for a field. If `append` is true, adds to existing sorts. */
|
|
276
|
-
setSort
|
|
277
|
-
field:
|
|
308
|
+
setSort(
|
|
309
|
+
field: TFieldName,
|
|
278
310
|
direction?: "Asc" | "Desc",
|
|
279
311
|
append?: boolean,
|
|
280
|
-
)
|
|
312
|
+
): void;
|
|
281
313
|
/** Clear all sort states */
|
|
282
|
-
clearSort
|
|
314
|
+
clearSort(): void;
|
|
283
315
|
|
|
284
316
|
// Pagination operations
|
|
285
317
|
/** Number of items per page */
|
|
@@ -287,11 +319,11 @@ export interface UseCollectionParamsReturn {
|
|
|
287
319
|
/** Current cursor position */
|
|
288
320
|
cursor: string | null;
|
|
289
321
|
/** Navigate to next page */
|
|
290
|
-
nextPage
|
|
322
|
+
nextPage(endCursor: string): void;
|
|
291
323
|
/** Navigate to previous page */
|
|
292
|
-
prevPage
|
|
324
|
+
prevPage(): void;
|
|
293
325
|
/** Reset to first page */
|
|
294
|
-
resetPage
|
|
326
|
+
resetPage(): void;
|
|
295
327
|
/** Whether there is a previous page */
|
|
296
328
|
hasPrevPage: boolean;
|
|
297
329
|
}
|