Skip to content

Commit 97dccf1

Browse files
author
waleed
committed
added intelligent next index selection if deleting active workflow
1 parent 7eadc1f commit 97dccf1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

apps/sim/app/workspace/[workspaceId]/w/hooks/use-delete-workflow.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,18 @@ export function useDeleteWorkflow({
7878

7979
// Find next workflow to navigate to (if active workflow is being deleted)
8080
const sidebarWorkflows = Object.values(workflows).filter((w) => w.workspaceId === workspaceId)
81-
const firstWorkflowId = workflowIdsToDelete[0]
82-
const currentIndex = sidebarWorkflows.findIndex((w) => w.id === firstWorkflowId)
81+
82+
// Find which specific workflow is the active one (if any in the deletion list)
83+
let activeWorkflowId: string | null = null
84+
if (isActiveWorkflowBeingDeleted && typeof isActive === 'function') {
85+
// Check each workflow being deleted to find which one is active
86+
activeWorkflowId =
87+
workflowIdsToDelete.find((id) => isActive([id])) || workflowIdsToDelete[0]
88+
} else {
89+
activeWorkflowId = workflowIdsToDelete[0]
90+
}
91+
92+
const currentIndex = sidebarWorkflows.findIndex((w) => w.id === activeWorkflowId)
8393

8494
let nextWorkflowId: string | null = null
8595
if (isActiveWorkflowBeingDeleted && sidebarWorkflows.length > workflowIdsToDelete.length) {

0 commit comments

Comments
 (0)