feat(utils): add buildCommentHref helper for comment deep-links
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) <noreply@anthropic.com>
This commit is contained in:
14
frontend/src/lib/utils/commentDeepLink.spec.ts
Normal file
14
frontend/src/lib/utils/commentDeepLink.spec.ts
Normal file
@@ -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');
|
||||||
|
});
|
||||||
|
});
|
||||||
8
frontend/src/lib/utils/commentDeepLink.ts
Normal file
8
frontend/src/lib/utils/commentDeepLink.ts
Normal file
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user