ballerina-core 1.0.72 → 1.0.74
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/main.ts +1 -0
- package/package.json +1 -1
- package/src/collections/domains/valueOrErrors/state.ts +13 -15
- package/src/forms/domains/launcher/coroutines/runner.ts +7 -1
- package/src/forms/domains/launcher/domains/create/coroutines/runner.ts +139 -15
- package/src/forms/domains/launcher/domains/create/state.ts +45 -9
- package/src/forms/domains/launcher/domains/create/template.tsx +10 -1
- package/src/forms/domains/launcher/domains/edit/coroutines/runner.ts +165 -35
- package/src/forms/domains/launcher/domains/edit/state.ts +45 -9
- package/src/forms/domains/launcher/domains/edit/template.tsx +15 -4
- package/src/forms/domains/launcher/state.ts +1 -1
- package/src/forms/domains/launcher/template.tsx +6 -0
- package/src/forms/domains/parser/coroutines/runner.ts +1 -0
- package/src/forms/domains/parser/domains/built-ins/state.ts +18 -14
- package/src/forms/domains/parser/domains/predicates/state.ts +434 -0
- package/src/forms/domains/parser/domains/renderer/state.ts +85 -62
- package/src/forms/domains/parser/domains/types/state.ts +31 -16
- package/src/forms/domains/parser/domains/validator/state.ts +32 -10
- package/src/forms/domains/parser/state.tsx +96 -55
- package/src/forms/domains/primitives/domains/list/template.tsx +8 -5
- package/src/forms/domains/primitives/domains/map/template.tsx +8 -4
- package/src/forms/domains/singleton/state.ts +4 -4
- package/src/forms/domains/singleton/template.tsx +28 -13
package/main.ts
CHANGED
|
@@ -117,6 +117,7 @@ export * from "./src/forms/domains/launcher/state"
|
|
|
117
117
|
export * from "./src/forms/domains/launcher/template"
|
|
118
118
|
export * from "./src/forms/domains/parser/domains/injectables/state"
|
|
119
119
|
export * from "./src/forms/domains/collection/domains/unionCase/state"
|
|
120
|
+
export * from "./src/forms/domains/parser/domains/predicates/state"
|
|
120
121
|
|
|
121
122
|
// import { simpleUpdater, simpleUpdaterWithChildren } from "./src/fun/domains/updater/domains/simpleUpdater/state"
|
|
122
123
|
// import { Updater } from "./src/fun/domains/updater/state"
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import { List } from "immutable";
|
|
|
2
2
|
import { BasicFun, BasicFun2, Fun } from "../../../fun/state";
|
|
3
3
|
import { Value } from "../../../value/state";
|
|
4
4
|
import { Errors } from "../errors/state"
|
|
5
|
-
import { unit, Unit, Updater, Option } from "../../../../main";
|
|
5
|
+
import { unit, Unit, Updater, Option, Sum } from "../../../../main";
|
|
6
6
|
|
|
7
7
|
export type ValueOrErrors<v, e> = (
|
|
8
8
|
| (Value<v> & { kind: "value" })
|
|
@@ -122,25 +122,23 @@ export const ValueOrErrors = {
|
|
|
122
122
|
ValueOrErrors.Operations.Map<a, ValueOrErrors<b, e>, e>(k)(_)
|
|
123
123
|
)
|
|
124
124
|
),
|
|
125
|
+
Catch: <v, e>(_: ValueOrErrors<v, e>): ValueOrErrors<Sum<v, List<e>>, e> =>
|
|
126
|
+
_.kind == "errors" ?
|
|
127
|
+
ValueOrErrors.Default.return(Sum.Default.right(_.errors)) : ValueOrErrors.Default.return(Sum.Default.left(_.value)),
|
|
125
128
|
Fold: <v, e, c>(
|
|
126
129
|
l: BasicFun<v, c>,
|
|
127
130
|
r: BasicFun<List<e>, c>
|
|
128
131
|
): Fun<ValueOrErrors<v, e>, c> =>
|
|
129
132
|
Fun((_) => (_.kind == "value" ? l(_.value) : r(_.errors))),
|
|
130
133
|
All: <v, e>(_: List<ValueOrErrors<v, e>>): ValueOrErrors<List<v>, e> =>
|
|
131
|
-
_.
|
|
132
|
-
(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
? reduction.MapErrors((_) => _.concat(es))
|
|
141
|
-
: ValueOrErrors.Default.throw(es)
|
|
142
|
-
)(value),
|
|
143
|
-
ValueOrErrors.Default.return(List<v>())
|
|
144
|
-
),
|
|
134
|
+
_.size == 0 ?
|
|
135
|
+
ValueOrErrors.Default.return(List())
|
|
136
|
+
: ValueOrErrors.Operations.Catch(_.first()!).Then(res_p =>
|
|
137
|
+
res_p.kind == "l" ?
|
|
138
|
+
ValueOrErrors.Operations.All(_.slice(1).toList()).Then(values =>
|
|
139
|
+
ValueOrErrors.Default.return(List<v>().push(res_p.value).concat(values))
|
|
140
|
+
)
|
|
141
|
+
: ValueOrErrors.Default.throw(res_p.value)
|
|
142
|
+
)
|
|
145
143
|
},
|
|
146
144
|
};
|
|
@@ -40,8 +40,11 @@ export const FormRunnerLoader = () => {
|
|
|
40
40
|
form: instantiatedForm.form,
|
|
41
41
|
formFieldStates: instantiatedForm.initialState.formFieldStates,
|
|
42
42
|
entity: instantiatedForm.initialState.entity,
|
|
43
|
+
rawEntity: instantiatedForm.initialState.rawEntity,
|
|
43
44
|
commonFormState: instantiatedForm.initialState.commonFormState,
|
|
44
45
|
customFormState: instantiatedForm.initialState.customFormState,
|
|
46
|
+
rawGlobalConfiguration: instantiatedForm.initialState.rawGlobalConfiguration,
|
|
47
|
+
globalConfiguration: instantiatedForm.initialState.globalConfiguration
|
|
45
48
|
})
|
|
46
49
|
)
|
|
47
50
|
)
|
|
@@ -62,8 +65,11 @@ export const FormRunnerLoader = () => {
|
|
|
62
65
|
form: instantiatedForm.form,
|
|
63
66
|
formFieldStates: instantiatedForm.initialState.formFieldStates,
|
|
64
67
|
entity: instantiatedForm.initialState.entity,
|
|
68
|
+
rawEntity: instantiatedForm.initialState.rawEntity,
|
|
65
69
|
commonFormState: instantiatedForm.initialState.commonFormState,
|
|
66
|
-
customFormState: instantiatedForm.initialState.customFormState
|
|
70
|
+
customFormState: instantiatedForm.initialState.customFormState,
|
|
71
|
+
rawGlobalConfiguration: instantiatedForm.initialState.rawGlobalConfiguration,
|
|
72
|
+
globalConfiguration: instantiatedForm.initialState.globalConfiguration
|
|
67
73
|
})
|
|
68
74
|
)
|
|
69
75
|
)
|
|
@@ -10,6 +10,13 @@ import {
|
|
|
10
10
|
Unit,
|
|
11
11
|
HandleApiResponse,
|
|
12
12
|
ApiResponseChecker,
|
|
13
|
+
Sum,
|
|
14
|
+
replaceWith,
|
|
15
|
+
PredicateValue,
|
|
16
|
+
evaluatePredicates,
|
|
17
|
+
FormFieldPredicateEvaluation,
|
|
18
|
+
ValueOrErrors,
|
|
19
|
+
ApiResultStatus,
|
|
13
20
|
} from "../../../../../../../main";
|
|
14
21
|
import { CoTypedFactory } from "../../../../../../coroutines/builder";
|
|
15
22
|
import { CreateFormContext, CreateFormWritableState } from "../state";
|
|
@@ -23,31 +30,124 @@ export const createFormRunner = <E, FS>() => {
|
|
|
23
30
|
const init = Co.GetState().then((current) =>
|
|
24
31
|
Co.Seq([
|
|
25
32
|
Co.SetState(
|
|
26
|
-
CreateFormState<
|
|
27
|
-
E,
|
|
28
|
-
FS
|
|
29
|
-
>().Updaters.Core.customFormState.children.initApiChecker(ApiResponseChecker.Updaters().toUnchecked())
|
|
33
|
+
CreateFormState<E,FS>().Updaters.Core.customFormState.children.initApiChecker(ApiResponseChecker.Updaters().toUnchecked())
|
|
30
34
|
),
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
Co.All([
|
|
36
|
+
Synchronize<Unit, E>(
|
|
37
|
+
() => current.api.default(),
|
|
38
|
+
(_) => "transient failure",
|
|
39
|
+
5,
|
|
40
|
+
50
|
|
41
|
+
).embed((_) => _.rawEntity, CreateFormState<E, FS>().Updaters.Core.rawEntity),
|
|
42
|
+
Synchronize<Unit, any>(
|
|
43
|
+
() => current.api.getGlobalConfiguration(),
|
|
44
|
+
(_) => "transient failure",
|
|
45
|
+
5,
|
|
46
|
+
50
|
|
47
|
+
).embed((_) => _.rawGlobalConfiguration, CreateFormState<E, FS>().Updaters.Core.rawGlobalConfiguration),
|
|
48
|
+
]),
|
|
37
49
|
HandleApiResponse<
|
|
38
50
|
CreateFormWritableState<E, FS>,
|
|
39
51
|
CreateFormContext<E, FS>,
|
|
40
|
-
|
|
41
|
-
>((_) => _.
|
|
52
|
+
any
|
|
53
|
+
>((_) => _.rawEntity.sync, {
|
|
42
54
|
handleSuccess: current.apiHandlers?.onDefaultSuccess,
|
|
43
55
|
handleError: current.apiHandlers?.onDefaultError,
|
|
44
56
|
}),
|
|
45
57
|
Co.SetState(
|
|
46
58
|
CreateFormState<E, FS>().Updaters.Core.customFormState.children.initApiChecker(ApiResponseChecker.Updaters().toChecked())
|
|
47
59
|
),
|
|
48
|
-
|
|
60
|
+
HandleApiResponse<
|
|
61
|
+
CreateFormWritableState<E, FS>,
|
|
62
|
+
CreateFormContext<E, FS>,
|
|
63
|
+
any
|
|
64
|
+
>((_) => _.rawGlobalConfiguration.sync, {
|
|
65
|
+
handleSuccess: current.apiHandlers?.onConfigSuccess,
|
|
66
|
+
handleError: current.apiHandlers?.onConfigError,
|
|
67
|
+
}),
|
|
68
|
+
Co.SetState(
|
|
69
|
+
CreateFormState<E, FS>().Updaters.Core.customFormState.children.configApiChecker(ApiResponseChecker.Updaters().toChecked())
|
|
70
|
+
),
|
|
71
|
+
]),
|
|
49
72
|
);
|
|
50
73
|
|
|
74
|
+
const parseEntity = Co.GetState().then((current) => {
|
|
75
|
+
if(current.rawEntity.sync.kind == "loaded") {
|
|
76
|
+
const parsed = current.fromApiParser(current.rawEntity.sync.value)
|
|
77
|
+
return Synchronize<Unit, any>(
|
|
78
|
+
() => Promise.resolve(parsed),
|
|
79
|
+
(_) => "transient failure",
|
|
80
|
+
5,
|
|
81
|
+
50
|
|
82
|
+
).embed((_) => _.entity, CreateFormState<E, FS>().Updaters.Core.entity)
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
return Co.Do(() => {})
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
const parseGlobalConfiguration = Co.GetState().then((current) => {
|
|
89
|
+
if(current.rawGlobalConfiguration.sync.kind == "loaded") {
|
|
90
|
+
const parsed = current.parseGlobalConfiguration(current.rawGlobalConfiguration.sync.value)
|
|
91
|
+
if(parsed.kind == "value")
|
|
92
|
+
return Co.SetState(CreateFormState<E, FS>().Updaters.Core.globalConfiguration(replaceWith(Sum.Default.left(parsed.value))))
|
|
93
|
+
}
|
|
94
|
+
return Co.Do(() => {})
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const calculateInitialVisibilities = Co.GetState().then((current) => {
|
|
98
|
+
if(current.rawEntity.sync.kind == "loaded" && current.rawGlobalConfiguration.sync.kind == "loaded") {
|
|
99
|
+
const parsedRootPredicate = PredicateValue.Operations.parse(current.rawEntity.sync.value, current.formType, current.types)
|
|
100
|
+
|
|
101
|
+
if(parsedRootPredicate.kind == "errors" || current.globalConfiguration.kind == "r")
|
|
102
|
+
return Co.Do(() => {})
|
|
103
|
+
if(typeof parsedRootPredicate.value != "object" || !("kind" in parsedRootPredicate.value) || parsedRootPredicate.value.kind != "record")
|
|
104
|
+
return Co.Do(() => {})
|
|
105
|
+
return Co.SetState(CreateFormState<E, FS>().Updaters.Core.customFormState.children.predicateEvaluations(
|
|
106
|
+
replaceWith(Debounced.Default(evaluatePredicates({
|
|
107
|
+
global: current.globalConfiguration.value,
|
|
108
|
+
types: current.types,
|
|
109
|
+
visibilityPredicateExpressions: current.visibilityPredicateExpressions,
|
|
110
|
+
disabledPredicatedExpressions: current.disabledPredicatedExpressions
|
|
111
|
+
}, parsedRootPredicate.value)))))
|
|
112
|
+
}
|
|
113
|
+
return Co.Do(() => {})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
const PredicatesCo = CoTypedFactory<CreateFormWritableState<E, FS> & CreateFormContext<E, FS>, ValueOrErrors<{
|
|
117
|
+
visiblityPredicateEvaluations: FormFieldPredicateEvaluation;
|
|
118
|
+
disabledPredicateEvaluations: FormFieldPredicateEvaluation;
|
|
119
|
+
}, string>>();
|
|
120
|
+
|
|
121
|
+
const calculateVisibilities =
|
|
122
|
+
Co.Repeat(
|
|
123
|
+
Debounce<ValueOrErrors<{visiblityPredicateEvaluations: FormFieldPredicateEvaluation; disabledPredicateEvaluations: FormFieldPredicateEvaluation;}, string>, CreateFormContext<E, FS> & CreateFormWritableState<E, FS>>(
|
|
124
|
+
PredicatesCo.GetState().then((current) => {
|
|
125
|
+
if((current.globalConfiguration.kind == "r" || current.entity.sync.kind != "loaded") ){
|
|
126
|
+
return PredicatesCo.Return<ApiResultStatus>("permanent failure")
|
|
127
|
+
}
|
|
128
|
+
const parsedEntity = current.toApiParser(current.entity.sync.value, current, false)
|
|
129
|
+
if(parsedEntity.kind == "errors") {
|
|
130
|
+
console.error('parsedEntity', parsedEntity)
|
|
131
|
+
return PredicatesCo.Return<ApiResultStatus>("permanent failure")
|
|
132
|
+
}
|
|
133
|
+
const parseRootPredicate = PredicateValue.Operations.parse(parsedEntity.value, current.formType, current.types)
|
|
134
|
+
if(parseRootPredicate.kind == "errors") {
|
|
135
|
+
console.error('parseRootPredicate', parseRootPredicate)
|
|
136
|
+
return PredicatesCo.Return<ApiResultStatus>("permanent failure")
|
|
137
|
+
}
|
|
138
|
+
return PredicatesCo.SetState(replaceWith(evaluatePredicates({
|
|
139
|
+
global: current.globalConfiguration.value,
|
|
140
|
+
types: current.types,
|
|
141
|
+
visibilityPredicateExpressions: current.visibilityPredicateExpressions,
|
|
142
|
+
disabledPredicatedExpressions: current.disabledPredicatedExpressions
|
|
143
|
+
}, parseRootPredicate.value))).then(() => PredicatesCo.Return<ApiResultStatus>("success"))
|
|
144
|
+
})
|
|
145
|
+
, 50)
|
|
146
|
+
.embed(
|
|
147
|
+
(_) => ({ ..._, ..._.customFormState.predicateEvaluations }),
|
|
148
|
+
CreateFormState<E, FS>().Updaters.Core.customFormState.children.predicateEvaluations)
|
|
149
|
+
)
|
|
150
|
+
|
|
51
151
|
const synchronize = Co.Repeat(
|
|
52
152
|
Co.GetState().then((current) =>
|
|
53
153
|
Co.Seq([
|
|
@@ -63,7 +163,7 @@ export const createFormRunner = <E, FS>() => {
|
|
|
63
163
|
50
|
|
64
164
|
)
|
|
65
165
|
}
|
|
66
|
-
const parsed = current.
|
|
166
|
+
const parsed = current.toApiParser(current.entity.sync.value, current, true)
|
|
67
167
|
|
|
68
168
|
return Synchronize<Unit, ApiErrors, CreateFormWritableState<E, FS>>(
|
|
69
169
|
(_) => parsed.kind == "errors" ? Promise.reject(parsed.errors) : current.api.create(parsed),
|
|
@@ -95,8 +195,25 @@ export const createFormRunner = <E, FS>() => {
|
|
|
95
195
|
return Co.Template<CreateFormForeignMutationsExpected<E, FS>>(init, {
|
|
96
196
|
interval: 15,
|
|
97
197
|
runFilter: (props) =>
|
|
98
|
-
!AsyncState.Operations.hasValue(props.context.
|
|
198
|
+
!AsyncState.Operations.hasValue(props.context.rawEntity.sync) || !AsyncState.Operations.hasValue(props.context.rawGlobalConfiguration.sync) || !ApiResponseChecker.Operations.checked(props.context.customFormState.initApiChecker),
|
|
99
199
|
}).any([
|
|
200
|
+
Co.Template<CreateFormForeignMutationsExpected<E, FS>>(parseEntity, {
|
|
201
|
+
interval: 15,
|
|
202
|
+
runFilter: (props) =>
|
|
203
|
+
props.context.rawEntity.sync.kind == "loaded" && !AsyncState.Operations.hasValue(props.context.entity.sync)
|
|
204
|
+
}),
|
|
205
|
+
Co.Template<CreateFormForeignMutationsExpected<E, FS>>(parseGlobalConfiguration, {
|
|
206
|
+
interval: 15,
|
|
207
|
+
runFilter: (props) =>
|
|
208
|
+
props.context.rawGlobalConfiguration.sync.kind == "loaded" &&
|
|
209
|
+
props.context.globalConfiguration.kind == "r"
|
|
210
|
+
}),
|
|
211
|
+
Co.Template<CreateFormForeignMutationsExpected<E, FS>>(calculateInitialVisibilities, {
|
|
212
|
+
interval: 15,
|
|
213
|
+
runFilter: (props) =>
|
|
214
|
+
props.context.rawEntity.sync.kind == "loaded" &&
|
|
215
|
+
props.context.globalConfiguration.kind == "l"
|
|
216
|
+
}),
|
|
100
217
|
Co.Template<CreateFormForeignMutationsExpected<E, FS>>(synchronize, {
|
|
101
218
|
interval: 15,
|
|
102
219
|
runFilter: (props) =>
|
|
@@ -104,5 +221,12 @@ export const createFormRunner = <E, FS>() => {
|
|
|
104
221
|
(Debounced.Operations.shouldCoroutineRun(props.context.customFormState.apiRunner) ||
|
|
105
222
|
!ApiResponseChecker.Operations.checked(props.context.customFormState.createApiChecker))
|
|
106
223
|
}),
|
|
224
|
+
Co.Template<CreateFormForeignMutationsExpected<E, FS>>(calculateVisibilities, {
|
|
225
|
+
interval: 15,
|
|
226
|
+
runFilter: (props) =>
|
|
227
|
+
props.context.entity.sync.kind == "loaded" &&
|
|
228
|
+
props.context.globalConfiguration.kind == "l" &&
|
|
229
|
+
Debounced.Operations.shouldCoroutineRun(props.context.customFormState.predicateEvaluations)
|
|
230
|
+
})
|
|
107
231
|
]);
|
|
108
232
|
};
|
|
@@ -1,26 +1,41 @@
|
|
|
1
|
-
import { ApiErrors, ApiResponseChecker, AsyncState, BasicUpdater, CommonFormState, Debounced, ForeignMutationsInput, id, SimpleCallback, simpleUpdater, simpleUpdaterWithChildren, Synchronized, Template, unit, Unit, Updater, Value } from "../../../../../../main"
|
|
2
|
-
import { ValueOrErrors } from "../../../../../collections/domains/valueOrErrors/state"
|
|
3
|
-
import {
|
|
1
|
+
import { ApiErrors, ApiResponseChecker, AsyncState, BasicUpdater, CommonFormState, Debounced, FieldPredicateExpressions, ForeignMutationsInput, FormFieldPredicateEvaluation, id, ParsedType, PredicateValue, SimpleCallback, simpleUpdater, simpleUpdaterWithChildren, Sum, Synchronized, Template, unit, Unit, Updater, Value } from "../../../../../../main"
|
|
2
|
+
import { ValueOrErrors } from "../../../../../collections/domains/valueOrErrors/state";
|
|
3
|
+
import { Map } from "immutable";
|
|
4
4
|
|
|
5
5
|
export type CreateFormContext<E,FS> = {
|
|
6
6
|
entityId:string,
|
|
7
7
|
api:{
|
|
8
8
|
default:() => Promise<E>,
|
|
9
|
-
create: (raw: any) => Promise<ApiErrors
|
|
9
|
+
create: (raw: any) => Promise<ApiErrors>,
|
|
10
|
+
getGlobalConfiguration: () => Promise<any>
|
|
10
11
|
},
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
formType: ParsedType<E>,
|
|
13
|
+
types: Map<string, ParsedType<E>>,
|
|
14
|
+
toApiParser: (entity:E, formstate: CreateFormState<E,FS>, checkKeys: boolean) => ValueOrErrors<E, ApiErrors>,
|
|
15
|
+
fromApiParser: (raw: any) => any,
|
|
16
|
+
parseGlobalConfiguration: (raw: any) => ValueOrErrors<PredicateValue, ApiErrors>,
|
|
17
|
+
visibilityPredicateExpressions: FieldPredicateExpressions,
|
|
18
|
+
disabledPredicatedExpressions: FieldPredicateExpressions,
|
|
19
|
+
actualForm:Template<Value<E> & {formFieldStates:FS} & { commonFormState: CommonFormState } & { visibilities: FormFieldPredicateEvaluation | undefined } & { disabledFields: FormFieldPredicateEvaluation | undefined }, {formFieldStates: FS} & { commonFormState: CommonFormState }, { onChange:SimpleCallback<BasicUpdater<E>> }>
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
export type CreateFormState<E,FS> = {
|
|
23
|
+
rawEntity: Synchronized<Unit, any>,
|
|
16
24
|
entity: Synchronized<Unit, E>
|
|
25
|
+
rawGlobalConfiguration: Synchronized<Unit, any>,
|
|
26
|
+
globalConfiguration: Sum<any, "not parsed">
|
|
17
27
|
formFieldStates: FS,
|
|
18
28
|
commonFormState: CommonFormState,
|
|
19
29
|
customFormState: {
|
|
20
30
|
initApiChecker: ApiResponseChecker,
|
|
31
|
+
configApiChecker: ApiResponseChecker,
|
|
21
32
|
createApiChecker: ApiResponseChecker,
|
|
33
|
+
predicateEvaluations: Debounced<ValueOrErrors<{
|
|
34
|
+
visiblityPredicateEvaluations: FormFieldPredicateEvaluation;
|
|
35
|
+
disabledPredicateEvaluations: FormFieldPredicateEvaluation;
|
|
36
|
+
}, string>>,
|
|
22
37
|
apiRunner: Debounced<Synchronized<Unit, ApiErrors>>
|
|
23
|
-
}
|
|
38
|
+
},
|
|
24
39
|
}
|
|
25
40
|
|
|
26
41
|
export const CreateFormState = <E,FS>() => ({
|
|
@@ -28,22 +43,36 @@ export const CreateFormState = <E,FS>() => ({
|
|
|
28
43
|
commonFormState: CommonFormState,
|
|
29
44
|
customFormState: {
|
|
30
45
|
initApiChecker: ApiResponseChecker,
|
|
46
|
+
configApiChecker: ApiResponseChecker,
|
|
31
47
|
createApiChecker: ApiResponseChecker,
|
|
48
|
+
predicateEvaluations: Debounced<ValueOrErrors<{
|
|
49
|
+
visiblityPredicateEvaluations: FormFieldPredicateEvaluation;
|
|
50
|
+
disabledPredicateEvaluations: FormFieldPredicateEvaluation;
|
|
51
|
+
}, string>>,
|
|
52
|
+
shouldCalculatePredicates: boolean,
|
|
32
53
|
apiRunner: Debounced<Synchronized<Unit, ApiErrors>>
|
|
33
54
|
}) : CreateFormState<E,FS> => ({
|
|
55
|
+
rawEntity: Synchronized.Default(unit),
|
|
34
56
|
entity:Synchronized.Default(unit),
|
|
57
|
+
rawGlobalConfiguration: Synchronized.Default(unit),
|
|
58
|
+
globalConfiguration: Sum.Default.right("not parsed"),
|
|
35
59
|
formFieldStates,
|
|
36
60
|
commonFormState,
|
|
37
|
-
customFormState
|
|
61
|
+
customFormState,
|
|
38
62
|
}),
|
|
39
63
|
Updaters:{
|
|
40
64
|
Core:{
|
|
65
|
+
...simpleUpdater<CreateFormState<E,FS>>()("rawEntity"),
|
|
41
66
|
...simpleUpdater<CreateFormState<E,FS>>()("entity"),
|
|
67
|
+
...simpleUpdater<CreateFormState<E,FS>>()("rawGlobalConfiguration"),
|
|
68
|
+
...simpleUpdater<CreateFormState<E,FS>>()("globalConfiguration"),
|
|
42
69
|
...simpleUpdater<CreateFormState<E,FS>>()("formFieldStates"),
|
|
43
70
|
...simpleUpdaterWithChildren<CreateFormState<E,FS>>()({
|
|
44
71
|
...simpleUpdater<CreateFormState<E,FS>["customFormState"]>()("initApiChecker"),
|
|
72
|
+
...simpleUpdater<CreateFormState<E,FS>["customFormState"]>()("configApiChecker"),
|
|
45
73
|
...simpleUpdater<CreateFormState<E,FS>["customFormState"]>()("createApiChecker"),
|
|
46
74
|
...simpleUpdater<CreateFormState<E,FS>["customFormState"]>()("apiRunner"),
|
|
75
|
+
...simpleUpdater<CreateFormState<E,FS>["customFormState"]>()("predicateEvaluations"),
|
|
47
76
|
})("customFormState"),
|
|
48
77
|
...simpleUpdater<CreateFormState<E,FS>>()("commonFormState"),
|
|
49
78
|
},
|
|
@@ -65,8 +94,13 @@ export const CreateFormState = <E,FS>() => ({
|
|
|
65
94
|
)
|
|
66
95
|
)
|
|
67
96
|
)
|
|
97
|
+
),
|
|
98
|
+
recalculatePredicates: () : Updater<CreateFormState<E,FS>> =>
|
|
99
|
+
CreateFormState<E,FS>().Updaters.Core.customFormState.children.predicateEvaluations(
|
|
100
|
+
Debounced.Updaters.Template.value(
|
|
101
|
+
id
|
|
68
102
|
)
|
|
69
|
-
|
|
103
|
+
)
|
|
70
104
|
}
|
|
71
105
|
},
|
|
72
106
|
ForeignMutations: (_: ForeignMutationsInput<CreateFormContext<E,FS>, CreateFormWritableState<E,FS>>) => ({
|
|
@@ -80,6 +114,8 @@ export type CreateFormForeignMutationsExpected<E,FS> = {
|
|
|
80
114
|
apiHandlers?: {
|
|
81
115
|
onDefaultSuccess?: (_: CreateFormWritableState<E, FS> & CreateFormContext<E, FS> | undefined) => void;
|
|
82
116
|
onDefaultError?: <ApiErrors>(_: ApiErrors | undefined) => void;
|
|
117
|
+
onConfigSuccess?: (_: CreateFormWritableState<E, FS> & CreateFormContext<E, FS> | undefined) => void;
|
|
118
|
+
onConfigError?: <ApiErrors>(_: ApiErrors | undefined) => void;
|
|
83
119
|
onCreateSuccess?: (_: CreateFormWritableState<E, FS> & CreateFormContext<E, FS> | undefined) => void;
|
|
84
120
|
onCreateError?: <ApiErrors>(_: ApiErrors | undefined) => void;
|
|
85
121
|
}
|
|
@@ -22,6 +22,12 @@ export const CreateFormTemplate = <E, FS>(): CreateFormTemplate<E, FS> =>
|
|
|
22
22
|
CreateFormWritableState<E, FS>,
|
|
23
23
|
CreateFormForeignMutationsExpected<E, FS>,
|
|
24
24
|
CreateFormView<E, FS>>(props => {
|
|
25
|
+
const visibilities = props.context.customFormState.predicateEvaluations.kind == "value" &&
|
|
26
|
+
props.context.customFormState.predicateEvaluations.value.visiblityPredicateEvaluations.kind == "form" ?
|
|
27
|
+
props.context.customFormState.predicateEvaluations.value.visiblityPredicateEvaluations : undefined;
|
|
28
|
+
const disabledFields = props.context.customFormState.predicateEvaluations.kind == "value"
|
|
29
|
+
&& props.context.customFormState.predicateEvaluations.value.disabledPredicateEvaluations.kind == "form" ?
|
|
30
|
+
props.context.customFormState.predicateEvaluations.value.disabledPredicateEvaluations : undefined;
|
|
25
31
|
return <>
|
|
26
32
|
{
|
|
27
33
|
props.view({
|
|
@@ -40,6 +46,8 @@ export const CreateFormTemplate = <E, FS>(): CreateFormTemplate<E, FS> =>
|
|
|
40
46
|
value: props.context.entity.sync.value,
|
|
41
47
|
formFieldStates: props.context.formFieldStates,
|
|
42
48
|
commonFormState: props.context.commonFormState,
|
|
49
|
+
visibilities,
|
|
50
|
+
disabledFields
|
|
43
51
|
},
|
|
44
52
|
setState: _ => {
|
|
45
53
|
props.setState(__ => ({
|
|
@@ -50,7 +58,8 @@ export const CreateFormTemplate = <E, FS>(): CreateFormTemplate<E, FS> =>
|
|
|
50
58
|
},
|
|
51
59
|
foreignMutations: {
|
|
52
60
|
onChange: (e) => {
|
|
53
|
-
props.setState(CreateFormState<E, FS>().Updaters.Template.entity(e))
|
|
61
|
+
props.setState(CreateFormState<E, FS>().Updaters.Template.entity(e));
|
|
62
|
+
props.setState(CreateFormState<E, FS>().Updaters.Template.recalculatePredicates())
|
|
54
63
|
}
|
|
55
64
|
},
|
|
56
65
|
view: unit
|