@ram_28/kf-ai-sdk 2.0.15 → 2.0.16
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 +8 -8
- package/dist/bdo/core/BaseBdo.d.ts +1 -1
- package/dist/bdo.mjs +2 -2
- 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 +2 -2
- 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 +4 -4
- 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 +1 -3
- package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +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 +12 -11
- package/dist/types/constants.d.ts +3 -3
- package/dist/workflow/Activity.d.ts +15 -3
- 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 +503 -546
- package/docs/bdo.md +1 -1
- package/docs/gaps.md +14 -64
- package/docs/useActivityForm.md +393 -0
- package/docs/useActivityTable.md +42 -105
- package/docs/{useForm.md → useBDOForm.md} +24 -24
- package/docs/useBDOTable.md +6 -39
- package/docs/workflow.md +43 -301
- package/package.json +2 -2
- 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 +4 -4
- package/sdk/components/hooks/useActivityForm/useActivityForm.ts +44 -194
- package/sdk/components/hooks/useActivityTable/types.ts +4 -2
- package/sdk/components/hooks/useActivityTable/useActivityTable.ts +8 -39
- 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 +1 -3
- package/sdk/components/hooks/useBDOTable/useBDOTable.ts +3 -2
- package/sdk/form.ts +2 -2
- package/sdk/form.types.ts +4 -4
- package/sdk/types/constants.ts +3 -3
- package/sdk/workflow/Activity.ts +29 -6
- 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/createResolver-AIgUwoS6.cjs +0 -1
- package/dist/createResolver-ZHXQ7QMa.js +0 -1078
- /package/dist/components/hooks/{useForm → useBDOForm}/createItemProxy.d.ts +0 -0
- /package/dist/components/hooks/{useForm → useBDOForm}/createResolver.d.ts +0 -0
- /package/sdk/components/hooks/{useForm → useBDOForm}/createItemProxy.ts +0 -0
- /package/sdk/components/hooks/{useForm → useBDOForm}/createResolver.ts +0 -0
package/docs/workflow.md
CHANGED
|
@@ -97,62 +97,12 @@ type ActivityInstanceFieldsType = {
|
|
|
97
97
|
|
|
98
98
|
See the dedicated [useActivityTable documentation](./useActivityTable.md) for `ActivityTableStatus`, `ActivityRowType`, `UseActivityTableOptionsType`, and `UseActivityTableReturnType`.
|
|
99
99
|
|
|
100
|
-
|
|
100
|
+
Entity fields and system fields are flat at the top level, same as BDO tables. Access entity fields as `row.FieldName`.
|
|
101
101
|
|
|
102
102
|
|
|
103
|
-
### UseActivityFormOptions\<A\>
|
|
103
|
+
### UseActivityFormOptions\<A\> / UseActivityFormReturn\<A\>
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
interface UseActivityFormOptions<A extends Activity<any, any, any>> {
|
|
107
|
-
/** Activity instance identifier (from wf.start() or getInProgressList()) */
|
|
108
|
-
activity_instance_id: string;
|
|
109
|
-
|
|
110
|
-
/** Default form values */
|
|
111
|
-
defaultValues?: Partial<ExtractActivityEditable<A>>;
|
|
112
|
-
|
|
113
|
-
/** Validation mode (default: "onBlur") */
|
|
114
|
-
mode?: "onBlur" | "onChange" | "onSubmit" | "onTouched" | "all";
|
|
115
|
-
|
|
116
|
-
/** Whether to load activity data on mount (default: true) */
|
|
117
|
-
enabled?: boolean;
|
|
118
|
-
}
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### UseActivityFormReturn\<A\>
|
|
122
|
-
|
|
123
|
-
```typescript
|
|
124
|
-
interface UseActivityFormReturn<A extends Activity<any, any, any>> {
|
|
125
|
-
// Core
|
|
126
|
-
item: FormItemType<EditableFields, ReadonlyFields>;
|
|
127
|
-
activity: A;
|
|
128
|
-
register: FormRegisterType<EditableFields, ReadonlyFields>;
|
|
129
|
-
handleSubmit: HandleSubmitType; // Save the activity form
|
|
130
|
-
handleComplete: HandleSubmitType; // Complete the activity
|
|
131
|
-
|
|
132
|
-
// RHF methods
|
|
133
|
-
watch: UseFormWatch;
|
|
134
|
-
setValue: UseFormSetValue;
|
|
135
|
-
getValues: UseFormGetValues;
|
|
136
|
-
reset: UseFormReset;
|
|
137
|
-
trigger: UseFormTrigger;
|
|
138
|
-
control: Control;
|
|
139
|
-
|
|
140
|
-
// Form state
|
|
141
|
-
errors: FieldErrors;
|
|
142
|
-
isValid: boolean;
|
|
143
|
-
isDirty: boolean;
|
|
144
|
-
isSubmitting: boolean;
|
|
145
|
-
isSubmitSuccessful: boolean;
|
|
146
|
-
|
|
147
|
-
// Loading
|
|
148
|
-
isLoading: boolean;
|
|
149
|
-
loadError: Error | null;
|
|
150
|
-
hasError: boolean;
|
|
151
|
-
|
|
152
|
-
// Operations
|
|
153
|
-
clearErrors: () => void;
|
|
154
|
-
}
|
|
155
|
-
```
|
|
105
|
+
See the dedicated [useActivityForm documentation](./useActivityForm.md) for the full type definitions.
|
|
156
106
|
|
|
157
107
|
### File & Image Types
|
|
158
108
|
|
|
@@ -303,22 +253,46 @@ for (const item of result.Data) {
|
|
|
303
253
|
}
|
|
304
254
|
```
|
|
305
255
|
|
|
306
|
-
###
|
|
256
|
+
### inProgressCount(options?)
|
|
307
257
|
|
|
308
|
-
Get count of in-progress activity instances. Returns `
|
|
258
|
+
Get count of in-progress activity instances. Returns `number`.
|
|
309
259
|
|
|
310
260
|
```typescript
|
|
311
|
-
const
|
|
312
|
-
console.log('In-progress count:',
|
|
261
|
+
const count = await activity.inProgressCount();
|
|
262
|
+
console.log('In-progress count:', count);
|
|
313
263
|
```
|
|
314
264
|
|
|
315
|
-
###
|
|
265
|
+
### completedCount(options?)
|
|
316
266
|
|
|
317
|
-
Get count of completed activity instances. Returns `
|
|
267
|
+
Get count of completed activity instances. Returns `number`.
|
|
318
268
|
|
|
319
269
|
```typescript
|
|
320
|
-
const
|
|
321
|
-
console.log('Completed count:',
|
|
270
|
+
const count = await activity.completedCount();
|
|
271
|
+
console.log('Completed count:', count);
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### inProgressMetric(options)
|
|
275
|
+
|
|
276
|
+
Get aggregated metrics for in-progress activity instances. Accepts `Omit<MetricOptionsType, 'Type'>` for custom aggregations (Sum, Avg, Count, etc.). Returns `MetricResponseType` (`{ Data: Record<string, any>[] }`).
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
const result = await activity.inProgressMetric({
|
|
280
|
+
GroupBy: ['Status'],
|
|
281
|
+
Metric: [{ Field: '_id', Type: 'Count' }],
|
|
282
|
+
});
|
|
283
|
+
console.log(result.Data);
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### completedMetric(options)
|
|
287
|
+
|
|
288
|
+
Get aggregated metrics for completed activity instances. Same signature as `inProgressMetric`.
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
const result = await activity.completedMetric({
|
|
292
|
+
GroupBy: [],
|
|
293
|
+
Metric: [{ Field: 'LeaveDays', Type: 'Sum' }],
|
|
294
|
+
});
|
|
295
|
+
console.log('Total leave days:', result.Data[0]?.sum_LeaveDays);
|
|
322
296
|
```
|
|
323
297
|
|
|
324
298
|
### getInstance(instanceId)
|
|
@@ -351,65 +325,7 @@ const progress = await instance.progress(); // get progress (ActivityP
|
|
|
351
325
|
|
|
352
326
|
## useActivityForm Hook
|
|
353
327
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
### Options
|
|
357
|
-
|
|
358
|
-
| Property | Type | Default | Description |
|
|
359
|
-
|----------|------|---------|-------------|
|
|
360
|
-
| `activity_instance_id` | `string` | *required* | Activity instance ID (from `wf.start()` or `getInProgressList()`) |
|
|
361
|
-
| `defaultValues` | `Partial<Editable>` | `{}` | Initial form values |
|
|
362
|
-
| `mode` | `"onBlur" \| "onChange" \| "onSubmit" \| "onTouched" \| "all"` | `"onBlur"` | Validation timing |
|
|
363
|
-
| `enabled` | `boolean` | `true` | Whether to load activity data on mount |
|
|
364
|
-
|
|
365
|
-
### Lifecycle
|
|
366
|
-
|
|
367
|
-
```
|
|
368
|
-
Mount
|
|
369
|
-
|
|
|
370
|
-
|-> Load activity instance data -> populate form
|
|
371
|
-
|
|
|
372
|
-
v
|
|
373
|
-
User edits field -> blurs
|
|
374
|
-
|
|
|
375
|
-
|-> Field validation (BaseField.validate)
|
|
376
|
-
|-> If valid + readonly fields exist -> update computed fields
|
|
377
|
-
|
|
|
378
|
-
v
|
|
379
|
-
User clicks Save
|
|
380
|
-
|
|
|
381
|
-
|-> handleSubmit -> save activity data
|
|
382
|
-
|
|
|
383
|
-
v
|
|
384
|
-
User clicks Complete
|
|
385
|
-
|
|
|
386
|
-
|-> handleComplete -> complete activity
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
### Return Value
|
|
390
|
-
|
|
391
|
-
| Property | Type | Description |
|
|
392
|
-
|----------|------|-------------|
|
|
393
|
-
| `item` | `FormItemType` | Proxy with typed field accessors (`.get()`, `.set()`, `.meta`) |
|
|
394
|
-
| `activity` | `A` | The Activity instance |
|
|
395
|
-
| `register` | `FormRegisterType` | Smart register (auto-disables readonly fields) |
|
|
396
|
-
| `handleSubmit` | `HandleSubmitType` | Save activity data |
|
|
397
|
-
| `handleComplete` | `HandleSubmitType` | Complete the activity |
|
|
398
|
-
| `watch` | `UseFormWatch` | Watch field values |
|
|
399
|
-
| `setValue` | `UseFormSetValue` | Set field value programmatically |
|
|
400
|
-
| `getValues` | `UseFormGetValues` | Get current field values |
|
|
401
|
-
| `reset` | `UseFormReset` | Reset form to default values |
|
|
402
|
-
| `trigger` | `UseFormTrigger` | Trigger validation |
|
|
403
|
-
| `control` | `Control` | RHF control (for Controller components) |
|
|
404
|
-
| `errors` | `FieldErrors` | Validation errors |
|
|
405
|
-
| `isValid` | `boolean` | Form is valid |
|
|
406
|
-
| `isDirty` | `boolean` | Form has been modified |
|
|
407
|
-
| `isSubmitting` | `boolean` | Currently submitting |
|
|
408
|
-
| `isSubmitSuccessful` | `boolean` | Last submission succeeded |
|
|
409
|
-
| `isLoading` | `boolean` | Loading activity data |
|
|
410
|
-
| `loadError` | `Error \| null` | Load error |
|
|
411
|
-
| `hasError` | `boolean` | Any error active |
|
|
412
|
-
| `clearErrors` | `() => void` | Clear all form errors |
|
|
328
|
+
See the dedicated [useActivityForm documentation](./useActivityForm.md) for the full API reference, type definitions, and examples.
|
|
413
329
|
|
|
414
330
|
---
|
|
415
331
|
|
|
@@ -417,7 +333,7 @@ User clicks Complete
|
|
|
417
333
|
|
|
418
334
|
See the dedicated [useActivityTable documentation](./useActivityTable.md) for the full API reference, type definitions, and examples.
|
|
419
335
|
|
|
420
|
-
`useActivityTable`
|
|
336
|
+
`useActivityTable` provides search, sort, filter, and pagination capabilities, same as `useBDOTable`. Entity fields are accessed at the top level (e.g., `row.FieldName`).
|
|
421
337
|
|
|
422
338
|
---
|
|
423
339
|
|
|
@@ -439,115 +355,7 @@ const progress = await wf.progress(BPInstanceId);
|
|
|
439
355
|
|
|
440
356
|
### Step 2 — React component with useActivityForm
|
|
441
357
|
|
|
442
|
-
|
|
443
|
-
import { useMemo } from "react";
|
|
444
|
-
import { useActivityForm } from "@ram_28/kf-ai-sdk/workflow";
|
|
445
|
-
import type { UseActivityFormOptions } from "@ram_28/kf-ai-sdk/workflow";
|
|
446
|
-
import type { FieldErrors } from "react-hook-form";
|
|
447
|
-
import { SimpleLeaveProcess, EmployeeInputActivity } from "@/bdo/workflows/SimpleLeaveProcess";
|
|
448
|
-
|
|
449
|
-
interface LeaveRequestFormProps {
|
|
450
|
-
activityInstanceId: string;
|
|
451
|
-
onComplete: () => void;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
function LeaveRequestForm({ activityInstanceId, onComplete }: LeaveRequestFormProps) {
|
|
455
|
-
// 1. Get the typed activity from the workflow
|
|
456
|
-
const activity = useMemo(() => new SimpleLeaveProcess().employeeInputActivity(), []);
|
|
457
|
-
|
|
458
|
-
// 2. Hook options
|
|
459
|
-
const options: UseActivityFormOptions<EmployeeInputActivity> = {
|
|
460
|
-
activity_instance_id: activityInstanceId,
|
|
461
|
-
defaultValues: {
|
|
462
|
-
StartDate: undefined,
|
|
463
|
-
EndDate: undefined,
|
|
464
|
-
LeaveType: undefined,
|
|
465
|
-
},
|
|
466
|
-
mode: "onBlur",
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
// 3. Initialize hook
|
|
470
|
-
const {
|
|
471
|
-
register,
|
|
472
|
-
handleSubmit,
|
|
473
|
-
handleComplete,
|
|
474
|
-
item,
|
|
475
|
-
errors,
|
|
476
|
-
isLoading,
|
|
477
|
-
isSubmitting,
|
|
478
|
-
loadError,
|
|
479
|
-
} = useActivityForm(activity, options);
|
|
480
|
-
|
|
481
|
-
if (isLoading) return <div>Loading...</div>;
|
|
482
|
-
if (loadError) return <div>Error: {loadError.message}</div>;
|
|
483
|
-
|
|
484
|
-
// 4. Handlers
|
|
485
|
-
const onSaveSuccess = (): void => {
|
|
486
|
-
console.log("Saved!");
|
|
487
|
-
};
|
|
488
|
-
|
|
489
|
-
const onCompleteSuccess = (): void => {
|
|
490
|
-
console.log("Leave request submitted!");
|
|
491
|
-
onComplete();
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
const onError = (error: FieldErrors | Error): void => {
|
|
495
|
-
if (error instanceof Error) {
|
|
496
|
-
console.error("API Error:", error.message);
|
|
497
|
-
} else {
|
|
498
|
-
console.error("Validation errors:", error);
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
return (
|
|
503
|
-
<form>
|
|
504
|
-
<h2>Leave Request</h2>
|
|
505
|
-
|
|
506
|
-
{/* Start Date */}
|
|
507
|
-
<div>
|
|
508
|
-
<label>{activity.StartDate.label}</label>
|
|
509
|
-
<input type="date" {...register(activity.StartDate.id)} />
|
|
510
|
-
{errors.StartDate && <span>{errors.StartDate.message}</span>}
|
|
511
|
-
</div>
|
|
512
|
-
|
|
513
|
-
{/* End Date */}
|
|
514
|
-
<div>
|
|
515
|
-
<label>{activity.EndDate.label}</label>
|
|
516
|
-
<input type="date" {...register(activity.EndDate.id)} />
|
|
517
|
-
{errors.EndDate && <span>{errors.EndDate.message}</span>}
|
|
518
|
-
</div>
|
|
519
|
-
|
|
520
|
-
{/* Leave Type */}
|
|
521
|
-
<div>
|
|
522
|
-
<label>{activity.LeaveType.label}</label>
|
|
523
|
-
<select {...register(activity.LeaveType.id)}>
|
|
524
|
-
<option value="">Select type</option>
|
|
525
|
-
<option value="PTO">PTO</option>
|
|
526
|
-
<option value="Sick">Sick</option>
|
|
527
|
-
<option value="Parental">Parental</option>
|
|
528
|
-
</select>
|
|
529
|
-
{errors.LeaveType && <span>{errors.LeaveType.message}</span>}
|
|
530
|
-
</div>
|
|
531
|
-
|
|
532
|
-
{/* Leave Days (readonly — auto-disabled, computed by server) */}
|
|
533
|
-
<div>
|
|
534
|
-
<label>{activity.LeaveDays.label}</label>
|
|
535
|
-
<input type="number" {...register(activity.LeaveDays.id)} />
|
|
536
|
-
</div>
|
|
537
|
-
|
|
538
|
-
{/* Actions */}
|
|
539
|
-
<div>
|
|
540
|
-
<button type="button" onClick={handleSubmit(onSaveSuccess, onError)}>
|
|
541
|
-
{isSubmitting ? "Saving..." : "Save Draft"}
|
|
542
|
-
</button>
|
|
543
|
-
<button type="button" onClick={handleComplete(onCompleteSuccess, onError)}>
|
|
544
|
-
{isSubmitting ? "Submitting..." : "Submit Leave Request"}
|
|
545
|
-
</button>
|
|
546
|
-
</div>
|
|
547
|
-
</form>
|
|
548
|
-
);
|
|
549
|
-
}
|
|
550
|
-
```
|
|
358
|
+
See [useActivityForm](./useActivityForm.md) for the full form component example.
|
|
551
359
|
|
|
552
360
|
### Full flow orchestration
|
|
553
361
|
|
|
@@ -592,7 +400,8 @@ import { SimpleLeaveProcess, ManagerApprovalActivity } from "@/bdo/workflows/Sim
|
|
|
592
400
|
const wf = new SimpleLeaveProcess();
|
|
593
401
|
const activity = wf.managerApprovalActivity();
|
|
594
402
|
|
|
595
|
-
const { rows, totalItems, isLoading, error, pagination, refetch } = useActivityTable(
|
|
403
|
+
const { rows, totalItems, isLoading, error, pagination, refetch } = useActivityTable({
|
|
404
|
+
activity,
|
|
596
405
|
status: ActivityTableStatus.InProgress,
|
|
597
406
|
initialState: {
|
|
598
407
|
pagination: { pageNo: 1, pageSize: 10 },
|
|
@@ -634,8 +443,8 @@ const activity = wf.managerApprovalActivity();
|
|
|
634
443
|
<td>{row._id}</td>
|
|
635
444
|
<td>{row.Status}</td>
|
|
636
445
|
<td>{row.AssignedTo.map((u) => u._name).join(", ")}</td>
|
|
637
|
-
<td>{row.
|
|
638
|
-
<td>{row.
|
|
446
|
+
<td>{row.ManagerApproved ? "Yes" : "No"}</td>
|
|
447
|
+
<td>{row.ManagerReason}</td>
|
|
639
448
|
<td>
|
|
640
449
|
<button onClick={() => setSelectedId(row._id)}>Review</button>
|
|
641
450
|
</td>
|
|
@@ -655,74 +464,7 @@ const activity = wf.managerApprovalActivity();
|
|
|
655
464
|
|
|
656
465
|
### Step 2 — Approval form component
|
|
657
466
|
|
|
658
|
-
|
|
659
|
-
import { useMemo } from "react";
|
|
660
|
-
import { useActivityForm } from "@ram_28/kf-ai-sdk/workflow";
|
|
661
|
-
import type { UseActivityFormOptions } from "@ram_28/kf-ai-sdk/workflow";
|
|
662
|
-
import type { FieldErrors } from "react-hook-form";
|
|
663
|
-
import { SimpleLeaveProcess, ManagerApprovalActivity } from "@/bdo/workflows/SimpleLeaveProcess";
|
|
664
|
-
|
|
665
|
-
interface ApprovalFormProps {
|
|
666
|
-
activityInstanceId: string;
|
|
667
|
-
onComplete: () => void;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
function ApprovalForm({ activityInstanceId, onComplete }: ApprovalFormProps) {
|
|
671
|
-
const activity = useMemo(() => new SimpleLeaveProcess().managerApprovalActivity(), []);
|
|
672
|
-
|
|
673
|
-
const options: UseActivityFormOptions<ManagerApprovalActivity> = {
|
|
674
|
-
activity_instance_id: activityInstanceId,
|
|
675
|
-
defaultValues: {
|
|
676
|
-
ManagerApproved: false,
|
|
677
|
-
ManagerReason: "",
|
|
678
|
-
},
|
|
679
|
-
mode: "onBlur",
|
|
680
|
-
};
|
|
681
|
-
|
|
682
|
-
const {
|
|
683
|
-
register,
|
|
684
|
-
handleComplete,
|
|
685
|
-
errors,
|
|
686
|
-
isLoading,
|
|
687
|
-
isSubmitting,
|
|
688
|
-
loadError,
|
|
689
|
-
} = useActivityForm(activity, options);
|
|
690
|
-
|
|
691
|
-
if (isLoading) return <div>Loading...</div>;
|
|
692
|
-
if (loadError) return <div>Error: {loadError.message}</div>;
|
|
693
|
-
|
|
694
|
-
const onSuccess = (): void => {
|
|
695
|
-
console.log("Approval submitted!");
|
|
696
|
-
onComplete();
|
|
697
|
-
};
|
|
698
|
-
|
|
699
|
-
const onError = (error: FieldErrors | Error): void => {
|
|
700
|
-
if (error instanceof Error) console.error("API Error:", error.message);
|
|
701
|
-
};
|
|
702
|
-
|
|
703
|
-
return (
|
|
704
|
-
<form>
|
|
705
|
-
<h2>Leave Approval</h2>
|
|
706
|
-
|
|
707
|
-
<div>
|
|
708
|
-
<label>
|
|
709
|
-
<input type="checkbox" {...register(activity.ManagerApproved.id)} />
|
|
710
|
-
{activity.ManagerApproved.label}
|
|
711
|
-
</label>
|
|
712
|
-
</div>
|
|
713
|
-
|
|
714
|
-
<div>
|
|
715
|
-
<label>{activity.ManagerReason.label}</label>
|
|
716
|
-
<textarea {...register(activity.ManagerReason.id)} rows={4} />
|
|
717
|
-
</div>
|
|
718
|
-
|
|
719
|
-
<button type="button" onClick={handleComplete(onSuccess, onError)}>
|
|
720
|
-
{isSubmitting ? "Submitting..." : "Submit Decision"}
|
|
721
|
-
</button>
|
|
722
|
-
</form>
|
|
723
|
-
);
|
|
724
|
-
}
|
|
725
|
-
```
|
|
467
|
+
See [useActivityForm](./useActivityForm.md) for the full approval form component example.
|
|
726
468
|
|
|
727
469
|
---
|
|
728
470
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ram_28/kf-ai-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "Type-safe, AI-driven SDK for building modern web applications with role-based access control",
|
|
5
5
|
"author": "Ramprasad",
|
|
6
6
|
"license": "MIT",
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
"react",
|
|
190
190
|
"hooks",
|
|
191
191
|
"typescript",
|
|
192
|
-
"
|
|
192
|
+
"useBDOForm",
|
|
193
193
|
"useTable",
|
|
194
194
|
"useFilter",
|
|
195
195
|
"bdo",
|
package/sdk/bdo/core/BaseBdo.ts
CHANGED
|
@@ -127,7 +127,7 @@ export abstract class BaseBdo<
|
|
|
127
127
|
/**
|
|
128
128
|
* Load backend metadata for expression-based validation
|
|
129
129
|
*
|
|
130
|
-
* Called by
|
|
130
|
+
* Called by useBDOForm after fetching schema from the backend.
|
|
131
131
|
* This enables expression-based validation rules to be used
|
|
132
132
|
* in addition to type validation.
|
|
133
133
|
*
|
|
@@ -241,7 +241,7 @@ export abstract class BaseBdo<
|
|
|
241
241
|
}
|
|
242
242
|
|
|
243
243
|
// ============================================================
|
|
244
|
-
// DRAFT OPERATIONS (for
|
|
244
|
+
// DRAFT OPERATIONS (for useBDOForm integration)
|
|
245
245
|
// ============================================================
|
|
246
246
|
|
|
247
247
|
/**
|
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
FormItemType,
|
|
19
19
|
EditableFormFieldAccessorType,
|
|
20
20
|
ReadonlyFormFieldAccessorType,
|
|
21
|
-
} from '../
|
|
21
|
+
} from '../useBDOForm/types';
|
|
22
22
|
import type { Activity } from '../../../workflow/Activity';
|
|
23
23
|
import type {
|
|
24
24
|
ExtractActivityEditable,
|
|
@@ -10,7 +10,7 @@ import type { FieldValues } from 'react-hook-form';
|
|
|
10
10
|
import type { Activity } from '../../../workflow/Activity';
|
|
11
11
|
import type { BaseField } from '../../../bdo/fields/BaseField';
|
|
12
12
|
import type { ValidationResultType } from '../../../bdo/core/types';
|
|
13
|
-
import { validateConstraints } from '../
|
|
13
|
+
import { validateConstraints } from '../useBDOForm/createResolver';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Creates a React Hook Form resolver for Activity field validation.
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// TYPE DEFINITIONS FOR useActivityForm HOOK
|
|
3
3
|
// ============================================================
|
|
4
4
|
// BDO-aligned types for the Activity pattern.
|
|
5
|
-
// Reuses shared types from
|
|
5
|
+
// Reuses shared types from useBDOForm where identical.
|
|
6
6
|
|
|
7
7
|
import type {
|
|
8
8
|
UseFormWatch,
|
|
@@ -16,14 +16,14 @@ import type {
|
|
|
16
16
|
|
|
17
17
|
import type { Activity } from '../../../workflow/Activity';
|
|
18
18
|
|
|
19
|
-
// Reuse shared types from
|
|
19
|
+
// Reuse shared types from useBDOForm — identical interfaces, no duplication
|
|
20
20
|
import type {
|
|
21
21
|
HandleSubmitType,
|
|
22
22
|
FormItemType,
|
|
23
23
|
FormRegisterType,
|
|
24
24
|
EditableFormFieldAccessorType,
|
|
25
25
|
ReadonlyFormFieldAccessorType,
|
|
26
|
-
} from '../
|
|
26
|
+
} from '../useBDOForm/types';
|
|
27
27
|
|
|
28
28
|
// Re-export for consumers who import from this module
|
|
29
29
|
export type {
|
|
@@ -89,7 +89,7 @@ export interface UseActivityFormOptions<A extends Activity<any, any, any>> {
|
|
|
89
89
|
// ============================================================
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
|
-
* useActivityForm hook return type — mirrors
|
|
92
|
+
* useActivityForm hook return type — mirrors useBDOForm return structure
|
|
93
93
|
*/
|
|
94
94
|
export interface UseActivityFormReturn<A extends Activity<any, any, any>> {
|
|
95
95
|
/** Item proxy with typed field accessors */
|