ballerina-core 1.0.8 → 1.0.10
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
CHANGED
|
@@ -20,7 +20,7 @@ export const FormRunnerErrorsTemplate = (parsedFormsConfig: FormParsingResult) =
|
|
|
20
20
|
export const FormRunnerTemplate =
|
|
21
21
|
Template.Default<FormRunnerContext & FormRunnerState, FormRunnerState, FormRunnerForeignMutationsExpected>(props => {
|
|
22
22
|
if (props.context.form.kind == "r") return <></>
|
|
23
|
-
console.log("props.context.form.value.formState", props.context)
|
|
23
|
+
// console.log("props.context.form.value.formState", props.context)
|
|
24
24
|
return <>
|
|
25
25
|
<props.context.form.value.form
|
|
26
26
|
context={{
|
|
@@ -32,6 +32,7 @@ export const Type = {
|
|
|
32
32
|
}
|
|
33
33
|
export type FieldConfig = {
|
|
34
34
|
renderer: string;
|
|
35
|
+
label: string
|
|
35
36
|
api: { stream?: string, enumOptions?: string },
|
|
36
37
|
elementRenderer?: string,
|
|
37
38
|
visible: BoolExpr<any>;
|
|
@@ -453,6 +454,7 @@ export const FormsConfig = {
|
|
|
453
454
|
formDef.fields = formDef.fields.set(
|
|
454
455
|
fieldName, {
|
|
455
456
|
renderer: fieldConfig.renderer,
|
|
457
|
+
label: fieldConfig.label ?? fieldName,
|
|
456
458
|
elementRenderer: fieldConfig.elementRenderer,
|
|
457
459
|
visible: BoolExpr.Default(fieldConfig.visible),
|
|
458
460
|
disabled: fieldConfig.disabled != undefined ?
|
|
@@ -24,48 +24,48 @@ const parseOptions = (leafPredicates: any, options: any) => {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
export const FieldView = //<Context, FieldViews extends DefaultFieldViews, EnumFieldConfigs extends {}, EnumSources extends {}>() => <ViewType extends keyof FieldViews, ViewName extends keyof FieldViews[ViewType]>
|
|
27
|
-
(fieldViews: any, viewType: any, viewName: any, fieldName: string, enumFieldConfigs: any, enumSources: any, leafPredicates: any): any => // FieldView<Context, FieldViews, ViewType, ViewName> =>
|
|
27
|
+
(fieldViews: any, viewType: any, viewName: any, fieldName: string, label: string, enumFieldConfigs: any, enumSources: any, leafPredicates: any): any => // FieldView<Context, FieldViews, ViewType, ViewName> =>
|
|
28
28
|
{
|
|
29
29
|
if (viewType == "MaybeBooleanViews")
|
|
30
30
|
return MaybeBooleanForm<any & FormLabel, Unit>(_ => PromiseRepo.Default.mock(() => []))
|
|
31
31
|
.withView(((fieldViews as any)[viewType] as any)[viewName]() as any)
|
|
32
|
-
.mapContext<any & SharedFormState & Value<boolean>>(_ => ({ ..._, label:
|
|
32
|
+
.mapContext<any & SharedFormState & Value<boolean>>(_ => ({ ..._, label: label })) as any
|
|
33
33
|
if (viewType == "BooleanViews")
|
|
34
34
|
return BooleanForm<any & FormLabel, Unit>(_ => PromiseRepo.Default.mock(() => []))
|
|
35
35
|
.withView(((fieldViews as any)[viewType] as any)[viewName]() as any)
|
|
36
|
-
.mapContext<any & SharedFormState & Value<boolean>>(_ => ({ ..._, label:
|
|
36
|
+
.mapContext<any & SharedFormState & Value<boolean>>(_ => ({ ..._, label: label })) as any
|
|
37
37
|
if (viewType == "DateViews")
|
|
38
38
|
return DateForm<any & FormLabel, Unit>(_ => PromiseRepo.Default.mock(() => []))
|
|
39
39
|
.withView(((fieldViews as any)[viewType] as any)[viewName]() as any)
|
|
40
|
-
.mapContext<any & DateFormState & Value<Date>>(_ => ({ ..._, label:
|
|
40
|
+
.mapContext<any & DateFormState & Value<Date>>(_ => ({ ..._, label: label })) as any
|
|
41
41
|
if (viewType == "NumberViews")
|
|
42
42
|
return NumberForm<any & FormLabel, Unit>(_ => PromiseRepo.Default.mock(() => []))
|
|
43
43
|
.withView(((fieldViews as any)[viewType] as any)[viewName]() as any)
|
|
44
|
-
.mapContext<any & SharedFormState & Value<number>>(_ => ({ ..._, label:
|
|
44
|
+
.mapContext<any & SharedFormState & Value<number>>(_ => ({ ..._, label: label })) as any
|
|
45
45
|
if (viewType == "StringViews")
|
|
46
46
|
return StringForm<any & FormLabel, Unit>(_ => PromiseRepo.Default.mock(() => []))
|
|
47
47
|
.withView(((fieldViews as any)[viewType] as any)[viewName]() as any)
|
|
48
|
-
.mapContext<any & SharedFormState & Value<string>>(_ => ({ ..._, label:
|
|
48
|
+
.mapContext<any & SharedFormState & Value<string>>(_ => ({ ..._, label: label })) as any
|
|
49
49
|
if (viewType == "EnumViews")
|
|
50
50
|
return EnumForm<any & FormLabel & BaseEnumContext<any, CollectionReference>, Unit, CollectionReference>(_ => PromiseRepo.Default.mock(() => []))
|
|
51
51
|
.withView(((fieldViews as any)[viewType] as any)[viewName]() as any)
|
|
52
52
|
.mapContext<any & EnumFormState<any & BaseEnumContext<any, CollectionReference>, CollectionReference> & Value<CollectionSelection<CollectionReference>>>(_ => ({
|
|
53
|
-
..._, label:
|
|
53
|
+
..._, label: label, getOptions: () => ((enumFieldConfigs as any)((enumSources as any)[fieldName]) as Promise<any>).then(options => parseOptions(leafPredicates, options))
|
|
54
54
|
})) as any
|
|
55
55
|
if (viewType == "EnumMultiselectViews")
|
|
56
56
|
return EnumMultiselectForm<any & FormLabel & BaseEnumContext<any, CollectionReference>, Unit, CollectionReference>(_ => PromiseRepo.Default.mock(() => []))
|
|
57
57
|
.withView(((fieldViews as any)[viewType] as any)[viewName]() as any)
|
|
58
58
|
.mapContext<any & EnumFormState<any & BaseEnumContext<any, CollectionReference>, CollectionReference> & Value<OrderedMap<Guid, CollectionReference>>>(_ => ({
|
|
59
|
-
..._, label:
|
|
59
|
+
..._, label: label, getOptions: () => ((enumFieldConfigs as any)((enumSources as any)[fieldName]) as Promise<any>).then(options => parseOptions(leafPredicates, options))
|
|
60
60
|
})) as any
|
|
61
61
|
if (viewType == "InfiniteStreamViews")
|
|
62
62
|
return SearchableInfiniteStreamForm<CollectionReference, any & FormLabel, Unit>(_ => PromiseRepo.Default.mock(() => []))
|
|
63
63
|
.withView(((fieldViews as any)[viewType] as any)[viewName]() as any)
|
|
64
|
-
.mapContext<any & SearchableInfiniteStreamState<CollectionReference> & Value<CollectionSelection<CollectionReference>>>(_ => ({ ..._, label:
|
|
64
|
+
.mapContext<any & SearchableInfiniteStreamState<CollectionReference> & Value<CollectionSelection<CollectionReference>>>(_ => ({ ..._, label: label })) as any
|
|
65
65
|
if (viewType == "InfiniteStreamMultiselectViews")
|
|
66
66
|
return InfiniteMultiselectDropdownForm<CollectionReference, any & FormLabel, Unit>(_ => PromiseRepo.Default.mock(() => []))
|
|
67
67
|
.withView(((fieldViews as any)[viewType] as any)[viewName]() as any)
|
|
68
|
-
.mapContext<any & FormLabel & SharedFormState & SearchableInfiniteStreamState<CollectionReference> & Value<OrderedMap<Guid, CollectionReference>>>(_ => ({ ..._, label:
|
|
68
|
+
.mapContext<any & FormLabel & SharedFormState & SearchableInfiniteStreamState<CollectionReference> & Value<OrderedMap<Guid, CollectionReference>>>(_ => ({ ..._, label: label })) as any
|
|
69
69
|
return `error: the view for ${viewType as string}::${viewName as string} cannot be found`;
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -145,40 +145,49 @@ export const ParseForm = (
|
|
|
145
145
|
}
|
|
146
146
|
});
|
|
147
147
|
const formConfig: any = {};
|
|
148
|
+
console.log(fieldsViewsConfig)
|
|
149
|
+
console.log(Object.keys(fieldsViewsConfig))
|
|
148
150
|
Object.keys(fieldsViewsConfig).forEach(fieldName => {
|
|
151
|
+
const label = formDef.fields.get(fieldName)!.label
|
|
149
152
|
const viewName = (fieldsViewsConfig as any)[fieldName];
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
153
|
+
const otherForm = otherForms.get(viewName)
|
|
154
|
+
if (otherForm != undefined) {
|
|
155
|
+
formConfig[fieldName] = otherForm.form.withView(containerFormView).mapContext<any>(_ => ({ ..._, label: label }))
|
|
156
|
+
} else {
|
|
157
|
+
const viewType = fieldNameToViewCategory(fieldName) as any
|
|
158
|
+
if (viewType == "ListViews") {
|
|
159
|
+
const elementRendererName = formFieldElementRenderers[fieldName]
|
|
160
|
+
const field = type.fields.get(fieldName)!
|
|
161
|
+
const initialElementValue = defaultValue(field.kind == "primitive" ? field.value : field.kind == "lookup" ? field.name : field.args[0])
|
|
162
|
+
const elementForm = otherForms.get(elementRendererName)
|
|
163
|
+
if (elementForm != undefined) { // the list argument is a nested form
|
|
164
|
+
const initialFormState = elementForm.initialFormState
|
|
165
|
+
formConfig[fieldName] = ListForm<any, any, any & FormLabel, Unit>(
|
|
166
|
+
{ Default: () => ({ ...initialFormState }) },
|
|
167
|
+
{ Default: () => ({ ...initialElementValue }) },
|
|
168
|
+
_ => PromiseRepo.Default.mock(() => []),
|
|
169
|
+
elementForm.form.withView(containerFormView)
|
|
170
|
+
).withView(((fieldViews as any)[viewType] as any)[viewName]() as any)
|
|
171
|
+
.mapContext<any>(_ => ({ ..._, label: label }))
|
|
172
|
+
} else { // the list argument is a primitive
|
|
173
|
+
const elementForm = FieldView(fieldViews, fieldNameToElementViewCategory(fieldName) as any, elementRendererName, fieldName, label, EnumOptionsSources, fieldsOptionsConfig, leafPredicates)
|
|
174
|
+
const initialFormState = FieldFormState(fieldViews, fieldNameToElementViewCategory(fieldName) as any, elementRendererName, fieldName, InfiniteStreamSources, fieldsInfiniteStreamsConfig);
|
|
175
|
+
formConfig[fieldName] = ListForm<any, any, any & FormLabel, Unit>(
|
|
176
|
+
{ Default: () => initialFormState },
|
|
177
|
+
{ Default: () => initialElementValue },
|
|
178
|
+
_ => PromiseRepo.Default.mock(() => []),
|
|
179
|
+
elementForm
|
|
180
|
+
).withView(((fieldViews as any)[viewType] as any)[viewName]() as any)
|
|
181
|
+
.mapContext<any>(_ => ({ ..._, label: label }))
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
formConfig[fieldName] = FieldView(fieldViews, viewType, viewName, fieldName, label, EnumOptionsSources, fieldsOptionsConfig, leafPredicates);
|
|
175
185
|
}
|
|
176
|
-
}
|
|
177
|
-
formConfig[fieldName] =
|
|
178
|
-
otherForms.get(viewName)?.form.withView(containerFormView).mapContext<any>(_ => ({ ..._, label: fieldName })) ??
|
|
179
|
-
FieldView(fieldViews, viewType, viewName, fieldName, EnumOptionsSources, fieldsOptionsConfig, leafPredicates);
|
|
186
|
+
}
|
|
180
187
|
if (typeof formConfig[fieldName] == "string") {
|
|
188
|
+
debugger
|
|
181
189
|
const err = formConfig[fieldName]
|
|
190
|
+
console.log(`error processing field ${fieldName}`, err)
|
|
182
191
|
formConfig[fieldName] = (props: any) => <>Error: field {fieldName} with {viewName} could not be instantiated</>
|
|
183
192
|
throw err
|
|
184
193
|
}
|