-
Notifications
You must be signed in to change notification settings - Fork 16
feat(code): add diff stats to convo view #2065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
apps/code/src/renderer/features/code-review/hooks/useTaskDiffStats.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { | ||
| useLocalBranchChangedFiles, | ||
| usePrChangedFiles, | ||
| } from "@features/git-interaction/hooks/useGitQueries"; | ||
| import { | ||
| computeDiffStats, | ||
| type DiffStats, | ||
| } from "@features/git-interaction/utils/diffStats"; | ||
| import { useCwd } from "@features/sidebar/hooks/useCwd"; | ||
| import { useCloudChangedFiles } from "@features/task-detail/hooks/useCloudChangedFiles"; | ||
| import { useWorkspace } from "@features/workspace/hooks/useWorkspace"; | ||
| import type { Task } from "@shared/types"; | ||
| import { useMemo } from "react"; | ||
| import { useEffectiveDiffSource } from "./useEffectiveDiffSource"; | ||
|
|
||
| export function useTaskDiffStats(task: Task): DiffStats { | ||
| const taskId = task.id; | ||
| const workspace = useWorkspace(taskId); | ||
| const isCloud = | ||
| workspace?.mode === "cloud" || task.latest_run?.environment === "cloud"; | ||
|
|
||
| const { reviewFiles } = useCloudChangedFiles(taskId, task, isCloud); | ||
|
|
||
| const repoPath = useCwd(taskId); | ||
| const { | ||
| effectiveSource, | ||
| linkedBranch, | ||
| prUrl, | ||
| diffStats: localDiffStats, | ||
| } = useEffectiveDiffSource(taskId); | ||
|
|
||
| const { data: branchFiles } = useLocalBranchChangedFiles( | ||
| !isCloud && effectiveSource === "branch" ? (repoPath ?? null) : null, | ||
| !isCloud && effectiveSource === "branch" ? linkedBranch : null, | ||
| ); | ||
| const { data: prFiles } = usePrChangedFiles( | ||
| !isCloud && effectiveSource === "pr" ? prUrl : null, | ||
| ); | ||
|
|
||
| return useMemo<DiffStats>(() => { | ||
| if (isCloud) return computeDiffStats(reviewFiles); | ||
| if (effectiveSource === "branch" && branchFiles) { | ||
| return computeDiffStats(branchFiles); | ||
| } | ||
| if (effectiveSource === "pr" && prFiles) { | ||
| return computeDiffStats(prFiles); | ||
| } | ||
| return localDiffStats; | ||
| }, [ | ||
| isCloud, | ||
| reviewFiles, | ||
| effectiveSource, | ||
| branchFiles, | ||
| prFiles, | ||
| localDiffStats, | ||
| ]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
apps/code/src/renderer/features/sessions/components/DiffStatsChip.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { Tooltip } from "@components/ui/Tooltip"; | ||
| import { useTaskDiffStats } from "@features/code-review/hooks/useTaskDiffStats"; | ||
| import { useReviewNavigationStore } from "@features/code-review/stores/reviewNavigationStore"; | ||
| import { GitDiff } from "@phosphor-icons/react"; | ||
| import { Flex, Text } from "@radix-ui/themes"; | ||
| import { | ||
| formatHotkey, | ||
| SHORTCUTS, | ||
| } from "@renderer/constants/keyboard-shortcuts"; | ||
| import type { Task } from "@shared/types"; | ||
|
|
||
| interface DiffStatsChipProps { | ||
| task: Task; | ||
| } | ||
|
|
||
| export function DiffStatsChip({ task }: DiffStatsChipProps) { | ||
| const taskId = task.id; | ||
| const { filesChanged, linesAdded, linesRemoved } = useTaskDiffStats(task); | ||
|
|
||
| const reviewMode = useReviewNavigationStore( | ||
| (s) => s.reviewModes[taskId] ?? "closed", | ||
| ); | ||
| const setReviewMode = useReviewNavigationStore((s) => s.setReviewMode); | ||
|
|
||
| if (filesChanged === 0) return null; | ||
|
|
||
| const isOpen = reviewMode !== "closed"; | ||
|
|
||
| const handleClick = () => { | ||
| setReviewMode(taskId, isOpen ? "closed" : "expanded"); | ||
| }; | ||
|
|
||
| return ( | ||
| <Tooltip | ||
| content={isOpen ? "Close review" : "Open review"} | ||
| shortcut={formatHotkey(SHORTCUTS.TOGGLE_REVIEW_PANEL)} | ||
| side="top" | ||
| > | ||
| <Flex | ||
| align="center" | ||
| gap="1" | ||
| onClick={handleClick} | ||
| className="cursor-pointer select-none text-[13px] text-gray-10 tabular-nums hover:text-gray-12" | ||
| > | ||
| <GitDiff size={12} className="shrink-0" /> | ||
| <Text className="text-[13px]"> | ||
| {filesChanged} {filesChanged === 1 ? "file" : "files"} | ||
| </Text> | ||
| {linesAdded > 0 && ( | ||
| <Text className="text-(--green-9) text-[13px]">+{linesAdded}</Text> | ||
| )} | ||
| {linesRemoved > 0 && ( | ||
| <Text className="text-(--red-9) text-[13px]">-{linesRemoved}</Text> | ||
| )} | ||
| </Flex> | ||
| </Tooltip> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DiffStatsChipandDiffStatsBadgeBoth components share the same
useTaskDiffStatscall,useReviewNavigationStoresubscription pattern,handleClicktoggle logic,GitDifficon, and Tooltip with the same keyboard shortcut. The only real differences are the wrapping element (FlexvsButton), tooltip side (topvsbottom), and the review mode opened ("expanded"vs"split"). Consider extracting the shared state/callback logic into a shared hook (e.g.useDiffStatsToggle) to satisfy OnceAndOnlyOnce.Prompt To Fix With AI