From 14eab3e629bd20219f60194aa669db8afd58f4cd Mon Sep 17 00:00:00 2001 From: yannickmonney Date: Mon, 5 Oct 2026 19:39:10 +0200 Subject: [PATCH 1/4] fix(platform): leave a deleted project's pages for the projects list Deleting a project from its General tab's danger zone left the reader on "We couldn't find that project": the dialog navigated only when a caller passed `navigateOnSuccess`, and the danger zone never did. The dialog now reads the open route instead. When the deleted project is the one on screen, it replaces that page with the projects list; deleted from the list, it stays there and keeps the list's Teams filter. --- .../components/project-delete-dialog.test.tsx | 68 +++++++++++++++++++ .../components/project-delete-dialog.tsx | 19 +++--- services/platform/tests/manual/readme.md | 2 +- .../platform/tests/manual/suites/projects.md | 12 +++- 4 files changed, 90 insertions(+), 11 deletions(-) diff --git a/services/platform/app/features/projects/components/project-delete-dialog.test.tsx b/services/platform/app/features/projects/components/project-delete-dialog.test.tsx index 3e0f5fa4e8..14ceffe3fe 100644 --- a/services/platform/app/features/projects/components/project-delete-dialog.test.tsx +++ b/services/platform/app/features/projects/components/project-delete-dialog.test.tsx @@ -16,6 +16,8 @@ import { ProjectDeleteDialog } from './project-delete-dialog'; const mockDeleteProject = vi.fn(); const mockNavigate = vi.fn(); const mockToast = vi.fn(); +// The route the dialog opens on: the projects list by default. +let mockParams: Record = { id: 'org-1' }; vi.mock('../hooks/mutations', () => ({ useDeleteProject: () => ({ mutateAsync: mockDeleteProject }), @@ -24,6 +26,7 @@ vi.mock('../hooks/mutations', () => ({ vi.mock('@tanstack/react-router', async (importOriginal) => ({ ...(await importOriginal()), useNavigate: () => mockNavigate, + useParams: () => mockParams, })); vi.mock('@tale/ui/use-toast', () => ({ @@ -53,6 +56,71 @@ function getDeleteButton() { describe('ProjectDeleteDialog', () => { beforeEach(() => { vi.clearAllMocks(); + mockParams = { id: 'org-1' }; + }); + + it('leaves the deleted project for the projects list when deleted from its own page', async () => { + // The General tab's danger zone deletes the project it sits in; staying + // would leave the reader on "We couldn't find that project". + mockParams = { id: 'org-1', projectId: 'project-1' }; + mockDeleteProject.mockResolvedValueOnce(null); + + const { user } = renderDialog(); + + await user.click(getDeleteButton()); + + expect(mockDeleteProject).toHaveBeenCalledWith({ + projectId: 'project-1', + mode: 'detach', + confirmPhrase: undefined, + }); + expect(mockNavigate).toHaveBeenCalledExactlyOnceWith({ + to: '/dashboard/$id/projects', + params: { id: 'org-1' }, + replace: true, + }); + }); + + it('stays on the projects list when deleted from it', async () => { + // The row menu deletes from the list: moving would drop its filters. + mockDeleteProject.mockResolvedValueOnce(null); + + const { user } = renderDialog(); + + await user.click(getDeleteButton()); + + expect(mockToast).toHaveBeenCalledWith( + expect.objectContaining({ title: 'Project deleted', variant: 'success' }), + ); + expect(mockNavigate).not.toHaveBeenCalled(); + }); + + it('stays on the page of another project', async () => { + mockParams = { id: 'org-1', projectId: 'project-2' }; + mockDeleteProject.mockResolvedValueOnce(null); + + const { user } = renderDialog(); + + await user.click(getDeleteButton()); + + expect(mockDeleteProject).toHaveBeenCalledOnce(); + expect(mockNavigate).not.toHaveBeenCalled(); + }); + + it('stays on the project page when the delete is refused', async () => { + mockParams = { id: 'org-1', projectId: 'project-1' }; + mockDeleteProject.mockRejectedValueOnce( + new AppError({ code: 'PROJECT_LEGAL_HOLD' }), + ); + + const { user } = renderDialog(); + + await user.click(getDeleteButton()); + + expect(mockToast).toHaveBeenCalledWith( + expect.objectContaining({ variant: 'destructive' }), + ); + expect(mockNavigate).not.toHaveBeenCalled(); }); it('surfaces the actionable message with bound automation names on PROJECT_HAS_BOUND_AUTOMATIONS', async () => { diff --git a/services/platform/app/features/projects/components/project-delete-dialog.tsx b/services/platform/app/features/projects/components/project-delete-dialog.tsx index 0c3d018369..66495c2c93 100644 --- a/services/platform/app/features/projects/components/project-delete-dialog.tsx +++ b/services/platform/app/features/projects/components/project-delete-dialog.tsx @@ -5,7 +5,7 @@ import { DeleteDialog } from '@tale/ui/dialog/delete-dialog'; import { Input } from '@tale/ui/input'; import { Stack } from '@tale/ui/layout'; import { toast } from '@tale/ui/use-toast'; -import { useNavigate } from '@tanstack/react-router'; +import { useNavigate, useParams } from '@tanstack/react-router'; import { useEffect, useState } from 'react'; import { failureDetail } from '@/app/lib/backend/adapters'; @@ -20,12 +20,6 @@ interface ProjectDeleteDialogProps { organizationId: string; projectId: string; projectName: string; - /** - * Navigate to the projects list after a successful delete. Set to false - * when the dialog is launched from the table row (caller is already on - * the list page). - */ - navigateOnSuccess?: boolean; } export function ProjectDeleteDialog({ @@ -34,10 +28,13 @@ export function ProjectDeleteDialog({ organizationId, projectId, projectName, - navigateOnSuccess = false, }: ProjectDeleteDialogProps) { const { t } = useT('projects'); const navigate = useNavigate(); + // The project whose pages are open, if any: the General tab's danger zone + // deletes the very project it sits in, the projects list deletes from + // outside every project. + const openProjectId = useParams({ strict: false }).projectId; const { mutateAsync: deleteProject } = useDeleteProject(); const [cascade, setCascade] = useState(false); const [confirmPhrase, setConfirmPhrase] = useState(''); @@ -75,10 +72,14 @@ export function ProjectDeleteDialog({ }); toast({ title: t('settings.deleteSuccess'), variant: 'success' }); onOpenChange(false); - if (navigateOnSuccess) { + // A deleted project's pages can only say it is gone, so leave them for + // the projects list, in place of the page that named it. On the list + // itself there is nothing to leave, and moving would drop its filters. + if (openProjectId === projectId) { void navigate({ to: '/dashboard/$id/projects', params: { id: organizationId }, + replace: true, }); } } catch (error) { diff --git a/services/platform/tests/manual/readme.md b/services/platform/tests/manual/readme.md index 4f6d6c237a..cf0d0e63e7 100644 --- a/services/platform/tests/manual/readme.md +++ b/services/platform/tests/manual/readme.md @@ -50,7 +50,7 @@ directory and greppable as one token. | [notifications](suites/notifications.md) | `NOTIF-` | the notification bell + panel | 32 | | [origins](suites/origins.md) | `ORIGIN-` | one deployment on several origins: sessions, file links, sign-in doors, an external TLS terminator | 12 | | [performance](suites/performance.md) | `PERF-` | cold load, chat TTFT, thread switch, pagination | 22 | -| [projects](suites/projects.md) | `PROJ-` | projects, agents, tasks (attachments, comments), files, secrets, threads, Home's projects section | 65 | +| [projects](suites/projects.md) | `PROJ-` | projects, agents, tasks (attachments, comments), files, secrets, threads, Home's projects section | 66 | | [responsive](suites/responsive.md) | `RESP-` | mobile viewport, bottom tab bar, the phone's Home list, mobile save bar, the narrow page column, short viewports | 35 | | [settings](suites/settings.md) | `SET-` | account, personalization, usage, org, teams, branding, connectors, API, providers | 121 | | [skills](suites/skills.md) | `SKILL-` | skill library: table + facets, create/upload bundles, visibility, equip on agents | 35 | diff --git a/services/platform/tests/manual/suites/projects.md b/services/platform/tests/manual/suites/projects.md index b262881a24..69492aed37 100644 --- a/services/platform/tests/manual/suites/projects.md +++ b/services/platform/tests/manual/suites/projects.md @@ -1,6 +1,6 @@ # Projects & tasks -> **Prefix** `PROJ-` · **Reset** none · **Cost** 64 boxes +> **Prefix** `PROJ-` · **Reset** none · **Cost** 65 boxes Exercise projects (identity edit, sharing/visibility), their tabs (files, threads, agents, instructions, secrets, metrics, automations), the task @@ -199,6 +199,16 @@ projects-list row ⋯ menu. (`projects.settings.deleteConfirmPhrase`) → **Delete project** (`projects.settings.deleteSubmit`) → The project row is gone from the list after the dialog closes and survives a reload; its tasks are also removed. +- [ ] `PROJ-F40` · **Delete from General lands on the list** — Open a + throwaway project's **General** tab (`projects.navigation.overview`) → in + the danger zone (`projects.dangerZone.title`) **Delete** + (`projects.rowActions.delete`) → **Delete project** + (`projects.settings.deleteSubmit`) → The toast **Project deleted** + (`projects.settings.deleteSuccess`) shows and the URL settles on + `/dashboard/{org}/projects`, never **We couldn't find that project. It may + have been deleted.** (`projects.errors.PROJECT_NOT_FOUND`); Back from the + list does not reopen the General page. Deleting from the list's row ⋯ + instead leaves you on the list with its **Teams** filter still in the URL. - [ ] `PROJ-F16` · **List + board basics** — Create a project + task, view board & list, then cascade-delete → Mirrors the automated happy path in `projects.spec.ts` From a81ee5297d984921d1ea1cd35971921f414ab8cb Mon Sep 17 00:00:00 2001 From: yannickmonney Date: Mon, 5 Oct 2026 19:40:01 +0200 Subject: [PATCH 2/4] fix(platform): open a fresh chat after deleting the open one Deleting the chat on screen, from its header or its row, went to plain `/chat`, which resumes the most recent chat. The thread list has not read again by then, so the resume could pick the chat just deleted and land on "This chat is not available", or else drop the reader into another chat. The delete dialog now leaves the deleted conversation itself: when the route's thread is the one deleted, it replaces the page with a fresh chat (`?new`). Deleting any other chat keeps the open one on screen. --- .../features/chat/components/chat-surface.tsx | 6 - .../components/thread-delete-dialog.test.tsx | 111 ++++++++++++++++++ .../chat/components/thread-delete-dialog.tsx | 20 +++- .../chat/components/thread-row.test.tsx | 1 + .../features/chat/components/thread-row.tsx | 1 - services/platform/tests/manual/readme.md | 2 +- services/platform/tests/manual/suites/chat.md | 10 +- 7 files changed, 138 insertions(+), 13 deletions(-) create mode 100644 services/platform/app/features/chat/components/thread-delete-dialog.test.tsx diff --git a/services/platform/app/features/chat/components/chat-surface.tsx b/services/platform/app/features/chat/components/chat-surface.tsx index 1d755a3608..722ee32899 100644 --- a/services/platform/app/features/chat/components/chat-surface.tsx +++ b/services/platform/app/features/chat/components/chat-surface.tsx @@ -2273,12 +2273,6 @@ function ChatSurfaceInner({ organizationId={organizationId} open={deleteOpen} onOpenChange={setDeleteOpen} - onDeleted={() => - void navigate({ - to: '/dashboard/$id/chat', - params: { id: organizationId }, - }) - } /> )} diff --git a/services/platform/app/features/chat/components/thread-delete-dialog.test.tsx b/services/platform/app/features/chat/components/thread-delete-dialog.test.tsx new file mode 100644 index 0000000000..18f8a9663d --- /dev/null +++ b/services/platform/app/features/chat/components/thread-delete-dialog.test.tsx @@ -0,0 +1,111 @@ +// @vitest-environment jsdom +import '@testing-library/jest-dom/vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import { render, screen, waitFor } from '@/tests/utils/render'; + +import { ThreadDeleteDialog } from './thread-delete-dialog'; + +// Where a delete lands: the conversation on screen is left for a fresh chat, +// never for plain `/chat` — that resumes the most recent chat, and the list +// still names the deleted one until it has read again, so the reader came +// straight back to "This chat is not available". + +const { mockNavigate, mockTrash, mockToast, routeParams } = vi.hoisted(() => ({ + mockNavigate: vi.fn(), + mockTrash: vi.fn<(threadId: string) => Promise>(), + mockToast: vi.fn(), + routeParams: { current: {} as Record }, +})); + +vi.mock('@tanstack/react-router', async (importOriginal) => ({ + ...(await importOriginal()), + useNavigate: () => mockNavigate, + useParams: () => routeParams.current, +})); + +vi.mock('../data/thread-actions', () => ({ + useThreadActions: () => ({ trash: mockTrash }), +})); + +vi.mock('@tale/ui/use-toast', () => ({ + toast: (...args: unknown[]) => mockToast(...args), + useToast: () => ({ toast: mockToast }), +})); + +function renderDialog() { + const onOpenChange = vi.fn(); + const view = render( + , + ); + return { ...view, onOpenChange }; +} + +describe('ThreadDeleteDialog', () => { + beforeEach(() => { + vi.clearAllMocks(); + routeParams.current = { id: 'org-1' }; + }); + + it('leaves the deleted conversation for a fresh chat', async () => { + routeParams.current = { id: 'org-1', threadId: 't1' }; + mockTrash.mockResolvedValueOnce(true); + const { user, onOpenChange } = renderDialog(); + + await user.click(screen.getByRole('button', { name: 'Delete chat' })); + + await waitFor(() => + expect(mockNavigate).toHaveBeenCalledExactlyOnceWith({ + to: '/dashboard/$id/chat', + params: { id: 'org-1' }, + search: { new: true }, + replace: true, + }), + ); + expect(mockTrash).toHaveBeenCalledWith('t1'); + expect(onOpenChange).toHaveBeenCalledWith(false); + }); + + it('stays on another conversation when a row deletes this chat', async () => { + routeParams.current = { id: 'org-1', threadId: 't2' }; + mockTrash.mockResolvedValueOnce(true); + const { user, onOpenChange } = renderDialog(); + + await user.click(screen.getByRole('button', { name: 'Delete chat' })); + + await waitFor(() => expect(onOpenChange).toHaveBeenCalledWith(false)); + expect(mockNavigate).not.toHaveBeenCalled(); + }); + + it('stays where it is off the chat pages', async () => { + mockTrash.mockResolvedValueOnce(true); + const { user, onOpenChange } = renderDialog(); + + await user.click(screen.getByRole('button', { name: 'Delete chat' })); + + await waitFor(() => expect(onOpenChange).toHaveBeenCalledWith(false)); + expect(mockNavigate).not.toHaveBeenCalled(); + }); + + it('keeps the conversation and the dialog when the delete is refused', async () => { + routeParams.current = { id: 'org-1', threadId: 't1' }; + mockTrash.mockResolvedValueOnce(false); + const { user, onOpenChange } = renderDialog(); + + await user.click(screen.getByRole('button', { name: 'Delete chat' })); + + await waitFor(() => + expect(mockToast).toHaveBeenCalledWith({ + title: "Couldn't delete chat", + variant: 'destructive', + }), + ); + expect(onOpenChange).not.toHaveBeenCalled(); + expect(mockNavigate).not.toHaveBeenCalled(); + }); +}); diff --git a/services/platform/app/features/chat/components/thread-delete-dialog.tsx b/services/platform/app/features/chat/components/thread-delete-dialog.tsx index df7d9142de..0bcb283c69 100644 --- a/services/platform/app/features/chat/components/thread-delete-dialog.tsx +++ b/services/platform/app/features/chat/components/thread-delete-dialog.tsx @@ -2,6 +2,7 @@ import { DeleteDialog } from '@tale/ui/dialog/delete-dialog'; import { toast } from '@tale/ui/use-toast'; +import { useNavigate, useParams } from '@tanstack/react-router'; import { useState } from 'react'; import { useT } from '@/lib/i18n/client'; @@ -17,16 +18,17 @@ export function ThreadDeleteDialog({ organizationId, open, onOpenChange, - onDeleted, }: { thread: Pick; organizationId: string; open: boolean; onOpenChange: (open: boolean) => void; - /** Runs after a successful delete — leave the dead conversation. */ - onDeleted?: () => void; }) { const { t } = useT('chat'); + const navigate = useNavigate(); + // The conversation on screen, if any: the header menu deletes it, a row + // menu deletes it or any other chat. + const openThreadId = useParams({ strict: false }).threadId; const actions = useThreadActions(organizationId); const [deleting, setDeleting] = useState(false); @@ -40,7 +42,17 @@ export function ThreadDeleteDialog({ return; } onOpenChange(false); - onDeleted?.(); + // Leave the deleted conversation for a fresh chat, in place of its + // page. Plain `/chat` would resume the most recent chat, and the list + // still names the deleted one until it has read again. + if (openThreadId === thread.id) { + void navigate({ + to: '/dashboard/$id/chat', + params: { id: organizationId }, + search: { new: true }, + replace: true, + }); + } }) .finally(() => setDeleting(false)); }; diff --git a/services/platform/app/features/chat/components/thread-row.test.tsx b/services/platform/app/features/chat/components/thread-row.test.tsx index 14b9309fe0..995fee32e8 100644 --- a/services/platform/app/features/chat/components/thread-row.test.tsx +++ b/services/platform/app/features/chat/components/thread-row.test.tsx @@ -41,6 +41,7 @@ vi.mock('@tanstack/react-router', () => ({ ), useNavigate: () => navigateMock, + useParams: () => ({ id: 'org-1' }), })); const renameMock = vi.hoisted(() => vi.fn(() => Promise.resolve(true))); diff --git a/services/platform/app/features/chat/components/thread-row.tsx b/services/platform/app/features/chat/components/thread-row.tsx index d39d57c64b..8fcaa080b7 100644 --- a/services/platform/app/features/chat/components/thread-row.tsx +++ b/services/platform/app/features/chat/components/thread-row.tsx @@ -464,7 +464,6 @@ export function ThreadRowMenu({ organizationId={organizationId} open={deleteOpen} onOpenChange={setDeleteOpen} - onDeleted={leaveIfActive} /> )} diff --git a/services/platform/tests/manual/readme.md b/services/platform/tests/manual/readme.md index cf0d0e63e7..f34f08f94f 100644 --- a/services/platform/tests/manual/readme.md +++ b/services/platform/tests/manual/readme.md @@ -39,7 +39,7 @@ directory and greppable as one token. | [approvals](suites/approvals.md) | `APV-` | human-in-the-loop: run approval/ask cards, task review gate, DSAR dual-approval | 22 | | [auth](suites/auth.md) | `AUTH-` | login, SSO, 2FA, passkeys, password policy, first-run setup, RBAC | 59 | | [automations](suites/automations.md) | `AUTO-` | draft→deploy→version automations: list, builder, upload, trigger, runs, bindings | 79 | -| [chat](suites/chat.md) | `CHAT-` | messages, attachments, tools + approvals, arena, share, reasoning, the chat header and rows | 102 | +| [chat](suites/chat.md) | `CHAT-` | messages, attachments, tools + approvals, arena, share, reasoning, the chat header and rows | 103 | | [connectors](suites/connectors.md) | `CONN-` | credential table + catalog picker; mailbox (IMAP/SMTP), OAuth, MCP endpoint | 41 | | [conversations](suites/conversations.md) | `CONV-` | the shared Inbox: statuses, priority, search, mailbox sync | 63 | | [data-residency](suites/data-residency.md) | `DATA-` | BYO knowledge database + object storage, embedding settings | 26 | diff --git a/services/platform/tests/manual/suites/chat.md b/services/platform/tests/manual/suites/chat.md index d416397f02..0ff72960df 100644 --- a/services/platform/tests/manual/suites/chat.md +++ b/services/platform/tests/manual/suites/chat.md @@ -1,6 +1,6 @@ # Chat -> **Prefix** `CHAT-` · **Reset** none · **Cost** 102 boxes +> **Prefix** `CHAT-` · **Reset** none · **Cost** 103 boxes Exercise the AI chat surface — the welcome view, messaging and the composer (model + reasoning-effort picker, attachments, dictation, voice output), @@ -378,6 +378,14 @@ i18n keys were pruned in #2919 — so this guide carries no canvas cases. period (`chat.deletePermanentMessage`); after confirming the chat leaves the Home panel; opening its old URL shows **This chat is not available.** (`chat.notFound`) +- [ ] `CHAT-F61` · **Deleting the open chat starts a fresh one** — Open a + chat, then its header ⋯ → **Delete** (`common.actions.delete`) → **Delete + chat** (`chat.deleteChat`) → The URL settles on + `/dashboard/{org}/chat?new=true` with an empty composer — never **This chat + is not available.** (`chat.notFound`) and never another chat — and Back does + not reopen the deleted chat. The same from the open chat's own row in the + Home panel. Deleting a different chat from its row keeps the open one on + screen. - [ ] `CHAT-F30` · **Search chats** — Open the palette from the rail's **Search** tile (`navigation.sidebar.search`) or with ⌘K and switch its scope to **Chats** (`dialogs.search.scopeChats`) → it retitles to **Search chats** From bc65f28b8a6b4b9baf663450e91548506651be5b Mon Sep 17 00:00:00 2001 From: yannickmonney Date: Mon, 5 Oct 2026 19:40:30 +0200 Subject: [PATCH 3/4] fix(platform): keep Documents in place when a folder is deleted A folder deleted from its row always sits in the folder on screen, yet the page then jumped to the Documents root and lost the reader's place. The delete now only closes its confirmation, and the row leaves the list. A deleted folder's own address never recovered either. Its breadcrumb read is refused with 404 (403 out of reach), and the adapter surfaced that as an error, so the self-heal waiting for an empty trail never ran. The page showed an empty folder that no longer exists, with uploads still aimed at it. The adapter now answers no trail for those refusals, as the 0.4 read did, so the page toasts "Folder not found or no longer accessible" and replaces the dead address with the root. Any other failure stays an error. --- .../components/breadcrumb-navigation.test.tsx | 63 +++++++- .../components/breadcrumb-navigation.tsx | 10 +- .../components/document-row-actions.tsx | 9 +- .../documents-table.folder-delete.test.tsx | 152 ++++++++++++++++++ .../documents/components/documents-table.tsx | 9 +- ...se-documents-table-config.browser.test.tsx | 2 - .../hooks/use-documents-table-config.test.tsx | 1 - .../hooks/use-documents-table-config.tsx | 4 - .../lib/backend/documents.breadcrumb.test.ts | 39 ++++- .../platform/app/lib/backend/documents.ts | 15 +- services/platform/tests/manual/readme.md | 2 +- .../platform/tests/manual/suites/knowledge.md | 11 +- 12 files changed, 282 insertions(+), 35 deletions(-) create mode 100644 services/platform/app/features/documents/components/documents-table.folder-delete.test.tsx diff --git a/services/platform/app/features/documents/components/breadcrumb-navigation.test.tsx b/services/platform/app/features/documents/components/breadcrumb-navigation.test.tsx index 8e81e395b6..dc16c45437 100644 --- a/services/platform/app/features/documents/components/breadcrumb-navigation.test.tsx +++ b/services/platform/app/features/documents/components/breadcrumb-navigation.test.tsx @@ -1,6 +1,6 @@ // @vitest-environment jsdom import '@testing-library/jest-dom/vitest'; -import { describe, it, vi } from 'vitest'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; import { checkAccessibility } from '@/tests/utils/a11y'; import { render } from '@/tests/utils/render'; @@ -29,19 +29,66 @@ vi.mock('@/app/hooks/use-organization-id', () => ({ useOrganizationId: () => 'org-1', })); +const TRAIL = [ + { _id: 'folder-1', name: 'Documents' }, + { _id: 'folder-2', name: 'Reports' }, +]; + +const { breadcrumbRead } = vi.hoisted(() => ({ + breadcrumbRead: { + current: { data: undefined as unknown, isLoading: false }, + }, +})); + vi.mock('@/app/hooks/use-backend-query', () => ({ - useBackendQuery: () => ({ - data: [ - { _id: 'folder-1', name: 'Documents' }, - { _id: 'folder-2', name: 'Reports' }, - ], - isLoading: false, - }), + useBackendQuery: () => breadcrumbRead.current, })); +import { toast } from '@tale/ui/use-toast'; + import { BreadcrumbNavigation } from './breadcrumb-navigation'; +beforeEach(() => { + vi.clearAllMocks(); + breadcrumbRead.current = { data: TRAIL, isLoading: false }; +}); + describe('BreadcrumbNavigation', () => { + // A deleted folder's address answers no trail. The page leaves it for the + // root in place of the dead entry, so Back does not walk into it again. + it('leaves a folder that is gone for the root, replacing its address', () => { + breadcrumbRead.current = { data: [], isLoading: false }; + const onNavigate = vi.fn(); + render( + , + ); + + expect(onNavigate).toHaveBeenCalledExactlyOnceWith(undefined, { + replace: true, + }); + expect(toast).toHaveBeenCalledWith({ title: 'documents.folderNotFound' }); + }); + + it('stays on a folder whose trail is still loading', () => { + breadcrumbRead.current = { data: undefined, isLoading: true }; + const onNavigate = vi.fn(); + render( + , + ); + + expect(onNavigate).not.toHaveBeenCalled(); + expect(toast).not.toHaveBeenCalled(); + }); + + it('stays on a folder with a trail', () => { + const onNavigate = vi.fn(); + render( + , + ); + + expect(onNavigate).not.toHaveBeenCalled(); + }); + describe('accessibility', () => { it('passes axe audit', async () => { const { container } = render( diff --git a/services/platform/app/features/documents/components/breadcrumb-navigation.tsx b/services/platform/app/features/documents/components/breadcrumb-navigation.tsx index 7ae109e8d3..9f779b29f3 100644 --- a/services/platform/app/features/documents/components/breadcrumb-navigation.tsx +++ b/services/platform/app/features/documents/components/breadcrumb-navigation.tsx @@ -11,7 +11,10 @@ import { useT } from '@/lib/i18n/client'; interface BreadcrumbNavigationProps { folderId: string; - onNavigate: (folderId: string | undefined) => void; + onNavigate: ( + folderId: string | undefined, + options?: { replace?: boolean }, + ) => void; } export function BreadcrumbNavigation({ @@ -29,10 +32,13 @@ export function BreadcrumbNavigation({ organizationId ? { folderId: folderId, organizationId } : 'skip', ); + // A folder with no trail is gone (deleted, here or in another tab) or out + // of reach: leave its address for the root, in place of it, so Back does + // not walk into it again. useEffect(() => { if (!isLoading && breadcrumb !== undefined && breadcrumb.length === 0) { toast({ title: t('folderNotFound') }); - onNavigateRef.current(undefined); + onNavigateRef.current(undefined, { replace: true }); } }, [breadcrumb, isLoading, t]); diff --git a/services/platform/app/features/documents/components/document-row-actions.tsx b/services/platform/app/features/documents/components/document-row-actions.tsx index d9a6c65367..256da82fc2 100644 --- a/services/platform/app/features/documents/components/document-row-actions.tsx +++ b/services/platform/app/features/documents/components/document-row-actions.tsx @@ -60,7 +60,6 @@ interface DocumentRowActionsProps { teamIds?: string[]; /** The folder the row sits in — the move dialog opens on it. */ currentFolderId?: string; - onFolderDeleted?: () => void; parentFolderTeamId?: string; /** Gates the "Reindex" action — terminal `unsupported` files (no text * extractor exists) never get a retry affordance, on the row menu any @@ -85,7 +84,6 @@ export function DocumentRowActions({ sourceProvider, teamIds, currentFolderId, - onFolderDeleted, parentFolderTeamId, ragStatus, record, @@ -156,10 +154,7 @@ export function DocumentRowActions({ const handleDeleteFolderConfirm = useCallback(() => { void deleteFolder({ folderId: documentId }).then( - () => { - dialogs.setOpen.deleteFolder(false); - onFolderDeleted?.(); - }, + () => dialogs.setOpen.deleteFolder(false), (error: unknown) => { console.error('Failed to delete folder:', error); // `AppError.message` is the serialized payload by design; the @@ -176,7 +171,7 @@ export function DocumentRowActions({ }); }, ); - }, [deleteFolder, documentId, dialogs.setOpen, tDocuments, onFolderDeleted]); + }, [deleteFolder, documentId, dialogs.setOpen, tDocuments]); const handleDeleteClick = useCallback(() => { if (itemType === 'folder') { diff --git a/services/platform/app/features/documents/components/documents-table.folder-delete.test.tsx b/services/platform/app/features/documents/components/documents-table.folder-delete.test.tsx new file mode 100644 index 0000000000..33e8c29e48 --- /dev/null +++ b/services/platform/app/features/documents/components/documents-table.folder-delete.test.tsx @@ -0,0 +1,152 @@ +// @vitest-environment jsdom +import '@testing-library/jest-dom/vitest'; +import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import type { ReactNode } from 'react'; +import { beforeEach, describe, expect, it, vi } from 'vitest'; + +import { render, screen, waitFor, within } from '@/tests/utils/render'; + +// A folder deleted from its row sat in the folder on screen, and the page +// used to jump to the Documents root after it, losing the place the reader +// was working in. The table, its columns, the row menu and the confirmation +// run for real; the reads, the write and the router are stubbed seams. + +const { navigate, deleteFolder } = vi.hoisted(() => ({ + navigate: vi.fn(), + deleteFolder: vi.fn(), +})); + +vi.mock('@tanstack/react-router', async (importOriginal) => ({ + ...(await importOriginal()), + useNavigate: () => navigate, + useParams: () => ({ id: 'org-1' }), + useLocation: () => ({ pathname: '/dashboard/org-1/documents', search: {} }), + Link: ({ children, to }: { children: ReactNode; to: string }) => ( + {children} + ), +})); + +vi.mock('@tale/ui/use-debounce', () => ({ + useDebounce: (value: string) => value, +})); + +vi.mock('@tale/ui/use-toast', () => ({ + toast: vi.fn(), + useToast: () => ({ toast: vi.fn() }), +})); + +vi.mock('@/app/hooks/use-ability', () => ({ + useAbility: () => ({ can: () => true }), +})); + +vi.mock('@/app/hooks/use-organization-id', () => ({ + useOrganizationId: () => 'org-1', +})); + +vi.mock('@/app/hooks/use-current-user', () => ({ + useCurrentUser: () => ({ data: { userId: 'user-1' } }), +})); + +vi.mock('@/app/features/settings/governance/hooks/queries', () => ({ + useLegalHoldByTarget: () => ({ data: null }), +})); + +vi.mock('@/app/features/settings/teams/hooks/queries', () => ({ + useTeams: () => ({ teams: [], isLoading: false }), + useTeamNames: () => ({ + teams: [], + nameOf: () => undefined, + isLoading: false, + }), +})); + +// The reader is in "Contracts", which holds one subfolder, "Meetings". +vi.mock('../hooks/queries', () => ({ + useApproxDocumentCount: () => ({ data: 0 }), + useFolder: () => ({ data: { _id: 'folder-contracts', name: 'Contracts' } }), + useFolders: () => ({ + data: [ + { + _id: 'folder-meetings', + name: 'Meetings', + _creationTime: 1_700_000_000_000, + parentId: 'folder-contracts', + }, + ], + }), + useListDocumentsPaginated: () => ({ + results: [], + status: 'Exhausted', + loadMore: vi.fn(), + isLoading: false, + error: null, + retry: vi.fn(), + isRetrying: false, + unavailable: false, + errorCount: 0, + }), +})); + +vi.mock('../hooks/mutations', () => ({ + useCancelOneDriveSync: () => ({ mutateAsync: vi.fn(), isPending: false }), + useCancelGoogleDriveSync: () => ({ mutateAsync: vi.fn(), isPending: false }), + useDeleteDocument: () => ({ mutateAsync: vi.fn(), isPending: false }), + useDeleteFolder: () => ({ mutateAsync: deleteFolder, isPending: false }), + useMarkDocumentControlled: () => ({ mutateAsync: vi.fn(), isPending: false }), + useOpenRecordRevision: () => ({ mutateAsync: vi.fn(), isPending: false }), +})); + +vi.mock('../hooks/actions', () => ({ + useRetryRagIndexing: () => ({ mutateAsync: vi.fn(), isPending: false }), +})); + +vi.mock('./documents-action-menu', () => ({ + DocumentsActionMenu: () => null, +})); + +vi.mock('./document-preview-dialog', () => ({ + DocumentPreviewDialog: () => null, +})); + +vi.mock('./breadcrumb-navigation', () => ({ + BreadcrumbNavigation: () =>