Skip to content

Commit fe82166

Browse files
authored
fix(condition): fix bug where user can't edit if container when else if is added (#760)
1 parent 4433100 commit fe82166

File tree

1 file changed

+10
-14
lines changed
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components

1 file changed

+10
-14
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/workflow-block/components/sub-block/components/condition-input.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function ConditionInput({
5252
disabled = false,
5353
}: ConditionInputProps) {
5454
const [storeValue, setStoreValue] = useSubBlockValue(blockId, subBlockId)
55-
const editorRef = useRef<HTMLDivElement>(null)
55+
const containerRef = useRef<HTMLDivElement>(null)
5656
const [visualLineHeights, setVisualLineHeights] = useState<{
5757
[key: string]: number[]
5858
}>({})
@@ -233,10 +233,10 @@ export function ConditionInput({
233233

234234
// Update the line counting logic to be block-specific
235235
useEffect(() => {
236-
if (!editorRef.current || conditionalBlocks.length === 0) return
236+
if (!containerRef.current || conditionalBlocks.length === 0) return
237237

238238
const calculateVisualLines = () => {
239-
const preElement = editorRef.current?.querySelector('pre')
239+
const preElement = containerRef.current?.querySelector('pre')
240240
if (!preElement) return
241241

242242
const newVisualLineHeights: { [key: string]: number[] } = {}
@@ -296,7 +296,7 @@ export function ConditionInput({
296296
calculateVisualLines()
297297

298298
const resizeObserver = new ResizeObserver(calculateVisualLines)
299-
resizeObserver.observe(editorRef.current)
299+
resizeObserver.observe(containerRef.current)
300300

301301
return () => resizeObserver.disconnect()
302302
}, [conditionalBlocks])
@@ -332,7 +332,7 @@ export function ConditionInput({
332332
const data = JSON.parse(e.dataTransfer.getData('application/json'))
333333
if (data.type !== 'connectionBlock') return
334334

335-
const textarea: any = editorRef.current?.querySelector(
335+
const textarea: any = containerRef.current?.querySelector(
336336
`[data-block-id="${blockId}"] textarea`
337337
)
338338
const dropPosition = textarea?.selectionStart ?? 0
@@ -434,7 +434,7 @@ export function ConditionInput({
434434

435435
// Focus the new block's editor after a short delay
436436
setTimeout(() => {
437-
const textarea: any = editorRef.current?.querySelector(
437+
const textarea: any = containerRef.current?.querySelector(
438438
`[data-block-id="${newBlock.id}"] textarea`
439439
)
440440
if (textarea) {
@@ -479,7 +479,7 @@ export function ConditionInput({
479479
// Add useEffect to handle keyboard events for both dropdowns
480480
useEffect(() => {
481481
conditionalBlocks.forEach((block) => {
482-
const textarea = editorRef.current?.querySelector(`[data-block-id="${block.id}"] textarea`)
482+
const textarea = containerRef.current?.querySelector(`[data-block-id="${block.id}"] textarea`)
483483
if (textarea) {
484484
textarea.addEventListener('keydown', (e: Event) => {
485485
if ((e as KeyboardEvent).key === 'Escape') {
@@ -511,7 +511,7 @@ export function ConditionInput({
511511
}
512512

513513
return (
514-
<div className='space-y-4'>
514+
<div className='space-y-4' ref={containerRef}>
515515
{conditionalBlocks.map((block, index) => (
516516
<div
517517
key={block.id}
@@ -642,11 +642,7 @@ export function ConditionInput({
642642
{renderLineNumbers(block.id)}
643643
</div>
644644

645-
<div
646-
className='relative mt-0 pt-0 pl-[30px]'
647-
ref={editorRef}
648-
data-block-id={block.id}
649-
>
645+
<div className='relative mt-0 pt-0 pl-[30px]' data-block-id={block.id}>
650646
{block.value.length === 0 && (
651647
<div className='pointer-events-none absolute top-[12px] left-[42px] select-none text-muted-foreground/50'>
652648
{'<response> === true'}
@@ -656,7 +652,7 @@ export function ConditionInput({
656652
value={block.value}
657653
onValueChange={(newCode) => {
658654
if (!isPreview && !disabled) {
659-
const textarea = editorRef.current?.querySelector(
655+
const textarea = containerRef.current?.querySelector(
660656
`[data-block-id="${block.id}"] textarea`
661657
) as HTMLTextAreaElement | null
662658
if (textarea) {

0 commit comments

Comments
 (0)