From 7de1ee12c8628dcbde780258a9a7972a8c28dd1a Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Mon, 4 Dec 2023 18:37:33 -0300 Subject: [PATCH] Fixed disabled variable at EditNodeModal --- .../src/modals/EditNodeModal/index.tsx | 641 ++++++++++-------- 1 file changed, 342 insertions(+), 299 deletions(-) diff --git a/src/frontend/src/modals/EditNodeModal/index.tsx b/src/frontend/src/modals/EditNodeModal/index.tsx index a571b51cd..1e9888d96 100644 --- a/src/frontend/src/modals/EditNodeModal/index.tsx +++ b/src/frontend/src/modals/EditNodeModal/index.tsx @@ -37,6 +37,7 @@ import { convertObjToArray, convertValuesToNumbers, hasDuplicateKeys, + scapedJSONStringfy, } from "../../utils/reactflowUtils"; import { classNames } from "../../utils/utils"; import BaseModal from "../baseModal"; @@ -62,10 +63,6 @@ const EditNodeModal = forwardRef( const { setTabsState, tabId } = useContext(FlowsContext); const { reactFlowInstance } = useContext(typesContext); - let disabled = - reactFlowInstance - ?.getEdges() - .some((edge) => edge.targetHandle === data.id) ?? false; function changeAdvanced(n) { setMyData((old) => { @@ -150,52 +147,329 @@ const EditNodeModal = forwardRef( myData.node.template[templateParam].type ) ) - .map((templateParam, index) => ( - - - - - {myData.node?.template[templateParam] - .display_name - ? myData.node.template[templateParam] - .display_name - : myData.node?.template[templateParam].name} - - - - - {myData.node?.template[templateParam].type === - "str" && - !myData.node.template[templateParam].options ? ( -
- {myData.node.template[templateParam].list ? ( - { + let id = { + inputTypes: + data.node!.template[templateParam].input_types, + type: data.node!.template[templateParam].type, + id: data.id, + fieldName: templateParam, + }; + let disabled = + reactFlowInstance?.getEdges().some( + (edge) => + edge.targetHandle === + scapedJSONStringfy( + data.node!.template[templateParam].proxy + ? { + ...id, + proxy: + data.node?.template[templateParam] + .proxy, + } + : id + ) + ) ?? false; + return ( + + + + + {myData.node?.template[templateParam] + .display_name + ? myData.node.template[templateParam] + .display_name + : myData.node?.template[templateParam] + .name} + + + + + {myData.node?.template[templateParam].type === + "str" && + !myData.node.template[templateParam].options ? ( +
+ {myData.node.template[templateParam] + .list ? ( + { + handleOnNewValue( + value, + templateParam + ); + }} + /> + ) : myData.node.template[templateParam] + .multiline ? ( + { + handleOnNewValue( + value, + templateParam + ); + }} + /> + ) : ( + { + handleOnNewValue( + value, + templateParam + ); + }} + /> + )} +
+ ) : myData.node?.template[templateParam] + .type === "NestedDict" ? ( +
+ { + onChange={(newValue) => { + myData.node!.template[ + templateParam + ].value = newValue; + handleOnNewValue( + newValue, + templateParam + ); + }} + id="editnode-div-dict-input" + /> +
+ ) : myData.node?.template[templateParam] + .type === "dict" ? ( +
1 + ? "my-3" + : "" + )} + > + { + const valueToNumbers = + convertValuesToNumbers(newValue); + myData.node!.template[ + templateParam + ].value = valueToNumbers; + setErrorDuplicateKey( + hasDuplicateKeys(valueToNumbers) + ); + handleOnNewValue( + valueToNumbers, + templateParam + ); + }} + /> +
+ ) : myData.node?.template[templateParam] + .type === "bool" ? ( +
+ {" "} + { + handleOnNewValue( + isEnabled, + templateParam + ); + }} + size="small" + /> +
+ ) : myData.node?.template[templateParam] + .type === "float" ? ( +
+ { handleOnNewValue(value, templateParam); }} /> - ) : myData.node.template[templateParam] - .multiline ? ( - + ) : myData.node?.template[templateParam] + .type === "str" && + myData.node.template[templateParam] + .options ? ( +
+ + handleOnNewValue(value, templateParam) + } + value={ + myData.node.template[templateParam] + .value ?? "Choose an option" + } + id={"dropdown-edit-" + index} + > +
+ ) : myData.node?.template[templateParam] + .type === "int" ? ( +
+ { + handleOnNewValue(value, templateParam); + }} + /> +
+ ) : myData.node?.template[templateParam] + .type === "file" ? ( +
+ { + handleOnNewValue(value, templateParam); + }} + fileTypes={ + myData.node.template[templateParam] + .fileTypes + } + onFileChange={(filePath: string) => { + data.node!.template[ + templateParam + ].file_path = filePath; + }} + > +
+ ) : myData.node?.template[templateParam] + .type === "prompt" ? ( +
+ { + myData.node = nodeClass; + }} + value={ + myData.node.template[templateParam] + .value ?? "" + } + onChange={(value: string | string[]) => { + handleOnNewValue(value, templateParam); + }} + id={"prompt-area-edit" + index} + /> +
+ ) : myData.node?.template[templateParam] + .type === "code" ? ( +
+ { + data.node = nodeClass; + }} + nodeClass={data.node} disabled={disabled} editNode={true} value={ @@ -205,269 +479,38 @@ const EditNodeModal = forwardRef( onChange={(value: string | string[]) => { handleOnNewValue(value, templateParam); }} + id={"code-area-edit" + index} /> - ) : ( - { - handleOnNewValue(value, templateParam); - }} - /> - )} -
- ) : myData.node?.template[templateParam].type === - "NestedDict" ? ( -
- { - myData.node!.template[ - templateParam - ].value = newValue; - handleOnNewValue(newValue, templateParam); - }} - id="editnode-div-dict-input" - /> -
- ) : myData.node?.template[templateParam].type === - "dict" ? ( -
1 - ? "my-3" - : "" - )} - > - { - const valueToNumbers = - convertValuesToNumbers(newValue); - myData.node!.template[ - templateParam - ].value = valueToNumbers; - setErrorDuplicateKey( - hasDuplicateKeys(valueToNumbers) - ); - handleOnNewValue( - valueToNumbers, - templateParam - ); - }} - /> -
- ) : myData.node?.template[templateParam].type === - "bool" ? ( -
- {" "} +
+ ) : myData.node?.template[templateParam] + .type === "Any" ? ( + "-" + ) : ( +
+ )} + + +
{ - handleOnNewValue( - isEnabled, - templateParam - ); + enabled={ + !myData.node?.template[templateParam] + .advanced + } + setEnabled={(e) => { + changeAdvanced(templateParam); }} + disabled={disabled} size="small" />
- ) : myData.node?.template[templateParam].type === - "float" ? ( -
- { - handleOnNewValue(value, templateParam); - }} - /> -
- ) : myData.node?.template[templateParam].type === - "str" && - myData.node.template[templateParam].options ? ( -
- - handleOnNewValue(value, templateParam) - } - value={ - myData.node.template[templateParam] - .value ?? "Choose an option" - } - id={"dropdown-edit-" + index} - > -
- ) : myData.node?.template[templateParam].type === - "int" ? ( -
- { - handleOnNewValue(value, templateParam); - }} - /> -
- ) : myData.node?.template[templateParam].type === - "file" ? ( -
- { - handleOnNewValue(value, templateParam); - }} - fileTypes={ - myData.node.template[templateParam] - .fileTypes - } - onFileChange={(filePath: string) => { - data.node!.template[ - templateParam - ].file_path = filePath; - }} - > -
- ) : myData.node?.template[templateParam].type === - "prompt" ? ( -
- { - myData.node = nodeClass; - }} - value={ - myData.node.template[templateParam] - .value ?? "" - } - onChange={(value: string | string[]) => { - handleOnNewValue(value, templateParam); - }} - id={"prompt-area-edit" + index} - /> -
- ) : myData.node?.template[templateParam].type === - "code" ? ( -
- { - data.node = nodeClass; - }} - nodeClass={data.node} - disabled={disabled} - editNode={true} - value={ - myData.node.template[templateParam] - .value ?? "" - } - onChange={(value: string | string[]) => { - handleOnNewValue(value, templateParam); - }} - id={"code-area-edit" + index} - /> -
- ) : myData.node?.template[templateParam].type === - "Any" ? ( - "-" - ) : ( -
- )} -
- -
- { - changeAdvanced(templateParam); - }} - disabled={disabled} - size="small" - /> -
-
- - ))} + + + ); + })}