Skip to content

Commit ae38f20

Browse files
committed
fix(parallel): fixed dropdown, set active execution block for parallel flow
1 parent b1126e3 commit ae38f20

File tree

5 files changed

+629
-75
lines changed

5 files changed

+629
-75
lines changed

apps/sim/app/w/[id]/components/parallel-node/components/parallel-badges.tsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ export function ParallelBadges({ nodeId, data }: ParallelBadgesProps) {
4444
const [editorValue, setEditorValue] = useState('')
4545
const [typePopoverOpen, setTypePopoverOpen] = useState(false)
4646
const [configPopoverOpen, setConfigPopoverOpen] = useState(false)
47-
const [showTags, setShowTags] = useState(false)
47+
const [showTagDropdown, setShowTagDropdown] = useState(false)
4848
const [cursorPosition, setCursorPosition] = useState(0)
49-
const editorRef = useRef<HTMLDivElement>(null)
49+
const editorContainerRef = useRef<HTMLDivElement>(null)
50+
const textareaRef = useRef<HTMLTextAreaElement | null>(null)
5051

5152
// Get store methods
5253
const updateParallelCount = useWorkflowStore((state) => state.updateParallelCount)
@@ -144,14 +145,15 @@ export function ParallelBadges({ nodeId, data }: ParallelBadgesProps) {
144145
updateParallelCollection(nodeId, value)
145146

146147
// Get the textarea element and cursor position
147-
const textarea = editorRef.current?.querySelector('textarea')
148+
const textarea = editorContainerRef.current?.querySelector('textarea')
148149
if (textarea) {
150+
textareaRef.current = textarea
149151
const position = textarea.selectionStart || 0
150152
setCursorPosition(position)
151153

152154
// Check for tag trigger
153155
const tagTrigger = checkTagTrigger(value, position)
154-
setShowTags(tagTrigger.show)
156+
setShowTagDropdown(tagTrigger.show)
155157
}
156158
},
157159
[nodeId, updateParallelCollection]
@@ -162,11 +164,11 @@ export function ParallelBadges({ nodeId, data }: ParallelBadgesProps) {
162164
(newValue: string) => {
163165
setEditorValue(newValue)
164166
updateParallelCollection(nodeId, newValue)
165-
setShowTags(false)
167+
setShowTagDropdown(false)
166168

167169
// Focus back on the editor after selection
168170
setTimeout(() => {
169-
const textarea = editorRef.current?.querySelector('textarea')
171+
const textarea = textareaRef.current
170172
if (textarea) {
171173
textarea.focus()
172174
}
@@ -178,7 +180,7 @@ export function ParallelBadges({ nodeId, data }: ParallelBadgesProps) {
178180
// Handle key events
179181
const handleKeyDown = useCallback((e: React.KeyboardEvent) => {
180182
if (e.key === 'Escape') {
181-
setShowTags(false)
183+
setShowTagDropdown(false)
182184
}
183185
}, [])
184186

@@ -269,7 +271,7 @@ export function ParallelBadges({ nodeId, data }: ParallelBadgesProps) {
269271
// Code editor for collection-based parallel
270272
<div className='relative'>
271273
<div
272-
ref={editorRef}
274+
ref={editorContainerRef}
273275
className='relative min-h-[80px] rounded-md border border-input bg-background px-3 pt-2 pb-3 font-mono text-sm'
274276
>
275277
{editorValue === '' && (
@@ -290,28 +292,26 @@ export function ParallelBadges({ nodeId, data }: ParallelBadgesProps) {
290292
textareaClassName='focus:outline-none focus:ring-0 bg-transparent resize-none w-full overflow-hidden whitespace-pre-wrap'
291293
onKeyDown={(e) => {
292294
if (e.key === 'Escape') {
293-
setShowTags(false)
295+
setShowTagDropdown(false)
294296
}
295297
}}
296298
/>
297-
298-
{/* Tag dropdown positioned inside the editor container */}
299-
{showTags && (
300-
<TagDropdown
301-
visible={showTags}
302-
onSelect={handleTagSelect}
303-
blockId={nodeId}
304-
activeSourceBlockId={nodeId}
305-
inputValue={editorValue}
306-
cursorPosition={cursorPosition}
307-
onClose={() => setShowTags(false)}
308-
/>
309-
)}
310299
</div>
311300
<div className='mt-2 text-[10px] text-muted-foreground'>
312301
Array or object to use for parallel execution. Type "{'<'}" to reference other
313302
blocks.
314303
</div>
304+
{showTagDropdown && (
305+
<TagDropdown
306+
visible={showTagDropdown}
307+
onSelect={handleTagSelect}
308+
blockId={nodeId}
309+
activeSourceBlockId={null}
310+
inputValue={editorValue}
311+
cursorPosition={cursorPosition}
312+
onClose={() => setShowTagDropdown(false)}
313+
/>
314+
)}
315315
</div>
316316
)}
317317

0 commit comments

Comments
 (0)