()
| 83 | // Load initial component data when the component mounts |
| 84 | useEffect(() => { |
| 85 | const loadComponentData = async () => { |
| 86 | // Get the node name from inputs |
| 87 | const nodeName = data.inputs[inputParam.name] |
| 88 | const node = await nodesApi.getSpecificNode(nodeName) |
| 89 | |
| 90 | if (!node.data) return |
| 91 | |
| 92 | // Initialize component node with basic data |
| 93 | const componentNodeData = cloneDeep(initNode(node.data, `${node.data.nodeName}_0`)) |
| 94 | |
| 95 | // Helper function to check if array-based configuration exists |
| 96 | const isArray = () => { |
| 97 | return parentParamForArray && data.inputs[parentParamForArray.name] |
| 98 | } |
| 99 | |
| 100 | const hasArrayConfig = () => { |
| 101 | return ( |
| 102 | parentParamForArray && |
| 103 | data.inputs[parentParamForArray.name] && |
| 104 | Array.isArray(data.inputs[parentParamForArray.name]) && |
| 105 | data.inputs[parentParamForArray.name][arrayIndex] && |
| 106 | data.inputs[parentParamForArray.name][arrayIndex][`${inputParam.name}Config`] |
| 107 | ) |
| 108 | } |
| 109 | |
| 110 | // Helper function to get current input value |
| 111 | const getCurrentInputValue = () => { |
| 112 | return hasArrayConfig() ? data.inputs[parentParamForArray.name][arrayIndex][inputParam.name] : data.inputs[inputParam.name] |
| 113 | } |
| 114 | |
| 115 | // Helper function to get config data |
| 116 | const getConfigData = () => { |
| 117 | return hasArrayConfig() |
| 118 | ? data.inputs[parentParamForArray.name][arrayIndex][`${inputParam.name}Config`] |
| 119 | : data.inputs[`${inputParam.name}Config`] |
| 120 | } |
| 121 | |
| 122 | // Update component inputs based on configuration |
| 123 | if (hasArrayConfig() || data.inputs[`${inputParam.name}Config`]) { |
| 124 | const configData = getConfigData() |
| 125 | const currentValue = getCurrentInputValue() |
| 126 | |
| 127 | // If stored config value doesn't match current input, reset to defaults |
| 128 | if (configData[inputParam.name] !== currentValue) { |
| 129 | const defaultInput = initializeDefaultNodeData(componentNodeData.inputParams) |
| 130 | componentNodeData.inputs = { ...defaultInput, [inputParam.name]: currentValue } |
| 131 | } else { |
| 132 | // Use existing config with current input value |
| 133 | componentNodeData.inputs = { ...configData, [inputParam.name]: currentValue } |
| 134 | } |
| 135 | } else { |
| 136 | const currentValue = isArray() |
| 137 | ? data.inputs[parentParamForArray.name][arrayIndex][inputParam.name] |
| 138 | : data.inputs[inputParam.name] |
| 139 | componentNodeData.inputs = { |
| 140 | ...componentNodeData.inputs, |
| 141 | [inputParam.name]: currentValue |
| 142 | } |
no test coverage detected