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.
- package/package.json +1 -1
- package/src/forms/domains/dispatched-forms/deserializer/state.ts +7 -1
- package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/table/coroutines/builder.ts +31 -0
- package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/table/coroutines/infiniteLoader.ts +84 -0
- package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/table/coroutines/initialiseFiltersAndSorting.ts +112 -0
- package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/table/coroutines/initialiseTable.ts +89 -0
- package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/table/coroutines/loadWithRetries.ts +69 -0
- package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/table/coroutines/runner.ts +51 -182
- package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/table/state.ts +43 -55
- package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/table/template.tsx +98 -171
- package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/table/state.ts +5 -7
package/package.json
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
SpecificationApis,
|
|
28
28
|
LookupTypeAbstractRendererView,
|
|
29
29
|
ValueFilter,
|
|
30
|
+
ValueTable,
|
|
30
31
|
} from "../../../../../main";
|
|
31
32
|
|
|
32
33
|
import {
|
|
@@ -196,12 +197,17 @@ export type DispatchTableFiltersAndSorting = {
|
|
|
196
197
|
filters: Map<string, List<ValueFilter>>;
|
|
197
198
|
sorting: Map<string, "Ascending" | "Descending" | undefined>;
|
|
198
199
|
};
|
|
200
|
+
export type TableGetManyParams = {
|
|
201
|
+
chunkSize: number;
|
|
202
|
+
from: number;
|
|
203
|
+
filtersAndSorting?: string;
|
|
204
|
+
};
|
|
199
205
|
export type DispatchTableApiName = string;
|
|
200
206
|
export type DispatchTableApiSource = {
|
|
201
207
|
get: BasicFun<Guid, Promise<any>>;
|
|
202
208
|
getMany: BasicFun<
|
|
203
209
|
BasicFun<any, ValueOrErrors<PredicateValue, string>>,
|
|
204
|
-
BasicFun<
|
|
210
|
+
BasicFun<TableGetManyParams, Promise<ValueTable>>
|
|
205
211
|
>;
|
|
206
212
|
getDefaultFiltersAndSorting: BasicFun<
|
|
207
213
|
Map<string, SumNType<any>>,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CoTypedFactory,
|
|
3
|
+
TableAbstractRendererForeignMutationsExpected,
|
|
4
|
+
} from "../../../../../../../../../main";
|
|
5
|
+
import {
|
|
6
|
+
TableAbstractRendererReadonlyContext,
|
|
7
|
+
TableAbstractRendererState,
|
|
8
|
+
Unit,
|
|
9
|
+
} from "../../../../../../../../../main";
|
|
10
|
+
|
|
11
|
+
export const Co = <CustomPresentationContext = Unit, ExtraContext = Unit>() =>
|
|
12
|
+
CoTypedFactory<
|
|
13
|
+
TableAbstractRendererReadonlyContext<
|
|
14
|
+
CustomPresentationContext,
|
|
15
|
+
ExtraContext
|
|
16
|
+
>,
|
|
17
|
+
TableAbstractRendererState
|
|
18
|
+
>();
|
|
19
|
+
|
|
20
|
+
export const InfiniteLoaderCo = <
|
|
21
|
+
CustomPresentationContext = Unit,
|
|
22
|
+
ExtraContext = Unit,
|
|
23
|
+
>() =>
|
|
24
|
+
CoTypedFactory<
|
|
25
|
+
TableAbstractRendererReadonlyContext<
|
|
26
|
+
CustomPresentationContext,
|
|
27
|
+
ExtraContext
|
|
28
|
+
> &
|
|
29
|
+
Pick<TableAbstractRendererForeignMutationsExpected, "onChange">,
|
|
30
|
+
TableAbstractRendererState
|
|
31
|
+
>();
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseFlags,
|
|
3
|
+
DispatchDelta,
|
|
4
|
+
DispatchParsedType,
|
|
5
|
+
DispatchTableApiSource,
|
|
6
|
+
Option,
|
|
7
|
+
PredicateValue,
|
|
8
|
+
TableAbstractRendererState,
|
|
9
|
+
unit,
|
|
10
|
+
Unit,
|
|
11
|
+
ValueOrErrors,
|
|
12
|
+
ValueTable,
|
|
13
|
+
} from "../../../../../../../../../main";
|
|
14
|
+
import { replaceWith } from "../../../../../../../../fun/domains/updater/domains/replaceWith/state";
|
|
15
|
+
import { InfiniteLoaderCo as Co } from "./builder";
|
|
16
|
+
import { Map } from "immutable";
|
|
17
|
+
import { TableLoadWithRetries } from "./loadWithRetries";
|
|
18
|
+
|
|
19
|
+
export const TableInfiniteLoader = <
|
|
20
|
+
CustomPresentationContext = Unit,
|
|
21
|
+
ExtraContext = Unit,
|
|
22
|
+
>(
|
|
23
|
+
tableApiSource: DispatchTableApiSource,
|
|
24
|
+
fromTableApiParser: (value: unknown) => ValueOrErrors<PredicateValue, string>,
|
|
25
|
+
) => {
|
|
26
|
+
return Co<CustomPresentationContext, ExtraContext>().Seq([
|
|
27
|
+
Co<CustomPresentationContext, ExtraContext>().SetState(
|
|
28
|
+
TableAbstractRendererState.Updaters.Core.customFormState.children.loadMore(
|
|
29
|
+
replaceWith<TableAbstractRendererState["customFormState"]["loadMore"]>(
|
|
30
|
+
"loading more",
|
|
31
|
+
),
|
|
32
|
+
),
|
|
33
|
+
),
|
|
34
|
+
Co<CustomPresentationContext, ExtraContext>()
|
|
35
|
+
.GetState()
|
|
36
|
+
.then((current) =>
|
|
37
|
+
TableLoadWithRetries<CustomPresentationContext, ExtraContext>(
|
|
38
|
+
tableApiSource,
|
|
39
|
+
fromTableApiParser,
|
|
40
|
+
)(3)().then((res) =>
|
|
41
|
+
res.kind == "r"
|
|
42
|
+
? Co<CustomPresentationContext, ExtraContext>().Seq([
|
|
43
|
+
Co<CustomPresentationContext, ExtraContext>().Do(() => {
|
|
44
|
+
const updater = replaceWith<ValueTable>(
|
|
45
|
+
ValueTable.Default.fromParsed(
|
|
46
|
+
0,
|
|
47
|
+
current.value.data.size + res.value.data.size, // validate this
|
|
48
|
+
res.value.hasMoreValues,
|
|
49
|
+
current.value.data.concat(res.value.data),
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
// Only needed as a delta is mandatory for onchange but it is ignored upstream
|
|
53
|
+
const delta: DispatchDelta<BaseFlags> = {
|
|
54
|
+
kind: "UnitReplace",
|
|
55
|
+
replace: PredicateValue.Default.unit(),
|
|
56
|
+
state: {},
|
|
57
|
+
flags: {
|
|
58
|
+
kind: "localOnly",
|
|
59
|
+
},
|
|
60
|
+
type: DispatchParsedType.Default.primitive("unit"),
|
|
61
|
+
sourceAncestorLookupTypeNames:
|
|
62
|
+
current.lookupTypeAncestorNames,
|
|
63
|
+
};
|
|
64
|
+
current.onChange(Option.Default.some(updater), delta);
|
|
65
|
+
}),
|
|
66
|
+
Co<CustomPresentationContext, ExtraContext>().SetState(
|
|
67
|
+
TableAbstractRendererState.Updaters.Core.customFormState.children.loadMore(
|
|
68
|
+
replaceWith<
|
|
69
|
+
TableAbstractRendererState["customFormState"]["loadMore"]
|
|
70
|
+
>("don't load more"),
|
|
71
|
+
),
|
|
72
|
+
),
|
|
73
|
+
])
|
|
74
|
+
: Co<CustomPresentationContext, ExtraContext>().SetState(
|
|
75
|
+
TableAbstractRendererState.Updaters.Core.customFormState.children.loadMore(
|
|
76
|
+
replaceWith<
|
|
77
|
+
TableAbstractRendererState["customFormState"]["loadMore"]
|
|
78
|
+
>("error loading more"),
|
|
79
|
+
),
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
),
|
|
83
|
+
]);
|
|
84
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { Map } from "immutable";
|
|
2
|
+
import {
|
|
3
|
+
Coroutine,
|
|
4
|
+
DispatchParsedType,
|
|
5
|
+
DispatchTableApiSource,
|
|
6
|
+
DispatchTableFiltersAndSorting,
|
|
7
|
+
PredicateValue,
|
|
8
|
+
replaceWith,
|
|
9
|
+
Sum,
|
|
10
|
+
SumNType,
|
|
11
|
+
TableAbstractRendererReadonlyContext,
|
|
12
|
+
TableAbstractRendererState,
|
|
13
|
+
Unit,
|
|
14
|
+
ValueOrErrors,
|
|
15
|
+
} from "../../../../../../../../../main";
|
|
16
|
+
import { Co } from "./builder";
|
|
17
|
+
|
|
18
|
+
export const InitialiseFiltersAndSorting = <
|
|
19
|
+
CustomPresentationContext = Unit,
|
|
20
|
+
ExtraContext = Unit,
|
|
21
|
+
>(
|
|
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>,
|
|
31
|
+
filterTypes: Map<string, SumNType<any>>,
|
|
32
|
+
) => {
|
|
33
|
+
const getDefaultFiltersAndSortingWithRetries =
|
|
34
|
+
(maxRetries = 3) =>
|
|
35
|
+
(
|
|
36
|
+
attempt: number = 0,
|
|
37
|
+
): Coroutine<
|
|
38
|
+
TableAbstractRendererReadonlyContext<
|
|
39
|
+
CustomPresentationContext,
|
|
40
|
+
ExtraContext
|
|
41
|
+
> &
|
|
42
|
+
TableAbstractRendererState,
|
|
43
|
+
TableAbstractRendererState,
|
|
44
|
+
Sum<"permanent error", DispatchTableFiltersAndSorting>
|
|
45
|
+
> =>
|
|
46
|
+
attempt < maxRetries
|
|
47
|
+
? Co<CustomPresentationContext, ExtraContext>()
|
|
48
|
+
.Await(
|
|
49
|
+
tableApiSource.getDefaultFiltersAndSorting(filterTypes)(
|
|
50
|
+
parseFromApiByType,
|
|
51
|
+
),
|
|
52
|
+
() =>
|
|
53
|
+
console.error(
|
|
54
|
+
"error getting default filters and sorting from api",
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
.then((filtersAndSorting) =>
|
|
58
|
+
filtersAndSorting.kind == "l"
|
|
59
|
+
? Co<CustomPresentationContext, ExtraContext>().Return(
|
|
60
|
+
Sum.Default.right(filtersAndSorting.value),
|
|
61
|
+
)
|
|
62
|
+
: getDefaultFiltersAndSortingWithRetries(maxRetries)(
|
|
63
|
+
attempt + 1,
|
|
64
|
+
),
|
|
65
|
+
)
|
|
66
|
+
: Co<CustomPresentationContext, ExtraContext>().Return(
|
|
67
|
+
Sum.Default.left("permanent error"),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return filterTypes.size == 0
|
|
71
|
+
? Co<CustomPresentationContext, ExtraContext>().SetState(
|
|
72
|
+
TableAbstractRendererState.Updaters.Core.customFormState.children.isFilteringInitialized(
|
|
73
|
+
replaceWith<
|
|
74
|
+
TableAbstractRendererState["customFormState"]["isFilteringInitialized"]
|
|
75
|
+
>(true),
|
|
76
|
+
),
|
|
77
|
+
)
|
|
78
|
+
: Co<CustomPresentationContext, ExtraContext>().Seq([
|
|
79
|
+
getDefaultFiltersAndSortingWithRetries()().then((filtersAndSorting) =>
|
|
80
|
+
filtersAndSorting.kind == "r"
|
|
81
|
+
? Co<CustomPresentationContext, ExtraContext>().SetState(
|
|
82
|
+
TableAbstractRendererState.Updaters.Core.customFormState.children
|
|
83
|
+
.filters(replaceWith(filtersAndSorting.value.filters))
|
|
84
|
+
.then(
|
|
85
|
+
TableAbstractRendererState.Updaters.Core.customFormState.children.sorting(
|
|
86
|
+
replaceWith(filtersAndSorting.value.sorting),
|
|
87
|
+
),
|
|
88
|
+
)
|
|
89
|
+
.then(
|
|
90
|
+
TableAbstractRendererState.Updaters.Core.customFormState.children.filterAndSortParam(
|
|
91
|
+
replaceWith(
|
|
92
|
+
TableAbstractRendererState.Operations.parseFiltersAndSortingToBase64String(
|
|
93
|
+
filtersAndSorting.value.filters,
|
|
94
|
+
filterTypes,
|
|
95
|
+
filtersAndSorting.value.sorting,
|
|
96
|
+
parseToApiByType,
|
|
97
|
+
true,
|
|
98
|
+
),
|
|
99
|
+
),
|
|
100
|
+
),
|
|
101
|
+
),
|
|
102
|
+
) // in case of permanent error, we don't want to block the flow, so just do nothing
|
|
103
|
+
: Co<CustomPresentationContext, ExtraContext>().Wait(0),
|
|
104
|
+
),
|
|
105
|
+
Co<CustomPresentationContext, ExtraContext>().SetState(
|
|
106
|
+
TableAbstractRendererState.Updaters.Core.customFormState.children.isFilteringInitialized(
|
|
107
|
+
// always set to true even if the first call fails so we don't block the flow
|
|
108
|
+
replaceWith(true),
|
|
109
|
+
),
|
|
110
|
+
),
|
|
111
|
+
]);
|
|
112
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseFlags,
|
|
3
|
+
DispatchDelta,
|
|
4
|
+
DispatchParsedType,
|
|
5
|
+
DispatchTableApiSource,
|
|
6
|
+
Option,
|
|
7
|
+
PredicateValue,
|
|
8
|
+
TableAbstractRendererState,
|
|
9
|
+
unit,
|
|
10
|
+
Unit,
|
|
11
|
+
ValueOrErrors,
|
|
12
|
+
ValueTable,
|
|
13
|
+
} from "../../../../../../../../../main";
|
|
14
|
+
import { replaceWith } from "../../../../../../../../fun/domains/updater/domains/replaceWith/state";
|
|
15
|
+
import { InfiniteLoaderCo as Co } from "./builder";
|
|
16
|
+
import { TableLoadWithRetries } from "./loadWithRetries";
|
|
17
|
+
|
|
18
|
+
export const InitialiseTable = <
|
|
19
|
+
CustomPresentationContext = Unit,
|
|
20
|
+
ExtraContext = Unit,
|
|
21
|
+
>(
|
|
22
|
+
tableApiSource: DispatchTableApiSource,
|
|
23
|
+
fromTableApiParser: (value: unknown) => ValueOrErrors<PredicateValue, string>,
|
|
24
|
+
) => {
|
|
25
|
+
return Co<CustomPresentationContext, ExtraContext>().Seq([
|
|
26
|
+
Co<CustomPresentationContext, ExtraContext>()
|
|
27
|
+
.GetState()
|
|
28
|
+
.then((current) =>
|
|
29
|
+
(current.value.data.size == 0 && current.value.hasMoreValues) ||
|
|
30
|
+
current.customFormState.loadingState == "reload from 0"
|
|
31
|
+
? TableLoadWithRetries<CustomPresentationContext, ExtraContext>(
|
|
32
|
+
tableApiSource,
|
|
33
|
+
fromTableApiParser,
|
|
34
|
+
)(3)().then((res) =>
|
|
35
|
+
res.kind == "r"
|
|
36
|
+
? Co<CustomPresentationContext, ExtraContext>().Seq([
|
|
37
|
+
Co<CustomPresentationContext, ExtraContext>().Do(() => {
|
|
38
|
+
const updater = replaceWith<ValueTable>(
|
|
39
|
+
ValueTable.Default.fromParsed(
|
|
40
|
+
0,
|
|
41
|
+
res.value.data.size,
|
|
42
|
+
res.value.hasMoreValues,
|
|
43
|
+
res.value.data,
|
|
44
|
+
),
|
|
45
|
+
);
|
|
46
|
+
// Only needed as a delta is mandatory for onchange but it is ignored upstream
|
|
47
|
+
const delta: DispatchDelta<BaseFlags> = {
|
|
48
|
+
kind: "UnitReplace",
|
|
49
|
+
replace: PredicateValue.Default.unit(),
|
|
50
|
+
state: {},
|
|
51
|
+
flags: {
|
|
52
|
+
kind: "localOnly",
|
|
53
|
+
},
|
|
54
|
+
type: DispatchParsedType.Default.primitive("unit"),
|
|
55
|
+
sourceAncestorLookupTypeNames:
|
|
56
|
+
current.lookupTypeAncestorNames,
|
|
57
|
+
};
|
|
58
|
+
current.onChange(Option.Default.some(updater), delta);
|
|
59
|
+
return Co<
|
|
60
|
+
CustomPresentationContext,
|
|
61
|
+
ExtraContext
|
|
62
|
+
>().Return(unit);
|
|
63
|
+
}),
|
|
64
|
+
Co<CustomPresentationContext, ExtraContext>().SetState(
|
|
65
|
+
TableAbstractRendererState.Updaters.Core.customFormState.children.loadingState(
|
|
66
|
+
replaceWith<
|
|
67
|
+
TableAbstractRendererState["customFormState"]["loadingState"]
|
|
68
|
+
>("loaded"),
|
|
69
|
+
),
|
|
70
|
+
),
|
|
71
|
+
])
|
|
72
|
+
: Co<CustomPresentationContext, ExtraContext>().SetState(
|
|
73
|
+
TableAbstractRendererState.Updaters.Core.customFormState.children.loadingState(
|
|
74
|
+
replaceWith<
|
|
75
|
+
TableAbstractRendererState["customFormState"]["loadingState"]
|
|
76
|
+
>("error"),
|
|
77
|
+
),
|
|
78
|
+
),
|
|
79
|
+
)
|
|
80
|
+
: Co<CustomPresentationContext, ExtraContext>().SetState(
|
|
81
|
+
TableAbstractRendererState.Updaters.Core.customFormState.children.loadingState(
|
|
82
|
+
replaceWith<
|
|
83
|
+
TableAbstractRendererState["customFormState"]["loadingState"]
|
|
84
|
+
>("loaded"),
|
|
85
|
+
),
|
|
86
|
+
),
|
|
87
|
+
),
|
|
88
|
+
]);
|
|
89
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Coroutine,
|
|
3
|
+
DispatchTableApiSource,
|
|
4
|
+
PredicateValue,
|
|
5
|
+
Sum,
|
|
6
|
+
TableAbstractRendererForeignMutationsExpected,
|
|
7
|
+
TableAbstractRendererReadonlyContext,
|
|
8
|
+
TableAbstractRendererState,
|
|
9
|
+
Unit,
|
|
10
|
+
ValueOrErrors,
|
|
11
|
+
ValueTable,
|
|
12
|
+
} from "../../../../../../../../../main";
|
|
13
|
+
import { InfiniteLoaderCo as Co } from "./builder";
|
|
14
|
+
|
|
15
|
+
const DEFAULT_CHUNK_SIZE = 20;
|
|
16
|
+
|
|
17
|
+
export const TableLoadWithRetries =
|
|
18
|
+
<CustomPresentationContext = Unit, ExtraContext = Unit>(
|
|
19
|
+
tableApiSource: DispatchTableApiSource,
|
|
20
|
+
fromTableApiParser: (
|
|
21
|
+
value: unknown,
|
|
22
|
+
) => ValueOrErrors<PredicateValue, string>,
|
|
23
|
+
) =>
|
|
24
|
+
(maxRetries = 3) =>
|
|
25
|
+
(
|
|
26
|
+
attempt: number = 0,
|
|
27
|
+
): Coroutine<
|
|
28
|
+
TableAbstractRendererReadonlyContext<
|
|
29
|
+
CustomPresentationContext,
|
|
30
|
+
ExtraContext
|
|
31
|
+
> &
|
|
32
|
+
Pick<TableAbstractRendererForeignMutationsExpected, "onChange"> &
|
|
33
|
+
TableAbstractRendererState,
|
|
34
|
+
TableAbstractRendererState,
|
|
35
|
+
Sum<"permanent error", ValueTable>
|
|
36
|
+
> =>
|
|
37
|
+
attempt < maxRetries
|
|
38
|
+
? Co<CustomPresentationContext, ExtraContext>()
|
|
39
|
+
.GetState()
|
|
40
|
+
.then((current) =>
|
|
41
|
+
Co<CustomPresentationContext, ExtraContext>().Await(
|
|
42
|
+
() =>
|
|
43
|
+
tableApiSource.getMany(fromTableApiParser)({
|
|
44
|
+
chunkSize: DEFAULT_CHUNK_SIZE,
|
|
45
|
+
from:
|
|
46
|
+
current.customFormState.loadingState == "reload from 0"
|
|
47
|
+
? 0
|
|
48
|
+
: current.value.data.size,
|
|
49
|
+
filtersAndSorting:
|
|
50
|
+
current.customFormState.filterAndSortParam === ""
|
|
51
|
+
? undefined
|
|
52
|
+
: current.customFormState.filterAndSortParam,
|
|
53
|
+
}),
|
|
54
|
+
() => "error" as const,
|
|
55
|
+
),
|
|
56
|
+
)
|
|
57
|
+
.then((apiResult) =>
|
|
58
|
+
apiResult.kind == "l"
|
|
59
|
+
? Co<CustomPresentationContext, ExtraContext>().Return(
|
|
60
|
+
Sum.Default.right(apiResult.value),
|
|
61
|
+
)
|
|
62
|
+
: TableLoadWithRetries<CustomPresentationContext, ExtraContext>(
|
|
63
|
+
tableApiSource,
|
|
64
|
+
fromTableApiParser,
|
|
65
|
+
)(maxRetries)(attempt + 1),
|
|
66
|
+
)
|
|
67
|
+
: Co<CustomPresentationContext, ExtraContext>().Return(
|
|
68
|
+
Sum.Default.left("permanent error"),
|
|
69
|
+
);
|