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,179 +1,39 @@
1
1
  import { Map, Set } from "immutable";
2
+ import { ValueInfiniteStreamState } from "../../../../../../../../value-infinite-data-stream/state";
2
3
  import {
3
- ValueInfiniteStreamState,
4
- ValueStreamPosition,
5
- } from "../../../../../../../../value-infinite-data-stream/state";
6
- import {
7
- replaceWith,
4
+ DispatchParsedType,
5
+ DispatchTableApiSource,
6
+ PredicateValue,
8
7
  SumNType,
9
- TableAbstractRendererState,
10
8
  Unit,
9
+ ValueOrErrors,
11
10
  } from "../../../../../../../../../main";
12
- import { TableAbstractRendererReadonlyContext } from "../../../../../../../../../main";
13
- import { CoTypedFactory } from "../../../../../../../../../main";
14
-
15
- const Co = <CustomPresentationContext = Unit, ExtraContext = Unit>() =>
16
- CoTypedFactory<
17
- TableAbstractRendererReadonlyContext<
18
- CustomPresentationContext,
19
- ExtraContext
20
- >,
21
- TableAbstractRendererState
22
- >();
23
-
24
- // TODO -- very unsafe, needs work, checking undefined etc,,,
25
- const DEFAULT_CHUNK_SIZE = 20;
26
- const initialiseFiltersAndSorting = <
27
- CustomPresentationContext = Unit,
28
- ExtraContext = Unit,
29
- >(
30
- filterTypes: Map<string, SumNType<any>>,
31
- ) => {
32
- return filterTypes.size == 0
33
- ? Co<CustomPresentationContext, ExtraContext>().SetState(
34
- TableAbstractRendererState.Updaters.Core.customFormState.children.isFilteringInitialized(
35
- // always set to true even if the first call fails so we don't block the flow
36
- replaceWith(true),
37
- ),
38
- )
39
- : Co<CustomPresentationContext, ExtraContext>().Seq([
40
- Co<CustomPresentationContext, ExtraContext>()
41
- .GetState()
42
- .then((current) => {
43
- const getDefaultFiltersAndSorting =
44
- current.tableApiSource.getDefaultFiltersAndSorting(filterTypes);
45
- return Co<CustomPresentationContext, ExtraContext>()
46
- .Await(
47
- getDefaultFiltersAndSorting(current.parseFromApiByType),
48
- () =>
49
- console.error(
50
- "error getting default filters and sorting from api",
51
- ),
52
- )
53
- .then((filtersAndSorting) => {
54
- return filtersAndSorting.kind == "l"
55
- ? Co<CustomPresentationContext, ExtraContext>().SetState(
56
- TableAbstractRendererState.Updaters.Core.customFormState.children
57
- .filters(replaceWith(filtersAndSorting.value.filters))
58
- .then(
59
- TableAbstractRendererState.Updaters.Core.customFormState.children.sorting(
60
- replaceWith(filtersAndSorting.value.sorting),
61
- ),
62
- ),
63
- )
64
- : Co<CustomPresentationContext, ExtraContext>().Wait(0);
65
- });
66
- }),
67
- Co<CustomPresentationContext, ExtraContext>().SetState(
68
- TableAbstractRendererState.Updaters.Core.customFormState.children.isFilteringInitialized(
69
- // always set to true even if the first call fails so we don't block the flow
70
- replaceWith(true),
71
- ),
72
- ),
73
- ]);
74
- };
75
-
76
- const intialiseTable = <
77
- CustomPresentationContext = Unit,
78
- ExtraContext = Unit,
79
- >() =>
80
- Co<CustomPresentationContext, ExtraContext>()
81
- .GetState()
82
- .then((current) => {
83
- if (current.value == undefined) {
84
- return Co<CustomPresentationContext, ExtraContext>().Wait(0);
85
- }
86
- const initialData = current.value.data;
87
- const hasMoreValues = current.value.hasMoreValues;
88
- const from = current.value.from;
89
- const to = current.value.to;
90
- const getChunkWithParams = current.tableApiSource.getMany(
91
- current.fromTableApiParser,
92
- );
93
-
94
- const params =
95
- current.customFormState.filterAndSortParam == ""
96
- ? Map<string, string>()
97
- : Map([
98
- ["filtersAndSorting", current.customFormState.filterAndSortParam],
99
- ]);
100
-
101
- return Co<CustomPresentationContext, ExtraContext>().SetState(
102
- TableAbstractRendererState.Updaters.Core.customFormState.children
103
- .stream(
104
- replaceWith(
105
- ValueInfiniteStreamState.Default(
106
- DEFAULT_CHUNK_SIZE,
107
- getChunkWithParams(params),
108
- initialData.size == 0 && hasMoreValues ? "loadMore" : false,
109
- ),
110
- )
111
- .then(
112
- ValueInfiniteStreamState.Updaters.Coroutine.addLoadedChunk(0, {
113
- data: initialData,
114
- hasMoreValues: hasMoreValues,
115
- from,
116
- to,
117
- }),
118
- )
119
- .then(
120
- ValueInfiniteStreamState.Updaters.Core.position(
121
- ValueStreamPosition.Updaters.Core.nextStart(replaceWith(to)),
122
- ),
123
- ),
124
- )
125
- .thenMany([
126
- TableAbstractRendererState.Updaters.Core.customFormState.children.rowStates(
127
- replaceWith(Map()),
128
- ),
129
- TableAbstractRendererState.Updaters.Core.customFormState.children.selectedRows(
130
- replaceWith(Set()),
131
- ),
132
- TableAbstractRendererState.Updaters.Core.customFormState.children.selectedDetailRow(
133
- replaceWith(undefined as any),
134
- ),
135
- TableAbstractRendererState.Updaters.Core.customFormState.children.getChunkWithParams(
136
- replaceWith(getChunkWithParams),
137
- ),
138
- TableAbstractRendererState.Updaters.Template.shouldReinitialize(
139
- false,
140
- ),
141
- TableAbstractRendererState.Updaters.Core.customFormState.children.previousRemoteEntityVersionIdentifier(
142
- replaceWith(current.remoteEntityVersionIdentifier),
143
- ),
144
- TableAbstractRendererState.Updaters.Core.customFormState.children.initializationStatus(
145
- replaceWith<
146
- TableAbstractRendererState["customFormState"]["initializationStatus"]
147
- >("initialized"),
148
- ),
149
- ]),
150
- );
151
- });
152
-
153
- const reinitialise = <
154
- CustomPresentationContext = Unit,
155
- ExtraContext = Unit,
156
- >() =>
157
- Co<CustomPresentationContext, ExtraContext>()
158
- .GetState()
159
- .then((_) => {
160
- return Co<CustomPresentationContext, ExtraContext>().SetState(
161
- TableAbstractRendererState.Updaters.Core.customFormState.children.initializationStatus(
162
- replaceWith<
163
- TableAbstractRendererState["customFormState"]["initializationStatus"]
164
- >("reinitializing"),
165
- ),
166
- );
167
- });
11
+ import { Co, InfiniteLoaderCo } from "./builder";
12
+ import {} from "./initialiseFiltersAndSorting";
13
+ import { InitialiseFiltersAndSorting } from "./initialiseFiltersAndSorting";
14
+ import { TableInfiniteLoader } from "./infiniteLoader";
15
+ import { InitialiseTable } from "./initialiseTable";
168
16
 
