AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend): Fix input-field update on empty & default value (#8647)
Zamil Majdy98ab525e39df
diff --git a/autogpt_platform/frontend/src/components/CustomNode.tsx b/autogpt_platform/frontend/src/components/CustomNode.tsxindex a748784454..4157a65990 100644--- a/autogpt_platform/frontend/src/components/CustomNode.tsx+++ b/autogpt_platform/frontend/src/components/CustomNode.tsx@@ -22,6 +22,7 @@ import {beautifyString,cn,getValue,+ hasNonNullNonObjectValue,parseKeys,setNestedProperty,} from "@/lib/utils";@@ -239,7 +240,10 @@ export function CustomNode({nodeId={id}propKey={getInputPropKey(propKey)}propSchema={propSchema}- currentValue={getValue(propKey, data.hardcodedValues)}+ currentValue={getValue(+ getInputPropKey(propKey),+ data.hardcodedValues,+ )}connections={data.connections}handleInputChange={handleInputChange}handleInputClick={handleInputClick}@@ -384,9 +388,7 @@ export function CustomNode({});}, [id, data, height, addNodes, deleteElements, getNode, getNextNodeId]);- const hasConfigErrors =- data.errors &&- Object.entries(data.errors).some(([_, value]) => value !== null);+ const hasConfigErrors = data.errors && hasNonNullNonObjectValue(data.errors);const outputData = data.executionResults?.at(-1)?.data;const hasOutputError =typeof outputData === "object" &&@@ -396,8 +398,8 @@ export function CustomNode({useEffect(() => {if (hasConfigErrors) {const filteredErrors = Object.fromEntries(- Object.entries(data.errors || {}).filter(- ([_, value]) => value !== null,+ Object.entries(data.errors || {}).filter(([, value]) =>+ hasNonNullNonObjectValue(value),),);console.error(diff --git a/autogpt_platform/frontend/src/components/node-input-components.tsx b/autogpt_platform/frontend/src/components/node-input-components.tsxindex 78528eada0..7d4915f2a9 100644--- a/autogpt_platform/frontend/src/components/node-input-components.tsx+++ b/autogpt_platform/frontend/src/components/node-input-components.tsx@@ -322,7 +322,7 @@ const NodeCredentialsInput: FC<{};const InputRef = (value: any): ((el: HTMLInputElement | null) => void) => {- return (el) => el && value && (el.value = value);+ return (el) => el && value != null && (el.value = value);};const NodeKeyValueInput: FC<{diff --git a/autogpt_platform/frontend/src/lib/utils.ts b/autogpt_platform/frontend/src/lib/utils.tsindex ca317e5eca..029901cd81 100644--- a/autogpt_platform/frontend/src/lib/utils.ts+++ b/autogpt_platform/frontend/src/lib/utils.ts@@ -314,6 +314,14 @@ export function findNewlyAddedBlockCoordinates(};}+export function hasNonNullNonObjectValue(obj: any): boolean {+ if (obj !== null && typeof obj === "object") {+ return Object.values(obj).some((value) => hasNonNullNonObjectValue(value));+ } else {+ return obj !== null && typeof obj !== "object";+ }+}+type ParsedKey = { key: string; index?: number };export function parseKeys(key: string): ParsedKey[] {