ballerina-core 1.0.207 → 1.0.209

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,22 @@ 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,
39
+ ValueUnit,
43
40
  } from "../../../../../../../../main";
44
41
  import { Template } from "../../../../../../../template/state";
45
- import { ValueInfiniteStreamState } from "../../../../../../../value-infinite-data-stream/state";
46
42
  import {
43
+ TableInfiniteLoaderRunner,
47
44
  TableInitialiseFiltersAndSortingRunner,
48
- TableReinitialiseRunner,
49
- TableRunner,
45
+ TableInitialiseTableRunner,
50
46
  } from "./coroutines/runner";
51
47
 
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
48
  export const TableAbstractRenderer = <
74
49
  CustomPresentationContext = Unit,
75
50
  Flags = Unit,
@@ -133,6 +108,11 @@ export const TableAbstractRenderer = <
133
108
  value: PredicateValue,
134
109
  state: any,
135
110
  ) => ValueOrErrors<any, string>,
111
+ parseFromApiByType: (
112
+ type: DispatchParsedType<any>,
113
+ ) => (raw: any) => ValueOrErrors<PredicateValue, string>,
114
+ fromTableApiParser: (value: unknown) => ValueOrErrors<PredicateValue, string>,
115
+ tableApiSource: DispatchTableApiSource,
136
116
  ): Template<
137
117
  TableAbstractRendererReadonlyContext<
138
118
  CustomPresentationContext,
@@ -143,25 +123,24 @@ export const TableAbstractRenderer = <
143
123
  TableAbstractRendererForeignMutationsExpected<Flags>,
144
124
  TableAbstractRendererView<CustomPresentationContext, Flags, ExtraContext>
145
125
  > => {
146
- const InstantiatedTableRunner = TableRunner<
147
- CustomPresentationContext,
148
- ExtraContext
149
- >();
150
- const InstantiatedTableReinitialiseRunner = TableReinitialiseRunner<
126
+ const InstantiatedInfiniteLoaderRunner = TableInfiniteLoaderRunner<
151
127
  CustomPresentationContext,
152
128
  ExtraContext
153
- >();
154
- const InstantiatedEmbeddedParseFromApiByTypeTemplate =
129
+ >(tableApiSource, fromTableApiParser);
130
+ const InstantiatedInitialiseFiltersAndSortingRunner =
155
131
  TableInitialiseFiltersAndSortingRunner<
156
132
  CustomPresentationContext,
157
133
  ExtraContext
158
- >(Filters.map(({ filters }) => filters));
159
- const InstantiatedEmbeddedValueInfiniteStreamTemplate =
160
- EmbeddedValueInfiniteStreamTemplate<
161
- CustomPresentationContext,
162
- Flags,
163
- ExtraContext
164
- >();
134
+ >(
135
+ Filters.map(({ filters }) => filters),
136
+ tableApiSource,
137
+ parseFromApiByType,
138
+ parseToApiByType,
139
+ );
140
+ const InstantiatedInitialiseTableRunner = TableInitialiseTableRunner<
141
+ CustomPresentationContext,
142
+ ExtraContext
143
+ >(tableApiSource, fromTableApiParser);
165
144
 
166
145
  const embedCellTemplate =
167
146
  (
@@ -177,7 +156,6 @@ export const TableAbstractRenderer = <
177
156
  CommonAbstractRendererForeignMutationsExpected<Flags>
178
157
  >,
179
158
  ) =>
180
- (chunkIndex: number) =>
181
159
  (rowId: string) =>
182
160
  (value: PredicateValue) =>
183
161
  (disabled: boolean) =>
@@ -196,13 +174,11 @@ export const TableAbstractRenderer = <
196
174
  rowState?.fieldStates.get(column) ??
197
175
  CellTemplates.get(column)!.GetDefaultState();
198
176
 
199
- const rowValue = _.customFormState.stream.loadedElements
200
- .get(chunkIndex)
201
- ?.data.get(rowId);
177
+ const rowValue = _.value.data.get(rowId);
202
178
 
203
179
  if (rowValue == undefined) {
204
180
  console.error(
205
- `Row value is undefined for row ${rowId} in chunk ${chunkIndex}\n
181
+ `Row value is undefined for row ${rowId}\n
206
182
  ...When rendering table field ${column}\n
207
183
  ...${_.domNodeAncestorPath}`,
208
184
  );
@@ -275,15 +251,6 @@ export const TableAbstractRenderer = <
275
251
  TableAbstractRendererState.Updaters.Core.commonFormState.children.modifiedByUser(
276
252
  replaceWith(true),
277
253
  ),
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
254
  ),
288
255
  );
289
256
 
@@ -345,35 +312,20 @@ export const TableAbstractRenderer = <
345
312
  }
346
313
 
347
314
  if (
348
- !PredicateValue.Operations.IsTuple(selectedDetailRow) &&
315
+ !PredicateValue.Operations.IsString(selectedDetailRow) &&
349
316
  !PredicateValue.Operations.IsUnit(selectedDetailRow)
350
317
  ) {
351
318
  console.error(
352
- `Selected detail row is not a tuple or unit\n
319
+ `Selected detail row is not a string or unit\n
353
320
  ...When rendering table field\n
354
321
  ...${_.domNodeAncestorPath}`,
355
322
  );
356
323
  return undefined;
357
324
  }
358
325
 
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
326
  const value = PredicateValue.Operations.IsUnit(selectedDetailRow)
371
327
  ? ValueUnit.Default()
372
- : chunkIndex !== undefined && chunkValueKey !== undefined
373
- ? _.customFormState.stream.loadedElements
374
- .get(chunkIndex)
375
- ?.data.get(chunkValueKey)
376
- : undefined;
328
+ : _.value.data.get(selectedDetailRow);
377
329
 
378
330
  if (value == undefined) {
379
331
  console.error(
@@ -384,8 +336,9 @@ export const TableAbstractRenderer = <
384
336
  return undefined;
385
337
  }
386
338
 
387
- const rowState = chunkValueKey
388
- ? _.customFormState.rowStates.get(chunkValueKey)
339
+ const rowState = PredicateValue.Operations.IsString(selectedDetailRow)
340
+ ? (_.customFormState.rowStates.get(selectedDetailRow) ??
341
+ RecordAbstractRendererState.Default.fieldState(Map()))
389
342
  : RecordAbstractRendererState.Default.fieldState(Map());
390
343
 
391
344
  return {
@@ -416,25 +369,12 @@ export const TableAbstractRenderer = <
416
369
  );
417
370
  return id;
418
371
  }
419
-
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
- );
372
+ if (!PredicateValue.Operations.IsString(selectedDetailRow)) {
432
373
  return id;
433
374
  }