169
17
  export const TableInitialiseFiltersAndSortingRunner = <
170
18
  CustomPresentationContext = Unit,
171
19
  ExtraContext = Unit,
172
20
  >(
173
21
  filterTypes: Map<string, SumNType<any>>,
22
+ tableApiSource: DispatchTableApiSource,
23
+ parseFromApiByType: (
24
+ type: DispatchParsedType<any>,
25
+ ) => (raw: any) => ValueOrErrors<PredicateValue, string>,
26
+ parseToApiByType: (
27
+ type: DispatchParsedType<any>,
28
+ value: PredicateValue,
29
+ state: any,
30
+ ) => ValueOrErrors<any, string>,
174
31
  ) =>
175
32
  Co<CustomPresentationContext, ExtraContext>().Template<any>(
176
- initialiseFiltersAndSorting<CustomPresentationContext, ExtraContext>(
33
+ InitialiseFiltersAndSorting<CustomPresentationContext, ExtraContext>(
34
+ tableApiSource,
35
+ parseFromApiByType,
36
+ parseToApiByType,
177
37
  filterTypes,
178
38
  ),
179
39
  {
@@ -182,37 +42,46 @@ export const TableInitialiseFiltersAndSortingRunner = <
182
42
  props.context.customFormState.isFilteringInitialized == false,
183
43
  },
184
44
  );
185
- export const TableReinitialiseRunner = <
45
+
46
+ export const TableInitialiseTableRunner = <
186
47
  CustomPresentationContext = Unit,
187
48
  ExtraContext = Unit,
188
- >() =>
189
- Co<CustomPresentationContext, ExtraContext>().Template<any>(
190
- reinitialise<CustomPresentationContext, ExtraContext>(),
49
+ >(
50
+ tableApiSource: DispatchTableApiSource,
51
+ fromTableApiParser: (value: unknown) => ValueOrErrors<PredicateValue, string>,
52
+ ) =>
53
+ InfiniteLoaderCo<CustomPresentationContext, ExtraContext>().Template<any>(
54
+ InitialiseTable<CustomPresentationContext, ExtraContext>(
55
+ tableApiSource,
56
+ fromTableApiParser,
57
+ ),
191
58
  {
192
59
  interval: 15,
193
60
  runFilter: (props) =>
194
- props.context.customFormState.initializationStatus === "initialized" &&
195
61
  props.context.customFormState.isFilteringInitialized &&
196
- props.context.customFormState.shouldReinitialize,
62
+ (props.context.customFormState.loadingState == "loading" ||
63
+ props.context.customFormState.loadingState == "reload from 0"),
197
64
  },
198
65
  );
199
66
 
200
- export const TableRunner = <
67
+ export const TableInfiniteLoaderRunner = <
201
68
  CustomPresentationContext = Unit,
202
69
  ExtraContext = Unit,
203
- >() =>
204
- Co<CustomPresentationContext, ExtraContext>().Template<any>(
205
- intialiseTable<CustomPresentationContext, ExtraContext>(),
70
+ >(
71
+ tableApiSource: DispatchTableApiSource,
72
+ fromTableApiParser: (value: unknown) => ValueOrErrors<PredicateValue, string>,
73
+ ) =>
74
+ InfiniteLoaderCo<CustomPresentationContext, ExtraContext>().Template<any>(
75
+ TableInfiniteLoader<CustomPresentationContext, ExtraContext>(
76
+ tableApiSource,
77
+ fromTableApiParser,
78
+ ),
206
79
  {
207
80
  interval: 15,
208
- runFilter: (props) => {
209
- return (
210
- (props.context.customFormState.initializationStatus ===
211
- "not initialized" ||
212
- props.context.customFormState.initializationStatus ===
213
- "reinitializing") &&
214
- props.context.customFormState.isFilteringInitialized
215
- );
216
- },
81
+ runFilter: (props) =>
82
+ props.context.customFormState.isFilteringInitialized &&
83
+ props.context.customFormState.loadingState == "loaded" &&
84
+ (props.context.customFormState.loadMore == "load more" ||
85
+ props.context.customFormState.loadMore == "loading more"),
217
86
  },
218
87
  );
@@ -10,7 +10,6 @@ import {
10
10
  ValueRecord,
11
11
  ValueTable,
12
12
  replaceWith,
13
- DispatchTableApiSource,
14
13
  DispatchOnChange,
15
14
  Unit,
16
15
  ValueCallbackWithOptionalFlags,
@@ -22,8 +21,6 @@ import {
22
21
  TableMethod,
23
22
  CommonAbstractRendererViewOnlyReadonlyContext,
24
23
  RecordType,
25
- ValueTuple,
26
- ValueUnit,
27
24
  FilterType,
28
25
  MapRepo,
29
26
  ValueFilter,
@@ -32,13 +29,10 @@ import {
32
29
  Value,
33
30
  SumNType,
34
31
  ValueSumN,
32
+ ValueUnit,
35
33
  } from "../../../../../../../../main";
36
- import { Debounced } from "../../../../../../../debounced/state";
37
- import { BasicFun } from "../../../../../../../fun/state";
38
34
  import { Template, View } from "../../../../../../../template/state";
39
35
 
40
- import { ValueInfiniteStreamState } from "../../../../../../../value-infinite-data-stream/state";
41
-
42
36
  export type TableAbstractRendererReadonlyContext<
43
37
  CustomPresentationContext = Unit,
44
38
  ExtraContext = Unit,
@@ -48,11 +42,6 @@ export type TableAbstractRendererReadonlyContext<
48
42
  CustomPresentationContext,
49
43
  ExtraContext
50
44
  > & {
51
- tableApiSource: DispatchTableApiSource;
52
- fromTableApiParser: (value: unknown) => ValueOrErrors<PredicateValue, string>;
53
- parseFromApiByType: (
54
- type: DispatchParsedType<any>,
55
- ) => (raw: any) => ValueOrErrors<PredicateValue, string>;
56
45
  tableHeaders: string[];
57
46
  columnLabels: Map<string, string | undefined>;
58
47
  apiMethods: Array<TableMethod>;
@@ -61,27 +50,25 @@ export type TableAbstractRendererReadonlyContext<
61
50
  };
62
51
 
63
52
  export type TableAbstractRendererSelectedDetailRow =
64
- | ValueTuple
65
- | ValueUnit
66
- | undefined;
53
+ | string
54
+ | undefined
55
+ | ValueUnit;
67
56
 
68
57
  export type TableAbstractRendererState = CommonAbstractRendererState & {
69
58
  customFormState: {
59
+ loadingState: "loading" | "loaded" | "error" | "reload from 0";
60
+ loadMore:
61
+ | "load more"
62
+ | "loading more"
63
+ | "don't load more"
64
+ | "error loading more";
70
65
  isFilteringInitialized: boolean;
71
66
  selectedRows: Set<string>;
72
67
  rowStates: Map<string, RecordAbstractRendererState>;
73
68
  selectedDetailRow: TableAbstractRendererSelectedDetailRow;
74
- initializationStatus: "not initialized" | "initialized" | "reinitializing";
75
69
  filters: Map<string, List<ValueFilter>>;
76
70
  sorting: Map<string, "Ascending" | "Descending" | undefined>;
77
71
  filterAndSortParam: string;
78
- stream: ValueInfiniteStreamState;
79
- getChunkWithParams: BasicFun<
80
- Map<string, string>,
81
- ValueInfiniteStreamState["getChunk"]
82
- >;
83
- previousRemoteEntityVersionIdentifier: string;
84
- shouldReinitialize: boolean;
85
72
  filterStates: Map<string, List<any>>;
86
73
  };
87
74
  };
@@ -89,19 +76,15 @@ export const TableAbstractRendererState = {
89
76
  Default: (): TableAbstractRendererState => ({
90
77
  ...CommonAbstractRendererState.Default(),
91
78
  customFormState: {
79
+ loadingState: "loading",
80
+ loadMore: "don't load more",
92
81
  isFilteringInitialized: false,
93
- initializationStatus: "not initialized",
94
82
  selectedRows: Set(),
95
83
  selectedDetailRow: undefined,
96
84
  filterAndSortParam: "",
97
85
  rowStates: Map(),
98
86
  filters: Map(),
99
87
  sorting: Map(),
100
- // TODO: replace with sum
101
- getChunkWithParams: undefined as any,
102
- stream: undefined as any,
103
- previousRemoteEntityVersionIdentifier: "",
104
- shouldReinitialize: false,
105
88
  filterStates: Map(),
106
89
  },
107
90
  }),
@@ -109,13 +92,10 @@ export const TableAbstractRendererState = {
109
92
  Core: {
110
93
  ...simpleUpdaterWithChildren<TableAbstractRendererState>()({
111
94
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
112
- "getChunkWithParams",
113
- ),
114
- ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
115
- "stream",
95
+ "filterAndSortParam",
116
96
  ),
117
97
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
118
- "filterAndSortParam",
98
+ "loadMore",
119
99
  ),
120
100
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
121
101
  "filters",
@@ -123,21 +103,12 @@ export const TableAbstractRendererState = {
123
103
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
124
104
  "sorting",
125
105
  ),
126
- ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
127
- "initializationStatus",
128
- ),
129
106
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
130
107
  "selectedDetailRow",
131
108
  ),
132
109
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
133
110
  "selectedRows",
134
111
  ),
135
- ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
136
- "previousRemoteEntityVersionIdentifier",
137
- ),
138
- ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
139
- "shouldReinitialize",
140
- ),
141
112
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
142
113
  "rowStates",
143
114
  ),
@@ -147,6 +118,9 @@ export const TableAbstractRendererState = {
147
118
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
148
119
  "isFilteringInitialized",
149
120
  ),
121
+ ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
122
+ "loadingState",
123
+ ),
150
124
  })("customFormState"),
