Skip to content

Commit b963ca6

Browse files
committed
Update compositeNodes to match Omigost lastest internal version
1 parent 023f130 commit b963ca6

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/compositeNodes.tsx

+25-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export abstract class CompositeNode<O, M extends NodeSchema> extends Node<NodeS,
2828
abstract getCompositeOutput(output: NodeO): NodeOutputValue<O>;
2929

3030
renderComposite(context: FormContext, children: ChildrenMap<React.ReactNode>): React.ReactNode {
31-
return Object.values(children);
31+
return Object.keys(children).map(key => children[key]);
3232
}
3333

3434
resolveInitialState() {
@@ -39,10 +39,29 @@ export abstract class CompositeNode<O, M extends NodeSchema> extends Node<NodeS,
3939
return initialState;
4040
}
4141

42-
getRawOutput() {
42+
getValueMapFromValue(value: NodeOutputValue<O>): NodeOutputValue<O> {
43+
return { ...value };
44+
}
45+
46+
setValue(value: NodeOutputValue<O>) {
47+
if (this.getSchema().formatInput) {
48+
value = this.getSchema().formatInput(value);
49+
}
50+
value = this.getValueMapFromValue(value);
51+
52+
Object.keys(this.getChildrenMapFromSchema()).forEach(key => {
53+
if (this.findChild(key)) {
54+
this.findChild(key).setValue(value[key]);
55+
}
56+
});
57+
}
58+
59+
getRawOutput(options) {
4360
const output = {};
4461
Object.keys(this.getChildrenMapFromSchema()).forEach(key => {
45-
output[key] = this.findChild(key).getOutput();
62+
if (this.findChild(key) && this.findChild(key).isOutputAvailable()) {
63+
output[key] = this.findChild(key).getOutput(options);
64+
}
4665
});
4766
return this.getCompositeOutput(output);
4867
}
@@ -67,7 +86,9 @@ export abstract class CompositeNode<O, M extends NodeSchema> extends Node<NodeS,
6786
const childrenMap: ChildrenMap<React.ReactNode> = {};
6887

6988
Object.keys(this.getChildrenMapFromSchema()).forEach((key: string, index: number) => {
70-
childrenMap[key] = this.findChild(key).render(context);
89+
if (this.findChild(key)) {
90+
childrenMap[key] = this.findChild(key).render(context);
91+
}
7192
});
7293

7394
return this.renderComposite(context, childrenMap);

0 commit comments

Comments
 (0)