-
Notifications
You must be signed in to change notification settings - Fork 0
[design-doctor effort xhigh] replacement clone of sourcebot#2: [design-doctor test] sourcebot-1154: Commit diff viewer #25
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
Changes from all commits
00784f2
059240a
3b53335
dbc4d14
7fe2972
4c33b60
29ed7b9
3e20e0d
df906c4
5c36e73
038edcc
5b7b01b
fae7b72
0a11df8
ba6da44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| 'use client'; | ||
|
|
||
| import { CopyIconButton } from "@/app/(app)/components/copyIconButton"; | ||
| import { useToast } from "@/components/hooks/use-toast"; | ||
| import Link from "next/link"; | ||
| import { Fragment, useCallback } from "react"; | ||
| import { getBrowsePath } from "../../../hooks/utils"; | ||
|
|
||
| interface CommitHashLineProps { | ||
| repoName: string; | ||
| commitHash: string; | ||
| parents: string[]; | ||
| } | ||
|
|
||
| export const CommitHashLine = ({ repoName, commitHash, parents }: CommitHashLineProps) => { | ||
| const { toast } = useToast(); | ||
|
|
||
| const onCopyHash = useCallback(() => { | ||
| navigator.clipboard.writeText(commitHash).then(() => { | ||
| toast({ description: "✅ Copied commit SHA to clipboard" }); | ||
| }); | ||
| return true; | ||
| }, [commitHash, toast]); | ||
|
|
||
| return ( | ||
| <div className="text-xs font-mono text-muted-foreground flex flex-row items-center gap-1"> | ||
| {parents.length > 0 && ( | ||
| <> | ||
| <span> | ||
| {parents.length} parent{parents.length > 1 ? 's' : ''} | ||
| </span> | ||
| {parents.map((parent, i) => ( | ||
| <Fragment key={parent}> | ||
| {i > 0 && <span>+</span>} | ||
| <Link | ||
| href={getBrowsePath({ | ||
| repoName, | ||
| path: '', | ||
| pathType: 'commit', | ||
| commitSha: parent, | ||
| })} | ||
| className="underline hover:text-foreground" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parent-commit links look different from other commit links The links to parent commits are styled differently from the other commit references shown in the same view, so commit links don't read as one consistent, recognizable affordance. Aligning them would make it clearer at a glance which pieces of text navigate to another commit. Prompt to fix with AI |
||
| title={parent} | ||
| > | ||
| {parent.slice(0, 7)} | ||
| </Link> | ||
| </Fragment> | ||
| ))} | ||
| </> | ||
| )} | ||
| <span>commit {commitHash.slice(0, 7)}</span> | ||
| <CopyIconButton onCopy={onCopyHash} /> | ||
| </div> | ||
| ); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| 'use client'; | ||
|
|
||
| import { CommitBody, CommitBodyToggle } from "@/app/(app)/browse/components/commitParts"; | ||
| import { useState } from "react"; | ||
|
|
||
| interface CommitMessageProps { | ||
| subject: string; | ||
| body: string; | ||
| } | ||
|
|
||
| export const CommitMessage = ({ subject, body }: CommitMessageProps) => { | ||
| const [isBodyExpanded, setIsBodyExpanded] = useState(false); | ||
| const hasBody = body.trim().length > 0; | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="flex flex-row items-center gap-2"> | ||
| <h1 className="text-lg font-semibold">{subject}</h1> | ||
| {hasBody && ( | ||
| <CommitBodyToggle | ||
| pressed={isBodyExpanded} | ||
| onPressedChange={setIsBodyExpanded} | ||
| /> | ||
| )} | ||
| </div> | ||
| {hasBody && isBodyExpanded && ( | ||
| <CommitBody body={body} className="rounded max-h-[40vh] overflow-y-auto" /> | ||
| )} | ||
| </> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { FileDiff } from "@/features/git"; | ||
|
|
||
| const TOTAL_SQUARES = 5; | ||
|
|
||
| // Count `+`/`-` lines across all hunks in a file. | ||
| export const computeChangeCounts = (file: FileDiff) => { | ||
| let additions = 0; | ||
| let deletions = 0; | ||
| for (const hunk of file.hunks) { | ||
| for (const raw of hunk.body.split('\n')) { | ||
| if (raw.startsWith('+')) { | ||
| additions++; | ||
| } else if (raw.startsWith('-')) { | ||
| deletions++; | ||
| } | ||
| } | ||
| } | ||
| return { additions, deletions }; | ||
| }; | ||
|
|
||
| // Sum line-level change counts across multiple files. | ||
| export const computeTotalChangeCounts = (files: FileDiff[]) => { | ||
| let additions = 0; | ||
| let deletions = 0; | ||
| for (const file of files) { | ||
| const counts = computeChangeCounts(file); | ||
| additions += counts.additions; | ||
| deletions += counts.deletions; | ||
| } | ||
| return { additions, deletions }; | ||
| }; | ||
|
|
||
| // Map a total change count to a number of filled squares (0–5) using a | ||
| // log-ish scale so tiny diffs still show one square and huge diffs cap out. | ||
| // Mirrors GitHub's diffstat indicator behavior. | ||
| const filledSquaresForTotal = (total: number): number => { | ||
| if (total === 0) { | ||
| return 0; | ||
| } | ||
| if (total < 5) { | ||
| return 1; | ||
| } | ||
| if (total < 10) { | ||
| return 2; | ||
| } | ||
| if (total < 30) { | ||
| return 3; | ||
| } | ||
| if (total < 100) { | ||
| return 4; | ||
| } | ||
| return 5; | ||
| }; | ||
|
|
||
| interface DiffStatProps { | ||
| additions: number; | ||
| deletions: number; | ||
| } | ||
|
|
||
| export const DiffStat = ({ additions, deletions }: DiffStatProps) => { | ||
| const total = additions + deletions; | ||
|
|
||
| // Skip rendering when there are no line-level changes (e.g. pure renames). | ||
| if (total === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const filled = filledSquaresForTotal(total); | ||
| const greenCount = Math.round((filled * additions) / total); | ||
| const redCount = filled - greenCount; | ||
| const emptyCount = TOTAL_SQUARES - filled; | ||
|
|
||
| return ( | ||
| <div | ||
| className="flex flex-row items-center gap-2 text-xs flex-shrink-0 font-mono" | ||
| title={`${additions} additions, ${deletions} deletions`} | ||
| > | ||
| {additions > 0 && ( | ||
| <span className="text-green-700 dark:text-green-400">+{additions}</span> | ||
| )} | ||
| {deletions > 0 && ( | ||
| <span className="text-red-700 dark:text-red-400">-{deletions}</span> | ||
| )} | ||
| <div className="flex flex-row gap-px"> | ||
| {Array.from({ length: greenCount }).map((_, i) => ( | ||
| <span key={`g-${i}`} className="w-2 h-2 bg-green-500 dark:bg-green-400 rounded-[1px]" /> | ||
| ))} | ||
| {Array.from({ length: redCount }).map((_, i) => ( | ||
| <span key={`r-${i}`} className="w-2 h-2 bg-red-500 dark:bg-red-400 rounded-[1px]" /> | ||
| ))} | ||
| {Array.from({ length: emptyCount }).map((_, i) => ( | ||
| <span key={`e-${i}`} className="w-2 h-2 bg-border rounded-[1px]" /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; |
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.
Close control on the preview banner is wrapped in an extra layer
On the file preview banner, the close control is wrapped in a redundant interactive layer instead of being a single clean icon button, which can make its hover and focus states feel inconsistent and adds a duplicate tab stop. It should match the tidy icon buttons used elsewhere.
Prompt to fix with AI