@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.
Files changed (130) hide show
  1. package/README.md +22 -14
  2. package/dist/api.cjs +1 -1
  3. package/dist/api.mjs +1 -1
  4. package/dist/auth/authConfig.d.ts +1 -1
  5. package/dist/auth/types.d.ts +1 -1
  6. package/dist/auth/types.d.ts.map +1 -1
  7. package/dist/auth.cjs +1 -1
  8. package/dist/auth.mjs +1 -1
  9. package/dist/bdo/core/BaseBdo.d.ts +1 -1
  10. package/dist/bdo.cjs +1 -1
  11. package/dist/bdo.mjs +3 -3
  12. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts +1 -1
  13. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts.map +1 -1
  14. package/dist/components/hooks/useActivityForm/types.d.ts +6 -7
  15. package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
  16. package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
  17. package/dist/components/hooks/useActivityTable/types.d.ts +7 -6
  18. package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
  19. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts +1 -1
  20. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
  21. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -0
  22. package/dist/components/hooks/useBDOForm/createResolver.d.ts.map +1 -0
  23. package/dist/components/hooks/useBDOForm/index.d.ts +6 -0
  24. package/dist/components/hooks/useBDOForm/index.d.ts.map +1 -0
  25. package/dist/components/hooks/useBDOForm/shared.d.ts +50 -0
  26. package/dist/components/hooks/useBDOForm/shared.d.ts.map +1 -0
  27. package/dist/components/hooks/{useForm → useBDOForm}/types.d.ts +6 -6
  28. package/dist/components/hooks/useBDOForm/types.d.ts.map +1 -0
  29. package/dist/components/hooks/{useForm/useForm.d.ts → useBDOForm/useBDOForm.d.ts} +4 -4
  30. package/dist/components/hooks/useBDOForm/useBDOForm.d.ts.map +1 -0
  31. package/dist/components/hooks/useBDOTable/types.d.ts +20 -14
  32. package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
  33. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +2 -2
  34. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
  35. package/dist/{constants-ConHc1oS.js → constants-Cyi942Yr.js} +5 -5
  36. package/dist/constants-DEmYwKfC.cjs +1 -0
  37. package/dist/filter.cjs +1 -1
  38. package/dist/filter.mjs +1 -1
  39. package/dist/form.cjs +1 -1
  40. package/dist/form.d.ts +1 -1
  41. package/dist/form.d.ts.map +1 -1
  42. package/dist/form.mjs +250 -253
  43. package/dist/form.types.d.ts +1 -1
  44. package/dist/form.types.d.ts.map +1 -1
  45. package/dist/shared-5a7UkED1.js +1180 -0
  46. package/dist/shared-nnmlRVs7.cjs +1 -0
  47. package/dist/table.cjs +1 -1
  48. package/dist/table.mjs +14 -14
  49. package/dist/table.types.d.ts +1 -1
  50. package/dist/table.types.d.ts.map +1 -1
  51. package/dist/types/constants.d.ts +4 -4
  52. package/dist/workflow/Activity.d.ts +22 -7
  53. package/dist/workflow/Activity.d.ts.map +1 -1
  54. package/dist/workflow/client.d.ts +2 -2
  55. package/dist/workflow/client.d.ts.map +1 -1
  56. package/dist/workflow/types.d.ts +7 -3
  57. package/dist/workflow/types.d.ts.map +1 -1
  58. package/dist/workflow.cjs +1 -1
  59. package/dist/workflow.mjs +518 -576
  60. package/docs/README.md +51 -0
  61. package/docs/bdo/README.md +161 -0
  62. package/docs/bdo/api_reference.md +281 -0
  63. package/docs/examples/bdo/create-product.md +69 -0
  64. package/docs/examples/bdo/edit-product-dialog.md +95 -0
  65. package/docs/examples/bdo/filtered-product-table.md +100 -0
  66. package/docs/examples/bdo/product-listing.md +73 -0
  67. package/docs/examples/bdo/supplier-dropdown.md +60 -0
  68. package/docs/examples/workflow/approve-leave-request.md +76 -0
  69. package/docs/examples/workflow/filtered-activity-table.md +101 -0
  70. package/docs/examples/workflow/my-pending-requests.md +90 -0
  71. package/docs/examples/workflow/start-new-workflow.md +47 -0
  72. package/docs/examples/workflow/submit-leave-request.md +72 -0
  73. package/docs/examples/workflow/workflow-progress.md +49 -0
  74. package/docs/useActivityForm/README.md +241 -0
  75. package/docs/useActivityForm/api_reference.md +279 -0
  76. package/docs/useActivityTable/README.md +263 -0
  77. package/docs/useActivityTable/api_reference.md +294 -0
  78. package/docs/useBDOForm/README.md +172 -0
  79. package/docs/useBDOForm/api_reference.md +244 -0
  80. package/docs/useBDOTable/README.md +242 -0
  81. package/docs/useBDOTable/api_reference.md +253 -0
  82. package/docs/useFilter/README.md +323 -0
  83. package/docs/useFilter/api_reference.md +228 -0
  84. package/docs/workflow/README.md +158 -0
  85. package/docs/workflow/api_reference.md +161 -0
  86. package/package.json +2 -2
  87. package/sdk/auth/authConfig.ts +1 -1
  88. package/sdk/auth/types.ts +1 -1
  89. package/sdk/bdo/core/BaseBdo.ts +2 -2
  90. package/sdk/components/hooks/useActivityForm/createActivityItemProxy.ts +1 -1
  91. package/sdk/components/hooks/useActivityForm/createActivityResolver.ts +1 -1
  92. package/sdk/components/hooks/useActivityForm/types.ts +8 -10
  93. package/sdk/components/hooks/useActivityForm/useActivityForm.ts +52 -265
  94. package/sdk/components/hooks/useActivityTable/types.ts +6 -5
  95. package/sdk/components/hooks/useActivityTable/useActivityTable.ts +14 -43
  96. package/sdk/components/hooks/{useForm → useBDOForm}/index.ts +4 -3
  97. package/sdk/components/hooks/useBDOForm/shared.ts +250 -0
  98. package/sdk/components/hooks/{useForm → useBDOForm}/types.ts +9 -9
  99. package/sdk/components/hooks/{useForm/useForm.ts → useBDOForm/useBDOForm.ts} +70 -96
  100. package/sdk/components/hooks/useBDOTable/types.ts +20 -12
  101. package/sdk/components/hooks/useBDOTable/useBDOTable.ts +12 -7
  102. package/sdk/form.ts +2 -2
  103. package/sdk/form.types.ts +4 -4
  104. package/sdk/table.types.ts +2 -0
  105. package/sdk/types/constants.ts +4 -4
  106. package/sdk/workflow/Activity.ts +68 -13
  107. package/sdk/workflow/client.ts +65 -25
  108. package/sdk/workflow/types.ts +10 -2
  109. package/dist/components/hooks/useForm/createItemProxy.d.ts.map +0 -1
  110. package/dist/components/hooks/useForm/createResolver.d.ts.map +0 -1
  111. package/dist/components/hooks/useForm/index.d.ts +0 -5
  112. package/dist/components/hooks/useForm/index.d.ts.map +0 -1
  113. package/dist/components/hooks/useForm/types.d.ts.map +0 -1
  114. package/dist/components/hooks/useForm/useForm.d.ts.map +0 -1
  115. package/dist/constants-QX2RX-wu.cjs +0 -1
  116. package/dist/createResolver-AIgUwoS6.cjs +0 -1
  117. package/dist/createResolver-ZHXQ7QMa.js +0 -1078
  118. package/docs/api.md +0 -95
  119. package/docs/bdo.md +0 -224
  120. package/docs/gaps.md +0 -410
  121. package/docs/useActivityTable.md +0 -481
  122. package/docs/useBDOTable.md +0 -317
  123. package/docs/useFilter.md +0 -188
  124. package/docs/useForm.md +0 -376
  125. package/docs/workflow.md +0 -818
  126. /package/dist/components/hooks/{useForm → useBDOForm}/createItemProxy.d.ts +0 -0
  127. /package/dist/components/hooks/{useForm → useBDOForm}/createResolver.d.ts +0 -0
  128. /package/docs/{useAuth.md → useAuth/README.md} +0 -0
  129. /package/sdk/components/hooks/{useForm → useBDOForm}/createItemProxy.ts +0 -0
  130. /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
