From bd034da2db986701671ecb8aa33270ee3c137d50 Mon Sep 17 00:00:00 2001 From: Louis Knight-Webb Date: Mon, 12 Jan 2026 23:39:42 +0000 Subject: [PATCH] Navigate away when deleting the currently selected workspace (Vibe Kanban) (#1984) * Done! I've implemented the feature. Here's a summary of the changes to `vibe-kanban/frontend/src/components/ui-new/actions/index.ts`: 1. **Added `getNextWorkspaceId` helper function** (lines 184-196) - A reusable function that finds the next workspace to navigate to when removing a workspace from the active list 2. **Refactored `ArchiveWorkspace`** - Now uses the helper function instead of inline logic 3. **Updated `DeleteWorkspace`** - Added navigation logic that: - Only triggers when deleting the currently viewed workspace - Navigates to the next workspace in the list (or previous if at end) - Falls back to `/workspaces/create` if no other workspaces exist * Cleanup script changes for workspace a60eb506-5db1-4ba7-8ee6-26592885587b --- .../src/components/ui-new/actions/index.ts | 46 ++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/ui-new/actions/index.ts b/frontend/src/components/ui-new/actions/index.ts index b69bc8a6..7f4e4e42 100644 --- a/frontend/src/components/ui-new/actions/index.ts +++ b/frontend/src/components/ui-new/actions/index.ts @@ -185,6 +185,22 @@ function invalidateWorkspaceQueries( queryClient.invalidateQueries({ queryKey: workspaceSummaryKeys.all }); } +// Helper to find the next workspace to navigate to when removing current workspace +function getNextWorkspaceId( + activeWorkspaces: SidebarWorkspace[], + removingWorkspaceId: string +): string | null { + const currentIndex = activeWorkspaces.findIndex( + (ws) => ws.id === removingWorkspaceId + ); + if (currentIndex >= 0 && activeWorkspaces.length > 1) { + const nextWorkspace = + activeWorkspaces[currentIndex + 1] || activeWorkspaces[currentIndex - 1]; + return nextWorkspace?.id ?? null; + } + return null; +} + // All application actions export const Actions = { // === Workspace Actions === @@ -247,18 +263,9 @@ export const Actions = { const wasArchived = workspace.archived; // Calculate next workspace before archiving - let nextWorkspaceId: string | null = null; - if (!wasArchived) { - const currentIndex = ctx.activeWorkspaces.findIndex( - (ws) => ws.id === workspaceId - ); - if (currentIndex >= 0 && ctx.activeWorkspaces.length > 1) { - const nextWorkspace = - ctx.activeWorkspaces[currentIndex + 1] || - ctx.activeWorkspaces[currentIndex - 1]; - nextWorkspaceId = nextWorkspace?.id ?? null; - } - } + const nextWorkspaceId = !wasArchived + ? getNextWorkspaceId(ctx.activeWorkspaces, workspaceId) + : null; // Perform the archive/unarchive await attemptsApi.update(workspaceId, { archived: !wasArchived }); @@ -288,11 +295,26 @@ export const Actions = { variant: 'destructive', }); if (result === 'confirmed') { + // Calculate next workspace before deleting (only if deleting current) + const isCurrentWorkspace = ctx.currentWorkspaceId === workspaceId; + const nextWorkspaceId = isCurrentWorkspace + ? getNextWorkspaceId(ctx.activeWorkspaces, workspaceId) + : null; + await tasksApi.delete(workspace.task_id); ctx.queryClient.invalidateQueries({ queryKey: taskKeys.all }); ctx.queryClient.invalidateQueries({ queryKey: workspaceSummaryKeys.all, }); + + // Navigate away if we deleted the current workspace + if (isCurrentWorkspace) { + if (nextWorkspaceId) { + ctx.selectWorkspace(nextWorkspaceId); + } else { + ctx.navigate('/workspaces/create'); + } + } } }, },