Skip to content

Commit

Permalink
fix(frontend): Fix input-field update on empty & default value (#8647)
Browse files Browse the repository at this point in the history
* fix(frontend): Fix input-field update on empty & default value

* Fix error message

* Revert
  • Loading branch information
majdyz authored Nov 14, 2024
1 parent c707ee9 commit 98ab525
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
14 changes: 8 additions & 6 deletions autogpt_platform/frontend/src/components/CustomNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
beautifyString,
cn,
getValue,
hasNonNullNonObjectValue,
parseKeys,
setNestedProperty,
} from "@/lib/utils";
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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" &&
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand Down
8 changes: 8 additions & 0 deletions autogpt_platform/frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand Down

0 comments on commit 98ab525

Please sign in to comment.