ballerina-core 1.0.207 → 1.0.208

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.
@@ -1,11 +1,10 @@
1
- import { List, Map, Set } from "immutable";
1
+ import { List, Map, OrderedMap, Set } from "immutable";
2
2
  import {
3
3
  BasicUpdater,
4
4
  id,
5
5
  PredicateValue,
6
6
  TableAbstractRendererState,
7
7
  TableLayout,
8
- ValueInfiniteStreamTemplate,
9
8
  Expr,
10
9
  PredicateVisibleColumns,
11
10
  DispatchDelta,
@@ -30,46 +29,21 @@ import {
30
29
  MapRepo,
31
30
  ValueTable,
32
31
  RecordType,
33
- unit,
34
- ValueUnit,
35
32
  TableAbstractRendererSelectedDetailRow,
36
- TableApiFiltering,
37
33
  ValueFilter,
38
- CommonAbstractRendererViewOnlyReadonlyContext,
39
34
  FilterType,
40
35
  ListRepo,
41
36
  Updater,
42
37
  SumNType,
38
+ DispatchTableApiSource,
43
39
  } from "../../../../../../../../main";
44
40
  import { Template } from "../../../../../../../template/state";
45
- import { ValueInfiniteStreamState } from "../../../../../../../value-infinite-data-stream/state";
46
41
  import {
42
+ TableInfiniteLoaderRunner,
47
43
  TableInitialiseFiltersAndSortingRunner,
48
- TableReinitialiseRunner,
49
- TableRunner,
44
+ TableInitialiseTableRunner,
50
45
  } from "./coroutines/runner";
51
46
 
52
- const EmbeddedValueInfiniteStreamTemplate = <
53
- CustomPresentationContext = Unit,
54
- Flags = Unit,
55
- ExtraContext = Unit,
56
- >() =>
57
- ValueInfiniteStreamTemplate.mapContext<
58
- TableAbstractRendererReadonlyContext<
59
- CustomPresentationContext,
60
- ExtraContext
61
- > &
62
- TableAbstractRendererState
63
- >((_) => _.customFormState.stream)
64
- .mapState<TableAbstractRendererState>(
65
- TableAbstractRendererState.Updaters.Core.customFormState.children.stream,
66
- )
67
- .mapForeignMutationsFromProps<
68
- TableAbstractRendererForeignMutationsExpected<Flags>
69
- >((props) => ({
70
- ...props.foreignMutations,
71
- }));
72
-
73
47
  export const TableAbstractRenderer = <
74
48
  CustomPresentationContext = Unit,
75
49
  Flags = Unit,
@@ -133,6 +107,11 @@ export const TableAbstractRenderer = <
133
107
  value: PredicateValue,
134
108
  state: any,
135
109
  ) => ValueOrErrors<any, string>,
110
+ parseFromApiByType: (
111
+ type: DispatchParsedType<any>,
112
+ ) => (raw: any) => ValueOrErrors<PredicateValue, string>,
113
+ fromTableApiParser: (value: unknown) => ValueOrErrors<PredicateValue, string>,
114
+ tableApiSource: DispatchTableApiSource,
136
115
  ): Template<
137
116
  TableAbstractRendererReadonlyContext<
138
117
  CustomPresentationContext,
@@ -143,25 +122,24 @@ export const TableAbstractRenderer = <
143
122
  TableAbstractRendererForeignMutationsExpected<Flags>,
144
123
  TableAbstractRendererView<CustomPresentationContext, Flags, ExtraContext>
