From ae3f483cb6e251de8e1390f1bed803679e4b6faf Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 11 May 2026 12:14:51 +0200 Subject: [PATCH] feat(documents): hide completed workflows from folder views When listDocuments is called with folderId set (including folderId=null for root-only), exclude status='completed' rows. The signed-PDF file appears in the Files section with a "view signing details" link; the workflow row would just be noise alongside the file. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/lib/services/documents.service.ts | 4 +++ .../documents-list-folder-filter.test.ts | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/lib/services/documents.service.ts b/src/lib/services/documents.service.ts index d0b9d821..09909a7b 100644 --- a/src/lib/services/documents.service.ts +++ b/src/lib/services/documents.service.ts @@ -184,6 +184,10 @@ export async function listDocuments( } else { filters.push(eq(documents.folderId, query.folderId)); } + // When viewing a specific folder, hide completed workflows — they surface + // via their resulting signed-PDF file row in the Files section, not the + // Signing section. + filters.push(ne(documents.status, 'completed')); } if (sentSince) filters.push(gte(documents.createdAt, new Date(sentSince))); if (sentUntil) filters.push(lte(documents.createdAt, new Date(sentUntil))); diff --git a/tests/integration/documents-list-folder-filter.test.ts b/tests/integration/documents-list-folder-filter.test.ts index f764631b..d9189d29 100644 --- a/tests/integration/documents-list-folder-filter.test.ts +++ b/tests/integration/documents-list-folder-filter.test.ts @@ -126,4 +126,38 @@ describe('documents.listDocuments folder filtering', () => { const titles = (res.data as Array<{ title: string }>).map((d) => d.title); expect(titles).toEqual(['At Root']); }); + + it('hides completed workflows when folderId is set', async () => { + const folder = await createFolder(portId, testUserId, { name: 'ClientFolder', parentId: null }); + await db.insert(documents).values([ + { + portId, + documentType: 'eoi', + title: 'In flight', + createdBy: testUserId, + folderId: folder.id, + status: 'sent', + }, + { + portId, + documentType: 'eoi', + title: 'Completed workflow', + createdBy: testUserId, + folderId: folder.id, + status: 'completed', + }, + ]); + + const res = await listDocuments(portId, { + page: 1, + limit: 50, + order: 'desc', + includeArchived: false, + includeDescendants: false, + folderId: folder.id, + }); + const titles = (res.data as Array<{ title: string }>).map((d) => d.title); + expect(titles).toContain('In flight'); + expect(titles).not.toContain('Completed workflow'); + }); });