Repository navigation
feat(desktop,host-service): show full commit message on hover in v2 changes tab #6126
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
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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,9 @@ | ||||||
| import type { AppRouter } from "@superset/host-service"; | ||||||
| import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip"; | ||||||
| import { workspaceTrpc } from "@superset/workspace-client"; | ||||||
| import type { inferRouterOutputs } from "@trpc/server"; | ||||||
| import { Check } from "lucide-react"; | ||||||
| import { useState } from "react"; | ||||||
|
|
||||||
| type Commit = | ||||||
| inferRouterOutputs<AppRouter>["git"]["listCommits"]["commits"][number]; | ||||||
|
|
@@ -18,26 +21,74 @@ function timeAgo(date: string): string { | |||||
|
|
||||||
| interface CommitRowProps { | ||||||
| commit: Commit; | ||||||
| workspaceId: string; | ||||||
| isSelected?: boolean; | ||||||
| wrap?: boolean; | ||||||
| } | ||||||
|
|
||||||
| export function CommitRow({ | ||||||
| commit, | ||||||
| workspaceId, | ||||||
| isSelected, | ||||||
| wrap = false, | ||||||
| }: CommitRowProps) { | ||||||
| const [open, setOpen] = useState(false); | ||||||
|
|
||||||
| // listCommits only carries `%s`, so the body is fetched per commit and only | ||||||
| // once the card is actually opened. Commit messages are immutable, so a | ||||||
| // hover that reopens the same card never refetches. | ||||||
| const message = workspaceTrpc.git.getCommitMessage.useQuery( | ||||||
| { workspaceId, commitHash: commit.hash }, | ||||||
| { enabled: open, staleTime: Number.POSITIVE_INFINITY }, | ||||||
| ); | ||||||
| const subject = message.data?.subject ?? commit.message; | ||||||
| const body = message.data?.body ?? ""; | ||||||
|
|
||||||
| return ( | ||||||
| <div className="flex min-w-0 flex-1 items-start justify-between gap-2"> | ||||||
| <div className="min-w-0 flex-1 overflow-hidden"> | ||||||
| <div className={wrap ? "text-sm wrap-break-word" : "truncate text-sm"}> | ||||||
| {commit.message} | ||||||
| <Tooltip open={open} onOpenChange={setOpen} delayDuration={400}> | ||||||
| <TooltipTrigger asChild> | ||||||
| <div className="flex min-w-0 flex-1 items-start justify-between gap-2"> | ||||||
| <div className="min-w-0 flex-1 overflow-hidden"> | ||||||
| <div | ||||||
| className={wrap ? "text-sm wrap-break-word" : "truncate text-sm"} | ||||||
| > | ||||||
| {commit.message} | ||||||
| </div> | ||||||
| <div className="truncate text-xs text-muted-foreground"> | ||||||
| {commit.shortHash} · {commit.author} · {timeAgo(commit.date)} | ||||||
| </div> | ||||||
| </div> | ||||||
| {isSelected && <Check className="mt-0.5 size-3.5 shrink-0" />} | ||||||
| </div> | ||||||
| </TooltipTrigger> | ||||||
| {/* The arrow points back at the hovered row, which matters in a list | ||||||
| this dense. Only the message scrolls: bodies are unbounded, and a | ||||||
| long one would otherwise grow the card past the window — the | ||||||
| arrow and the hash line have to stay put and visible. | ||||||
| The card is wide enough for a conventionally wrapped body (~72 | ||||||
| columns) so the message is not re-wrapped into a ragged column | ||||||
| on top of the author's own line breaks. */} | ||||||
| <TooltipContent | ||||||
| side="left" | ||||||
| align="start" | ||||||
| showArrow | ||||||
| collisionPadding={8} | ||||||
| className="w-[26rem] max-w-[calc(100vw-6rem)] p-0 text-wrap" | ||||||
| > | ||||||
| <div className="max-h-64 overflow-y-auto px-2.5 py-2"> | ||||||
| <div className="font-medium text-foreground wrap-break-word"> | ||||||
| {subject} | ||||||
| </div> | ||||||
| {body && ( | ||||||
| <div className="mt-1.5 cursor-text select-text whitespace-pre-wrap font-normal leading-relaxed wrap-break-word"> | ||||||
|
Contributor
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Remove text-selection styling from the hover tooltip.
Based on learnings, do not use Proposed fix- <div className="mt-1.5 cursor-text select-text whitespace-pre-wrap font-normal leading-relaxed wrap-break-word">
+ <div className="mt-1.5 whitespace-pre-wrap font-normal leading-relaxed wrap-break-word">📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsSource: Learnings |
||||||
| {body} | ||||||
| </div> | ||||||
| )} | ||||||
| </div> | ||||||
| <div className="truncate text-xs text-muted-foreground"> | ||||||
| <div className="border-border border-t px-2.5 py-1.5 font-normal text-[11px] text-muted-foreground/70"> | ||||||
| {commit.shortHash} · {commit.author} · {timeAgo(commit.date)} | ||||||
| </div> | ||||||
| </div> | ||||||
| {isSelected && <Check className="mt-0.5 size-3.5 shrink-0" />} | ||||||
| </div> | ||||||
| </TooltipContent> | ||||||
| </Tooltip> | ||||||
| ); | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { isValidCommitHash, splitCommitMessage } from "./commit-message"; | ||
|
|
||
| describe("splitCommitMessage", () => { | ||
| test("subject-only message has an empty body", () => { | ||
| expect(splitCommitMessage("fix(ui): tighten chip spacing\n")).toEqual({ | ||
| subject: "fix(ui): tighten chip spacing", | ||
| body: "", | ||
| }); | ||
| }); | ||
|
|
||
| test("splits subject from body at the first blank line", () => { | ||
| const raw = | ||
| "feat(landing): peraga cara kerja\n\nContoh Adem diganti marjan.\n"; | ||
|
|
||
| expect(splitCommitMessage(raw)).toEqual({ | ||
| subject: "feat(landing): peraga cara kerja", | ||
| body: "Contoh Adem diganti marjan.", | ||
| }); | ||
| }); | ||
|
|
||
| test("preserves blank lines and indentation inside the body", () => { | ||
| const raw = ["subject", "", "para one", "", " - indented bullet", ""].join( | ||
| "\n", | ||
| ); | ||
|
|
||
| expect(splitCommitMessage(raw).body).toBe( | ||
| "para one\n\n - indented bullet", | ||
| ); | ||
| }); | ||
|
|
||
| test("keeps trailers, which is where Co-Authored-By lives", () => { | ||
| const raw = | ||
| "subject\n\nwhy this change\n\nCo-Authored-By: Someone <someone@example.com>\n"; | ||
|
|
||
| expect(splitCommitMessage(raw).body).toContain( | ||
| "Co-Authored-By: Someone <someone@example.com>", | ||
| ); | ||
| }); | ||
|
|
||
| test("folds a wrapped subject onto one line, matching %s", () => { | ||
| const raw = "a subject that git\nwrapped across lines\n\nbody\n"; | ||
|
|
||
| expect(splitCommitMessage(raw).subject).toBe( | ||
| "a subject that git wrapped across lines", | ||
| ); | ||
| }); | ||
|
|
||
| test("only the first blank line splits — later ones stay in the body", () => { | ||
| const raw = "subject\n\nfirst\n\nsecond\n"; | ||
|
|
||
| expect(splitCommitMessage(raw)).toEqual({ | ||
| subject: "subject", | ||
| body: "first\n\nsecond", | ||
| }); | ||
| }); | ||
|
|
||
| test("handles CRLF line endings", () => { | ||
| expect(splitCommitMessage("subject\r\n\r\nbody line\r\n")).toEqual({ | ||
| subject: "subject", | ||
| body: "body line", | ||
| }); | ||
| }); | ||
|
|
||
| test("empty input yields empty subject and body", () => { | ||
| expect(splitCommitMessage("")).toEqual({ subject: "", body: "" }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("isValidCommitHash", () => { | ||
| test("accepts short, full, and uppercase hex object names", () => { | ||
| expect(isValidCommitHash("48aa309")).toBe(true); | ||
| expect(isValidCommitHash("b7bc64f4e2c1a09d3f5e8a7b6c4d2e1f0a9b8c7d")).toBe( | ||
| true, | ||
| ); | ||
| expect(isValidCommitHash("48AA309")).toBe(true); | ||
| }); | ||
|
|
||
| test("rejects flags and revision expressions", () => { | ||
| expect(isValidCommitHash("--output=/tmp/pwned")).toBe(false); | ||
| expect(isValidCommitHash("HEAD~1")).toBe(false); | ||
| expect(isValidCommitHash("HEAD; rm -rf /")).toBe(false); | ||
| expect(isValidCommitHash("feat/sveltekit-studio-db")).toBe(false); | ||
| }); | ||
|
|
||
| test("rejects input that is too short or not hex", () => { | ||
| expect(isValidCommitHash("48aa3")).toBe(false); | ||
| expect(isValidCommitHash("")).toBe(false); | ||
| expect(isValidCommitHash("zzzzzzz")).toBe(false); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /** Full commit message, split the way git itself presents it. */ | ||
| export interface CommitMessage { | ||
| /** First paragraph, folded to one line — matches `git log --format=%s`. */ | ||
| subject: string; | ||
| /** Everything after the first blank line, verbatim. Empty when absent. */ | ||
| body: string; | ||
| } | ||
|
|
||
| /** | ||
| * `git log --format=%s` collapses a multi-line first paragraph into a single | ||
| * line, so folding here keeps a popover header identical to the list row that | ||
| * opened it. Everything after the first blank line is the body and is left | ||
| * untouched — blank lines and indentation are meaningful in trailers and | ||
| * bullet lists. | ||
| */ | ||
| export function splitCommitMessage(raw: string): CommitMessage { | ||
| const normalized = raw.replace(/\r\n/g, "\n").replace(/^\n+/, ""); | ||
| const separator = normalized.indexOf("\n\n"); | ||
|
|
||
| if (separator === -1) { | ||
| return { subject: foldSubject(normalized), body: "" }; | ||
| } | ||
|
|
||
| return { | ||
| subject: foldSubject(normalized.slice(0, separator)), | ||
| body: normalized.slice(separator + 2).replace(/\s+$/, ""), | ||
| }; | ||
| } | ||
|
|
||
| function foldSubject(paragraph: string): string { | ||
| return paragraph.replace(/\s*\n\s*/g, " ").trim(); | ||
| } | ||
|
|
||
| /** | ||
| * Restricts a ref to a hex object name before it reaches `git log`. Without | ||
| * this a caller could pass a flag (`--output=…`) or a revision expression | ||
| * (`HEAD~1`, a branch name) and read something other than the commit the UI | ||
| * is showing. | ||
| */ | ||
| export function isValidCommitHash(hash: string): boolean { | ||
| return /^[0-9a-fA-F]{7,64}$/.test(hash); | ||
| } |
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.
P2: When the on-demand getCommitMessage fetch fails, the tooltip silently falls back to the commit subject and an empty body (
subject = message.data?.subject ?? commit.message,body = message.data?.body ?? ""), so a failed read is indistinguishable from a commit that genuinely has no body. Since surfacing the full message is the entire point of this hover interaction, a user who sees the tooltip after a load failure will reasonably conclude the commit has no body. Consider surfacing the failure — e.g. an error note and/or a retry — whenmessage.isErroris set, while still keeping the subject as the graceful fallback for the brief loading window.Prompt for AI agents