145
124
  > => {
146
- const InstantiatedTableRunner = TableRunner<
125
+ const InstantiatedInfiniteLoaderRunner = TableInfiniteLoaderRunner<
147
126
  CustomPresentationContext,
148
127
  ExtraContext
149
- >();
150
- const InstantiatedTableReinitialiseRunner = TableReinitialiseRunner<
151
- CustomPresentationContext,
152
- ExtraContext
153
- >();
154
- const InstantiatedEmbeddedParseFromApiByTypeTemplate =
128
+ >(tableApiSource, fromTableApiParser);
129
+ const InstantiatedInitialiseFiltersAndSortingRunner =
155
130
  TableInitialiseFiltersAndSortingRunner<
156
131
  CustomPresentationContext,
157
132
  ExtraContext
158
- >(Filters.map(({ filters }) => filters));
159
- const InstantiatedEmbeddedValueInfiniteStreamTemplate =
160
- EmbeddedValueInfiniteStreamTemplate<
161
- CustomPresentationContext,
162
- Flags,
163
- ExtraContext
164
- >();
133
+ >(
134
+ Filters.map(({ filters }) => filters),
135
+ tableApiSource,
136
+ parseFromApiByType,
137
+ parseToApiByType,
138
+ );
139
+ const InstantiatedInitialiseTableRunner = TableInitialiseTableRunner<
140
+ CustomPresentationContext,
141
+ ExtraContext
142
+ >(tableApiSource, fromTableApiParser);
165
143
 
166
144
  const embedCellTemplate =
167
145
  (
@@ -177,7 +155,6 @@ export const TableAbstractRenderer = <
177
155
  CommonAbstractRendererForeignMutationsExpected<Flags>
178
156
  >,
179
157
  ) =>
180
- (chunkIndex: number) =>
181
158
  (rowId: string) =>
182
159
  (value: PredicateValue) =>
183
160
  (disabled: boolean) =>
@@ -196,13 +173,11 @@ export const TableAbstractRenderer = <
196
173
  rowState?.fieldStates.get(column) ??
197
174
  CellTemplates.get(column)!.GetDefaultState();
198
175
 
199
- const rowValue = _.customFormState.stream.loadedElements
200
- .get(chunkIndex)
201
- ?.data.get(rowId);
176
+ const rowValue = _.value.data.get(rowId);
202
177
 
203
178
  if (rowValue == undefined) {
204
179
  console.error(
205
- `Row value is undefined for row ${rowId} in chunk ${chunkIndex}\n
180
+ `Row value is undefined for row ${rowId}\n
206
181
  ...When rendering table field ${column}\n
207
182
  ...${_.domNodeAncestorPath}`,
208
183
  );
@@ -275,15 +250,6 @@ export const TableAbstractRenderer = <
275
250
  TableAbstractRendererState.Updaters.Core.commonFormState.children.modifiedByUser(
276
251
  replaceWith(true),
277
252
  ),
278
- )
279
- .then(
280
- TableAbstractRendererState.Updaters.Core.customFormState.children.stream(
281
- ValueInfiniteStreamState.Updaters.Template.updateChunkValueItem(
282
- chunkIndex,
283
- rowId,
284
- column,
285
- )(nestedUpdater.kind == "r" ? nestedUpdater.value : id),
286
- ),
287
253
  ),
288
254
  );
289
255
 
@@ -344,36 +310,7 @@ export const TableAbstractRenderer = <
344
310
  return undefined;
345
311
  }
346
312
 
347
- if (
348
- !PredicateValue.Operations.IsTuple(selectedDetailRow) &&
349
- !PredicateValue.Operations.IsUnit(selectedDetailRow)
350
- ) {
351
- console.error(
352
- `Selected detail row is not a tuple or unit\n
353
- ...When rendering table field\n
354
- ...${_.domNodeAncestorPath}`,
355
- );
356
- return undefined;
357
- }
358
-
359
- const chunkIndex = PredicateValue.Operations.IsTuple(
360
- selectedDetailRow,
361
- )
362
- ? Number(selectedDetailRow.values.get(0))
363
- : undefined;
364
- const chunkValueKey = PredicateValue.Operations.IsTuple(
365
- selectedDetailRow,
366
- )
367
- ? selectedDetailRow.values.get(1)?.toString()
368
- : undefined;
369
-
370
- const value = PredicateValue.Operations.IsUnit(selectedDetailRow)
371
- ? ValueUnit.Default()
372
- : chunkIndex !== undefined && chunkValueKey !== undefined
373
- ? _.customFormState.stream.loadedElements
374
- .get(chunkIndex)
375
- ?.data.get(chunkValueKey)
376
- : undefined;
313
+ const value = _.value.data.get(selectedDetailRow);
377
314
 
378
315
  if (value == undefined) {
379
316
  console.error(
@@ -384,9 +321,9 @@ export const TableAbstractRenderer = <
384
321
  return undefined;
385
322
  }
386
323
 
387
- const rowState = chunkValueKey
388
- ? _.customFormState.rowStates.get(chunkValueKey)
389
- : RecordAbstractRendererState.Default.fieldState(Map());
324
+ const rowState =
325
+ _.customFormState.rowStates.get(selectedDetailRow) ??
326
+ RecordAbstractRendererState.Default.fieldState(Map());
390
327
 
391
328
  return {
392
329
  value,
@@ -417,24 +354,9 @@ export const TableAbstractRenderer = <
417
354
  return id;
418
355
  }
419
356
 
420
- if (!PredicateValue.Operations.IsTuple(selectedDetailRow)) {
421
- return id;
422
- }
423
-
424
- const chunkValueKey = selectedDetailRow.values.get(1);
425
-
426
- if (chunkValueKey == undefined) {
427
- console.error(
428
- `Chunk value key is undefined for selected detail row\n
429
- ...When rendering table detail view \n
430
- ...${props.context.domNodeAncestorPath}`,
431
- );
432
- return id;
433
- }
434
-
435
357
  return TableAbstractRendererState.Updaters.Core.customFormState.children.rowStates(
436
358
  MapRepo.Updaters.upsert(
437
- chunkValueKey.toString(),
359
+ selectedDetailRow,
438
360
  () => RecordAbstractRendererState.Default.fieldState(Map()),
439
361
  updater,
440
362
  ),
@@ -444,7 +366,7 @@ export const TableAbstractRenderer = <
444
366
  TableAbstractRendererForeignMutationsExpected<Flags>
445
367
  >((props) => ({
446
368
  onChange: (
447
- _: Option<BasicUpdater<ValueRecord>>,
369
+ nestedUpdater: Option<BasicUpdater<ValueRecord>>,
448
370
  nestedDelta: DispatchDelta<Flags>,
449
371
  ) => {
450
372
  const { selectedDetailRow } = props.context.customFormState;
@@ -458,56 +380,43 @@ export const TableAbstractRenderer = <
458
380
  return id;
459
381
  }
460
382
 
461
- if (
462
- !PredicateValue.Operations.IsTuple(selectedDetailRow) &&
463
- !PredicateValue.Operations.IsUnit(selectedDetailRow)
464
- ) {
383
+ if (!selectedDetailRow) {
465
384
  console.error(
466
- `Selected detail row is not a tuple or unit\n
467
- ...When rendering table field\n
468
- ...${props.context.domNodeAncestorPath}`,
385
+ `Chunk value key is undefined for selected detail row\n
386
+ ...When rendering table field\n
387
+ ...${props.context.domNodeAncestorPath}`,
469
388
  );
470
389
  return id;
471
390
  }
472
391
 
473
- if (PredicateValue.Operations.IsTuple(selectedDetailRow)) {
474
- const chunkIndex = Number(selectedDetailRow.values.get(0));
475
- const chunkValueKey = selectedDetailRow.values.get(1);
476
-
477
- if (!chunkValueKey) {
478
- console.error(
479
- `Chunk value key is undefined for selected detail row\n
480
- ...When rendering table field\n
481
- ...${props.context.domNodeAncestorPath}`,
482
- );
483
- return id;
484
- }
392
+ props.setState(
393
+ TableAbstractRendererState.Updaters.Core.commonFormState.children.modifiedByUser(
394
+ replaceWith(true),
395
+ ),
396
+ );
485
397
 
486
- props.setState(
487
- TableAbstractRendererState.Updaters.Core.commonFormState.children
488
- .modifiedByUser(replaceWith(true))
489
- .then(
490
- TableAbstractRendererState.Updaters.Core.customFormState.children.stream(
491
- ValueInfiniteStreamState.Updaters.Template.updateChunkValue(
492
- chunkIndex,
493
- chunkValueKey.toString(),
494
- )(_.kind == "r" ? _.value : id),
398
+ const delta: DispatchDelta<Flags> = {
399
+ kind: "TableValue",
400
+ id: selectedDetailRow,
401
+ nestedDelta: nestedDelta,
402
+ flags,
403
+ sourceAncestorLookupTypeNames:
404
+ nestedDelta.sourceAncestorLookupTypeNames,
405
+ };
406
+
407
+ const updater =
408
+ nestedUpdater.kind == "l"
409
+ ? nestedUpdater
410
+ : Option.Default.some(
411
+ ValueTable.Updaters.data(
412
+ MapRepo.Updaters.update(
413
+ selectedDetailRow,
414
+ nestedUpdater.value,
415
+ ),
495
416
  ),
496
- ),
497
- );
417
+ );
498
418
 
499
- // TODO, different delta for details
500
- const delta: DispatchDelta<Flags> = {
501
- kind: "TableValue",
502
- id: chunkValueKey.toString(),
503
- nestedDelta: nestedDelta,
504
- flags,
505
- sourceAncestorLookupTypeNames:
506
- nestedDelta.sourceAncestorLookupTypeNames,
507
- };
508
-
509
- props.foreignMutations.onChange(Option.Default.none(), delta);
510
- }
419
+ props.foreignMutations.onChange(updater, delta);
511
420
  },
512
421
  }))
513
422
  : undefined;
@@ -587,13 +496,6 @@ export const TableAbstractRenderer = <
587
496
  );
588
497
  }
589
498
 
590
- if (
591
- props.context.customFormState.initializationStatus !== "initialized" &&
592
- props.context.customFormState.initializationStatus !== "reinitializing"
593
- ) {
594
- return <></>;
595
- }
596
-
597
499
  const updatedBindings = props.context.bindings.set(
598
500
  "local",
599
501
  props.context.value,
@@ -648,38 +550,31 @@ export const TableAbstractRenderer = <
648
550
  disabledColumnKeys.value.filter((fieldName) => fieldName != null),
649
551
  );
650
552
 
651
- const hasMoreValues =
652
- props.context.customFormState.stream.loadedElements.last()?.hasMoreValues;
553
+ const hasMoreValues = props.context.value.hasMoreValues;
653
554
 
654
555
  const embeddedTableData =
655
- props.context.customFormState.stream.loadedElements.flatMap(
656
- (chunk, chunkIndex) =>
657
- chunk.data.map((rowData, rowId) =>
556
+ props.context.customFormState.loadingState != "loaded"
557
+ ? OrderedMap<string, OrderedMap<string, any>>()
558
+ : props.context.value.data.map((rowData, rowId) =>
658
559
  rowData.fields
659
560
  .filter((_, column) =>
660
561
  visibleColumns.value.columns.includes(column),
661
562
  )
662
- .flatMap((_, column) => {
663
- const EmbeddedCell = EmbeddedCellTemplates.get(column);
664
- if (EmbeddedCell == undefined) {
665
- return [];
666
- }
667
- return [
668
- [
669
- column,
670
- EmbeddedCell(chunkIndex)(rowId)(
671
- rowData.fields.get(column)!,
672
- )(disabledColumnKeysSet.has(column)),
673
- ],
674
- ];
563
+ .map((_, column) => {
564
+ return EmbeddedCellTemplates.get(column)!(rowId)(
565
+ rowData.fields.get(column)!,
566
+ )(disabledColumnKeysSet.has(column));
675
567
  }),
676
- ),
677
- );
568
+ );
678
569
 
679
570
  const validVisibleColumns = visibleColumns.value.columns.filter((_) =>
680
571
  TableEntityType.fields.keySeq().toArray().includes(_),
681
572
  );
682
573
 
574
+ if (props.context.customFormState.isFilteringInitialized == false) {
575
+ return <></>;
576
+ }
577
+
683
578
  return (
684
579
  <>
685
580
  <IdProvider domNodeId={domNodeId}>
@@ -703,20 +598,9 @@ export const TableAbstractRenderer = <
703
598
  }
704
599
  },
705
600
  selectDetailView: (rowId: string) => {
706
- const chunkIndex =
707
- ValueInfiniteStreamState.Operations.getChunkIndexForValue(
708
- props.context.customFormState.stream,
709
- rowId,
710
- );
711
601
  props.setState(
712
602
  TableAbstractRendererState.Updaters.Core.customFormState.children.selectedDetailRow(
713
- chunkIndex.kind == "value"
714
- ? replaceWith<TableAbstractRendererSelectedDetailRow>(
715
- PredicateValue.Default.tuple(
716
- List([chunkIndex.value, rowId]),
717
- ),
718
- )
719
- : id,
603
+ replaceWith<TableAbstractRendererSelectedDetailRow>(rowId),
720
604
  ),
721
605
  );
722
606
  },
@@ -865,11 +749,9 @@ export const TableAbstractRenderer = <
865
749
  ),
866
750
  );
867
751
  },
868
- reinitialize: () =>
752
+ reloadFrom0: () =>
869
753
  props.setState(
870
- TableAbstractRendererState.Updaters.Template.shouldReinitialize(
871
- true,
872
- ),
754
+ TableAbstractRendererState.Updaters.Template.reloadFrom0(),
873
755
  ),
874
756
  }}
875
757
  DetailsRenderer={embedDetailsRenderer}
@@ -885,9 +767,14 @@ export const TableAbstractRenderer = <
885
767
  </>
886
768
  );
887
769
  }).any([
888
- InstantiatedTableRunner,
889
- InstantiatedTableReinitialiseRunner,
890
- InstantiatedEmbeddedValueInfiniteStreamTemplate,
891
- InstantiatedEmbeddedParseFromApiByTypeTemplate,
770
+ InstantiatedInfiniteLoaderRunner.mapContextFromProps((props) => ({
771
+ ...props.context,
772
+ onChange: props.foreignMutations.onChange,
773
+ })),
774
+ InstantiatedInitialiseFiltersAndSortingRunner,
775
+ InstantiatedInitialiseTableRunner.mapContextFromProps((props) => ({
776
+ ...props.context,
777
+ onChange: props.foreignMutations.onChange,
778
+ })),
892
779
  ]);
893
780
  };
@@ -282,6 +282,11 @@ export const TableDispatcher = {
282
282
  tableEntityType,
283
283
  AllowedFilters,
284
284
  dispatcherContext.parseToApiByType,
285
+ dispatcherContext.parseFromApiByType,
286
+ dispatcherContext.parseFromApiByType(
287
+ renderer.type.arg,
288
+ ),
289
+ tableApiSource,
285
290
  )
286
291
  .mapContext((_: any) => ({
287
292
  ..._,
@@ -292,15 +297,8 @@ export const TableDispatcher = {
292
297
  : (dispatcherContext.specApis.tables?.get(
293
298
  api!,
294
299
  )?.methods ?? []),
295
- tableApiSource,
296
300
  sorting,
297
301
  highlightedFilters,
298
- fromTableApiParser:
299
- dispatcherContext.parseFromApiByType(
300
- renderer.type.arg,
301
- ),
302
- parseFromApiByType:
303
- dispatcherContext.parseFromApiByType,
304
302
  }))
305
303
  .withView(concreteRenderer),
306
304
  );