Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit 621e924

Browse files
committed
refactor(code-review): simplify PR comment badges
Generated-By: PostHog Code Task-Id: 2e4a7ce2-5055-4c59-99c9-6daed60688c4
1 parent 5ad613e commit 621e924

5 files changed

Lines changed: 29 additions & 91 deletions

File tree

packages/ui/src/features/code-review/components/PatchedFileDiff.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { PrCommentThread } from "@posthog/core/code-review/types";
33
import { isBinaryFile } from "@posthog/shared";
44
import type { ChangedFile } from "@posthog/shared/domain-types";
55
import { type ReactNode, useMemo } from "react";
6-
import { countPrCommentsForFile } from "../prCommentThreads";
76
import { DeferredDiffPlaceholder, DiffFileHeader } from "../reviewShellParts";
87
import type { DiffOptions } from "../types";
98
import { InteractiveFileDiff } from "./InteractiveFileDiff";
@@ -106,3 +105,19 @@ export function PatchedFileDiff({
106105
/>
107106
);
108107
}
108+
109+
function countPrCommentsForFile(
110+
threads: Map<number, PrCommentThread> | undefined,
111+
file: Pick<ChangedFile, "path" | "originalPath">,
112+
): number {
113+
let count = 0;
114+
for (const thread of threads?.values() ?? []) {
115+
if (
116+
thread.filePath === file.path ||
117+
(file.originalPath != null && thread.filePath === file.originalPath)
118+
) {
119+
count += thread.comments.length;
120+
}
121+
}
122+
return count;
123+
}

packages/ui/src/features/code-review/prCommentThreads.test.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

packages/ui/src/features/code-review/prCommentThreads.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/ui/src/features/code-review/reviewShellParts.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
splitFilePath,
1515
sumHunkStats,
1616
} from "@posthog/core/code-review/reviewShellGeometry";
17+
import { Badge } from "@posthog/quill";
1718
import type { ChangedFile, Task } from "@posthog/shared/domain-types";
1819
import { type ReactNode, useCallback, useMemo, useState } from "react";
1920
import { FileIcon } from "../../primitives/FileIcon";
@@ -385,13 +386,14 @@ export function DeferredDiffPlaceholder({
385386
function PrCommentCountBadge({ count }: { count: number }) {
386387
const label = `${count} comment${count === 1 ? "" : "s"}`;
387388
return (
388-
<span
389+
<Badge
390+
variant="info"
389391
title={label}
390-
className="inline-flex shrink-0 items-center gap-[3px] rounded-full bg-(--accent-3) px-[6px] py-[2px] text-(--accent-11) text-[11px] tabular-nums"
392+
className="shrink-0 gap-[3px] text-[11px] tabular-nums"
391393
>
392394
<ChatCircle size={12} weight="fill" />
393395
{count}
394396
<span className="sr-only"> comment{count === 1 ? "" : "s"}</span>
395-
</span>
397+
</Badge>
396398
);
397399
}

packages/ui/src/features/git-interaction/usePrDetails.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import { useHostTRPC } from "@posthog/host-router/react";
2+
import type { PrReviewThread } from "@posthog/shared";
23
import { useQueries, useQuery } from "@tanstack/react-query";
34
import { useMemo } from "react";
4-
import { mapPrCommentThreads } from "../code-review/prCommentThreads";
5+
import type { PrCommentThread } from "../code-review/prCommentAnnotations";
56

67
interface UsePrDetailsOptions {
78
includeComments?: boolean;
89
}
910

11+
function mapPrCommentThreads(
12+
threads: PrReviewThread[],
13+
): Map<number, PrCommentThread> {
14+
return new Map(threads.map((thread) => [thread.rootId, thread]));
15+
}
16+
1017
export interface PrStateDetails {
1118
state: string;
1219
merged: boolean;

0 commit comments

Comments
 (0)