@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
|
@@ -8,17 +8,20 @@
|
|
|
8
8
|
import { useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
|
9
9
|
import { useForm as useReactHookForm } from 'react-hook-form';
|
|
10
10
|
import { useQuery } from '@tanstack/react-query';
|
|
11
|
-
import type { Path, FieldValues } from 'react-hook-form';
|
|
12
11
|
|
|
13
12
|
import type { Activity } from '../../../workflow/Activity';
|
|
14
|
-
import type {
|
|
15
|
-
UseActivityFormOptions,
|
|
16
|
-
UseActivityFormReturn,
|
|
17
|
-
AllActivityFields,
|
|
18
|
-
} from './types';
|
|
13
|
+
import type { UseActivityFormOptions, UseActivityFormReturn } from './types';
|
|
19
14
|
|
|
15
|
+
import type { CreateUpdateResponseType } from '../../../types/common';
|
|
20
16
|
import { createActivityResolver } from './createActivityResolver';
|
|
21
17
|
import { createActivityItemProxy } from './createActivityItemProxy';
|
|
18
|
+
import {
|
|
19
|
+
coerceFieldValue,
|
|
20
|
+
coerceRecordForForm,
|
|
21
|
+
createSyncField,
|
|
22
|
+
createEnhancedRegister,
|
|
23
|
+
createEnhancedControl,
|
|
24
|
+
} from '../useBDOForm/shared';
|
|
22
25
|
import { toError } from '../../../utils/error-handling';
|
|
23
26
|
import { getBdoSchema } from '../../../api/metadata';
|
|
24
27
|
import {
|
|
@@ -28,66 +31,6 @@ import {
|
|
|
28
31
|
} from '../../../workflow/createFieldFromMeta';
|
|
29
32
|
import type { BaseField } from '../../../bdo/fields/BaseField';
|
|
30
33
|
|
|
31
|
-
// ============================================================
|
|
32
|
-
// FIELD VALUE COERCION (HTML inputs return strings)
|
|
33
|
-
// ============================================================
|
|
34
|
-
|
|
35
|
-
/** Coerce form value to match field's expected type before sending to API */
|
|
36
|
-
function coerceFieldValue(
|
|
37
|
-
field: BaseField<unknown>,
|
|
38
|
-
value: unknown,
|
|
39
|
-
): unknown {
|
|
40
|
-
const type = field.meta.Type;
|
|
41
|
-
// Number: string → number
|
|
42
|
-
if (typeof value === 'string' && type === 'Number') {
|
|
43
|
-
return value === '' ? undefined : Number(value);
|
|
44
|
-
}
|
|
45
|
-
// Date/DateTime: empty string → undefined
|
|
46
|
-
if (
|
|
47
|
-
typeof value === 'string' &&
|
|
48
|
-
value === '' &&
|
|
49
|
-
(type === 'Date' || type === 'DateTime')
|
|
50
|
-
) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
// DateTime: normalize to HH:MM:SS and ensure Z suffix
|
|
54
|
-
if (typeof value === 'string' && value !== '' && type === 'DateTime') {
|
|
55
|
-
let normalized = value;
|
|
56
|
-
if (normalized.endsWith('Z')) normalized = normalized.slice(0, -1);
|
|
57
|
-
const timePart = normalized.split('T')[1] || '';
|
|
58
|
-
if ((timePart.match(/:/g) || []).length === 1) {
|
|
59
|
-
normalized += ':00';
|
|
60
|
-
}
|
|
61
|
-
return normalized + 'Z';
|
|
62
|
-
}
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// ============================================================
|
|
67
|
-
// RECORD COERCION (strip trailing Z from DateTime for HTML inputs)
|
|
68
|
-
// ============================================================
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Coerce record values for form display.
|
|
72
|
-
* Strips trailing 'Z' from DateTime values so `<input type="datetime-local">` works.
|
|
73
|
-
*/
|
|
74
|
-
function coerceRecordForForm(
|
|
75
|
-
fields: Record<string, BaseField<unknown>>,
|
|
76
|
-
data: Record<string, unknown>,
|
|
77
|
-
): Record<string, unknown> {
|
|
78
|
-
const result = { ...data };
|
|
79
|
-
for (const [key, value] of Object.entries(result)) {
|
|
80
|
-
if (
|
|
81
|
-
typeof value === 'string' &&
|
|
82
|
-
fields[key]?.meta.Type === 'DateTime' &&
|
|
83
|
-
value.endsWith('Z')
|
|
84
|
-
) {
|
|
85
|
-
result[key] = value.slice(0, -1);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
34
|
// ============================================================
|
|
92
35
|
// MAIN HOOK
|
|
93
36
|
// ============================================================
|
|
@@ -303,160 +246,64 @@ export function useActivityForm<A extends Activity<any, any, any>>(
|
|
|
303
246
|
}, [enabled, isMetadataLoading, activityRef, activity_instance_id]);
|
|
304
247
|
|
|
305
248
|
// ============================================================
|
|
306
|
-
//
|
|
249
|
+
// PER-FIELD SYNC (shared with useBDOForm)
|
|
307
250
|
// ============================================================
|
|
308
251
|
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
const isValid = await rhf.trigger(fieldName as Path<FieldValues>);
|
|
316
|
-
if (!isValid) return;
|
|
317
|
-
|
|
318
|
-
const rawValue = rhf.getValues(fieldName as any);
|
|
319
|
-
const field = allFields[fieldName];
|
|
320
|
-
const value = field
|
|
321
|
-
? coerceFieldValue(field, rawValue)
|
|
322
|
-
: rawValue;
|
|
323
|
-
|
|
324
|
-
const response = await activityRef.update(activity_instance_id, {
|
|
325
|
-
[fieldName]: value,
|
|
326
|
-
} as any);
|
|
327
|
-
|
|
328
|
-
// Field saved — reset dirty state so it's not re-sent on submit
|
|
329
|
-
rhf.resetField(fieldName as Path<FieldValues>, {
|
|
330
|
-
defaultValue: rawValue,
|
|
331
|
-
keepTouched: true,
|
|
332
|
-
keepError: true,
|
|
333
|
-
} as any);
|
|
334
|
-
|
|
335
|
-
// Update computed/readonly fields from response
|
|
336
|
-
if (response && typeof response === 'object') {
|
|
337
|
-
const responseData =
|
|
338
|
-
(response as any).Data ?? (response as any);
|
|
339
|
-
if (responseData && typeof responseData === 'object') {
|
|
340
|
-
const readonlySet = new Set(readonlyFieldNames);
|
|
341
|
-
for (const key of Object.keys(responseData)) {
|
|
342
|
-
if (readonlySet.has(key) && responseData[key] !== undefined) {
|
|
343
|
-
const current = rhf.getValues(key as any);
|
|
344
|
-
if (current !== responseData[key]) {
|
|
345
|
-
rhf.setValue(
|
|
346
|
-
key as Path<FieldValues>,
|
|
347
|
-
responseData[key] as any,
|
|
348
|
-
{ shouldDirty: false, shouldValidate: false },
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
} catch (error) {
|
|
356
|
-
console.warn('syncField failed:', error);
|
|
357
|
-
} finally {
|
|
358
|
-
isComputingRef.current = false;
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
[activityRef, readonlyFieldNames, allFields, rhf, activity_instance_id],
|
|
252
|
+
const syncApiFn = useCallback(
|
|
253
|
+
(fieldName: string, value: unknown) =>
|
|
254
|
+
activityRef.update(activity_instance_id, {
|
|
255
|
+
[fieldName]: value,
|
|
256
|
+
} as any),
|
|
257
|
+
[activityRef, activity_instance_id],
|
|
362
258
|
);
|
|
363
259
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
260
|
+
const syncField = useMemo(
|
|
261
|
+
() =>
|
|
262
|
+
createSyncField({
|
|
263
|
+
apiFn: syncApiFn,
|
|
264
|
+
allFields,
|
|
265
|
+
readonlyFieldNames,
|
|
266
|
+
rhf,
|
|
267
|
+
isComputingRef,
|
|
268
|
+
}),
|
|
269
|
+
[syncApiFn, allFields, readonlyFieldNames, rhf],
|
|
270
|
+
);
|
|
368
271
|
|
|
369
272
|
const syncOnChange = mode === 'onChange' || mode === 'all';
|
|
370
|
-
const syncOnBlur =
|
|
273
|
+
const syncOnBlur =
|
|
274
|
+
mode === 'onBlur' || mode === 'onTouched' || mode === 'all';
|
|
371
275
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
const result = rhf.register(name as Path<FieldValues>, {
|
|
382
|
-
...registerOptions,
|
|
383
|
-
...(syncOnBlur
|
|
384
|
-
? {
|
|
385
|
-
onBlur: async (e: any) => {
|
|
386
|
-
await registerOptions?.onBlur?.(e);
|
|
387
|
-
await syncField(name);
|
|
388
|
-
},
|
|
389
|
-
}
|
|
390
|
-
: {}),
|
|
391
|
-
...(syncOnChange
|
|
392
|
-
? {
|
|
393
|
-
onChange: async (e: any) => {
|
|
394
|
-
await registerOptions?.onChange?.(e);
|
|
395
|
-
await syncField(name);
|
|
396
|
-
},
|
|
397
|
-
}
|
|
398
|
-
: {}),
|
|
399
|
-
...(isReadonly ? { disabled: true } : {}),
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
if (isReadonly) {
|
|
403
|
-
return { ...result, disabled: true as const };
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return result;
|
|
407
|
-
},
|
|
276
|
+
const register = useMemo(
|
|
277
|
+
() =>
|
|
278
|
+
createEnhancedRegister({
|
|
279
|
+
rhf,
|
|
280
|
+
allFields,
|
|
281
|
+
syncField,
|
|
282
|
+
syncOnBlur,
|
|
283
|
+
syncOnChange,
|
|
284
|
+
}),
|
|
408
285
|
[rhf, allFields, syncField, syncOnBlur, syncOnChange],
|
|
409
286
|
) as UseActivityFormReturn<A>['register'];
|
|
410
287
|
|
|
411
|
-
// ============================================================
|
|
412
|
-
// ENHANCED CONTROL (for Controller — same sync behavior as register)
|
|
413
|
-
// ============================================================
|
|
414
|
-
|
|
415
288
|
const enhancedControl = useMemo(
|
|
416
289
|
() =>
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const originalOnChange = result.onChange;
|
|
423
|
-
const originalOnBlur = result.onBlur;
|
|
424
|
-
|
|
425
|
-
return {
|
|
426
|
-
...result,
|
|
427
|
-
...(syncOnChange
|
|
428
|
-
? {
|
|
429
|
-
onChange: async (event: any) => {
|
|
430
|
-
await originalOnChange(event);
|
|
431
|
-
await syncField(name);
|
|
432
|
-
},
|
|
433
|
-
}
|
|
434
|
-
: {}),
|
|
435
|
-
...(syncOnBlur
|
|
436
|
-
? {
|
|
437
|
-
onBlur: async (event: any) => {
|
|
438
|
-
await originalOnBlur(event);
|
|
439
|
-
await syncField(name);
|
|
440
|
-
},
|
|
441
|
-
}
|
|
442
|
-
: {}),
|
|
443
|
-
};
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
return Reflect.get(target, prop, receiver);
|
|
447
|
-
},
|
|
290
|
+
createEnhancedControl({
|
|
291
|
+
control: rhf.control,
|
|
292
|
+
syncField,
|
|
293
|
+
syncOnBlur,
|
|
294
|
+
syncOnChange,
|
|
448
295
|
}),
|
|
449
|
-
[rhf.control, syncField,
|
|
296
|
+
[rhf.control, syncField, syncOnBlur, syncOnChange],
|
|
450
297
|
);
|
|
451
298
|
|
|
452
299
|
// ============================================================
|
|
453
|
-
// HANDLE SUBMIT — activity.update()
|
|
300
|
+
// HANDLE SUBMIT — activity.update() + activity.complete()
|
|
454
301
|
// ============================================================
|
|
455
302
|
|
|
456
303
|
const handleSubmit = useCallback(
|
|
457
304
|
(
|
|
458
305
|
onSuccess?: (
|
|
459
|
-
data:
|
|
306
|
+
data: CreateUpdateResponseType,
|
|
460
307
|
e?: React.BaseSyntheticEvent,
|
|
461
308
|
) => void | Promise<void>,
|
|
462
309
|
onError?: (
|
|
@@ -469,7 +316,7 @@ export function useActivityForm<A extends Activity<any, any, any>>(
|
|
|
469
316
|
setIsSubmitting(true);
|
|
470
317
|
|
|
471
318
|
try {
|
|
472
|
-
// Only send dirty (changed) fields — matches
|
|
319
|
+
// Only send dirty (changed) fields — matches useBDOForm behavior
|
|
473
320
|
// Use getValues() to capture Image/File values set via setValue()
|
|
474
321
|
// that RHF resolver doesn't include in `data`
|
|
475
322
|
const cleanedData: Record<string, unknown> = {};
|
|
@@ -489,7 +336,7 @@ export function useActivityForm<A extends Activity<any, any, any>>(
|
|
|
489
336
|
: value;
|
|
490
337
|
}
|
|
491
338
|
|
|
492
|
-
//
|
|
339
|
+
// Send remaining dirty fields via update
|
|
493
340
|
if (Object.keys(cleanedData).length > 0) {
|
|
494
341
|
await activityRef.update(
|
|
495
342
|
activity_instance_id,
|
|
@@ -497,69 +344,10 @@ export function useActivityForm<A extends Activity<any, any, any>>(
|
|
|
497
344
|
);
|
|
498
345
|
}
|
|
499
346
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
onError?.(toError(error), event);
|
|
503
|
-
} finally {
|
|
504
|
-
setIsSubmitting(false);
|
|
505
|
-
}
|
|
506
|
-
},
|
|
507
|
-
(errors, event) => {
|
|
508
|
-
onError?.(errors, event);
|
|
509
|
-
},
|
|
510
|
-
);
|
|
511
|
-
},
|
|
512
|
-
[rhf, activityRef, readonlyFieldNames, allFields, activity_instance_id],
|
|
513
|
-
) as UseActivityFormReturn<A>['handleSubmit'];
|
|
347
|
+
// Complete the activity — advances the workflow
|
|
348
|
+
const result = await activityRef.complete(activity_instance_id);
|
|
514
349
|
|
|
515
|
-
|
|
516
|
-
// HANDLE COMPLETE — activity.update() + activity.complete()
|
|
517
|
-
// ============================================================
|
|
518
|
-
|
|
519
|
-
const handleComplete = useCallback(
|
|
520
|
-
(
|
|
521
|
-
onSuccess?: (
|
|
522
|
-
data: AllActivityFields<A>,
|
|
523
|
-
e?: React.BaseSyntheticEvent,
|
|
524
|
-
) => void | Promise<void>,
|
|
525
|
-
onError?: (
|
|
526
|
-
error: any,
|
|
527
|
-
e?: React.BaseSyntheticEvent,
|
|
528
|
-
) => void | Promise<void>,
|
|
529
|
-
) => {
|
|
530
|
-
return rhf.handleSubmit(
|
|
531
|
-
async (data, event) => {
|
|
532
|
-
setIsSubmitting(true);
|
|
533
|
-
|
|
534
|
-
try {
|
|
535
|
-
// Only send dirty (changed) fields — matches useForm update behavior
|
|
536
|
-
// Use getValues() to capture Image/File values set via setValue()
|
|
537
|
-
// that RHF resolver doesn't include in `data`
|
|
538
|
-
const cleanedData: Record<string, unknown> = {};
|
|
539
|
-
const readonlySet = new Set(readonlyFieldNames);
|
|
540
|
-
const dirtyFields = rhf.formState.dirtyFields;
|
|
541
|
-
const allValues = rhf.getValues() as Record<string, unknown>;
|
|
542
|
-
|
|
543
|
-
for (const key of Object.keys(allValues)) {
|
|
544
|
-
if (readonlySet.has(key) || !dirtyFields[key]) continue;
|
|
545
|
-
const value =
|
|
546
|
-
allValues[key] !== undefined
|
|
547
|
-
? allValues[key]
|
|
548
|
-
: (data as Record<string, unknown>)[key];
|
|
549
|
-
const field = allFields[key];
|
|
550
|
-
cleanedData[key] = field
|
|
551
|
-
? coerceFieldValue(field, value)
|
|
552
|
-
: value;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
if (Object.keys(cleanedData).length > 0) {
|
|
556
|
-
await activityRef.update(
|
|
557
|
-
activity_instance_id,
|
|
558
|
-
cleanedData as any,
|
|
559
|
-
);
|
|
560
|
-
}
|
|
561
|
-
await activityRef.complete(activity_instance_id);
|
|
562
|
-
await onSuccess?.(data as AllActivityFields<A>, event);
|
|
350
|
+
await onSuccess?.(result, event);
|
|
563
351
|
} catch (error) {
|
|
564
352
|
onError?.(toError(error), event);
|
|
565
353
|
} finally {
|
|
@@ -572,7 +360,7 @@ export function useActivityForm<A extends Activity<any, any, any>>(
|
|
|
572
360
|
);
|
|
573
361
|
},
|
|
574
362
|
[rhf, activityRef, readonlyFieldNames, allFields, activity_instance_id],
|
|
575
|
-
) as UseActivityFormReturn<A>['
|
|
363
|
+
) as UseActivityFormReturn<A>['handleSubmit'];
|
|
576
364
|
|
|
577
365
|
// ============================================================
|
|
578
366
|
// CLEAR ERRORS
|
|
@@ -598,7 +386,6 @@ export function useActivityForm<A extends Activity<any, any, any>>(
|
|
|
598
386
|
// Form methods
|
|
599
387
|
register,
|
|
600
388
|
handleSubmit,
|
|
601
|
-
handleComplete,
|
|
602
389
|
watch: rhf.watch as any,
|
|
603
390
|
setValue: rhf.setValue as any,
|
|
604
391
|
getValues: rhf.getValues as any,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Activity } from '../../../workflow/Activity';
|
|
2
|
-
import type { ActivityInstanceFieldsType } from '../../../workflow/types';
|
|
3
2
|
import type { UseTableReturnType, PaginationStateType } from '../useTable/types';
|
|
4
3
|
import type { UseFilterOptionsType } from '../useFilter/types';
|
|
5
4
|
import type { SortType } from '../../../types/common';
|
|
@@ -16,17 +15,19 @@ export type ActivityTableStatusType =
|
|
|
16
15
|
(typeof ActivityTableStatus)[keyof typeof ActivityTableStatus];
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
|
-
* Row type
|
|
20
|
-
*
|
|
18
|
+
* Row type — inferred from Activity's getInProgressList() return type.
|
|
19
|
+
* Resolves to ActivityInstanceType (proxy with .get()/.set()).
|
|
21
20
|
*/
|
|
22
21
|
export type ActivityRowType<A extends Activity<any, any, any>> =
|
|
23
|
-
A extends
|
|
24
|
-
?
|
|
22
|
+
A extends { getInProgressList(opts?: any): Promise<(infer R)[]> }
|
|
23
|
+
? R
|
|
25
24
|
: never;
|
|
26
25
|
|
|
27
26
|
export interface UseActivityTableOptionsType<
|
|
28
27
|
A extends Activity<any, any, any>,
|
|
29
28
|
> {
|
|
29
|
+
/** The activity instance to fetch data for */
|
|
30
|
+
activity: A;
|
|
30
31
|
/** Which operation — determines endpoint (inprogress vs completed) */
|
|
31
32
|
status: ActivityTableStatusType;
|
|
32
33
|
/** Initial state */
|
|
@@ -7,59 +7,30 @@ import type {
|
|
|
7
7
|
ActivityRowType,
|
|
8
8
|
} from './types';
|
|
9
9
|
|
|
10
|
-
const ACTIVITY_SYSTEM_FIELDS = new Set([
|
|
11
|
-
'_id',
|
|
12
|
-
'BPInstanceId',
|
|
13
|
-
'Status',
|
|
14
|
-
'AssignedTo',
|
|
15
|
-
'CompletedAt',
|
|
16
|
-
]);
|
|
17
|
-
|
|
18
|
-
function nestEntityFields(
|
|
19
|
-
flatRow: Record<string, unknown>,
|
|
20
|
-
): Record<string, unknown> {
|
|
21
|
-
const result: Record<string, unknown> = {};
|
|
22
|
-
const ado: Record<string, unknown> = {};
|
|
23
|
-
for (const [key, value] of Object.entries(flatRow)) {
|
|
24
|
-
if (ACTIVITY_SYSTEM_FIELDS.has(key)) {
|
|
25
|
-
result[key] = value;
|
|
26
|
-
} else {
|
|
27
|
-
ado[key] = value;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
result.ADO = ado;
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
10
|
export function useActivityTable<A extends Activity<any, any, any>>(
|
|
35
|
-
activity: A,
|
|
36
11
|
options: UseActivityTableOptionsType<A>,
|
|
37
12
|
): UseActivityTableReturnType<A> {
|
|
38
|
-
const { status, ...rest } = options;
|
|
13
|
+
const { activity, status, ...rest } = options;
|
|
39
14
|
const { businessProcessId, activityId } = activity.meta;
|
|
40
15
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const listFn = useMemo(() => {
|
|
44
|
-
const rawFn =
|
|
16
|
+
const listFn = useMemo(
|
|
17
|
+
() =>
|
|
45
18
|
status === 'inprogress'
|
|
46
|
-
? (opts: any) =>
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
}, [ops, status]);
|
|
19
|
+
? async (opts: any) => ({
|
|
20
|
+
Data: (await activity.getInProgressList(opts)) as ActivityRowType<A>[],
|
|
21
|
+
})
|
|
22
|
+
: async (opts: any) => ({
|
|
23
|
+
Data: (await activity.getCompletedList(opts)) as ActivityRowType<A>[],
|
|
24
|
+
}),
|
|
25
|
+
[activity, status],
|
|
26
|
+
);
|
|
56
27
|
|
|
57
28
|
const countFn = useMemo(
|
|
58
29
|
() =>
|
|
59
30
|
status === 'inprogress'
|
|
60
|
-
? (opts: any) =>
|
|
61
|
-
: (opts: any) =>
|
|
62
|
-
[
|
|
31
|
+
? async (opts: any) => ({ Count: await activity.inProgressCount(opts) })
|
|
32
|
+
: async (opts: any) => ({ Count: await activity.completedCount(opts) }),
|
|
33
|
+
[activity, status],
|
|
63
34
|
);
|
|
64
35
|
|
|
65
36
|
return useTable<ActivityRowType<A>>({
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { useBDOForm } from "./useBDOForm";
|
|
2
2
|
export { createResolver } from "./createResolver";
|
|
3
3
|
export { createItemProxy } from "./createItemProxy";
|
|
4
|
+
export { coerceFieldValue, coerceRecordForForm } from "./shared";
|
|
4
5
|
export type {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
UseBDOFormOptionsType,
|
|
7
|
+
UseBDOFormReturnType,
|
|
7
8
|
FormItemType,
|
|
8
9
|
EditableFormFieldAccessorType,
|
|
9
10
|
ReadonlyFormFieldAccessorType,
|