@ram_28/kf-ai-sdk 2.0.15 → 2.0.17
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 +22 -14
- package/dist/api.cjs +1 -1
- package/dist/api.mjs +1 -1
- package/dist/auth/authConfig.d.ts +1 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth.cjs +1 -1
- package/dist/auth.mjs +1 -1
- package/dist/bdo/core/BaseBdo.d.ts +1 -1
- package/dist/bdo.cjs +1 -1
- package/dist/bdo.mjs +3 -3
- package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts +1 -1
- package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts.map +1 -1
- package/dist/components/hooks/useActivityForm/types.d.ts +6 -7
- package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
- package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
- package/dist/components/hooks/useActivityTable/types.d.ts +7 -6
- package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useActivityTable/useActivityTable.d.ts +1 -1
- package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
- package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -0
- package/dist/components/hooks/useBDOForm/createResolver.d.ts.map +1 -0
- package/dist/components/hooks/useBDOForm/index.d.ts +6 -0
- package/dist/components/hooks/useBDOForm/index.d.ts.map +1 -0
- package/dist/components/hooks/useBDOForm/shared.d.ts +50 -0
- package/dist/components/hooks/useBDOForm/shared.d.ts.map +1 -0
- package/dist/components/hooks/{useForm → useBDOForm}/types.d.ts +6 -6
- package/dist/components/hooks/useBDOForm/types.d.ts.map +1 -0
- package/dist/components/hooks/{useForm/useForm.d.ts → useBDOForm/useBDOForm.d.ts} +4 -4
- package/dist/components/hooks/useBDOForm/useBDOForm.d.ts.map +1 -0
- package/dist/components/hooks/useBDOTable/types.d.ts +20 -14
- package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +2 -2
- package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
- package/dist/{constants-ConHc1oS.js → constants-Cyi942Yr.js} +5 -5
- package/dist/constants-DEmYwKfC.cjs +1 -0
- package/dist/filter.cjs +1 -1
- package/dist/filter.mjs +1 -1
- package/dist/form.cjs +1 -1
- package/dist/form.d.ts +1 -1
- package/dist/form.d.ts.map +1 -1
- package/dist/form.mjs +250 -253
- package/dist/form.types.d.ts +1 -1
- package/dist/form.types.d.ts.map +1 -1
- package/dist/shared-5a7UkED1.js +1180 -0
- package/dist/shared-nnmlRVs7.cjs +1 -0
- package/dist/table.cjs +1 -1
- package/dist/table.mjs +14 -14
- package/dist/table.types.d.ts +1 -1
- package/dist/table.types.d.ts.map +1 -1
- package/dist/types/constants.d.ts +4 -4
- package/dist/workflow/Activity.d.ts +22 -7
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow/client.d.ts +2 -2
- package/dist/workflow/client.d.ts.map +1 -1
- package/dist/workflow/types.d.ts +7 -3
- package/dist/workflow/types.d.ts.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.mjs +518 -576
- package/docs/README.md +51 -0
- package/docs/bdo/README.md +161 -0
- package/docs/bdo/api_reference.md +281 -0
- package/docs/examples/bdo/create-product.md +69 -0
- package/docs/examples/bdo/edit-product-dialog.md +95 -0
- package/docs/examples/bdo/filtered-product-table.md +100 -0
- package/docs/examples/bdo/product-listing.md +73 -0
- package/docs/examples/bdo/supplier-dropdown.md +60 -0
- package/docs/examples/workflow/approve-leave-request.md +76 -0
- package/docs/examples/workflow/filtered-activity-table.md +101 -0
- package/docs/examples/workflow/my-pending-requests.md +90 -0
- package/docs/examples/workflow/start-new-workflow.md +47 -0
- package/docs/examples/workflow/submit-leave-request.md +72 -0
- package/docs/examples/workflow/workflow-progress.md +49 -0
- package/docs/useActivityForm/README.md +241 -0
- package/docs/useActivityForm/api_reference.md +279 -0
- package/docs/useActivityTable/README.md +263 -0
- package/docs/useActivityTable/api_reference.md +294 -0
- package/docs/useBDOForm/README.md +172 -0
- package/docs/useBDOForm/api_reference.md +244 -0
- package/docs/useBDOTable/README.md +242 -0
- package/docs/useBDOTable/api_reference.md +253 -0
- package/docs/useFilter/README.md +323 -0
- package/docs/useFilter/api_reference.md +228 -0
- package/docs/workflow/README.md +158 -0
- package/docs/workflow/api_reference.md +161 -0
- package/package.json +2 -2
- package/sdk/auth/authConfig.ts +1 -1
- package/sdk/auth/types.ts +1 -1
- package/sdk/bdo/core/BaseBdo.ts +2 -2
- package/sdk/components/hooks/useActivityForm/createActivityItemProxy.ts +1 -1
- package/sdk/components/hooks/useActivityForm/createActivityResolver.ts +1 -1
- package/sdk/components/hooks/useActivityForm/types.ts +8 -10
- package/sdk/components/hooks/useActivityForm/useActivityForm.ts +52 -265
- package/sdk/components/hooks/useActivityTable/types.ts +6 -5
- package/sdk/components/hooks/useActivityTable/useActivityTable.ts +14 -43
- package/sdk/components/hooks/{useForm → useBDOForm}/index.ts +4 -3
- package/sdk/components/hooks/useBDOForm/shared.ts +250 -0
- package/sdk/components/hooks/{useForm → useBDOForm}/types.ts +9 -9
- package/sdk/components/hooks/{useForm/useForm.ts → useBDOForm/useBDOForm.ts} +70 -96
- package/sdk/components/hooks/useBDOTable/types.ts +20 -12
- package/sdk/components/hooks/useBDOTable/useBDOTable.ts +12 -7
- package/sdk/form.ts +2 -2
- package/sdk/form.types.ts +4 -4
- package/sdk/table.types.ts +2 -0
- package/sdk/types/constants.ts +4 -4
- package/sdk/workflow/Activity.ts +68 -13
- package/sdk/workflow/client.ts +65 -25
- package/sdk/workflow/types.ts +10 -2
- package/dist/components/hooks/useForm/createItemProxy.d.ts.map +0 -1
- package/dist/components/hooks/useForm/createResolver.d.ts.map +0 -1
- package/dist/components/hooks/useForm/index.d.ts +0 -5
- package/dist/components/hooks/useForm/index.d.ts.map +0 -1
- package/dist/components/hooks/useForm/types.d.ts.map +0 -1
- package/dist/components/hooks/useForm/useForm.d.ts.map +0 -1
- package/dist/constants-QX2RX-wu.cjs +0 -1
- package/dist/createResolver-AIgUwoS6.cjs +0 -1
- package/dist/createResolver-ZHXQ7QMa.js +0 -1078
- package/docs/api.md +0 -95
- package/docs/bdo.md +0 -224
- package/docs/gaps.md +0 -410
- package/docs/useActivityTable.md +0 -481
- package/docs/useBDOTable.md +0 -317
- package/docs/useFilter.md +0 -188
- package/docs/useForm.md +0 -376
- package/docs/workflow.md +0 -818
- /package/dist/components/hooks/{useForm → useBDOForm}/createItemProxy.d.ts +0 -0
- /package/dist/components/hooks/{useForm → useBDOForm}/createResolver.d.ts +0 -0
- /package/docs/{useAuth.md → useAuth/README.md} +0 -0
- /package/sdk/components/hooks/{useForm → useBDOForm}/createItemProxy.ts +0 -0
- /package/sdk/components/hooks/{useForm → useBDOForm}/createResolver.ts +0 -0
package/docs/useBDOTable.md
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
# useBDOTable
|
|
2
|
-
|
|
3
|
-
Thin wrapper around `useTable` for BDO (Business Data Object) tables. Instead of manually wiring up `queryKey`, `listFn`, and `countFn`, you pass a BDO instance and the hook handles the rest.
|
|
4
|
-
|
|
5
|
-
## Imports
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { useBDOTable } from "@ram_28/kf-ai-sdk/table";
|
|
9
|
-
import { ConditionOperator, RHSType } from "@ram_28/kf-ai-sdk/table";
|
|
10
|
-
import type { UseBDOTableOptionsType, UseBDOTableReturnType } from "@ram_28/kf-ai-sdk/table/types";
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
## Common Mistakes (READ FIRST)
|
|
16
|
-
|
|
17
|
-
### 1. Passing `source` instead of `bdo`
|
|
18
|
-
|
|
19
|
-
`useBDOTable` takes a `bdo` instance, NOT a `source` string.
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
// ❌ WRONG — source is not a valid property on useBDOTable
|
|
23
|
-
useBDOTable({ source: product.meta._id });
|
|
24
|
-
|
|
25
|
-
// ✅ CORRECT — pass the BDO instance
|
|
26
|
-
useBDOTable({ bdo: product });
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### 2. Passing a raw object instead of a BDO instance
|
|
30
|
-
|
|
31
|
-
The `bdo` property expects an object with `meta`, `list()`, and `count()`. A plain object or entity type will not work.
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
// ❌ WRONG — plain object without list/count methods
|
|
35
|
-
useBDOTable({ bdo: { _id: 'BO_Product', name: 'Product' } });
|
|
36
|
-
|
|
37
|
-
// ✅ CORRECT — a BDO class instance
|
|
38
|
-
const product = useMemo(() => new BuyerProduct(), []);
|
|
39
|
-
useBDOTable({ bdo: product });
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
### 3. Recreating the BDO on every render
|
|
43
|
-
|
|
44
|
-
Constructing the BDO inside the component body without `useMemo` creates a new instance on every render, which destabilizes the query key and causes infinite refetching.
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
// ❌ WRONG — new instance every render
|
|
48
|
-
function ProductsTable() {
|
|
49
|
-
const product = new BuyerProduct();
|
|
50
|
-
const table = useBDOTable({ bdo: product }); // infinite refetch loop
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// ✅ CORRECT — memoize the instance
|
|
54
|
-
function ProductsTable() {
|
|
55
|
-
const product = useMemo(() => new BuyerProduct(), []);
|
|
56
|
-
const table = useBDOTable({ bdo: product });
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### 4. Using `columns` with useBDOTable
|
|
61
|
-
|
|
62
|
-
`useBDOTable` does not accept a `columns` property. Column definitions are a UI concern handled in your rendering logic, not in the hook options.
|
|
63
|
-
|
|
64
|
-
```typescript
|
|
65
|
-
// ❌ WRONG — columns is not a hook option
|
|
66
|
-
useBDOTable({
|
|
67
|
-
bdo: product,
|
|
68
|
-
columns: [{ fieldId: 'Title', label: 'Title' }],
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
// ✅ CORRECT — define columns separately for rendering
|
|
72
|
-
const columns = [
|
|
73
|
-
{ fieldId: product.Title.id, label: product.Title.label },
|
|
74
|
-
{ fieldId: product.Price.id, label: product.Price.label },
|
|
75
|
-
];
|
|
76
|
-
const table = useBDOTable({ bdo: product });
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### 5. Calling `.get()` on table rows
|
|
80
|
-
|
|
81
|
-
Table `rows` are plain objects, NOT `ItemType`. The `.get()` accessor is only available on items returned by `bdo.get()`, `bdo.create()`, or the `useForm` item proxy.
|
|
82
|
-
|
|
83
|
-
```typescript
|
|
84
|
-
// ❌ WRONG — rows are plain objects, not ItemType
|
|
85
|
-
table.rows.map((row) => row.Title.get());
|
|
86
|
-
|
|
87
|
-
// ✅ CORRECT — access properties directly
|
|
88
|
-
table.rows.map((row) => row.Title);
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### 6. Wrong initialState property names
|
|
92
|
-
|
|
93
|
-
This is not react-table. Do not use react-table naming conventions.
|
|
94
|
-
|
|
95
|
-
```typescript
|
|
96
|
-
// ❌ WRONG — sorting and pageIndex are react-table names
|
|
97
|
-
useBDOTable({
|
|
98
|
-
bdo: product,
|
|
99
|
-
initialState: { sorting: [...], pagination: { pageIndex: 0, pageSize: 10 } },
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// ✅ CORRECT — use sort and pageNo (1-indexed)
|
|
103
|
-
useBDOTable({
|
|
104
|
-
bdo: product,
|
|
105
|
-
initialState: {
|
|
106
|
-
sort: [{ [product.Title.id]: 'ASC' }],
|
|
107
|
-
pagination: { pageNo: 1, pageSize: 10 },
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
---
|
|
113
|
-
|
|
114
|
-
## Complete Example
|
|
115
|
-
|
|
116
|
-
A product listing page with search, filter, sort, and pagination.
|
|
117
|
-
|
|
118
|
-
```tsx
|
|
119
|
-
import { useMemo, useState } from "react";
|
|
120
|
-
import { useBDOTable } from "@ram_28/kf-ai-sdk/table";
|
|
121
|
-
import { ConditionOperator, RHSType } from "@ram_28/kf-ai-sdk/table";
|
|
122
|
-
import type { UseBDOTableReturnType } from "@ram_28/kf-ai-sdk/table/types";
|
|
123
|
-
import { BuyerProduct } from "../bdo/buyer/Product";
|
|
124
|
-
import type { BuyerProductFieldType } from "../bdo/buyer/Product";
|
|
125
|
-
|
|
126
|
-
function ProductListPage() {
|
|
127
|
-
const productBdo = useMemo(() => new BuyerProduct(), []);
|
|
128
|
-
const [selectedCategory, setSelectedCategory] = useState("all");
|
|
129
|
-
|
|
130
|
-
const table: UseBDOTableReturnType<BuyerProductFieldType> =
|
|
131
|
-
useBDOTable<BuyerProductFieldType>({
|
|
132
|
-
bdo: productBdo,
|
|
133
|
-
initialState: {
|
|
134
|
-
sort: [{ [productBdo.Title.id]: "ASC" }],
|
|
135
|
-
pagination: { pageNo: 1, pageSize: 10 },
|
|
136
|
-
},
|
|
137
|
-
onError: (error) => {
|
|
138
|
-
console.error("Table fetch failed:", error.message);
|
|
139
|
-
},
|
|
140
|
-
onSuccess: (data) => {
|
|
141
|
-
console.log("Loaded", data.length, "rows");
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const handleCategoryChange = (category: string) => {
|
|
146
|
-
setSelectedCategory(category);
|
|
147
|
-
table.filter.clearAllConditions();
|
|
148
|
-
if (category !== "all") {
|
|
149
|
-
table.filter.addCondition({
|
|
150
|
-
LHSField: productBdo.Category.id,
|
|
151
|
-
Operator: ConditionOperator.EQ,
|
|
152
|
-
RHSValue: category,
|
|
153
|
-
RHSType: RHSType.Constant,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
if (table.isLoading) return <div>Loading...</div>;
|
|
159
|
-
if (table.error) {
|
|
160
|
-
return (
|
|
161
|
-
<div>
|
|
162
|
-
<p>Error: {table.error.message}</p>
|
|
163
|
-
<button onClick={() => table.refetch()}>Retry</button>
|
|
164
|
-
</div>
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return (
|
|
169
|
-
<div>
|
|
170
|
-
{/* Search */}
|
|
171
|
-
<input
|
|
172
|
-
type="text"
|
|
173
|
-
placeholder="Search products..."
|
|
174
|
-
value={table.search.query}
|
|
175
|
-
onChange={(e) => table.search.set(productBdo.Title.id, e.target.value)}
|
|
176
|
-
/>
|
|
177
|
-
{table.search.query && (
|
|
178
|
-
<button onClick={table.search.clear}>Clear Search</button>
|
|
179
|
-
)}
|
|
180
|
-
|
|
181
|
-
{/* Category Filter */}
|
|
182
|
-
<select
|
|
183
|
-
value={selectedCategory}
|
|
184
|
-
onChange={(e) => handleCategoryChange(e.target.value)}
|
|
185
|
-
>
|
|
186
|
-
<option value="all">All Categories</option>
|
|
187
|
-
<option value="Electronics">Electronics</option>
|
|
188
|
-
<option value="Books">Books</option>
|
|
189
|
-
</select>
|
|
190
|
-
|
|
191
|
-
{/* Sort */}
|
|
192
|
-
<select
|
|
193
|
-
onChange={(e) => {
|
|
194
|
-
const [field, dir] = e.target.value.split(":");
|
|
195
|
-
table.sort.set(field, dir as "ASC" | "DESC");
|
|
196
|
-
}}
|
|
197
|
-
>
|
|
198
|
-
<option value={`${productBdo.Title.id}:ASC`}>Name A-Z</option>
|
|
199
|
-
<option value={`${productBdo.Price.id}:ASC`}>Price: Low to High</option>
|
|
200
|
-
<option value={`${productBdo.Price.id}:DESC`}>Price: High to Low</option>
|
|
201
|
-
</select>
|
|
202
|
-
|
|
203
|
-
{/* Results */}
|
|
204
|
-
<p>{table.totalItems} results</p>
|
|
205
|
-
<div>
|
|
206
|
-
{table.rows.map((row) => (
|
|
207
|
-
<div key={row._id}>
|
|
208
|
-
<h3>{row.Title}</h3>
|
|
209
|
-
<p>${row.Price}</p>
|
|
210
|
-
<p>{row.Category}</p>
|
|
211
|
-
</div>
|
|
212
|
-
))}
|
|
213
|
-
</div>
|
|
214
|
-
|
|
215
|
-
{/* Pagination */}
|
|
216
|
-
<div>
|
|
217
|
-
<button
|
|
218
|
-
onClick={table.pagination.goToPrevious}
|
|
219
|
-
disabled={!table.pagination.canGoPrevious}
|
|
220
|
-
>
|
|
221
|
-
Previous
|
|
222
|
-
</button>
|
|
223
|
-
<span>
|
|
224
|
-
Page {table.pagination.pageNo} of {table.pagination.totalPages}
|
|
225
|
-
</span>
|
|
226
|
-
<button
|
|
227
|
-
onClick={table.pagination.goToNext}
|
|
228
|
-
disabled={!table.pagination.canGoNext}
|
|
229
|
-
>
|
|
230
|
-
Next
|
|
231
|
-
</button>
|
|
232
|
-
</div>
|
|
233
|
-
</div>
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
---
|
|
239
|
-
|
|
240
|
-
## Type Definitions
|
|
241
|
-
|
|
242
|
-
### UseBDOTableOptionsType
|
|
243
|
-
|
|
244
|
-
```typescript
|
|
245
|
-
export interface UseBDOTableOptionsType<T> {
|
|
246
|
-
/** BDO instance with list() and count() methods */
|
|
247
|
-
bdo: {
|
|
248
|
-
meta: { readonly _id: string; readonly name: string };
|
|
249
|
-
list(options?: any): Promise<any>;
|
|
250
|
-
count(options?: any): Promise<any>;
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
/** Initial state */
|
|
254
|
-
initialState?: {
|
|
255
|
-
sort?: SortType;
|
|
256
|
-
pagination?: PaginationStateType;
|
|
257
|
-
filter?: UseFilterOptionsType<T>;
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
/** Error callback */
|
|
261
|
-
onError?: (error: Error) => void;
|
|
262
|
-
|
|
263
|
-
/** Success callback — receives rows from current page */
|
|
264
|
-
onSuccess?: (data: T[]) => void;
|
|
265
|
-
}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
### UseBDOTableReturnType
|
|
269
|
-
|
|
270
|
-
```typescript
|
|
271
|
-
export type UseBDOTableReturnType<T> = UseTableReturnType<T>;
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
The return type is identical to `UseTableReturnType<T>`. All properties — `rows`, `totalItems`, `isLoading`, `isFetching`, `error`, `search`, `sort`, `filter`, `pagination`, and `refetch` — behave the same.
|
|
275
|
-
|
|
276
|
-
---
|
|
277
|
-
|
|
278
|
-
## Search, Sort, Filter, and Pagination
|
|
279
|
-
|
|
280
|
-
These features are inherited from the base `useTable` hook. `useBDOTable` passes `initialState`, `onError`, and `onSuccess` straight through.
|
|
281
|
-
|
|
282
|
-
- **Search** — `table.search.set(field, query)`, `table.search.clear()`, 300ms debounce
|
|
283
|
-
- **Sort** — `table.sort.toggle(field)`, `table.sort.set(field, direction)`, `table.sort.clear()`
|
|
284
|
-
- **Filter** — `table.filter.addCondition(...)`, `table.filter.removeCondition(...)`, `table.filter.clearAllConditions()`
|
|
285
|
-
- **Pagination** — `table.pagination.goToNext()`, `table.pagination.goToPrevious()`, `table.pagination.goToPage(n)`, `table.pagination.setPageSize(n)`
|
|
286
|
-
|
|
287
|
-
---
|
|
288
|
-
|
|
289
|
-
## Migration Guide: `useTable` to `useBDOTable`
|
|
290
|
-
|
|
291
|
-
### Before (useTable)
|
|
292
|
-
|
|
293
|
-
```typescript
|
|
294
|
-
const table = useTable<BuyerProductFieldType>({
|
|
295
|
-
queryKey: ["table", product.meta._id],
|
|
296
|
-
listFn: (opts) => product.list(opts),
|
|
297
|
-
countFn: (opts) => product.count(opts),
|
|
298
|
-
initialState: { sort: [{ [product.Title.id]: "ASC" }], pagination: { pageNo: 1, pageSize: 10 } },
|
|
299
|
-
});
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
### After (useBDOTable)
|
|
303
|
-
|
|
304
|
-
```typescript
|
|
305
|
-
const table = useBDOTable<BuyerProductFieldType>({
|
|
306
|
-
bdo: product,
|
|
307
|
-
initialState: { sort: [{ [product.Title.id]: "ASC" }], pagination: { pageNo: 1, pageSize: 10 } },
|
|
308
|
-
});
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
| Property | `useTable` | `useBDOTable` |
|
|
312
|
-
|----------|-----------|---------------|
|
|
313
|
-
| Data source | `queryKey` + `listFn` + `countFn` | `bdo` (single property) |
|
|
314
|
-
| Query key | Manual: `["table", bdo.meta._id]` | Automatic: derived from `bdo.meta._id` |
|
|
315
|
-
| List function | Manual: `(opts) => bdo.list(opts)` | Automatic: bound from `bdo.list()` |
|
|
316
|
-
| Count function | Manual: `(opts) => bdo.count(opts)` | Automatic: bound from `bdo.count()` |
|
|
317
|
-
| Return type | `UseTableReturnType<T>` | `UseBDOTableReturnType<T>` (alias) |
|
package/docs/useFilter.md
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
# Filter SDK API
|
|
2
|
-
|
|
3
|
-
React hook for building filter conditions for tables, forms, and API calls.
|
|
4
|
-
|
|
5
|
-
## Imports
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { useFilter, isCondition, isConditionGroup, ConditionOperator, GroupOperator, FilterValueSource } from "@ram_28/kf-ai-sdk/filter";
|
|
9
|
-
import type { UseFilterOptionsType, UseFilterReturnType, ConditionType, ConditionGroupType, FilterType } from "@ram_28/kf-ai-sdk/filter/types";
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## Common Mistakes (READ FIRST)
|
|
15
|
-
|
|
16
|
-
### 1. Importing `RHSType` instead of `FilterValueSource`
|
|
17
|
-
|
|
18
|
-
There is NO named export `RHSType`. Import `FilterValueSource`. The JSON key IS called `RHSType`, but the value comes from `FilterValueSource`.
|
|
19
|
-
|
|
20
|
-
```typescript
|
|
21
|
-
// ❌ WRONG — RHSType is not an importable enum
|
|
22
|
-
import { RHSType } from "@ram_28/kf-ai-sdk/filter";
|
|
23
|
-
|
|
24
|
-
// ✅ CORRECT
|
|
25
|
-
import { FilterValueSource } from "@ram_28/kf-ai-sdk/filter";
|
|
26
|
-
{ RHSType: FilterValueSource.Constant }
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### 2. Wrong field name casing in ConditionType
|
|
30
|
-
|
|
31
|
-
`ConditionType` uses **PascalCase**: `Operator`, `LHSField`, `RHSValue`, `RHSType`. NOT camelCase.
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
// ❌ WRONG — camelCase
|
|
35
|
-
{ operator: "EQ", lhsField: "status", rhsValue: "Active" }
|
|
36
|
-
|
|
37
|
-
// ✅ CORRECT — PascalCase
|
|
38
|
-
{ Operator: ConditionOperator.EQ, LHSField: bdo.status.id, RHSValue: "Active", RHSType: FilterValueSource.Constant }
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### 3. Mixing hook init format with API format
|
|
42
|
-
|
|
43
|
-
Hook init (`UseFilterOptionsType`) uses lowercase `conditions`/`operator`. API format (`FilterType`/`ConditionType`) uses uppercase `Condition`/`Operator`.
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
// Hook initialization — lowercase
|
|
47
|
-
useTable({ initialState: { filter: { conditions: [...], operator: "And" } } });
|
|
48
|
-
|
|
49
|
-
// API calls — uppercase
|
|
50
|
-
bdo.list({ Filter: { Operator: "And", Condition: [...] } });
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
### 4. Hardcoded operator strings
|
|
54
|
-
|
|
55
|
-
ALWAYS use `ConditionOperator` constants. NEVER write `"Equals"`, `"equals"`, or `"eq"`.
|
|
56
|
-
|
|
57
|
-
```typescript
|
|
58
|
-
// ❌ WRONG
|
|
59
|
-
{ Operator: "Equals" } { Operator: "equals" } { Operator: "eq" }
|
|
60
|
-
|
|
61
|
-
// ✅ CORRECT
|
|
62
|
-
{ Operator: ConditionOperator.EQ } // "EQ"
|
|
63
|
-
{ Operator: ConditionOperator.Contains } // "Contains"
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### 5. Accessing `filter.conditions` instead of `filter.items`
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
// ❌ WRONG — conditions does NOT exist
|
|
70
|
-
filter.conditions.length
|
|
71
|
-
|
|
72
|
-
// ✅ CORRECT
|
|
73
|
-
filter.items.length
|
|
74
|
-
filter.hasConditions // boolean shortcut
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### 6. Using `as const` on Operator values
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
// ❌ WRONG — causes narrowing errors in arrays
|
|
81
|
-
[{ Operator: ConditionOperator.EQ as const, ... }]
|
|
82
|
-
|
|
83
|
-
// ✅ CORRECT — type the array
|
|
84
|
-
const conditions: Omit<ConditionType, "id">[] = [{ Operator: ConditionOperator.EQ, ... }];
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
---
|
|
88
|
-
|
|
89
|
-
## Constants
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
// Condition operators
|
|
93
|
-
ConditionOperator.EQ ConditionOperator.NE // Equal, Not Equal
|
|
94
|
-
ConditionOperator.GT ConditionOperator.GTE // Greater Than (or Equal)
|
|
95
|
-
ConditionOperator.LT ConditionOperator.LTE // Less Than (or Equal)
|
|
96
|
-
ConditionOperator.Contains ConditionOperator.NotContains // String contains
|
|
97
|
-
ConditionOperator.IN ConditionOperator.NIN // Value in/not-in list
|
|
98
|
-
ConditionOperator.Empty ConditionOperator.NotEmpty // Null/empty check
|
|
99
|
-
ConditionOperator.Between ConditionOperator.NotBetween // Range
|
|
100
|
-
|
|
101
|
-
// Group operators
|
|
102
|
-
GroupOperator.And GroupOperator.Or GroupOperator.Not
|
|
103
|
-
|
|
104
|
-
// RHS value source (KEY is "RHSType", VALUE from FilterValueSource)
|
|
105
|
-
FilterValueSource.Constant // "Constant" — literal value
|
|
106
|
-
FilterValueSource.BDOField // "BDOField" — compare against another field
|
|
107
|
-
FilterValueSource.AppVariable // "AppVariable" — app variable
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## Type Definitions
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
interface ConditionType<T = any> {
|
|
116
|
-
id?: string; // Auto-generated
|
|
117
|
-
Operator: ConditionOperatorType; // PascalCase
|
|
118
|
-
LHSField: keyof T | string;
|
|
119
|
-
RHSValue: any;
|
|
120
|
-
RHSType?: "Constant" | "BDOField" | "AppVariable";
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
interface ConditionGroupType<T = any> {
|
|
124
|
-
id?: string;
|
|
125
|
-
Operator: "And" | "Or" | "Not";
|
|
126
|
-
Condition: Array<ConditionType<T> | ConditionGroupType<T>>;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
interface UseFilterOptionsType<T = any> { // lowercase — hook init
|
|
130
|
-
conditions?: Array<ConditionType<T> | ConditionGroupType<T>>;
|
|
131
|
-
operator?: "And" | "Or" | "Not";
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
interface UseFilterReturnType<T = any> {
|
|
135
|
-
operator: "And" | "Or" | "Not";
|
|
136
|
-
items: Array<ConditionType<T> | ConditionGroupType<T>>;
|
|
137
|
-
payload: FilterType<T> | undefined; // API-ready, undefined if empty
|
|
138
|
-
hasConditions: boolean;
|
|
139
|
-
addCondition: (condition: Omit<ConditionType<T>, "id">, parentId?: string) => string;
|
|
140
|
-
addConditionGroup: (operator: "And" | "Or" | "Not", parentId?: string) => string;
|
|
141
|
-
updateCondition: (id: string, updates: Partial<Omit<ConditionType<T>, "id">>) => void;
|
|
142
|
-
removeCondition: (id: string) => void;
|
|
143
|
-
clearAllConditions: () => void;
|
|
144
|
-
setRootOperator: (op: "And" | "Or" | "Not") => void;
|
|
145
|
-
}
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
---
|
|
149
|
-
|
|
150
|
-
## Usage Example
|
|
151
|
-
|
|
152
|
-
```tsx
|
|
153
|
-
import { useFilter, ConditionOperator, GroupOperator, FilterValueSource } from "@ram_28/kf-ai-sdk/filter";
|
|
154
|
-
import type { UseFilterOptionsType } from "@ram_28/kf-ai-sdk/filter/types";
|
|
155
|
-
|
|
156
|
-
// Standalone filter
|
|
157
|
-
const filter = useFilter<AdminProductFieldType>();
|
|
158
|
-
filter.addCondition({ Operator: ConditionOperator.EQ, LHSField: bdo.status.id, RHSValue: "Active", RHSType: FilterValueSource.Constant });
|
|
159
|
-
filter.addCondition({ Operator: ConditionOperator.GT, LHSField: bdo.unit_price.id, RHSValue: 100, RHSType: FilterValueSource.Constant });
|
|
160
|
-
|
|
161
|
-
// With useTable initialState
|
|
162
|
-
const table = useTable<AdminProductFieldType>({
|
|
163
|
-
source: bdo.meta._id,
|
|
164
|
-
columns,
|
|
165
|
-
initialState: {
|
|
166
|
-
filter: {
|
|
167
|
-
conditions: [
|
|
168
|
-
{ Operator: ConditionOperator.EQ, LHSField: "_created_by", RHSValue: user._id, RHSType: FilterValueSource.Constant },
|
|
169
|
-
],
|
|
170
|
-
operator: GroupOperator.And,
|
|
171
|
-
},
|
|
172
|
-
},
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
// Dynamic filter with useEffect
|
|
176
|
-
useEffect(() => {
|
|
177
|
-
table.filter.clearAllConditions();
|
|
178
|
-
if (status !== "all") {
|
|
179
|
-
table.filter.addCondition({ Operator: ConditionOperator.EQ, LHSField: bdo.status.id, RHSValue: status, RHSType: FilterValueSource.Constant });
|
|
180
|
-
}
|
|
181
|
-
}, [status]);
|
|
182
|
-
|
|
183
|
-
// Nested: Category = "Electronics" AND (Price < 100 OR OnSale = true)
|
|
184
|
-
filter.addCondition({ Operator: ConditionOperator.EQ, LHSField: bdo.category.id, RHSValue: "Electronics", RHSType: FilterValueSource.Constant });
|
|
185
|
-
const orGroupId = filter.addConditionGroup(GroupOperator.Or);
|
|
186
|
-
filter.addCondition({ Operator: ConditionOperator.LT, LHSField: bdo.price.id, RHSValue: 100, RHSType: FilterValueSource.Constant }, orGroupId);
|
|
187
|
-
filter.addCondition({ Operator: ConditionOperator.EQ, LHSField: bdo.on_sale.id, RHSValue: true, RHSType: FilterValueSource.Constant }, orGroupId);
|
|
188
|
-
```
|