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,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,
@@ -33,12 +30,8 @@ import {
33
30
  SumNType,
34
31
  ValueSumN,
35
32
  } from "../../../../../../../../main";
36
- import { Debounced } from "../../../../../../../debounced/state";
37
- import { BasicFun } from "../../../../../../../fun/state";
38
33
  import { Template, View } from "../../../../../../../template/state";
39
34
 
40
- import { ValueInfiniteStreamState } from "../../../../../../../value-infinite-data-stream/state";
41
-
42
35
  export type TableAbstractRendererReadonlyContext<
43
36
  CustomPresentationContext = Unit,
44
37
  ExtraContext = Unit,
@@ -48,11 +41,6 @@ export type TableAbstractRendererReadonlyContext<
48
41
  CustomPresentationContext,
49
42
  ExtraContext
50
43
  > & {
51
- tableApiSource: DispatchTableApiSource;
52
- fromTableApiParser: (value: unknown) => ValueOrErrors<PredicateValue, string>;
53
- parseFromApiByType: (
54
- type: DispatchParsedType<any>,
55
- ) => (raw: any) => ValueOrErrors<PredicateValue, string>;
56
44
  tableHeaders: string[];
57
45
  columnLabels: Map<string, string | undefined>;
58
46
  apiMethods: Array<TableMethod>;
@@ -60,28 +48,23 @@ export type TableAbstractRendererReadonlyContext<
60
48
  highlightedFilters: Array<string>;
61
49
  };
62
50
 
63
- export type TableAbstractRendererSelectedDetailRow =
64
- | ValueTuple
65
- | ValueUnit
66
- | undefined;
51
+ export type TableAbstractRendererSelectedDetailRow = string | undefined;
67
52
 
68
53
  export type TableAbstractRendererState = CommonAbstractRendererState & {
69
54
  customFormState: {
55
+ loadingState: "loading" | "loaded" | "error" | "reload from 0";
56
+ loadMore:
57
+ | "load more"
58
+ | "loading more"
59
+ | "don't load more"
60
+ | "error loading more";
70
61
  isFilteringInitialized: boolean;
71
62
  selectedRows: Set<string>;
72
63
  rowStates: Map<string, RecordAbstractRendererState>;
73
64
  selectedDetailRow: TableAbstractRendererSelectedDetailRow;
74
- initializationStatus: "not initialized" | "initialized" | "reinitializing";
75
65
  filters: Map<string, List<ValueFilter>>;
76
66
  sorting: Map<string, "Ascending" | "Descending" | undefined>;
77
67
  filterAndSortParam: string;
78
- stream: ValueInfiniteStreamState;
79
- getChunkWithParams: BasicFun<
80
- Map<string, string>,
81
- ValueInfiniteStreamState["getChunk"]
82
- >;
83
- previousRemoteEntityVersionIdentifier: string;
84
- shouldReinitialize: boolean;
85
68
  filterStates: Map<string, List<any>>;
86
69
  };
87
70
  };
@@ -89,19 +72,15 @@ export const TableAbstractRendererState = {
89
72
  Default: (): TableAbstractRendererState => ({
90
73
  ...CommonAbstractRendererState.Default(),
91
74
  customFormState: {
75
+ loadingState: "loading",
76
+ loadMore: "don't load more",
92
77
  isFilteringInitialized: false,
93
- initializationStatus: "not initialized",
94
78
  selectedRows: Set(),
95
79
  selectedDetailRow: undefined,
96
80
  filterAndSortParam: "",
97
81
  rowStates: Map(),
98
82
  filters: Map(),
99
83
  sorting: Map(),
100
- // TODO: replace with sum
101
- getChunkWithParams: undefined as any,
102
- stream: undefined as any,
103
- previousRemoteEntityVersionIdentifier: "",
104
- shouldReinitialize: false,
105
84
  filterStates: Map(),
106
85
  },
107
86
  }),
@@ -109,13 +88,10 @@ export const TableAbstractRendererState = {
109
88
  Core: {
110
89
  ...simpleUpdaterWithChildren<TableAbstractRendererState>()({
111
90
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
112
- "getChunkWithParams",
113
- ),
114
- ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
115
- "stream",
91
+ "filterAndSortParam",
116
92
  ),
117
93
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
118
- "filterAndSortParam",
94
+ "loadMore",
119
95
  ),
120
96
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
121
97
  "filters",
@@ -123,21 +99,12 @@ export const TableAbstractRendererState = {
123
99
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
124
100
  "sorting",
125
101
  ),
126
- ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
127
- "initializationStatus",
128
- ),
129
102
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
130
103
  "selectedDetailRow",
131
104
  ),