151
125
  ...simpleUpdaterWithChildren<TableAbstractRendererState>()({
152
126
  ...simpleUpdater<TableAbstractRendererState["commonFormState"]>()(
@@ -181,8 +155,10 @@ export const TableAbstractRendererState = {
181
155
  ),
182
156
  )
183
157
  .then(
184
- TableAbstractRendererState.Updaters.Core.customFormState.children.shouldReinitialize(
185
- replaceWith(true),
158
+ TableAbstractRendererState.Updaters.Core.customFormState.children.loadingState(
159
+ replaceWith<
160
+ TableAbstractRendererState["customFormState"]["loadingState"]
161
+ >("reload from 0"),
186
162
  ),
187
163
  )(_),
188
164
  ),
@@ -218,8 +194,10 @@ export const TableAbstractRendererState = {
218
194
  ),
219
195
  )
220
196
  .then(
221
- TableAbstractRendererState.Updaters.Core.customFormState.children.shouldReinitialize(
222
- replaceWith(true),
197
+ TableAbstractRendererState.Updaters.Core.customFormState.children.loadingState(
198
+ replaceWith<
199
+ TableAbstractRendererState["customFormState"]["loadingState"]
200
+ >("reload from 0"),
223
201
  ),
224
202
  )(_),
225
203
  );
@@ -254,19 +232,29 @@ export const TableAbstractRendererState = {
254
232
  ),
255
233
  )
