@@ -3,6 +3,7 @@ import type { ContributionState } from "@/lib/types/state/contribution";
33import type { ComponentState } from "@/lib/types/state/component" ;
44import { isSubscriptable } from "@/lib/utils/isSubscriptable" ;
55import { isContainerState } from "@/lib/actions/helpers/isContainerState" ;
6+ import { getValue } from "@/lib/utils/getValue" ;
67
78export function getInputValues < S extends object = object > (
89 inputs : Input [ ] ,
@@ -24,11 +25,11 @@ export function getInputValue<S extends object = object>(
2425 let inputValue : unknown = undefined ;
2526 const dataSource = input . link || "component" ;
2627 if ( dataSource === "component" && contributionState . component ) {
27- // Return value of a property of some component in the tree
28- inputValue = getInputValueFromComponent ( contributionState . component , input ) ;
28+ inputValue = getInputValueFromComponent ( input , contributionState . component ) ;
2929 } else if ( dataSource === "container" && contributionState . container ) {
30- inputValue = getInputValueFromState ( input , hostState ) ;
30+ inputValue = getInputValueFromState ( input , contributionState . container ) ;
3131 } else if ( dataSource === "app" && hostState ) {
32+ console . log ( ) ;
3233 inputValue = getInputValueFromState ( input , hostState ) ;
3334 } else {
3435 console . warn ( `input with unknown data source:` , input ) ;
@@ -43,8 +44,8 @@ export function getInputValue<S extends object = object>(
4344
4445// we export for testing only
4546export function getInputValueFromComponent (
46- componentState : ComponentState ,
4747 input : Input ,
48+ componentState : ComponentState ,
4849) : unknown {
4950 if ( componentState . id === input . id && input . property ) {
5051 return ( componentState as unknown as Record < string , unknown > ) [
@@ -53,7 +54,7 @@ export function getInputValueFromComponent(
5354 } else if ( isContainerState ( componentState ) ) {
5455 for ( let i = 0 ; i < componentState . components . length ; i ++ ) {
5556 const item = componentState . components [ i ] ;
56- const itemValue = getInputValueFromComponent ( item , input ) ;
57+ const itemValue = getInputValueFromComponent ( input , item ) ;
5758 if ( itemValue !== noValue ) {
5859 return itemValue ;
5960 }
@@ -72,7 +73,16 @@ export function getInputValueFromState(
7273 inputValue = inputValue [ input . id ] ;
7374 }
7475 if ( isSubscriptable ( inputValue ) ) {
75- inputValue = inputValue [ input . property ] ;
76+ const property = input . property ;
77+ // TODO: The Input.property should be normalized to be a path
78+ // and have type string[].
79+ // See also interface Input in types/model/channel.ts
80+ if ( property . includes ( "." ) ) {
81+ const path = property . split ( "." ) ;
82+ inputValue = getValue ( inputValue , path ) ;
83+ } else {
84+ inputValue = inputValue [ property ] ;
85+ }
7686 }
7787 return inputValue ;
7888}
0 commit comments