434
-
435
375
  return TableAbstractRendererState.Updaters.Core.customFormState.children.rowStates(
436
376
  MapRepo.Updaters.upsert(
437
- chunkValueKey.toString(),
377
+ selectedDetailRow,
438
378
  () => RecordAbstractRendererState.Default.fieldState(Map()),
439
379
  updater,
440
380
  ),
@@ -444,7 +384,7 @@ export const TableAbstractRenderer = <
444
384
  TableAbstractRendererForeignMutationsExpected<Flags>
445
385
  >((props) => ({
446
386
  onChange: (
447
- _: Option<BasicUpdater<ValueRecord>>,
387
+ nestedUpdater: Option<BasicUpdater<ValueRecord>>,
448
388
  nestedDelta: DispatchDelta<Flags>,
449
389
  ) => {
450
390
  const { selectedDetailRow } = props.context.customFormState;
@@ -459,54 +399,46 @@ export const TableAbstractRenderer = <
459
399
  }
460
400
 
461
401
  if (
462
- !PredicateValue.Operations.IsTuple(selectedDetailRow) &&
402
+ !PredicateValue.Operations.IsString(selectedDetailRow) &&
463
403
  !PredicateValue.Operations.IsUnit(selectedDetailRow)
464
404
  ) {
465
405
  console.error(
466
- `Selected detail row is not a tuple or unit\n
467
- ...When rendering table field\n
468
- ...${props.context.domNodeAncestorPath}`,
406
+ `Selected detail row is not a string or unit\n
407
+ ...When rendering table field\n
408
+ ...${props.context.domNodeAncestorPath}`,
469
409
  );
470
410
  return id;
471
411
  }
472
412
 
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
- }
485
-
413
+ if (PredicateValue.Operations.IsString(selectedDetailRow)) {
486
414
  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),
495
- ),
496
- ),
415
+ TableAbstractRendererState.Updaters.Core.commonFormState.children.modifiedByUser(
416
+ replaceWith(true),
417
+ ),
497
418
  );
498
419
 
499
- // TODO, different delta for details
500
420
  const delta: DispatchDelta<Flags> = {
501
421
  kind: "TableValue",
502
- id: chunkValueKey.toString(),
422
+ id: selectedDetailRow,
503
423
  nestedDelta: nestedDelta,
504
424
  flags,
505
425
  sourceAncestorLookupTypeNames:
506
426
  nestedDelta.sourceAncestorLookupTypeNames,
507
427
  };
508
428
 
509
- props.foreignMutations.onChange(Option.Default.none(), delta);
429
+ const updater =
430
+ nestedUpdater.kind == "l"
431
+ ? nestedUpdater
432
+ : Option.Default.some(
433
+ ValueTable.Updaters.data(
434
+ MapRepo.Updaters.update(
435
+ selectedDetailRow,
436
+ nestedUpdater.value,
437
+ ),
438
+ ),
439
+ );
440
+
441
+ props.foreignMutations.onChange(updater, delta);
510
442
  }
511
443
  },
512
444
  }))
@@ -587,13 +519,6 @@ export const TableAbstractRenderer = <
587
519
  );
588
520
  }
589
521
 
