ballerina-core 1.0.228 → 1.0.230

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.
Files changed (37) hide show
  1. package/package.json +1 -1
  2. package/src/forms/domains/dispatched-forms/deserializer/state.ts +292 -94
  3. package/src/forms/domains/dispatched-forms/runner/domains/abstract-renderers/table/state.ts +37 -32
  4. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/list/state.ts +1 -1
  5. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/lookup/state.ts +1 -1
  6. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/map/state.ts +1 -1
  7. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/multiSelection/state.ts +1 -1
  8. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/nestedDispatcher/state.ts +1 -1
  9. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/one/state.ts +1 -1
  10. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/primitive/state.ts +1 -1
  11. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/readOnly/state.ts +1 -1
  12. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/record/recordField/state.ts +1 -1
  13. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/record/state.ts +1 -1
  14. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/singleSelectionDispatcher/state.ts +1 -1
  15. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/sum/state.ts +1 -1
  16. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/table/state.ts +1 -1
  17. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/tupleDispatcher/state.ts +1 -1
  18. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/domains/unionDispatcher/state.ts +1 -1
  19. package/src/forms/domains/dispatched-forms/runner/domains/dispatcher/state.ts +1 -1
  20. package/src/forms/domains/dispatched-forms/runner/domains/kind/create/coroutines/_init.ts +279 -0
  21. package/src/forms/domains/dispatched-forms/runner/domains/kind/create/coroutines/_sync.ts +103 -0
  22. package/src/forms/domains/dispatched-forms/runner/domains/kind/create/coroutines/builder.ts +24 -0
  23. package/src/forms/domains/dispatched-forms/runner/domains/kind/create/coroutines/runner.ts +44 -0
  24. package/src/forms/domains/dispatched-forms/runner/domains/kind/create/state.ts +100 -0
  25. package/src/forms/domains/dispatched-forms/runner/domains/kind/create/template.tsx +116 -0
  26. package/src/forms/domains/dispatched-forms/runner/domains/kind/edit/coroutines/_init.ts +272 -0
  27. package/src/forms/domains/dispatched-forms/runner/domains/kind/edit/coroutines/_sync.ts +101 -0
  28. package/src/forms/domains/dispatched-forms/runner/domains/kind/edit/coroutines/builder.ts +24 -0
  29. package/src/forms/domains/dispatched-forms/runner/domains/kind/edit/coroutines/runner.ts +43 -0
  30. package/src/forms/domains/dispatched-forms/runner/domains/kind/edit/state.ts +96 -0
  31. package/src/forms/domains/dispatched-forms/runner/domains/kind/edit/template.tsx +115 -0
  32. package/src/forms/domains/dispatched-forms/runner/{coroutines → domains/kind/passthrough/coroutines}/runner.ts +49 -45
  33. package/src/forms/domains/dispatched-forms/runner/domains/kind/passthrough/state.ts +45 -0
  34. package/src/forms/domains/dispatched-forms/runner/domains/kind/passthrough/template.tsx +118 -0
  35. package/src/forms/domains/dispatched-forms/runner/state.ts +141 -11
  36. package/src/forms/domains/dispatched-forms/runner/template.tsx +102 -59
  37. package/src/value-infinite-data-stream/coroutines/infiniteLoader.ts +1 -1
