fix(frontend): Fix input-field update on empty & default value (#8647)

* fix(frontend): Fix input-field update on empty & default value

* Fix error message

* Revert
This commit is contained in:
Zamil Majdy
2024-11-14 16:03:12 +07:00
committed by GitHub
parent c707ee9cb6
commit 98ab525e39
3 changed files with 17 additions and 7 deletions

View File

@@ -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(

View File

@@ -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<{

View File

@@ -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[] {