132
105
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
133
106
  "selectedRows",
134
107
  ),
135
- ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
136
- "previousRemoteEntityVersionIdentifier",
137
- ),
138
- ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
139
- "shouldReinitialize",
140
- ),
141
108
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
142
109
  "rowStates",
143
110
  ),
@@ -147,6 +114,9 @@ export const TableAbstractRendererState = {
147
114
  ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
148
115
  "isFilteringInitialized",
149
116
  ),
117
+ ...simpleUpdater<TableAbstractRendererState["customFormState"]>()(
118
+ "loadingState",
119
+ ),
150
120
  })("customFormState"),
151
121
  ...simpleUpdaterWithChildren<TableAbstractRendererState>()({
152
122
  ...simpleUpdater<TableAbstractRendererState["commonFormState"]>()(
@@ -181,8 +151,10 @@ export const TableAbstractRendererState = {
181
151
  ),
182
152
  )
183
153
  .then(
184
- TableAbstractRendererState.Updaters.Core.customFormState.children.shouldReinitialize(
185
- replaceWith(true),
154
+ TableAbstractRendererState.Updaters.Core.customFormState.children.loadingState(
155
+ replaceWith<
156
+ TableAbstractRendererState["customFormState"]["loadingState"]
157
+ >("reload from 0"),
186
158
  ),
187
159
  )(_),
188
160
  ),
@@ -218,8 +190,10 @@ export const TableAbstractRendererState = {
218
190
  ),
219
191
  )
220
192
  .then(
221
- TableAbstractRendererState.Updaters.Core.customFormState.children.shouldReinitialize(
222
- replaceWith(true),
193
+ TableAbstractRendererState.Updaters.Core.customFormState.children.loadingState(
194
+ replaceWith<
195
+ TableAbstractRendererState["customFormState"]["loadingState"]
196
+ >("reload from 0"),
223
197
  ),
224
198
  )(_),
225
199
  );
@@ -254,19 +228,29 @@ export const TableAbstractRendererState = {
254
228
  ),
255
229
  )
256
230
  .then(
257
- TableAbstractRendererState.Updaters.Core.customFormState.children.shouldReinitialize(
258
- replaceWith(true),
231
+ TableAbstractRendererState.Updaters.Core.customFormState.children.loadingState(
232
+ replaceWith<
233
+ TableAbstractRendererState["customFormState"]["loadingState"]
234
+ >("reload from 0"),
259
235
  ),
260
236
  )(_),
261
237
  );
262
238
  },
263
239
  loadMore: (): Updater<TableAbstractRendererState> =>
264
- TableAbstractRendererState.Updaters.Core.customFormState.children.stream(
265
- ValueInfiniteStreamState.Updaters.Template.loadMore(),
240
+ Updater((_) =>
241
+ _.customFormState.loadMore == "loading more"
242
+ ? _
243
+ : TableAbstractRendererState.Updaters.Core.customFormState.children.loadMore(
244
+ replaceWith<
245
+ TableAbstractRendererState["customFormState"]["loadMore"]
246
+ >("load more"),
247
+ )(_),
266
248
  ),
267
- shouldReinitialize: (_: boolean) =>
268
- TableAbstractRendererState.Updaters.Core.customFormState.children.shouldReinitialize(
269
- replaceWith(_),
249
+ reloadFrom0: (): Updater<TableAbstractRendererState> =>
250
+ TableAbstractRendererState.Updaters.Core.customFormState.children.loadingState(
251
+ replaceWith<
252
+ TableAbstractRendererState["customFormState"]["loadingState"]
253
+ >("reload from 0"),
270
254
  ),
271
255
  },
272
256
  },
@@ -443,13 +427,13 @@ export type TableAbstractRendererViewForeignMutationsExpected<Flags = Unit> = {
443
427
  | ((key: string, to: string, flags: Flags | undefined) => void)
444
428
  | undefined;
445
429
  duplicate: ValueCallbackWithOptionalFlags<string, Flags> | undefined;
446
- reinitialize: SimpleCallback<void>;
447
430
  updateFilters: (filters: Map<string, List<ValueFilter>>) => void;
448
431
  addSorting: (
449
432
  columnName: string,
450
433
  direction: "Ascending" | "Descending" | undefined,
451
434
  ) => void;
452
435
  removeSorting: (columnName: string) => void;
436
+ reloadFrom0: () => void;
453
437
  };
454
438
 
455
439
  export type TableAbstractRendererView<