256
234
  .then(
257
- TableAbstractRendererState.Updaters.Core.customFormState.children.shouldReinitialize(
258
- replaceWith(true),
235
+ TableAbstractRendererState.Updaters.Core.customFormState.children.loadingState(
236
+ replaceWith<
237
+ TableAbstractRendererState["customFormState"]["loadingState"]
238
+ >("reload from 0"),
259
239
  ),
260
240
  )(_),
261
241
  );
262
242
  },
263
243
  loadMore: (): Updater<TableAbstractRendererState> =>
264
- TableAbstractRendererState.Updaters.Core.customFormState.children.stream(
265
- ValueInfiniteStreamState.Updaters.Template.loadMore(),
244
+ Updater((_) =>
245
+ _.customFormState.loadMore == "loading more"
246
+ ? _
247
+ : TableAbstractRendererState.Updaters.Core.customFormState.children.loadMore(
248
+ replaceWith<
249
+ TableAbstractRendererState["customFormState"]["loadMore"]
250
+ >("load more"),
251
+ )(_),
266
252
  ),
267
- shouldReinitialize: (_: boolean) =>
268
- TableAbstractRendererState.Updaters.Core.customFormState.children.shouldReinitialize(
269
- replaceWith(_),
253
+ reloadFrom0: (): Updater<TableAbstractRendererState> =>
254
+ TableAbstractRendererState.Updaters.Core.customFormState.children.loadingState(
255
+ replaceWith<
256
+ TableAbstractRendererState["customFormState"]["loadingState"]
257
+ >("reload from 0"),
270
258
  ),
271
259
  },
272
260
  },
@@ -443,13 +431,13 @@ export type TableAbstractRendererViewForeignMutationsExpected<Flags = Unit> = {
443
431
  | ((key: string, to: string, flags: Flags | undefined) => void)
444
432
  | undefined;
445
433
  duplicate: ValueCallbackWithOptionalFlags<string, Flags> | undefined;
446
- reinitialize: SimpleCallback<void>;
447
434
  updateFilters: (filters: Map<string, List<ValueFilter>>) => void;
448
435
  addSorting: (
449
436
  columnName: string,
450
437
  direction: "Ascending" | "Descending" | undefined,
451
438
  ) => void;
452
439
  removeSorting: (columnName: string) => void;
440
+ reloadFrom0: () => void;
453
441
  };
454
442
 
455
443
  export type TableAbstractRendererView<