Skip to content

Commit 6b9c337

Browse files
committed
fix(sidebar): use getWorkflowLockToggleIds utility for lock toggle
Replaces manual pivot-sorting logic with the existing utility function, which handles block ordering and no-op guards consistently.
1 parent 4db11e4 commit 6b9c337

1 file changed

Lines changed: 2 additions & 12 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/workflow-item

apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/workflow-item/workflow-item.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
useExportSelection,
2525
useExportWorkflow,
2626
} from '@/app/workspace/[workspaceId]/w/hooks'
27+
import { getWorkflowLockToggleIds } from '@/app/workspace/[workspaceId]/w/[workflowId]/utils'
2728
import { useFolderStore } from '@/stores/folders/store'
2829
import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
2930
import type { WorkflowMetadata } from '@/stores/workflows/registry/types'
@@ -188,19 +189,8 @@ export function WorkflowItem({
188189
const handleToggleLock = useCallback(() => {
189190
if (!isActiveWorkflow) return
190191
const blocks = useWorkflowStore.getState().blocks
191-
const blockIds = Object.keys(blocks)
192+
const blockIds = getWorkflowLockToggleIds(blocks, !isWorkflowLocked)
192193
if (blockIds.length === 0) return
193-
// batchToggleLocked determines target state from the first block's locked value.
194-
// Ensure the first ID is a block whose state matches our intent:
195-
// when locking (not all locked), put an unlocked block first;
196-
// when unlocking (all locked), put a locked block first.
197-
const wantLocked = !isWorkflowLocked
198-
const pivotId = blockIds.find((id) => Boolean(blocks[id].locked) !== wantLocked)
199-
if (pivotId && pivotId !== blockIds[0]) {
200-
const idx = blockIds.indexOf(pivotId)
201-
blockIds[idx] = blockIds[0]
202-
blockIds[0] = pivotId
203-
}
204194
window.dispatchEvent(new CustomEvent('toggle-workflow-lock', { detail: { blockIds } }))
205195
}, [isActiveWorkflow, isWorkflowLocked])
206196

0 commit comments

Comments
 (0)