From 7f40c54b3ff0cbf087a7c7c29a58e4a674f1601d Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 21 Apr 2026 17:15:48 +0200 Subject: [PATCH] feat(utils): add buildCommentHref helper for comment deep-links MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Single source of truth for constructing /documents/:id?commentId=… (&annotationId=…) URLs. Used by the notification bell, the chronik "Für dich" sidebar, and the chronik main feed so the three surfaces can no longer diverge. Refs #300. Co-Authored-By: Claude Opus 4.7 (1M context) --- frontend/src/lib/utils/commentDeepLink.spec.ts | 14 ++++++++++++++ frontend/src/lib/utils/commentDeepLink.ts | 8 ++++++++ 2 files changed, 22 insertions(+) create mode 100644 frontend/src/lib/utils/commentDeepLink.spec.ts create mode 100644 frontend/src/lib/utils/commentDeepLink.ts diff --git a/frontend/src/lib/utils/commentDeepLink.spec.ts b/frontend/src/lib/utils/commentDeepLink.spec.ts new file mode 100644 index 00000000..15c7f103 --- /dev/null +++ b/frontend/src/lib/utils/commentDeepLink.spec.ts @@ -0,0 +1,14 @@ +import { describe, it, expect } from 'vitest'; +import { buildCommentHref } from './commentDeepLink'; + +describe('buildCommentHref', () => { + it('includes both commentId and annotationId when annotationId is present', () => { + const href = buildCommentHref('doc-1', 'comment-2', 'annot-3'); + expect(href).toBe('/documents/doc-1?commentId=comment-2&annotationId=annot-3'); + }); + + it('omits annotationId when null', () => { + const href = buildCommentHref('doc-1', 'comment-2', null); + expect(href).toBe('/documents/doc-1?commentId=comment-2'); + }); +}); diff --git a/frontend/src/lib/utils/commentDeepLink.ts b/frontend/src/lib/utils/commentDeepLink.ts new file mode 100644 index 00000000..95b5ef1d --- /dev/null +++ b/frontend/src/lib/utils/commentDeepLink.ts @@ -0,0 +1,8 @@ +export function buildCommentHref( + documentId: string, + commentId: string, + annotationId: string | null +): string { + const base = `/documents/${documentId}?commentId=${commentId}`; + return annotationId ? `${base}&annotationId=${annotationId}` : base; +}