:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(desktop): color work column PR badges by PR state (#105647)
Shy Alteredc2adaf0106
diff --git a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsx b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsxindex e81322b2b3df..3f8c0bdcc2e4 100644--- a/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/ChannelItemRow.tsx@@ -390,7 +390,6 @@ export function ChannelItemRow({bulk,optionValue,spaceName,- withPrStatus = true,onContextMenuOpenChange,}: {item: ChannelItemModel;@@ -424,14 +423,9 @@ export function ChannelItemRow({optionValue?: string;/** Named in the subtitle by a list that spans spaces, where it is not implied. */spaceName?: string;- /**- * Off for a long list that spans spaces: the lookup is a query per row into- * git. The PR still shows where the task carries its own `prUrl`.- */- withPrStatus?: boolean;onContextMenuOpenChange?: (open: boolean) => void;}) {- const status = useChannelTaskStatus(item, { withPrStatus });+ const status = useChannelTaskStatus(item);const subtitle = useChannelItemMetadata(item, spaceName);const archivePresentation = useArchivingTasksStore((state) =>item.kind !== "task"diff --git a/products/desktop/packages/ui/src/features/canvas/components/work/WorkColumn.tsx b/products/desktop/packages/ui/src/features/canvas/components/work/WorkColumn.tsxindex 92d4b8c078ca..eafb9913d153 100644--- a/products/desktop/packages/ui/src/features/canvas/components/work/WorkColumn.tsx+++ b/products/desktop/packages/ui/src/features/canvas/components/work/WorkColumn.tsx@@ -559,7 +559,6 @@ export function WorkColumn() {optionValue={item.key}channelId={channelIdOf(item)}spaceName={spaceNameFor(item)}- withPrStatus={false}isActive={item.key === activeKey}isSelected={inSelection}actions={actions}diff --git a/products/desktop/packages/workspace-server/src/services/git/task-pr-status.test.ts b/products/desktop/packages/workspace-server/src/services/git/task-pr-status.test.tsindex 8af720d48ccb..d4ac2fa8df30 100644--- a/products/desktop/packages/workspace-server/src/services/git/task-pr-status.test.ts+++ b/products/desktop/packages/workspace-server/src/services/git/task-pr-status.test.ts@@ -212,6 +212,61 @@ describe("TaskPrStatusService revalidation PR detection", () => {}},);++ const PR_A = "https://github.com/acme/repo/pull/7";+ const PR_B = "https://github.com/acme/repo/pull/8";+ const flush = () => new Promise((resolve) => setImmediate(resolve));++ it.each([+ {+ name: "skips a repeat check inside the TTL",+ url: PR_A,+ laterMs: 1_000,+ calls: 1,+ },+ {+ name: "checks again once the TTL passes",+ url: PR_A,+ laterMs: 30_000,+ calls: 2,+ },+ {+ name: "checks a new cloud PR url at once",+ url: PR_B,+ laterMs: 1_000,+ calls: 2,+ },+ ])("$name", async ({ url, laterMs, calls }) => {+ const now = vi.spyOn(Date, "now").mockReturnValue(0);+ workspaceService.getWorkspace.mockResolvedValue({ mode: "cloud" });+ gitService.getPrDetailsByUrl.mockResolvedValue(null);++ await service.getTaskPrStatus("task-cloud", PR_A);+ await flush();+ now.mockReturnValue(laterMs);+ await service.getTaskPrStatus("task-cloud", url);+ await flush();++ expect(gitService.getPrDetailsByUrl).toHaveBeenCalledTimes(calls);+ });++ it("runs at most four checks at a time", async () => {+ workspaceService.getWorkspace.mockResolvedValue({ mode: "cloud" });+ const pending: Array<() => void> = [];+ gitService.getPrDetailsByUrl.mockImplementation(+ () => new Promise((resolve) => pending.push(() => resolve(null))),+ );++ for (let i = 0; i < 6; i++) {+ await service.getTaskPrStatus(`task-${i}`, PR_A);+ }+ await flush();+ expect(gitService.getPrDetailsByUrl).toHaveBeenCalledTimes(4);++ for (const release of pending.splice(0)) release();+ await flush();+ expect(gitService.getPrDetailsByUrl).toHaveBeenCalledTimes(6);+ });});describe("TaskPrStatusService.setPrimaryPrUrl", () => {diff --git a/products/desktop/packages/workspace-server/src/services/git/task-pr-status.ts b/products/desktop/packages/workspace-server/src/services/git/task-pr-status.tsindex 9bd85642ae4f..0dbc72546fa5 100644--- a/products/desktop/packages/workspace-server/src/services/git/task-pr-status.ts+++ b/products/desktop/packages/workspace-server/src/services/git/task-pr-status.ts@@ -12,9 +12,18 @@ import type {import type { WorkspaceService } from "../workspace/workspace";import { type GitService, mapPrState } from "./service";+const REVALIDATION_TTL_MS = 30_000;+const MAX_CONCURRENT_REVALIDATIONS = 4;+@injectable()export class TaskPrStatusService {private readonly taskPrRevalidations = new Map<string, Promise<void>>();+ private readonly lastRevalidations = new Map<+ string,+ { at: number; cloudPrUrl: string | null }+ >();+ private activeRevalidations = 0;+ private readonly revalidationQueue: Array<() => void> = [];constructor(@inject(GIT_SERVICE)@@ -99,8 +108,19 @@ export class TaskPrStatusService {): Promise<void> {const inFlight = this.taskPrRevalidations.get(taskId);if (inFlight) return inFlight;+ const last = this.lastRevalidations.get(taskId);+ if (+ last &&+ last.cloudPrUrl === cloudPrUrl &&+ Date.now() - last.at < REVALIDATION_TTL_MS+ ) {+ return;+ }+ this.lastRevalidations.set(taskId, { at: Date.now(), cloudPrUrl });- const promise = this.computeTaskPrStatus(taskId, cloudPrUrl)+ const promise = this.withRevalidationSlot(() =>+ this.computeTaskPrStatus(taskId, cloudPrUrl),+ ).then((fresh) => {const cached = this.workspaceRepo.findByTaskId(taskId);if (!cached) return;@@ -134,6 +154,21 @@ export class TaskPrStatusService {return promise;}+ private async withRevalidationSlot<T>(run: () => Promise<T>): Promise<T> {+ while (this.activeRevalidations >= MAX_CONCURRENT_REVALIDATIONS) {+ await new Promise<void>((resolve) =>+ this.revalidationQueue.push(resolve),+ );+ }+ this.activeRevalidations++;+ try {+ return await run();+ } finally {+ this.activeRevalidations--;+ this.revalidationQueue.shift()?.();+ }+ }+private async computeTaskPrStatus(taskId: string,cloudPrUrl: string | null,