mirror of
https://github.com/langflow-ai/langflow.git
synced 2026-07-24 10:50:35 +08:00
Fix: Saving Custom Component Resets Tool Actions (#11421)
* fix: validating and updating a dynamic component's code in the Langflow UI * fix: code overide --------- Co-authored-by: Olayinka Adelakun <olayinkaadelakun@mac.war.can.ibm.com> Co-authored-by: Olayinka Adelakun <olayinkaadelakun@Olayinkas-MacBook-Pro.local>
This commit is contained in:
@ -7,6 +7,7 @@ import "ace-builds/src-noconflict/ext-searchbox";
|
||||
import "ace-builds/src-noconflict/mode-python";
|
||||
import "ace-builds/src-noconflict/theme-github";
|
||||
import "ace-builds/src-noconflict/theme-monokai";
|
||||
import { cloneDeep } from "lodash";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import AceEditor from "react-ace";
|
||||
import type ReactAce from "react-ace/lib/ace";
|
||||
@ -120,9 +121,25 @@ export default function CodeAreaModal({
|
||||
onSuccess: ({ data, type }) => {
|
||||
if (data && type) {
|
||||
setValue(code);
|
||||
clearHandlesFromAdvancedFields(componentId!, data);
|
||||
try {
|
||||
const merged = cloneDeep(data);
|
||||
if (nodeClass?.template && merged?.template) {
|
||||
for (const fieldName of Object.keys(merged.template)) {
|
||||
if (fieldName === "code") continue;
|
||||
const existing = nodeClass.template[fieldName];
|
||||
if (existing && Object.hasOwn(existing, "value")) {
|
||||
// Preserve the user's current value for this parameter
|
||||
merged.template[fieldName].value = existing.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setNodeClass(data, type);
|
||||
clearHandlesFromAdvancedFields(componentId!, merged);
|
||||
setNodeClass(merged, type);
|
||||
} catch (e) {
|
||||
clearHandlesFromAdvancedFields(componentId!, data);
|
||||
setNodeClass(data, type);
|
||||
}
|
||||
setError({ detail: { error: undefined, traceback: undefined } });
|
||||
setOpen(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user