Skip to content

Commit da5e0aa

Browse files
waleedlatif1claude
andcommitted
fix(enable): consistent behavior - can't enable if parent disabled
Same pattern as lock: must enable parent container first before enabling children inside it. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ecb13a5 commit da5e0aa

File tree

3 files changed

+45
-25
lines changed

3 files changed

+45
-25
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/action-bar/action-bar.tsx

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -85,25 +85,33 @@ export const ActionBar = memo(
8585
)
8686
}, [blockId, addNotification, collaborativeBatchAddBlocks, setPendingSelection])
8787

88-
const { isEnabled, horizontalHandles, parentId, parentType, isLocked, isParentLocked } =
89-
useWorkflowStore(
90-
useCallback(
91-
(state) => {
92-
const block = state.blocks[blockId]
93-
const parentId = block?.data?.parentId
94-
const parentBlock = parentId ? state.blocks[parentId] : undefined
95-
return {
96-
isEnabled: block?.enabled ?? true,
97-
horizontalHandles: block?.horizontalHandles ?? false,
98-
parentId,
99-
parentType: parentBlock?.type,
100-
isLocked: block?.locked ?? false,
101-
isParentLocked: parentBlock?.locked ?? false,
102-
}
103-
},
104-
[blockId]
105-
)
88+
const {
89+
isEnabled,
90+
horizontalHandles,
91+
parentId,
92+
parentType,
93+
isLocked,
94+
isParentLocked,
95+
isParentDisabled,
96+
} = useWorkflowStore(
97+
useCallback(
98+
(state) => {
99+
const block = state.blocks[blockId]
100+
const parentId = block?.data?.parentId
101+
const parentBlock = parentId ? state.blocks[parentId] : undefined
102+
return {
103+
isEnabled: block?.enabled ?? true,
104+
horizontalHandles: block?.horizontalHandles ?? false,
105+
parentId,
106+
parentType: parentBlock?.type,
107+
isLocked: block?.locked ?? false,
108+
isParentLocked: parentBlock?.locked ?? false,
109+
isParentDisabled: parentBlock ? !parentBlock.enabled : false,
110+
}
111+
},
112+
[blockId]
106113
)
114+
)
107115

108116
const { activeWorkflowId } = useWorkflowRegistry()
109117
const { isExecuting, getLastExecutionSnapshot } = useExecutionStore()
@@ -200,20 +208,26 @@ export const ActionBar = memo(
200208
variant='ghost'
201209
onClick={(e) => {
202210
e.stopPropagation()
203-
if (!disabled && !isLocked && !isParentLocked) {
211+
// Can't enable if parent is disabled (must enable parent first)
212+
const cantEnable = !isEnabled && isParentDisabled
213+
if (!disabled && !isLocked && !isParentLocked && !cantEnable) {
204214
collaborativeBatchToggleBlockEnabled([blockId])
205215
}
206216
}}
207217
className={ACTION_BUTTON_STYLES}
208-
disabled={disabled || isLocked || isParentLocked}
218+
disabled={
219+
disabled || isLocked || isParentLocked || (!isEnabled && isParentDisabled)
220+
}
209221
>
210222
{isEnabled ? <Circle className={ICON_SIZE} /> : <CircleOff className={ICON_SIZE} />}
211223
</Button>
212224
</Tooltip.Trigger>
213225
<Tooltip.Content side='top'>
214226
{isLocked || isParentLocked
215227
? 'Block is locked'
216-
: getTooltipMessage(isEnabled ? 'Disable Block' : 'Enable Block')}
228+
: !isEnabled && isParentDisabled
229+
? 'Parent container is disabled'
230+
: getTooltipMessage(isEnabled ? 'Disable Block' : 'Enable Block')}
217231
</Tooltip.Content>
218232
</Tooltip.Root>
219233
)}

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/block-menu/block-menu.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface BlockInfo {
2222
parentType?: string
2323
locked?: boolean
2424
isParentLocked?: boolean
25+
isParentDisabled?: boolean
2526
}
2627

2728
/**
@@ -101,6 +102,8 @@ export function BlockMenu({
101102
const allUnlocked = selectedBlocks.every((b) => !b.locked)
102103
// Can't unlock blocks that have locked parents
103104
const hasBlockWithLockedParent = selectedBlocks.some((b) => b.locked && b.isParentLocked)
105+
// Can't enable blocks that have disabled parents
106+
const hasBlockWithDisabledParent = selectedBlocks.some((b) => !b.enabled && b.isParentDisabled)
104107

105108
const hasSingletonBlock = selectedBlocks.some(
106109
(b) =>
@@ -186,13 +189,15 @@ export function BlockMenu({
186189
{!allNoteBlocks && <PopoverDivider />}
187190
{!allNoteBlocks && (
188191
<PopoverItem
189-
disabled={disableEdit}
192+
disabled={disableEdit || hasBlockWithDisabledParent}
190193
onClick={() => {
191-
onToggleEnabled()
192-
onClose()
194+
if (!disableEdit && !hasBlockWithDisabledParent) {
195+
onToggleEnabled()
196+
onClose()
197+
}
193198
}}
194199
>
195-
{getToggleEnabledLabel()}
200+
{hasBlockWithDisabledParent ? 'Parent is disabled' : getToggleEnabledLabel()}
196201
</PopoverItem>
197202
)}
198203
{!allNoteBlocks && !isSubflow && (

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-canvas-context-menu.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export function useCanvasContextMenu({ blocks, getNodes, setNodes }: UseCanvasCo
4242
parentType,
4343
locked: block?.locked ?? false,
4444
isParentLocked: parentBlock?.locked ?? false,
45+
isParentDisabled: parentBlock ? !parentBlock.enabled : false,
4546
}
4647
}),
4748
[blocks]

0 commit comments

Comments
 (0)