Skip to content

Commit 1f6b07a

Browse files
committed
Fix gemini comments
1 parent bf66ed2 commit 1f6b07a

3 files changed

Lines changed: 47 additions & 14 deletions

File tree

packages/agentflow/src/atoms/ArrayInput.test.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,32 @@ describe('ArrayInput', () => {
281281
expect(deleteButtons[1]).toBeDisabled()
282282
})
283283

284-
// Test 11: itemParameters prop overrides inputParam.array display flags
284+
// Test 11: Type-specific defaults when no explicit default is provided
285+
it('should initialize new items with type-appropriate defaults when no default is specified', () => {
286+
const inputParamWithTypes: InputParam = {
287+
id: 'typed-array',
288+
name: 'testArray',
289+
label: 'Test Item',
290+
type: 'array',
291+
array: [
292+
{ id: 'str', name: 'str', label: 'String', type: 'string' } as InputParam,
293+
{ id: 'num', name: 'num', label: 'Number', type: 'number' } as InputParam,
294+
{ id: 'bool', name: 'bool', label: 'Boolean', type: 'boolean' } as InputParam,
295+
{ id: 'arr', name: 'arr', label: 'Array', type: 'array' } as InputParam
296+
]
297+
}
298+
299+
render(<ArrayInput inputParam={inputParamWithTypes} data={mockNodeData} onDataChange={mockOnDataChange} />)
300+
301+
fireEvent.click(screen.getByRole('button', { name: /Add Test Item/i }))
302+
303+
expect(mockOnDataChange).toHaveBeenCalledWith({
304+
inputParam: inputParamWithTypes,
305+
newValue: [{ str: '', num: 0, bool: false, arr: [] }]
306+
})
307+
})
308+
309+
// Test 12: itemParameters prop overrides inputParam.array display flags
285310
it('should use itemParameters prop for field visibility when provided, ignoring inputParam.array display flags', () => {
286311
// inputParam.array has both fields with no display flag (both would show)
287312
const dataWithItem: NodeData = {

packages/agentflow/src/atoms/ArrayInput.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,28 @@ export function ArrayInput({ inputParam, data, disabled = false, onDataChange, i
5151

5252
// Add new array item
5353
const handleAddItem = useCallback(() => {
54-
// Initialize new item with default values
54+
// Initialize new item with type-appropriate default values
5555
const newItem: Record<string, unknown> = {}
5656

5757
if (inputParam.array) {
5858
for (const field of inputParam.array) {
59-
newItem[field.name] = field.default ?? ''
59+
if (field.default !== undefined) {
60+
newItem[field.name] = field.default
61+
} else {
62+
switch (field.type) {
63+
case 'number':
64+
newItem[field.name] = 0
65+
break
66+
case 'boolean':
67+
newItem[field.name] = false
68+
break
69+
case 'array':
70+
newItem[field.name] = []
71+
break
72+
default:
73+
newItem[field.name] = ''
74+
}
75+
}
6076
}
6177
}
6278

packages/agentflow/src/features/node-editor/EditNodeDialog.test.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ jest.mock('@/atoms', () => ({
4444
<button
4545
data-testid={`add-${inputParam.name}`}
4646
onClick={() => {
47-
const newItem = inputParam.array?.reduce((acc, field) => {
48-
acc[field.name] = field.default ?? ''
49-
return acc
50-
}, {} as Record<string, unknown>)
51-
onDataChange({ inputParam, newValue: [...currentArray, newItem || {}] })
47+
onDataChange({ inputParam, newValue: [...currentArray, { _mockAdded: true }] })
5248
}}
5349
>
5450
Add {inputParam.label}
@@ -381,17 +377,13 @@ describe('EditNodeDialog', () => {
381377
expect(screen.getByTestId('change-connections-0')).toBeInTheDocument()
382378
expect(screen.getByTestId('change-connections-1')).toBeInTheDocument()
383379

384-
// Test Add operation - adds a new item with default values
380+
// Test Add operation - appends a new item to the array
385381
const addButton = screen.getByTestId('add-connections')
386382
fireEvent.click(addButton)
387383

388384
expect(mockUpdateNodeData).toHaveBeenCalledWith('node-1', {
389385
inputValues: {
390-
connections: [
391-
{ host: 'server1.com', port: 3000 },
392-
{ host: 'server2.com', port: 8080 },
393-
{ host: 'localhost', port: 5432 }
394-
]
386+
connections: [{ host: 'server1.com', port: 3000 }, { host: 'server2.com', port: 8080 }, { _mockAdded: true }]
395387
}
396388
})
397389

0 commit comments

Comments
 (0)