@ram_28/kf-ai-sdk 1.0.0
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/LICENSE +21 -0
- package/README.md +840 -0
- package/dist/api/client.d.ts +78 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/datetime.d.ts +21 -0
- package/dist/api/datetime.d.ts.map +1 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/metadata.d.ts +75 -0
- package/dist/api/metadata.d.ts.map +1 -0
- package/dist/components/hooks/index.d.ts +8 -0
- package/dist/components/hooks/index.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/index.d.ts +5 -0
- package/dist/components/hooks/useFilter/index.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts +33 -0
- package/dist/components/hooks/useFilter/payloadBuilder.utils.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/types.d.ts +137 -0
- package/dist/components/hooks/useFilter/types.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/useFilter.d.ts +3 -0
- package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -0
- package/dist/components/hooks/useFilter/validation.utils.d.ts +38 -0
- package/dist/components/hooks/useFilter/validation.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/apiClient.d.ts +71 -0
- package/dist/components/hooks/useForm/apiClient.d.ts.map +1 -0
- package/dist/components/hooks/useForm/expressionValidator.utils.d.ts +28 -0
- package/dist/components/hooks/useForm/expressionValidator.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/index.d.ts +6 -0
- package/dist/components/hooks/useForm/index.d.ts.map +1 -0
- package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts +88 -0
- package/dist/components/hooks/useForm/optimizedExpressionValidator.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts +28 -0
- package/dist/components/hooks/useForm/ruleClassifier.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/schemaParser.utils.d.ts +29 -0
- package/dist/components/hooks/useForm/schemaParser.utils.d.ts.map +1 -0
- package/dist/components/hooks/useForm/types.d.ts +412 -0
- package/dist/components/hooks/useForm/types.d.ts.map +1 -0
- package/dist/components/hooks/useForm/useForm.d.ts +3 -0
- package/dist/components/hooks/useForm/useForm.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/apiClient.d.ts +99 -0
- package/dist/components/hooks/useKanban/apiClient.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/context.d.ts +4 -0
- package/dist/components/hooks/useKanban/context.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/dragDropManager.d.ts +27 -0
- package/dist/components/hooks/useKanban/dragDropManager.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/index.d.ts +6 -0
- package/dist/components/hooks/useKanban/index.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/types.d.ts +438 -0
- package/dist/components/hooks/useKanban/types.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/useKanban.d.ts +3 -0
- package/dist/components/hooks/useKanban/useKanban.d.ts.map +1 -0
- package/dist/components/hooks/useKanban/useKanbanSimple.d.ts +62 -0
- package/dist/components/hooks/useKanban/useKanbanSimple.d.ts.map +1 -0
- package/dist/components/hooks/useTable/index.d.ts +3 -0
- package/dist/components/hooks/useTable/index.d.ts.map +1 -0
- package/dist/components/hooks/useTable/types.d.ts +107 -0
- package/dist/components/hooks/useTable/types.d.ts.map +1 -0
- package/dist/components/hooks/useTable/useTable.d.ts +8 -0
- package/dist/components/hooks/useTable/useTable.d.ts.map +1 -0
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/ui/index.d.ts +2 -0
- package/dist/components/ui/index.d.ts.map +1 -0
- package/dist/components/ui/kanban/Kanban.d.ts +12 -0
- package/dist/components/ui/kanban/Kanban.d.ts.map +1 -0
- package/dist/components/ui/kanban/index.d.ts +2 -0
- package/dist/components/ui/kanban/index.d.ts.map +1 -0
- package/dist/index.cjs +45 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +6522 -0
- package/dist/types/base-fields.d.ts +182 -0
- package/dist/types/base-fields.d.ts.map +1 -0
- package/dist/types/common.d.ts +238 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/utils/cn.d.ts +7 -0
- package/dist/utils/cn.d.ts.map +1 -0
- package/dist/utils/formatting.d.ts +52 -0
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +98 -0
- package/sdk/api/client.ts +447 -0
- package/sdk/api/datetime.ts +33 -0
- package/sdk/api/index.ts +61 -0
- package/sdk/api/metadata.ts +148 -0
- package/sdk/components/hooks/index.ts +34 -0
- package/sdk/components/hooks/useFilter/index.ts +37 -0
- package/sdk/components/hooks/useFilter/payloadBuilder.utils.ts +298 -0
- package/sdk/components/hooks/useFilter/types.ts +158 -0
- package/sdk/components/hooks/useFilter/useFilter.llm.txt +497 -0
- package/sdk/components/hooks/useFilter/useFilter.ts +494 -0
- package/sdk/components/hooks/useFilter/validation.utils.ts +401 -0
- package/sdk/components/hooks/useForm/apiClient.ts +441 -0
- package/sdk/components/hooks/useForm/expressionValidator.utils.ts +444 -0
- package/sdk/components/hooks/useForm/index.ts +64 -0
- package/sdk/components/hooks/useForm/optimizedExpressionValidator.utils.ts +482 -0
- package/sdk/components/hooks/useForm/ruleClassifier.utils.ts +424 -0
- package/sdk/components/hooks/useForm/schemaParser.utils.ts +519 -0
- package/sdk/components/hooks/useForm/types.ts +630 -0
- package/sdk/components/hooks/useForm/useForm.llm.txt +340 -0
- package/sdk/components/hooks/useForm/useForm.ts +821 -0
- package/sdk/components/hooks/useKanban/apiClient.ts +494 -0
- package/sdk/components/hooks/useKanban/context.ts +14 -0
- package/sdk/components/hooks/useKanban/dragDropManager.ts +529 -0
- package/sdk/components/hooks/useKanban/index.ts +63 -0
- package/sdk/components/hooks/useKanban/types.ts +606 -0
- package/sdk/components/hooks/useKanban/useKanban.llm.txt +482 -0
- package/sdk/components/hooks/useKanban/useKanban.ts +725 -0
- package/sdk/components/hooks/useKanban/useKanbanSimple.ts +389 -0
- package/sdk/components/hooks/useTable/index.ts +5 -0
- package/sdk/components/hooks/useTable/types.ts +154 -0
- package/sdk/components/hooks/useTable/useTable.llm.txt +344 -0
- package/sdk/components/hooks/useTable/useTable.ts +413 -0
- package/sdk/components/index.ts +15 -0
- package/sdk/components/ui/index.ts +2 -0
- package/sdk/components/ui/kanban/Kanban.tsx +134 -0
- package/sdk/components/ui/kanban/index.ts +11 -0
- package/sdk/index.ts +13 -0
- package/sdk/types/base-fields.ts +221 -0
- package/sdk/types/common.ts +306 -0
- package/sdk/types/index.ts +5 -0
- package/sdk/utils/cn.ts +10 -0
- package/sdk/utils/formatting.ts +212 -0
- package/sdk/utils/index.ts +5 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
# useTable Hook - LLM Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The `useTable` hook is a React hook that provides a complete table data management solution with built-in support for:
|
|
6
|
+
- Data fetching with TanStack Query
|
|
7
|
+
- Pagination (1-indexed)
|
|
8
|
+
- Sorting
|
|
9
|
+
- Search
|
|
10
|
+
- Advanced filtering (via integrated useFilter hook)
|
|
11
|
+
- Error handling
|
|
12
|
+
- Loading states
|
|
13
|
+
|
|
14
|
+
## Import
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { useTable } from "kf-ai-sdk";
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Basic Usage
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
const table = useTable<ProductType>({
|
|
24
|
+
source: "BDO_ProductMaster",
|
|
25
|
+
columns: [
|
|
26
|
+
{ fieldId: "Title", label: "Name", enableSorting: true },
|
|
27
|
+
{ fieldId: "Price", label: "Price", enableSorting: true },
|
|
28
|
+
{ fieldId: "Category", label: "Category", enableSorting: true },
|
|
29
|
+
{ fieldId: "Stock", label: "Stock", enableSorting: true },
|
|
30
|
+
],
|
|
31
|
+
enableSorting: true,
|
|
32
|
+
enableFiltering: true,
|
|
33
|
+
enablePagination: true,
|
|
34
|
+
initialState: {
|
|
35
|
+
pagination: { pageNo: 1, pageSize: 10 },
|
|
36
|
+
sorting: { field: "Title", direction: "asc" },
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Configuration Options
|
|
42
|
+
|
|
43
|
+
### UseTableOptions<T>
|
|
44
|
+
|
|
45
|
+
| Property | Type | Required | Description |
|
|
46
|
+
|----------|------|----------|-------------|
|
|
47
|
+
| `source` | `string` | Yes | Data source identifier (Business Data Object name) |
|
|
48
|
+
| `columns` | `ColumnDefinition<T>[]` | Yes | Column configurations |
|
|
49
|
+
| `enableSorting` | `boolean` | No | Enable sorting functionality |
|
|
50
|
+
| `enableFiltering` | `boolean` | No | Enable filtering functionality |
|
|
51
|
+
| `enablePagination` | `boolean` | No | Enable pagination |
|
|
52
|
+
| `fieldDefinitions` | `Record<keyof T, FieldDefinition>` | No | Field definitions for filter validation |
|
|
53
|
+
| `initialState` | `object` | No | Initial state for pagination, sorting, filters |
|
|
54
|
+
| `onError` | `(error: Error) => void` | No | Error callback |
|
|
55
|
+
| `onSuccess` | `(data: T[]) => void` | No | Success callback |
|
|
56
|
+
| `onFilterError` | `(errors: ValidationError[]) => void` | No | Filter error callback |
|
|
57
|
+
|
|
58
|
+
### ColumnDefinition<T>
|
|
59
|
+
|
|
60
|
+
| Property | Type | Description |
|
|
61
|
+
|----------|------|-------------|
|
|
62
|
+
| `fieldId` | `keyof T` | Field name from the data type |
|
|
63
|
+
| `label` | `string` | Display label (optional, defaults to fieldId) |
|
|
64
|
+
| `enableSorting` | `boolean` | Enable sorting for this column |
|
|
65
|
+
| `enableFiltering` | `boolean` | Enable filtering for this column |
|
|
66
|
+
| `transform` | `(value: any, row: T) => React.ReactNode` | Custom transform function |
|
|
67
|
+
|
|
68
|
+
## Return Value
|
|
69
|
+
|
|
70
|
+
### UseTableReturn<T>
|
|
71
|
+
|
|
72
|
+
#### Data
|
|
73
|
+
| Property | Type | Description |
|
|
74
|
+
|----------|------|-------------|
|
|
75
|
+
| `rows` | `T[]` | Array of data rows |
|
|
76
|
+
| `totalItems` | `number` | Total number of items (across all pages) |
|
|
77
|
+
|
|
78
|
+
#### Loading States
|
|
79
|
+
| Property | Type | Description |
|
|
80
|
+
|----------|------|-------------|
|
|
81
|
+
| `isLoading` | `boolean` | Initial data loading |
|
|
82
|
+
| `isFetching` | `boolean` | Background refetching |
|
|
83
|
+
|
|
84
|
+
#### Error Handling
|
|
85
|
+
| Property | Type | Description |
|
|
86
|
+
|----------|------|-------------|
|
|
87
|
+
| `error` | `Error \| null` | Current error state |
|
|
88
|
+
|
|
89
|
+
#### Search
|
|
90
|
+
| Property | Type | Description |
|
|
91
|
+
|----------|------|-------------|
|
|
92
|
+
| `search.query` | `string` | Current search query |
|
|
93
|
+
| `search.setQuery` | `(value: string) => void` | Set search query (auto-resets to page 1) |
|
|
94
|
+
| `search.clear` | `() => void` | Clear search query |
|
|
95
|
+
|
|
96
|
+
#### Sorting
|
|
97
|
+
| Property | Type | Description |
|
|
98
|
+
|----------|------|-------------|
|
|
99
|
+
| `sort.field` | `keyof T \| null` | Current sort field |
|
|
100
|
+
| `sort.direction` | `"asc" \| "desc" \| null` | Current sort direction |
|
|
101
|
+
| `sort.toggle` | `(field: keyof T) => void` | Toggle sort (cycles: asc -> desc -> none) |
|
|
102
|
+
| `sort.clear` | `() => void` | Clear sorting |
|
|
103
|
+
| `sort.set` | `(field: keyof T, direction: "asc" \| "desc") => void` | Set specific sort |
|
|
104
|
+
|
|
105
|
+
#### Filtering (Advanced)
|
|
106
|
+
| Property | Type | Description |
|
|
107
|
+
|----------|------|-------------|
|
|
108
|
+
| `filter.conditions` | `FilterConditionWithId[]` | Current filter conditions |
|
|
109
|
+
| `filter.logicalOperator` | `LogicalOperator` | "And" or "Or" |
|
|
110
|
+
| `filter.isValid` | `boolean` | Whether all conditions are valid |
|
|
111
|
+
| `filter.validationErrors` | `ValidationError[]` | Current validation errors |
|
|
112
|
+
| `filter.hasConditions` | `boolean` | Whether any conditions exist |
|
|
113
|
+
| `filter.addCondition` | `(condition) => string` | Add a filter condition, returns ID |
|
|
114
|
+
| `filter.updateCondition` | `(id, updates) => boolean` | Update a condition |
|
|
115
|
+
| `filter.removeCondition` | `(id) => boolean` | Remove a condition |
|
|
116
|
+
| `filter.clearConditions` | `() => void` | Clear all conditions |
|
|
117
|
+
| `filter.getCondition` | `(id) => FilterConditionWithId` | Get a specific condition |
|
|
118
|
+
| `filter.setLogicalOperator` | `(operator) => void` | Set logical operator |
|
|
119
|
+
|
|
120
|
+
#### Pagination
|
|
121
|
+
| Property | Type | Description |
|
|
122
|
+
|----------|------|-------------|
|
|
123
|
+
| `pagination.currentPage` | `number` | Current page (1-indexed) |
|
|
124
|
+
| `pagination.pageSize` | `number` | Items per page |
|
|
125
|
+
| `pagination.totalPages` | `number` | Total number of pages |
|
|
126
|
+
| `pagination.totalItems` | `number` | Total item count |
|
|
127
|
+
| `pagination.canGoNext` | `boolean` | Can navigate to next page |
|
|
128
|
+
| `pagination.canGoPrevious` | `boolean` | Can navigate to previous page |
|
|
129
|
+
| `pagination.goToNext` | `() => void` | Go to next page |
|
|
130
|
+
| `pagination.goToPrevious` | `() => void` | Go to previous page |
|
|
131
|
+
| `pagination.goToPage` | `(page: number) => void` | Go to specific page |
|
|
132
|
+
| `pagination.setPageSize` | `(size: number) => void` | Change page size (resets to page 1) |
|
|
133
|
+
|
|
134
|
+
#### Operations
|
|
135
|
+
| Property | Type | Description |
|
|
136
|
+
|----------|------|-------------|
|
|
137
|
+
| `refetch` | `() => Promise<ListResponse<T>>` | Manually refetch data |
|
|
138
|
+
|
|
139
|
+
## Filter Operators
|
|
140
|
+
|
|
141
|
+
The following operators are supported for filter conditions:
|
|
142
|
+
|
|
143
|
+
### Comparison Operators
|
|
144
|
+
- `EQ` - Equal
|
|
145
|
+
- `NE` - Not Equal
|
|
146
|
+
- `GT` - Greater Than
|
|
147
|
+
- `GTE` - Greater Than or Equal
|
|
148
|
+
- `LT` - Less Than
|
|
149
|
+
- `LTE` - Less Than or Equal
|
|
150
|
+
|
|
151
|
+
### Range Operators
|
|
152
|
+
- `Between` - Between two values (requires array of 2 values)
|
|
153
|
+
- `NotBetween` - Not between two values
|
|
154
|
+
|
|
155
|
+
### Set Operators
|
|
156
|
+
- `IN` - In array of values
|
|
157
|
+
- `NIN` - Not in array of values
|
|
158
|
+
|
|
159
|
+
### String Operators
|
|
160
|
+
- `Contains` - Contains substring
|
|
161
|
+
- `NotContains` - Does not contain substring
|
|
162
|
+
- `StartsWith` - Starts with string
|
|
163
|
+
- `EndsWith` - Ends with string
|
|
164
|
+
|
|
165
|
+
### Null Operators
|
|
166
|
+
- `Empty` - Is empty/null
|
|
167
|
+
- `NotEmpty` - Is not empty/null
|
|
168
|
+
|
|
169
|
+
## E-Commerce App Usage Examples
|
|
170
|
+
|
|
171
|
+
### Seller Products Page (SellerProductsPage.tsx)
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
const table = useTable<SellerProduct>({
|
|
175
|
+
source: "BDO_AmazonProductMaster",
|
|
176
|
+
columns: [
|
|
177
|
+
{ fieldId: "Title", label: "Name", enableSorting: true },
|
|
178
|
+
{ fieldId: "Price", label: "Price", enableSorting: true },
|
|
179
|
+
{ fieldId: "Category", label: "Category", enableSorting: true },
|
|
180
|
+
{ fieldId: "Stock", label: "Stock", enableSorting: true },
|
|
181
|
+
],
|
|
182
|
+
enableSorting: true,
|
|
183
|
+
enableFiltering: true,
|
|
184
|
+
enablePagination: true,
|
|
185
|
+
initialState: {
|
|
186
|
+
pagination: { pageNo: 1, pageSize: 10 },
|
|
187
|
+
sorting: { field: "Title", direction: "asc" },
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Search
|
|
192
|
+
<Input
|
|
193
|
+
value={table.search.query}
|
|
194
|
+
onChange={(e) => table.search.setQuery(e.target.value)}
|
|
195
|
+
/>
|
|
196
|
+
|
|
197
|
+
// Display rows
|
|
198
|
+
{table.rows.map((product) => (
|
|
199
|
+
<tr key={product._id}>...</tr>
|
|
200
|
+
))}
|
|
201
|
+
|
|
202
|
+
// Pagination controls
|
|
203
|
+
<Button
|
|
204
|
+
onClick={table.pagination.goToPrevious}
|
|
205
|
+
disabled={!table.pagination.canGoPrevious}
|
|
206
|
+
>
|
|
207
|
+
Previous
|
|
208
|
+
</Button>
|
|
209
|
+
<Button
|
|
210
|
+
onClick={table.pagination.goToNext}
|
|
211
|
+
disabled={!table.pagination.canGoNext}
|
|
212
|
+
>
|
|
213
|
+
Next
|
|
214
|
+
</Button>
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Buyer Product List Page (BuyerProductListPage.tsx)
|
|
218
|
+
|
|
219
|
+
```typescript
|
|
220
|
+
const table = useTable<BuyerProduct>({
|
|
221
|
+
source: "BDO_AmazonProductMaster",
|
|
222
|
+
columns: [...],
|
|
223
|
+
enableSorting: true,
|
|
224
|
+
enableFiltering: true,
|
|
225
|
+
enablePagination: true,
|
|
226
|
+
initialState: {
|
|
227
|
+
pagination: { pageNo: 1, pageSize: 10 },
|
|
228
|
+
sorting: { field: "Title", direction: "asc" },
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// Category filter
|
|
233
|
+
const handleCategoryChange = (category: string) => {
|
|
234
|
+
table.filter.clearConditions();
|
|
235
|
+
if (category !== "all") {
|
|
236
|
+
table.filter.addCondition({
|
|
237
|
+
lhsField: "Category",
|
|
238
|
+
operator: "EQ",
|
|
239
|
+
rhsValue: category,
|
|
240
|
+
rhsType: "Constant",
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// Price range filter
|
|
246
|
+
const handlePriceChange = (rangeLabel: string) => {
|
|
247
|
+
const range = PRICE_RANGES.find((r) => r.label === rangeLabel);
|
|
248
|
+
if (range) {
|
|
249
|
+
if (range.max === null) {
|
|
250
|
+
// "$200 & Above" - use GTE
|
|
251
|
+
table.filter.addCondition({
|
|
252
|
+
lhsField: "Price",
|
|
253
|
+
operator: "GTE",
|
|
254
|
+
rhsValue: range.min,
|
|
255
|
+
rhsType: "Constant",
|
|
256
|
+
});
|
|
257
|
+
} else if (range.min === 0) {
|
|
258
|
+
// "Under $25" - use LT
|
|
259
|
+
table.filter.addCondition({
|
|
260
|
+
lhsField: "Price",
|
|
261
|
+
operator: "LT",
|
|
262
|
+
rhsValue: range.max,
|
|
263
|
+
rhsType: "Constant",
|
|
264
|
+
});
|
|
265
|
+
} else {
|
|
266
|
+
// Range like "$25 to $50" - use Between
|
|
267
|
+
table.filter.addCondition({
|
|
268
|
+
lhsField: "Price",
|
|
269
|
+
operator: "Between",
|
|
270
|
+
rhsValue: [range.min, range.max],
|
|
271
|
+
rhsType: "Constant",
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// Sorting
|
|
278
|
+
const handleSortChange = (value: string) => {
|
|
279
|
+
switch (value) {
|
|
280
|
+
case "price-asc":
|
|
281
|
+
table.sort.set("Price", "asc");
|
|
282
|
+
break;
|
|
283
|
+
case "price-desc":
|
|
284
|
+
table.sort.set("Price", "desc");
|
|
285
|
+
break;
|
|
286
|
+
case "newest":
|
|
287
|
+
table.sort.set("_created_at", "desc");
|
|
288
|
+
break;
|
|
289
|
+
default:
|
|
290
|
+
table.sort.set("Title", "asc");
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// Clear all filters
|
|
296
|
+
<Button
|
|
297
|
+
onClick={() => {
|
|
298
|
+
table.search.clear();
|
|
299
|
+
table.filter.clearConditions();
|
|
300
|
+
}}
|
|
301
|
+
>
|
|
302
|
+
Clear All Filters
|
|
303
|
+
</Button>
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Key Behaviors
|
|
307
|
+
|
|
308
|
+
1. **Auto-pagination reset**: Search and filter changes automatically reset to page 1
|
|
309
|
+
2. **Separate count query**: Total count is fetched separately for accurate pagination
|
|
310
|
+
3. **Type-safe filters**: The `lhsField` in filter conditions is constrained to `keyof T`
|
|
311
|
+
4. **1-indexed pagination**: Pages start at 1, not 0
|
|
312
|
+
5. **Sort cycling**: `toggle()` cycles through: ascending -> descending -> none
|
|
313
|
+
6. **Integrated useFilter**: Advanced filtering is powered by the standalone useFilter hook
|
|
314
|
+
7. **TanStack Query**: Data fetching uses React Query for caching and state management
|
|
315
|
+
|
|
316
|
+
## API Format
|
|
317
|
+
|
|
318
|
+
The hook automatically converts state to the backend API format:
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
// Sort format sent to API
|
|
322
|
+
Sort: [{ "fieldName": "ASC" }]
|
|
323
|
+
|
|
324
|
+
// Filter format sent to API
|
|
325
|
+
Filter: {
|
|
326
|
+
Operator: "And",
|
|
327
|
+
Condition: [
|
|
328
|
+
{
|
|
329
|
+
Operator: "EQ",
|
|
330
|
+
LHSField: "Category",
|
|
331
|
+
RHSValue: "Electronics",
|
|
332
|
+
RHSType: "Constant"
|
|
333
|
+
}
|
|
334
|
+
]
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Architecture Notes
|
|
339
|
+
|
|
340
|
+
- Built on TanStack Query for data fetching
|
|
341
|
+
- Integrates `useFilter` hook for advanced filtering
|
|
342
|
+
- Maintains separate queries for data and count (optimized caching)
|
|
343
|
+
- Uses `useMemo` and `useCallback` for performance optimization
|
|
344
|
+
- Type-safe with full TypeScript generics support
|