- // SYNC FIELD validate + send single field value to API
249
+ // PER-FIELD SYNC (shared with useBDOForm)
307
250
  // ============================================================
308
251
 
309
- const syncField = useCallback(
310
- async (fieldName: string) => {
311
- if (isComputingRef.current) return;
312
- isComputingRef.current = true;
313
-
314
- try {
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
- // MODE-AWARE HANDLER ENHANCEMENT
366
- // Injects syncField into onChange/onBlur based on consumer's mode
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 = mode === 'onBlur' || mode === 'onTouched' || mode === 'all';
273
+ const syncOnBlur =
274
+ mode === 'onBlur' || mode === 'onTouched' || mode === 'all';
371
275
 
372
- // ============================================================
373
- // REGISTER (enhanced with mode-aware sync + auto-disable)
374
- // ============================================================
375
-
376
- const register = useCallback(
377
- (name: string, registerOptions?: any) => {
378
- const field = allFields[name];
379
- const isReadonly = field ? field.readOnly : false;
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
- new Proxy(rhf.control, {
418
- get(target, prop, receiver) {
419
- if (prop === 'register') {
420
- return (name: string, options?: any) => {
421
- const result = target.register(name as any, options);
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, syncOnChange, syncOnBlur],
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: AllActivityFields<A>,
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 useForm update behavior
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
- // Save via activity.update()
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
- await onSuccess?.(data as AllActivityFields<A>, event);
501
- } catch (error) {
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>['handleComplete'];
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 for activity table data.
20
- * System fields at top level, entity fields under ADO.
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 Activity<infer E, any, any>
24
- ? ActivityInstanceFieldsType & { ADO: E }
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 ops = useMemo(() => activity._getOps(), [activity]);
42
-
43
- const listFn = useMemo(() => {
44
- const rawFn =
16
+ const listFn = useMemo(
17
+ () =>
45
18
  status === 'inprogress'
46
- ? (opts: any) => ops.inProgressList(opts)
47
- : (opts: any) => ops.completedList(opts);
48
- return async (opts: any) => {
49
- const result = await rawFn(opts);
50
- return {
51
- ...result,
52
- Data: result.Data.map(nestEntityFields),
53
- } as typeof result;
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) => ops.inProgressMetric(opts)
61
- : (opts: any) => ops.completedMetric(opts),
62
- [ops, status],
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 { useForm } from "./useForm";
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
- UseFormOptionsType,
6
- UseFormReturnType,
6
+ UseBDOFormOptionsType,
7
+ UseBDOFormReturnType,
7
8
  FormItemType,
8
9
  EditableFormFieldAccessorType,
9
10
  ReadonlyFormFieldAccessorType,