Skip to content

Commit f02bda7

Browse files
committed
feat(code): new diff review panel
1 parent fabf75a commit f02bda7

9 files changed

Lines changed: 60 additions & 14 deletions

File tree

apps/code/src/renderer/features/git-interaction/components/CreatePrDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from "@features/git-interaction/components/GitInteractionDialogs";
55
import { useGitInteractionStore } from "@features/git-interaction/state/gitInteractionStore";
66
import type { CreatePrStep } from "@features/git-interaction/types";
7+
import type { DiffStats } from "@features/git-interaction/utils/diffStats";
78
import {
89
CheckCircle,
910
Circle,
@@ -113,7 +114,7 @@ export interface CreatePrDialogProps {
113114
open: boolean;
114115
onOpenChange: (open: boolean) => void;
115116
currentBranch: string | null;
116-
diffStats: { filesChanged: number; linesAdded: number; linesRemoved: number };
117+
diffStats: DiffStats;
117118
isSubmitting: boolean;
118119
onSubmit: () => void;
119120
onGenerateCommitMessage: () => void;

apps/code/src/renderer/features/git-interaction/components/GitInteractionDialogs.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Tooltip } from "@components/ui/Tooltip";
2+
import type { DiffStats } from "@features/git-interaction/utils/diffStats";
23
import {
34
CheckCircle,
45
CloudArrowUp,
@@ -243,7 +244,7 @@ interface GitCommitDialogProps {
243244
open: boolean;
244245
onOpenChange: (open: boolean) => void;
245246
branchName: string | null;
246-
diffStats: { filesChanged: number; linesAdded: number; linesRemoved: number };
247+
diffStats: DiffStats;
247248
commitMessage: string;
248249
onCommitMessageChange: (value: string) => void;
249250
nextStep: "commit" | "commit-push";

apps/code/src/renderer/features/git-interaction/hooks/useGitInteraction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
createBranch,
1515
getBranchNameInputState,
1616
} from "@features/git-interaction/utils/branchCreation";
17+
import type { DiffStats } from "@features/git-interaction/utils/diffStats";
1718
import { invalidateGitBranchQueries } from "@features/git-interaction/utils/gitCacheKeys";
1819
import { updateGitCacheFromSnapshot } from "@features/git-interaction/utils/updateGitCache";
1920
import { trpc, trpcClient } from "@renderer/trpc";
@@ -48,7 +49,7 @@ interface GitInteractionState {
4849
defaultBranch: string | null;
4950
prBaseBranch: string | null;
5051
prHeadBranch: string | null;
51-
diffStats: { filesChanged: number; linesAdded: number; linesRemoved: number };
52+
diffStats: DiffStats;
5253
prUrl: string | null;
5354
pushDisabledReason: string | null;
5455
isLoading: boolean;

apps/code/src/renderer/features/git-interaction/hooks/useGitQueries.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useTRPC } from "@renderer/trpc";
22
import { useQuery } from "@tanstack/react-query";
33

44
const EMPTY_DIFF_STATS = { filesChanged: 0, linesAdded: 0, linesRemoved: 0 };
5+
const EMPTY_CHANGED_FILES: never[] = [];
56

67
const GIT_QUERY_DEFAULTS = {
78
staleTime: 30_000,
@@ -20,7 +21,10 @@ export function useGitQueries(repoPath?: string) {
2021

2122
const repoEnabled = enabled && isRepo;
2223

23-
const { data: changedFiles = [], isLoading: changesLoading } = useQuery(
24+
const {
25+
data: changedFiles = EMPTY_CHANGED_FILES,
26+
isLoading: changesLoading,
27+
} = useQuery(
2428
trpc.git.getChangedFilesHead.queryOptions(
2529
{ directoryPath: repoPath as string },
2630
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { ChangedFile } from "@shared/types";
2+
3+
export interface DiffStats {
4+
filesChanged: number;
5+
linesAdded: number;
6+
linesRemoved: number;
7+
}
8+
9+
export function computeDiffStats(files: ChangedFile[]): DiffStats {
10+
let linesAdded = 0;
11+
let linesRemoved = 0;
12+
for (const file of files) {
13+
linesAdded += file.linesAdded ?? 0;
14+
linesRemoved += file.linesRemoved ?? 0;
15+
}
16+
return { filesChanged: files.length, linesAdded, linesRemoved };
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { GitFileStatus } from "@shared/types";
2+
3+
export type StatusColor = "green" | "orange" | "red" | "blue" | "gray";
4+
export interface StatusIndicator {
5+
label: string;
6+
fullLabel: string;
7+
color: StatusColor;
8+
}
9+
export function getStatusIndicator(status: GitFileStatus): StatusIndicator {
10+
switch (status) {
11+
case "added":
12+
case "untracked":
13+
return { label: "A", fullLabel: "Added", color: "green" };
14+
case "deleted":
15+
return { label: "D", fullLabel: "Deleted", color: "red" };
16+
case "modified":
17+
return { label: "M", fullLabel: "Modified", color: "orange" };
18+
case "renamed":
19+
return { label: "R", fullLabel: "Renamed", color: "blue" };
20+
default:
21+
return { label: "?", fullLabel: "Unknown", color: "gray" };
22+
}
23+
}

apps/code/src/renderer/features/message-editor/components/DiffStatsIndicator.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1+
import type { DiffStats } from "@features/git-interaction/utils/diffStats";
12
import { Flex, Text } from "@radix-ui/themes";
23
import { useTRPC } from "@renderer/trpc";
34
import { useQuery } from "@tanstack/react-query";
45

56
interface DiffStatsIndicatorProps {
67
repoPath: string | null | undefined;
7-
overrideStats?: {
8-
filesChanged: number;
9-
linesAdded: number;
10-
linesRemoved: number;
11-
} | null;
8+
overrideStats?: DiffStats | null;
129
}
1310

1411
export function DiffStatsIndicator({

apps/code/src/renderer/features/task-detail/components/TaskLogsPanel.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
useCloudBranchChangedFiles,
66
useCloudPrChangedFiles,
77
} from "@features/git-interaction/hooks/useGitQueries";
8+
import { computeDiffStats } from "@features/git-interaction/utils/diffStats";
89
import { useDraftStore } from "@features/message-editor/stores/draftStore";
910
import { ProvisioningView } from "@features/provisioning/components/ProvisioningView";
1011
import { useProvisioningStore } from "@features/provisioning/stores/provisioningStore";
@@ -100,11 +101,7 @@ export function TaskLogsPanel({ taskId, task }: TaskLogsPanelProps) {
100101
if (!isCloud) return null;
101102
const files = prUrl ? prFiles : branchFiles;
102103
if (!files || files.length === 0) return null;
103-
return {
104-
filesChanged: files.length,
105-
linesAdded: files.reduce((sum, f) => sum + (f.linesAdded ?? 0), 0),
106-
linesRemoved: files.reduce((sum, f) => sum + (f.linesRemoved ?? 0), 0),
107-
};
104+
return computeDiffStats(files);
108105
}, [isCloud, prUrl, prFiles, branchFiles]);
109106

110107
useEffect(() => {

apps/code/src/renderer/utils/path.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ export function compactHomePath(text: string): string {
3535
.replace(/\/Users\/[^/\s]+/g, "~")
3636
.replace(/\/home\/[^/\s]+/g, "~");
3737
}
38+
39+
export function getFileExtension(filePath: string): string {
40+
const parts = filePath.split(".");
41+
return parts.length > 1 ? parts[parts.length - 1] : "";
42+
}

0 commit comments

Comments
 (0)