fix(frontend): prune empty values from node inputs and fix object editor connection detection (#11507)

This PR addresses two issues:
1. **Empty values being sent to backend**: Node inputs were including
empty strings, null, and undefined values when converting to backend
format, causing unnecessary data to be sent.
2. **Incorrect connection detection in ObjectEditor**: The component was
checking if the parent field was connected instead of checking
individual key-value pairs, causing incorrect UI state for dynamic
properties.

### Changes 🏗️

<!-- Concisely describe all of the changes made in this pull request:
-->

- **nodeStore.ts**: Added `pruneEmptyValues` utility to remove
empty/null/undefined values from `hardcodedValues` before converting
nodes to backend format. This ensures only meaningful input values are
sent to the backend API.
- **ObjectEditorWidget.tsx**: 
  - Removed unused `fieldKey` prop from component interface
- Fixed connection detection logic to check individual key-value handle
IDs instead of the parent field key, ensuring correct connection state
for each dynamic property in object editors

### Checklist 📋

#### For code changes:

- [x] I have clearly listed my changes in the PR description
- [x] I have made a test plan
- [x] I have tested my changes according to the test plan:
- [x] Create a node with object input fields and verify empty values are
not sent to backend
  - [x] Add multiple key-value pairs to an object editor widget
- [x] Connect individual key-value pairs via handles and verify
connection state is correctly displayed
- [x] Disconnect a key-value pair and verify the input field becomes
editable
- [x] Save and reload an agent with object inputs to verify empty values
are pruned correctly
- [x] Verify that non-empty values are still correctly preserved and
sent to backend
This commit is contained in:
Abhimanyu Yadav
2025-12-02 18:17:12 +05:30
committed by GitHub
parent b8d67fc2a9
commit f987937046
2 changed files with 3 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import { NodeExecutionResult } from "@/app/api/__generated__/models/nodeExecutio
import { useHistoryStore } from "./historyStore";
import { useEdgeStore } from "./edgeStore";
import { BlockUIType } from "../components/types";
import { pruneEmptyValues } from "@/lib/utils";
// Minimum movement (in pixels) required before logging position change to history
// Prevents spamming history with small movements when clicking on inputs inside blocks
@@ -201,7 +202,7 @@ export const useNodeStore = create<NodeStore>((set, get) => ({
return {
id: node.id,
block_id: node.data.block_id,
input_default: node.data.hardcodedValues,
input_default: pruneEmptyValues(node.data.hardcodedValues),
metadata: {
position: node.position,
...(node.data.metadata?.customized_name !== undefined && {

View File

@@ -34,7 +34,6 @@ export const ObjectEditor = React.forwardRef<HTMLDivElement, ObjectEditorProps>(
disabled = false,
className,
nodeId,
fieldKey,
},
ref,
) => {
@@ -101,12 +100,12 @@ export const ObjectEditor = React.forwardRef<HTMLDivElement, ObjectEditorProps>(
id={parentFieldId}
>
{Object.entries(value).map(([key, propertyValue], idx) => {
const isDynamicPropertyConnected = isInputConnected(nodeId, fieldKey);
const handleId = generateHandleId(
parentFieldId,
[key],
HandleIdType.KEY_VALUE,
);
const isDynamicPropertyConnected = isInputConnected(nodeId, handleId);
return (
<div key={idx} className="flex flex-col gap-2">