590
- if (
591
- props.context.customFormState.initializationStatus !== "initialized" &&
592
- props.context.customFormState.initializationStatus !== "reinitializing"
593
- ) {
594
- return <></>;
595
- }
596
-
597
522
  const updatedBindings = props.context.bindings.set(
598
523
  "local",
599
524
  props.context.value,
@@ -648,38 +573,42 @@ export const TableAbstractRenderer = <
648
573
  disabledColumnKeys.value.filter((fieldName) => fieldName != null),
649
574
  );
650
575
 
651
- const hasMoreValues =
652
- props.context.customFormState.stream.loadedElements.last()?.hasMoreValues;
576
+ const hasMoreValues = props.context.value.hasMoreValues;
653
577
 
654
578
  const embeddedTableData =
655
- props.context.customFormState.stream.loadedElements.flatMap(
656
- (chunk, chunkIndex) =>
657
- chunk.data.map((rowData, rowId) =>
579
+ props.context.customFormState.loadingState != "loaded"
580
+ ? OrderedMap<string, OrderedMap<string, any>>()
581
+ : props.context.value.data.map((rowData, rowId) =>
658
582
  rowData.fields
659
583
  .filter((_, column) =>
660
584
  visibleColumns.value.columns.includes(column),
661
585
  )
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
- ];
586
+ .map((_, column) => {
587
+ return EmbeddedCellTemplates.get(column)!(rowId)(
588
+ rowData.fields.get(column)!,
589
+ )(disabledColumnKeysSet.has(column));
675
590
  }),
676
- ),
677
- );
591
+ );
678
592
 
679
593
  const validVisibleColumns = visibleColumns.value.columns.filter((_) =>
680
594
  TableEntityType.fields.keySeq().toArray().includes(_),
681
595
  );
682
596
 
597
+ if (props.context.customFormState.isFilteringInitialized == false) {
598
+ return <></>;
599
+ }
600
+
601
+ // Detail row may have been deleted from outside the table
602
+ const isSelectedDetailRowValid =
603
+ props.context.customFormState.selectedDetailRow != undefined &&
604
+ !PredicateValue.Operations.IsUnit(
605
+ props.context.customFormState.selectedDetailRow,
606
+ ) &&
607
+ props.context.value.data.size > 0 &&
608
+ props.context.value.data.has(
609
+ props.context.customFormState.selectedDetailRow,
610
+ );
611
+
683
612
  return (
684
613
  <>
685
614
  <IdProvider domNodeId={domNodeId}>
@@ -687,6 +616,12 @@ export const TableAbstractRenderer = <
687
616
  {...props}
688
617
  context={{
689
618
  ...props.context,
619
+ customFormState: {
620
+ ...props.context.customFormState,
621
+ selectedDetailRow: isSelectedDetailRowValid
622
+ ? props.context.customFormState.selectedDetailRow
623
+ : undefined,
624
+ },
690
625
  domNodeId,
691
626
  tableHeaders: validVisibleColumns,
692
627
  columnLabels: ColumnLabels,
@@ -703,20 +638,9 @@ export const TableAbstractRenderer = <
703
638
  }
704
639
  },
705
640
  selectDetailView: (rowId: string) => {
706
- const chunkIndex =
707
- ValueInfiniteStreamState.Operations.getChunkIndexForValue(
708
- props.context.customFormState.stream,
709
- rowId,
710
- );
711
641
  props.setState(
712
642
  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,
643
+ replaceWith<TableAbstractRendererSelectedDetailRow>(rowId),
720
644
  ),
721
645
  );
722
646
  },
@@ -865,11 +789,9 @@ export const TableAbstractRenderer = <
865
789
  ),
866
790
  );
867
791
  },
868
- reinitialize: () =>
792
+ reloadFrom0: () =>
869
793
  props.setState(
870
- TableAbstractRendererState.Updaters.Template.shouldReinitialize(
871
- true,
872
- ),
794
+ TableAbstractRendererState.Updaters.Template.reloadFrom0(),
873
795
  ),
874
796
  }}
875
797
  DetailsRenderer={embedDetailsRenderer}
@@ -885,9 +807,14 @@ export const TableAbstractRenderer = <
885
807
  </>
886
808
  );
887
809
  }).any([
888
- InstantiatedTableRunner,
889
- InstantiatedTableReinitialiseRunner,
890
- InstantiatedEmbeddedValueInfiniteStreamTemplate,
891
- InstantiatedEmbeddedParseFromApiByTypeTemplate,
810
+ InstantiatedInfiniteLoaderRunner.mapContextFromProps((props) => ({
811
+ ...props.context,
812
+ onChange: props.foreignMutations.onChange,
813
+ })),
814
+ InstantiatedInitialiseFiltersAndSortingRunner,
815
+ InstantiatedInitialiseTableRunner.mapContextFromProps((props) => ({
816
+ ...props.context,
817
+ onChange: props.foreignMutations.onChange,
818
+ })),
892
819
  ]);
893
820
  };
@@ -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
  );