@@ -0,0 +1,272 @@
1
+ import { List } from "immutable";
2
+ import {
3
+ DispatchInjectablesTypes,
4
+ Unit,
5
+ PredicateValue,
6
+ Synchronize,
7
+ DispatchParsedEditLauncher,
8
+ Synchronized,
9
+ unit,
10
+ AsyncState,
11
+ replaceWith,
12
+ DispatchFormRunnerStatus,
13
+ id,
14
+ Dispatcher,
15
+ HandleApiResponse,
16
+ DispatcherContextWithApiSources,
17
+ } from "../../../../../../../../../main";
18
+ import { ApiResponseChecker } from "../../../../../../../../api-response-handler/state";
19
+ import {
20
+ DispatchEditFormLauncherContext,
21
+ DispatchEditFormLauncherState,
22
+ } from "../state";
23
+ import { EditCoBuilder } from "./builder";
24
+
25
+ export const initCo = <
26
+ T extends DispatchInjectablesTypes<T>,
27
+ Flags,
28
+ CustomPresentationContexts,
29
+ ExtraContext,
30
+ >(
31
+ Co: ReturnType<
32
+ typeof EditCoBuilder<T, Flags, CustomPresentationContexts, ExtraContext>
33
+ >,
34
+ ) => {
35
+ const setChecked = (checked: boolean) =>
36
+ Co.SetState(
37
+ DispatchEditFormLauncherState<
38
+ T,
39
+ Flags
40
+ >().Updaters.Core.apiChecker.children.init(
41
+ checked
42
+ ? ApiResponseChecker.Updaters().toChecked()
43
+ : ApiResponseChecker.Updaters().toUnchecked(),
44
+ ),
45
+ );
46
+
47
+ const getValueCo = (
48
+ getValueApi: () => Promise<PredicateValue>,
49
+ editFormLauncher: DispatchParsedEditLauncher<T>,
50
+ ) =>
51
+ Synchronize<Unit, PredicateValue>(
52
+ () =>
53
+ getValueApi().then((raw) => {
54
+ const result = editFormLauncher.fromApiParser(raw);
55
+ return result.kind == "errors"
56
+ ? Promise.reject(result.errors)
57
+ : Promise.resolve(result.value);
58
+ }),
59
+ (_) => "transient failure",
60
+ 5,
61
+ 50,
62
+ ).embed(
63
+ (_: DispatchEditFormLauncherState<T, Flags>) => _.entity,
64
+ DispatchEditFormLauncherState<T, Flags>().Updaters.Core.entity,
65
+ );
66
+
67
+ const configValueCo = (
68
+ getGlobalConfig: () => Promise<PredicateValue>,
69
+ createFormLauncher: DispatchParsedEditLauncher<T>,
70
+ current: DispatchEditFormLauncherContext<
71
+ T,
72
+ Flags,
73
+ CustomPresentationContexts,
74
+ ExtraContext
75
+ >,
76
+ ) =>
77
+ current.launcherRef.config.source == "api"
78
+ ? Synchronize<Unit, PredicateValue>(() =>
79
+ getGlobalConfig().then((raw) => {
80
+ const result =
81
+ createFormLauncher.parseGlobalConfigurationFromApi(raw);
82
+ return result.kind == "errors"
83
+ ? Promise.reject(result.errors)
84
+ : Promise.resolve(result.value);
85
+ }),
86
+ ).embed(
87
+ (_: DispatchEditFormLauncherState<T, Flags>) => _.config,
88
+ DispatchEditFormLauncherState<T, Flags>().Updaters.Core.config,
89
+ )
90
+ : Co.SetState(
91
+ DispatchEditFormLauncherState<T, Flags>().Updaters.Core.config(
92
+ replaceWith(
93
+ current.launcherRef.config.value.kind == "l" &&
94
+ current.launcherRef.config.value.value.kind == "value"
95
+ ? Synchronized.Default(
96
+ unit,
97
+ AsyncState.Default.loaded(
98
+ current.launcherRef.config.value.value.value,
99
+ ),
100
+ )
101
+ : Synchronized.Default(unit),
102
+ ),
103
+ ),
104
+ );
105
+
106
+ const errorUpd = (errors: List<string>) =>
107
+ DispatchEditFormLauncherState<T, Flags>().Updaters.Core.status(
108
+ replaceWith<DispatchFormRunnerStatus<T, Flags>>({
109
+ kind: "error",
110
+ errors,
111
+ }),
112
+ );
113
+
114
+ return Co.Seq([
115
+ Co.SetState(
116
+ DispatchEditFormLauncherState<T, Flags>().Updaters.Core.status(
117
+ replaceWith<DispatchFormRunnerStatus<T, Flags>>({ kind: "loading" }),
118
+ ),
119
+ ),
120
+ setChecked(false),
121
+ Co.GetState().then((current) => {
122
+ if (
123
+ !AsyncState.Operations.hasValue(current.deserializedSpecification.sync)
124
+ ) {
125
+ return Co.SetState(id);
126
+ }
127
+
128
+ if (current.deserializedSpecification.sync.value.kind == "errors") {
129
+ return Co.SetState(
130
+ errorUpd(current.deserializedSpecification.sync.value.errors),
131
+ );
132
+ }
133
+
134
+ const dispatcherContext =
135
+ current.deserializedSpecification.sync.value.value.dispatcherContext;
136
+
137
+ const editFormLauncher =
138
+ current.deserializedSpecification.sync.value.value.launchers.edit.get(
139
+ current.launcherRef.name,
140
+ );
141
+
142
+ if (editFormLauncher == undefined) {
143
+ console.error(
144
+ `Cannot find form '${current.launcherRef.name}' in the edit launchers`,
145
+ );
146
+
147
+ return Co.SetState(
148
+ errorUpd(
149
+ List([
150
+ `Cannot find form '${current.launcherRef.name}' in the edit launchers`,
151
+ ]),
152
+ ),
153
+ );
154
+ }
155
+
156
+ const getApi = () =>
157
+ current.launcherRef.apiSources.entityApis.get(editFormLauncher.api)(
158
+ current.launcherRef.entityId,
159
+ );
160
+ const getGlobalConfig =
161
+ current.launcherRef.config.source == "api" &&
162
+ current.launcherRef.config.getGlobalConfig
163
+ ? current.launcherRef.config.getGlobalConfig
164
+ : () =>
165
+ current.launcherRef.apiSources.entityApis.get(
166
+ editFormLauncher.configApi,
167
+ )("");
168
+
169
+ return Co.Seq([
170
+ Co.Seq([
171
+ Co.All([
172
+ getValueCo(getApi, editFormLauncher),
173
+ configValueCo(getGlobalConfig, editFormLauncher, current),
174
+ ]),
175
+ Co.UpdateState((_) => {
176
+ if (_.entity.sync.kind == "error") {
177
+ return errorUpd(List([_.entity.sync.error]));
178
+ }
179
+
180
+ if (_.config.sync.kind == "error") {
181
+ return errorUpd(List([_.config.sync.error]));
182
+ }
183
+
184
+ if (
185
+ _.config.sync.kind == "loading" ||
186
+ _.config.sync.kind == "reloading"
187
+ ) {
188
+ return id;
189
+ }
190
+
191
+ if (
192
+ _.entity.sync.kind == "loading" ||
193
+ _.entity.sync.kind == "unloaded" ||
194
+ _.entity.sync.kind == "reloading"
195
+ ) {
196
+ return id;
197
+ }
198
+
199
+ const dispatcherContextWithApiSources: DispatcherContextWithApiSources<
200
+ T,
201
+ Flags,
202
+ CustomPresentationContexts,
203
+ ExtraContext
204
+ > = {
205
+ ...dispatcherContext,
206
+ ...current.launcherRef.apiSources,
207
+ defaultState: dispatcherContext.defaultState(
208
+ current.launcherRef.apiSources.infiniteStreamSources,
209
+ current.launcherRef.apiSources.lookupSources,
210
+ current.launcherRef.apiSources.tableApiSources,
211
+ ),
212
+ };
213
+
214
+ const Form = Dispatcher.Operations.Dispatch(
215
+ editFormLauncher.renderer,
216
+ dispatcherContextWithApiSources,
217
+ false,
218
+ false,
219
+ undefined,
220
+ );
221
+
222
+ if (Form.kind == "errors") {
223
+ console.error(Form.errors.valueSeq().toArray().join("\n"));
224
+ return errorUpd(Form.errors);
225
+ }
226
+
227
+ const initialState = dispatcherContext.defaultState(
228
+ current.launcherRef.apiSources.infiniteStreamSources,
229
+ current.launcherRef.apiSources.lookupSources,
230
+ current.launcherRef.apiSources.tableApiSources,
231
+ )(editFormLauncher.type, editFormLauncher.renderer);
232
+
233
+ if (initialState.kind == "errors") {
234
+ console.error(
235
+ initialState.errors.valueSeq().toArray().join("\n"),
236
+ );
237
+ return errorUpd(initialState.errors);
238
+ }
239
+
240
+ return DispatchEditFormLauncherState<T, Flags>()
241
+ .Updaters.Core.formState(replaceWith(initialState.value))
242
+ .thenMany([
243
+ DispatchEditFormLauncherState<T, Flags>().Updaters.Core.status(
244
+ replaceWith<DispatchFormRunnerStatus<T, Flags>>({
245
+ kind: "loaded",
246
+ Form: Form.value,
247
+ }),
248
+ ),
249
+ DispatchEditFormLauncherState<T, Flags>().Updaters.Core.config(
250
+ replaceWith(_.config),
251
+ ),
252
+ ]);
253
+ }),
254
+ ]),
255
+ HandleApiResponse<
256
+ DispatchEditFormLauncherState<T, Flags>,
257
+ DispatchEditFormLauncherContext<
258
+ T,
259
+ Flags,
260
+ CustomPresentationContexts,
261
+ ExtraContext
262
+ >,
263
+ any
264
+ >((_) => _.entity.sync, {
265
+ handleSuccess: current.launcherRef.apiHandlers?.onGetSuccess,
266
+ handleError: current.launcherRef.apiHandlers?.onGetError,
267
+ }),
268
+ setChecked(true),
269
+ ]);
270
+ }),
271
+ ]);
272
+ };
@@ -0,0 +1,101 @@
1
+ import {
2
+ ApiErrors,
3
+ DispatchInjectablesTypes,
4
+ HandleApiResponse,
5
+ id,
6
+ Synchronize,
7
+ Unit,
8
+ } from "../../../../../../../../../main";
9
+ import { ApiResponseChecker } from "../../../../../../../../api-response-handler/state";
10
+ import {
11
+ DispatchEditFormLauncherContext,
12
+ DispatchEditFormLauncherState,
13
+ } from "../state";
14
+ import { EditCoBuilder } from "./builder";
15
+
16
+ export const syncCo = <
17
+ T extends DispatchInjectablesTypes<T>,
18
+ Flags,
19
+ CustomPresentationContexts,
20
+ ExtraContext,
21
+ >(
22
+ Co: ReturnType<
23
+ typeof EditCoBuilder<T, Flags, CustomPresentationContexts, ExtraContext>
24
+ >,
25
+ ) => {
26
+ const setChecked = (checked: boolean) =>
27
+ Co.SetState(
28
+ DispatchEditFormLauncherState<
29
+ T,
30
+ Flags
31
+ >().Updaters.Core.apiChecker.children.update(
32
+ checked
33
+ ? ApiResponseChecker.Updaters().toChecked()
34
+ : ApiResponseChecker.Updaters().toUnchecked(),
35
+ ),
36
+ );
37
+
38
+ return Co.GetState().then((current) => {
39
+ if (current.deserializedSpecification.sync.kind !== "loaded") {
40
+ return Co.SetState(id);
41
+ }
42
+
43
+ if (current.deserializedSpecification.sync.value.kind == "errors") {
44
+ return Co.SetState(id);
45
+ }
46
+
47
+ const editFormLauncher =
48
+ current.deserializedSpecification.sync.value.value.launchers.edit.get(
49
+ current.launcherRef.name,
50
+ );
51
+
52
+ if (!editFormLauncher) {
53
+ return Co.SetState(id);
54
+ }
55
+
56
+ const update = current.launcherRef.apiSources.entityApis.update(
57
+ editFormLauncher.api,
58
+ );
59
+
60
+ return Co.Seq([
61
+ setChecked(false),
62
+ Synchronize<Unit, ApiErrors, Unit>(
63
+ (_) => {
64
+ if (current.entity.sync.kind !== "loaded") {
65
+ return Promise.resolve([]);
66
+ }
67
+
68
+ const parsed = editFormLauncher?.toApiParser(
69
+ current.entity.sync.value,
70
+ editFormLauncher?.type,
71
+ current.formState,
72
+ );
73
+
74
+ return !parsed || parsed?.kind == "errors"
75
+ ? Promise.reject(parsed?.errors)
76
+ : update(current.launcherRef.entityId, parsed.value).then(() => []);
77
+ },
78
+ (_) => "transient failure",
79
+ 3,
80
+ 50,
81
+ ).embed(
82
+ (_) => _.apiRunner,
83
+ DispatchEditFormLauncherState<T, Flags>().Updaters.Core.apiRunner,
84
+ ),
85
+ HandleApiResponse<
86
+ DispatchEditFormLauncherState<T, Flags>,
87
+ DispatchEditFormLauncherContext<
88
+ T,
89
+ Flags,
90
+ CustomPresentationContexts,
91
+ ExtraContext
92
+ >,
93
+ ApiErrors
94
+ >((_) => _.apiRunner.sync, {
95
+ handleSuccess: current.launcherRef.apiHandlers?.onUpdateSuccess,
96
+ handleError: current.launcherRef.apiHandlers?.onUpdateError,
97
+ }),
98
+ setChecked(true),
99
+ ]);
100
+ });
101
+ };
@@ -0,0 +1,24 @@
1
+ import {
2
+ CoTypedFactory,
3
+ DispatchInjectablesTypes,
4
+ } from "../../../../../../../../../main";
5
+ import {
6
+ DispatchEditFormLauncherContext,
7
+ DispatchEditFormLauncherState,
8
+ } from "../state";
9
+
10
+ export const EditCoBuilder = <
11
+ T extends DispatchInjectablesTypes<T>,
12
+ Flags,
13
+ CustomPresentationContexts,
14
+ ExtraContext,
15
+ >() =>
16
+ CoTypedFactory<
17
+ DispatchEditFormLauncherContext<
18
+ T,
19
+ Flags,
20
+ CustomPresentationContexts,
21
+ ExtraContext
22
+ >,
23
+ DispatchEditFormLauncherState<T, Flags>
24
+ >();
@@ -0,0 +1,43 @@
1
+ import {
2
+ ApiResponseChecker,
3
+ DispatchInjectablesTypes,
4
+ } from "../../../../../../../../../main";
5
+ import { initCo } from "./_init";
6
+ import { syncCo } from "./_sync";
7
+ import { DispatchEditFormLauncherForeignMutationsExpected } from "../state";
8
+ import { EditCoBuilder } from "./builder";
9
+
10
+ export const DispatchEditFormRunner = <
11
+ T extends DispatchInjectablesTypes<T>,
12
+ Flags,
13
+ CustomPresentationContexts,
14
+ ExtraContext,
15
+ >() => {
16
+ const Co = EditCoBuilder<
17
+ T,
18
+ Flags,
19
+ CustomPresentationContexts,
20
+ ExtraContext
21
+ >();
22
+
23
+ const init = initCo<T, Flags, CustomPresentationContexts, ExtraContext>(Co);
24
+ const sync = syncCo<T, Flags, CustomPresentationContexts, ExtraContext>(Co);
25
+
26
+ return Co.Template<DispatchEditFormLauncherForeignMutationsExpected<T>>(
27
+ init,
28
+ {
29
+ runFilter: (_) =>
30
+ !ApiResponseChecker.Operations.checked(_.context.apiChecker.init) ||
31
+ _.context.entity.sync.kind != "loaded",
32
+ },
33
+ ).any([
34
+ Co.Template<DispatchEditFormLauncherForeignMutationsExpected<T>>(sync, {
35
+ runFilter: (_) =>
36
+ _.context.entity.sync.kind == "loaded" &&
37
+ (_.context.apiRunner.sync.kind === "loading" ||
38
+ _.context.apiRunner.sync.kind === "reloading" ||
39
+ _.context.apiRunner.sync.kind === "loaded") &&
40
+ !ApiResponseChecker.Operations.checked(_.context.apiChecker.update),
41
+ }),
42
+ ]);
43
+ };
@@ -0,0 +1,96 @@
1
+ import {
2
+ DispatchFormRunnerContext,
3
+ DispatchFormRunnerState,
4
+ DispatchInjectablesTypes,
5
+ EditLauncherRef,
6
+ Guid,
7
+ ApiErrors,
8
+ Unit,
9
+ DispatchCommonFormRunnerState,
10
+ ApiResponseChecker,
11
+ Synchronized,
12
+ unit,
13
+ simpleUpdaterWithChildren,
14
+ simpleUpdater,
15
+ PredicateValue,
16
+ BasicUpdater,
17
+ Updater,
18
+ AsyncState,
19
+ } from "../../../../../../../../main";
20
+
21
+ export type DispatchEditFormLauncherApi = {
22
+ get: (id: Guid) => Promise<any>;
23
+ update: (id: Guid, raw: any) => Promise<ApiErrors>;
24
+ };
25
+
26
+ export type DispatchEditFormLauncherContext<
27
+ T extends DispatchInjectablesTypes<T>,
28
+ Flags = Unit,
29
+ CustomPresentationContexts = Unit,
30
+ ExtraContext = Unit,
31
+ > = Omit<
32
+ DispatchFormRunnerContext<T, Flags, CustomPresentationContexts, ExtraContext>,
33
+ "launcherRef"
34
+ > & {
35
+ launcherRef: EditLauncherRef;
36
+ };
37
+
38
+ export type DispatchEditFormLauncherState<
39
+ T extends DispatchInjectablesTypes<T>,
40
+ Flags = Unit,
41
+ > = DispatchCommonFormRunnerState<T, Flags> & {
42
+ entity: Synchronized<Unit, PredicateValue>;
43
+ config: Synchronized<Unit, PredicateValue>;
44
+ apiChecker: {
45
+ init: ApiResponseChecker;
46
+ update: ApiResponseChecker;
47
+ };
48
+ apiRunner: Synchronized<Unit, ApiErrors>;
49
+ };
50
+
51
+ export type DispatchEditFormLauncherForeignMutationsExpected<T> = {};
52
+
53
+ export const DispatchEditFormLauncherState = <
54
+ T extends DispatchInjectablesTypes<T>,
55
+ Flags = Unit,
56
+ >() => ({
57
+ Default: (): DispatchEditFormLauncherState<T, Flags> => ({
58
+ ...DispatchCommonFormRunnerState<T, Flags>().Default(),
59
+ entity: Synchronized.Default(unit),
60
+ config: Synchronized.Default(unit),
61
+ apiChecker: {
62
+ init: ApiResponseChecker.Default(false),
63
+ update: ApiResponseChecker.Default(false),
64
+ },
65
+ apiRunner: Synchronized.Default(unit),
66
+ }),
67
+ Updaters: {
68
+ Core: {
69
+ ...simpleUpdater<DispatchEditFormLauncherState<T, Flags>>()("status"),
70
+ ...simpleUpdater<DispatchEditFormLauncherState<T, Flags>>()("formState"),
71
+ ...simpleUpdater<DispatchEditFormLauncherState<T, Flags>>()("entity"),
72
+ ...simpleUpdater<DispatchEditFormLauncherState<T, Flags>>()("config"),
73
+ ...simpleUpdater<DispatchEditFormLauncherState<T, Flags>>()("apiRunner"),
74
+ ...simpleUpdaterWithChildren<DispatchEditFormLauncherState<T, Flags>>()({
75
+ ...simpleUpdater<
76
+ DispatchEditFormLauncherState<T, Flags>["apiChecker"]
77
+ >()("init"),
78
+ ...simpleUpdater<
79
+ DispatchEditFormLauncherState<T, Flags>["apiChecker"]
80
+ >()("update"),
81
+ })("apiChecker"),
82
+ },
83
+ Template: {
84
+ entity: (
85
+ _: BasicUpdater<PredicateValue>,
86
+ ): Updater<DispatchEditFormLauncherState<T, Flags>> =>
87
+ DispatchEditFormLauncherState<T, Flags>().Updaters.Core.entity(
88
+ Synchronized.Updaters.sync(AsyncState.Operations.map(_)),
89
+ ),
90
+ submit: (): Updater<DispatchEditFormLauncherState<T, Flags>> =>
91
+ DispatchEditFormLauncherState<T, Flags>().Updaters.Core.apiRunner(
92
+ Synchronized.Updaters.sync(AsyncState.Updaters.toLoading()),
93
+ ),
94
+ },
95
+ },
96
+ });
@@ -0,0 +1,115 @@
1
+ import {
2
+ DispatchEditFormLauncherContext,
3
+ DispatchEditFormLauncherState,
4
+ DispatchEditFormLauncherForeignMutationsExpected,
5
+ } from "./state";
6
+ import {
7
+ DispatchInjectablesTypes,
8
+ Template,
9
+ Unit,
10
+ AsyncState,
11
+ Bindings,
12
+ unit,
13
+ } from "../../../../../../../../main";
14
+ import React from "react";
15
+ import { DispatchEditFormRunner } from "./coroutines/runner";
16
+ import { Map } from "immutable";
17
+
18
+ export const DispatchEditFormLauncherTemplate = <
19
+ T extends DispatchInjectablesTypes<T>,
20
+ Flags,
21
+ CustomPresentationContexts,
22
+ ExtraContext,
23
+ >() =>
24
+ Template.Default<
25
+ DispatchEditFormLauncherContext<
26
+ T,
27
+ Flags,
28
+ CustomPresentationContexts,
29
+ ExtraContext
30
+ >,
31
+ DispatchEditFormLauncherState<T, Flags>,
32
+ DispatchEditFormLauncherForeignMutationsExpected<T>
33
+ >((props) => {
34
+ const entity = props.context.entity.sync;
35
+ const config = props.context.config.sync;
36
+
37
+ if (
38
+ !AsyncState.Operations.hasValue(entity) ||
39
+ !AsyncState.Operations.hasValue(config) ||
40
+ props.context.status.kind == "not initialized"
41
+ ) {
42
+ return <></>;
43
+ }
44
+
45
+ if (props.context.status.kind == "error") {
46
+ console.error(
47
+ props.context.status.errors.map((error) => error).join("\n"),
48
+ );
49
+ return (
50
+ props.context.errorComponent ?? <>Error: Check console for details</>
51
+ );
52
+ }
53
+
54
+ if (config.kind == "failed-reload") {
55
+ console.error(config.error);
56
+ return (
57
+ props.context.errorComponent ?? <>Error: Check console for details</>
58
+ );
59
+ }
60
+
61
+ if (props.context.status.kind == "loading" || config.kind == "reloading") {
62
+ return props.context.loadingComponent ?? <></>;
63
+ }
64
+
65
+ const bindings: Bindings = Map([
66
+ ["global", config.value],
67
+ ["root", entity.value],
68
+ ["local", entity.value],
69
+ ]);
70
+
71
+ return (
72
+ <props.context.status.Form
73
+ context={{
74
+ ...props.context.formState,
75
+ value: entity.value,
76
+ locked: false,
77
+ disabled: false,
78
+ bindings,
79
+ extraContext: props.context.extraContext,
80
+ remoteEntityVersionIdentifier:
81
+ props.context.remoteEntityVersionIdentifier,
82
+ domNodeAncestorPath: "",
83
+ lookupTypeAncestorNames: [],
84
+ }}
85
+ setState={(stateUpdater) =>
86
+ props.setState(
87
+ DispatchEditFormLauncherState<T, Flags>().Updaters.Core.formState(
88
+ stateUpdater,
89
+ ),
90
+ )
91
+ }
92
+ view={unit}
93
+ foreignMutations={{
94
+ ...props.foreignMutations,
95
+ onChange: (pvUpdater, delta) => {
96
+ if (pvUpdater.kind == "l") return;
97
+
98
+ props.setState(
99
+ DispatchEditFormLauncherState<
100
+ T,
101
+ Flags
102
+ >().Updaters.Template.entity(pvUpdater.value),
103
+ );
104
+ },
105
+ }}
106
+ />
107
+ );
108
+ }).any([
109
+ DispatchEditFormRunner<
110
+ T,
111
+ Flags,
112
+ CustomPresentationContexts,
113
+ ExtraContext
114
+ >(),
115
+ ]);