({ data, inputParam, disabled = false, arrayIndex = null, parentParamForArray = null })
| 20 | import { FLOWISE_CREDENTIAL_ID } from '@/store/constant' |
| 21 | |
| 22 | export const ConfigInput = ({ data, inputParam, disabled = false, arrayIndex = null, parentParamForArray = null }) => { |
| 23 | const theme = useTheme() |
| 24 | const { reactFlowInstance } = useContext(flowContext) |
| 25 | |
| 26 | const [expanded, setExpanded] = useState(false) |
| 27 | const [selectedComponentNodeData, setSelectedComponentNodeData] = useState({}) |
| 28 | |
| 29 | // Track the last processed input values to prevent infinite loops using useState |
| 30 | const [lastProcessedInputs, setLastProcessedInputs] = useState({ |
| 31 | mainValue: null, |
| 32 | configValue: null, |
| 33 | arrayValue: null |
| 34 | }) |
| 35 | |
| 36 | const handleAccordionChange = (event, isExpanded) => { |
| 37 | setExpanded(isExpanded) |
| 38 | } |
| 39 | |
| 40 | const onCustomDataChange = ({ inputParam, newValue }) => { |
| 41 | let nodeData = cloneDeep(selectedComponentNodeData) |
| 42 | |
| 43 | const updatedInputs = { ...nodeData.inputs } |
| 44 | updatedInputs[inputParam.name] = newValue |
| 45 | |
| 46 | const updatedInputParams = showHideInputParams({ |
| 47 | ...nodeData, |
| 48 | inputs: updatedInputs |
| 49 | }) |
| 50 | |
| 51 | // Remove inputs with display set to false |
| 52 | Object.keys(updatedInputs).forEach((key) => { |
| 53 | const input = updatedInputParams.find((param) => param.name === key) |
| 54 | if (input && input.display === false) { |
| 55 | delete updatedInputs[key] |
| 56 | } |
| 57 | }) |
| 58 | |
| 59 | const credential = updatedInputs.credential || updatedInputs[FLOWISE_CREDENTIAL_ID] |
| 60 | |
| 61 | nodeData = { |
| 62 | ...nodeData, |
| 63 | inputParams: updatedInputParams, |
| 64 | inputs: updatedInputs, |
| 65 | credential: credential ? credential : undefined |
| 66 | } |
| 67 | |
| 68 | setSelectedComponentNodeData(nodeData) |
| 69 | } |
| 70 | |
| 71 | // Memoize current input values for reliable comparison |
| 72 | const currentInputValues = useMemo( |
| 73 | () => ({ |
| 74 | mainValue: data.inputs[inputParam.name], |
| 75 | configValue: data.inputs[`${inputParam.name}Config`], |
| 76 | arrayValue: parentParamForArray ? data.inputs[parentParamForArray.name] : null |
| 77 | }), |
| 78 | |
| 79 | // eslint-disable-next-line react-hooks/exhaustive-deps |
nothing calls this directly
no test coverage detected