Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { create } from "zustand";
import { persist } from "zustand/middleware";

export type ViewMode = "split" | "unified";
export type DiffSource = "local" | "branch";
export type DiffSource = "local" | "branch" | "pr";

interface DiffViewerStoreState {
viewMode: ViewMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ import { Flex, Spinner, Text } from "@radix-ui/themes";
import { useReviewNavigationStore } from "@renderer/features/code-review/stores/reviewNavigationStore";
import type { Task } from "@shared/types";
import { useMemo } from "react";
import { LazyDiff } from "./LazyDiff";
import { PatchedFileDiff } from "./PatchedFileDiff";
import {
DeferredDiffPlaceholder,
ReviewShell,
useReviewState,
} from "./ReviewShell";
import { RemoteDiffList } from "./RemoteDiffList";
import { ReviewShell, useReviewState } from "./ReviewShell";

interface CloudReviewPageProps {
task: Task;
Expand Down Expand Up @@ -52,8 +47,8 @@ export function CloudReviewPage({ task }: CloudReviewPageProps) {
getDeferredReason,
} = useReviewState(reviewFiles, allPaths);

const toolCallDiffs = useMemo(() => {
if (remoteFiles.length > 0) return null;
const toolCallFallbacks = useMemo(() => {
if (remoteFiles.length > 0) return undefined;
const diffs = new Map<
string,
{ oldText: string | null; newText: string | null }
Expand Down Expand Up @@ -97,48 +92,18 @@ export function CloudReviewPage({ task }: CloudReviewPageProps) {
onCollapseAll={collapseAll}
onUncollapseFile={uncollapseFile}
>
{reviewFiles.map((file) => {
const isCollapsed = collapsedFiles.has(file.path);
const deferredReason = getDeferredReason(file.path);

if (deferredReason) {
return (
<div key={file.path} data-file-path={file.path}>
<DeferredDiffPlaceholder
filePath={file.path}
linesAdded={file.linesAdded ?? 0}
linesRemoved={file.linesRemoved ?? 0}
reason={deferredReason}
collapsed={isCollapsed}
onToggle={() => toggleFile(file.path)}
onShow={() => revealFile(file.path)}
/>
</div>
);
}

const githubFileUrl = prUrl
? `${prUrl}/files#diff-${file.path.replaceAll("/", "-")}`
: undefined;

return (
<div key={file.path} data-file-path={file.path}>
<LazyDiff>
<PatchedFileDiff
file={file}
taskId={taskId}
prUrl={prUrl}
options={diffOptions}
collapsed={isCollapsed}
onToggle={() => toggleFile(file.path)}
commentThreads={showReviewComments ? commentThreads : undefined}
fallback={toolCallDiffs?.get(file.path) ?? null}
externalUrl={githubFileUrl}
/>
</LazyDiff>
</div>
);
})}
<RemoteDiffList
files={reviewFiles}
taskId={taskId}
prUrl={prUrl}
options={diffOptions}
collapsedFiles={collapsedFiles}
toggleFile={toggleFile}
revealFile={revealFile}
getDeferredReason={getDeferredReason}
commentThreads={showReviewComments ? commentThreads : undefined}
fallbacks={toolCallFallbacks}
/>
</ReviewShell>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { CaretDown, GitBranch, HardDrives } from "@phosphor-icons/react";
import {
CaretDown,
GitBranch,
GitPullRequest,
HardDrives,
} from "@phosphor-icons/react";
import {
Button,
DropdownMenu,
Expand All @@ -13,22 +18,29 @@ interface DiffSourceSelectorProps {
taskId: string;
effectiveSource: ResolvedDiffSource;
branchAvailable: boolean;
prSourceAvailable: boolean;
defaultBranch: string | null;
}

export function DiffSourceSelector({
taskId,
effectiveSource,
branchAvailable,
prSourceAvailable,
defaultBranch,
}: DiffSourceSelectorProps) {
const setDiffSource = useDiffViewerStore((s) => s.setDiffSource);

if (!branchAvailable || !defaultBranch) return null;
const anyAlternative = branchAvailable || prSourceAvailable;
if (!anyAlternative) return null;

const Icon = effectiveSource === "branch" ? GitBranch : HardDrives;
const branchLabel = `Branch vs. ${defaultBranch}`;
const triggerLabel = effectiveSource === "branch" ? branchLabel : "Local";
const branchLabel = defaultBranch ? `Branch vs. ${defaultBranch}` : "Branch";
const { icon: Icon, label: triggerLabel } = (() => {
if (effectiveSource === "pr") return { icon: GitPullRequest, label: "PR" };
if (effectiveSource === "branch")
return { icon: GitBranch, label: branchLabel };
return { icon: HardDrives, label: "Local" };
})();

return (
<DropdownMenu>
Expand Down Expand Up @@ -56,10 +68,18 @@ export function DiffSourceSelector({
<HardDrives size={12} />
Local changes
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setDiffSource(taskId, "branch")}>
<GitBranch size={12} />
{branchLabel}
</DropdownMenuItem>
{branchAvailable && defaultBranch && (
<DropdownMenuItem onClick={() => setDiffSource(taskId, "branch")}>
<GitBranch size={12} />
{branchLabel}
</DropdownMenuItem>
)}
{prSourceAvailable && (
<DropdownMenuItem onClick={() => setDiffSource(taskId, "pr")}>
<GitPullRequest size={12} />
Pull request
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import type { ChangedFile } from "@shared/types";
import type { DiffOptions } from "../types";
import type { PrCommentThread } from "../utils/prCommentAnnotations";
import { LazyDiff } from "./LazyDiff";
import { PatchedFileDiff } from "./PatchedFileDiff";
import { DeferredDiffPlaceholder, type DeferredReason } from "./ReviewShell";

interface RemoteDiffListProps {
files: ChangedFile[];
taskId: string;
options: DiffOptions;
collapsedFiles: Set<string>;
toggleFile: (path: string) => void;
revealFile: (path: string) => void;
getDeferredReason: (path: string) => DeferredReason | null;
prUrl?: string | null;
commentThreads?: Map<number, PrCommentThread>;
fallbacks?: Map<string, { oldText: string | null; newText: string | null }>;
}

export function RemoteDiffList({
files,
taskId,
options,
collapsedFiles,
toggleFile,
revealFile,
getDeferredReason,
prUrl,
commentThreads,
fallbacks,
}: RemoteDiffListProps) {
return files.map((file) => {
const isCollapsed = collapsedFiles.has(file.path);
const deferredReason = getDeferredReason(file.path);

if (deferredReason) {
return (
<div key={file.path} data-file-path={file.path}>
<DeferredDiffPlaceholder
filePath={file.path}
linesAdded={file.linesAdded ?? 0}
linesRemoved={file.linesRemoved ?? 0}
reason={deferredReason}
collapsed={isCollapsed}
onToggle={() => toggleFile(file.path)}
onShow={() => revealFile(file.path)}
/>
</div>
);
}

const githubFileUrl = prUrl
? `${prUrl}/files#diff-${file.path.replaceAll("/", "-")}`
: undefined;

return (
<div key={file.path} data-file-path={file.path}>
<LazyDiff>
<PatchedFileDiff
file={file}
taskId={taskId}
prUrl={prUrl}
options={options}
collapsed={isCollapsed}
onToggle={() => toggleFile(file.path)}
commentThreads={commentThreads}
fallback={fallbacks?.get(file.path) ?? null}
externalUrl={githubFileUrl}
/>
</LazyDiff>
</div>
);
});
}
Loading
Loading