refactor(desktop): extract the latest repository commit row

Keep ProjectRepositoryPanel below the 1,000-line ceiling after the latest
main changes by moving the interactive latest-commit row shell into a
focused component. Click and Enter/Space behavior remain unchanged.

Signed-off-by: Thomas Petersen <thomasp@squareup.com>
This commit is contained in:
Thomas Petersen
2026-08-19 19:28:05 -04:00
parent 4cac268f4f
commit e9bd8cdc14
2 changed files with 46 additions and 24 deletions

View File

@@ -0,0 +1,41 @@
import type * as React from "react";
import { cn } from "@/shared/lib/cn";
/** Interactive table-header row that opens the repository's latest commit. */
export function ProjectRepositoryLatestCommitRow({
children,
commitShortHash,
onOpen,
}: {
children: React.ReactNode;
commitShortHash?: string;
onOpen?: () => void;
}) {
return (
<tr
aria-label={
commitShortHash ? `Open commit ${commitShortHash}` : undefined
}
className={cn(
"bg-muted/20",
onOpen &&
"cursor-pointer transition-colors hover:bg-muted/35 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
)}
data-testid="project-repository-latest-commit"
onClick={onOpen}
onKeyDown={
onOpen
? (event) => {
if (event.key !== "Enter" && event.key !== " ") return;
event.preventDefault();
onOpen();
}
: undefined
}
tabIndex={onOpen ? 0 : undefined}
>
{children}
</tr>
);
}

View File

@@ -46,6 +46,7 @@ import {
PROJECT_DETAIL_PANEL_CLASS,
PROJECT_DETAIL_PANEL_MESSAGE_CLASS,
} from "./projectPanelStyles";
import { ProjectRepositoryLatestCommitRow } from "./ProjectRepositoryLatestCommitRow";
import {
type RepoSourceHeaderControls,
RepoSourceDropdown,
@@ -854,33 +855,13 @@ export function RepositoryFilesPanel({
<div className="overflow-x-auto px-2 pb-2">
<table className="w-full border-collapse caption-bottom text-sm">
<thead>
<tr
aria-label={
latestCommit
? `Open commit ${latestCommit.shortHash}`
: undefined
}
className={cn(
"bg-muted/20",
latestCommit &&
onOpenCommit &&
"cursor-pointer transition-colors hover:bg-muted/35 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
)}
data-testid="project-repository-latest-commit"
onClick={
<ProjectRepositoryLatestCommitRow
commitShortHash={latestCommit?.shortHash}
onOpen={
latestCommit && onOpenCommit
? () => onOpenCommit(latestCommit.hash)
: undefined
}
onKeyDown={
latestCommit && onOpenCommit
? (event) =>
handleRepositoryEntryKeyDown(event, () =>
onOpenCommit(latestCommit.hash),
)
: undefined
}
tabIndex={latestCommit && onOpenCommit ? 0 : undefined}
>
<th className="px-4 py-3 text-left font-normal" colSpan={3}>
{latestCommit ? (
@@ -933,7 +914,7 @@ export function RepositoryFilesPanel({
</p>
)}
</th>
</tr>
</ProjectRepositoryLatestCommitRow>
</thead>
<tbody>
{visibleEntries.map((entry) => {