diff --git a/apps/web/src/components/DiffPanel.tsx b/apps/web/src/components/DiffPanel.tsx index e7e6d614ef77f..f3a45419b1b9a 100644 --- a/apps/web/src/components/DiffPanel.tsx +++ b/apps/web/src/components/DiffPanel.tsx @@ -1,3 +1,4 @@ +import { DiffOptionsMenu } from "./diffs/DiffOptionsMenu"; import { RefreshIcon } from "~/components/ui/refresh-icon"; import { useAtomValue } from "@effect/atom-react"; import type { FileDiffContentsLoader, FileDiffMetadata } from "@pierre/diffs"; @@ -816,11 +817,11 @@ export default function DiffPanel({ const headerRow = ( <> -
+
} - className={cn("max-w-full", headerCommitSha !== null && "min-w-0 shrink")} + className="min-w-0 max-w-full shrink" aria-label={`Diff scope: ${selectedScopeLabel}`} data-workspace-focus-default > @@ -984,7 +985,7 @@ export default function DiffPanel({ {canSelectBranchBase && (
@@ -1024,14 +1025,24 @@ export default function DiffPanel({ selectBranchBaseRef(value === AUTOMATIC_BASE_REF ? null : value); }} > - } - className="min-w-9 max-w-48 shrink-0" - aria-label={`Change comparison target. Currently ${comparisonBaseRef}`} - > - {comparisonBaseRef} - - + + } + className="min-w-16 max-w-48 shrink" + aria-label={`Change comparison target. Currently ${comparisonBaseRef}`} + > + + {comparisonBaseRef.slice(0, -5)} + {comparisonBaseRef.slice(-5)} + + + + } + /> + {`${comparisonHeadRef} → ${comparisonBaseRef}`} +
)} -
-
{codeViewFiles.length > 0 || (isGitSelection && selectedGitSource?.files?.length) ? ( ) : null} +
+
{canRefreshGitDiff && ( )} - {diffFileKeys.length > 0 && ( - - + +
+ {diffFileKeys.length > 0 && ( +
+ + + } + > + + + + {allDiffFilesCollapsed ? "Expand all files" : "Collapse all files"} + + +
+ )} + { + const next = value[0]; + if (next === "stacked" || next === "split") { + updateClientSettings({ diffLayout: next }); } - > - - - - {allDiffFilesCollapsed ? "Expand all files" : "Collapse all files"} - - - )} - { - const next = value[0]; - if (next === "stacked" || next === "split") { - updateClientSettings({ diffLayout: next }); - } - }} - > - - - - - - - - - { - setWordWrap(Boolean(pressed)); - }} - /> - } - > - - - - {wordWrap ? "Disable line wrapping" : "Enable line wrapping"} - - - - { - setDiffIgnoreWhitespace(Boolean(pressed)); - }} - /> - } + }} > - - - - {diffIgnoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"} - - - {testFileCount > 0 && ( - - setHideTestFiles(Boolean(pressed))} - /> - } - > - - - - {hideTestFiles - ? `Show ${testFileCount} hidden test ${testFileCount === 1 ? "file" : "files"}` - : "Hide test files"} - - - )} - {diffFileKeys.length > 0 && ( + + + + + + + setFileTreeOpen(Boolean(pressed))} + pressed={wordWrap} + onPressedChange={(pressed) => { + setWordWrap(Boolean(pressed)); + }} /> } > - + - {fileTreeOpen ? "Hide file tree" : "Show file tree"} + {wordWrap ? "Disable line wrapping" : "Enable line wrapping"} - )} +
+ + { + setDiffIgnoreWhitespace(Boolean(pressed)); + }} + /> + } + > + + + + {diffIgnoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"} + + +
+ {testFileCount > 0 && ( +
+ + setHideTestFiles(Boolean(pressed))} + /> + } + > + + + + {hideTestFiles + ? `Show ${testFileCount} hidden test ${testFileCount === 1 ? "file" : "files"}` + : "Hide test files"} + + +
+ )} + {diffFileKeys.length > 0 && ( + + setFileTreeOpen(Boolean(pressed))} + /> + } + > + + + + {fileTreeOpen ? "Hide file tree" : "Show file tree"} + + + )} +
+ 0 + ? { + collapsed: allDiffFilesCollapsed, + onToggleCollapsed: toggleDiffFileCollapse, + } + : null + } + testFiles={ + testFileCount > 0 + ? { + hidden: hideTestFiles, + onHiddenChange: setHideTestFiles, + } + : null + } + />
); diff --git a/apps/web/src/components/DiffPanelShell.tsx b/apps/web/src/components/DiffPanelShell.tsx index 456f70516b23b..ff87e7c1fd37f 100644 --- a/apps/web/src/components/DiffPanelShell.tsx +++ b/apps/web/src/components/DiffPanelShell.tsx @@ -10,11 +10,11 @@ export type DiffPanelMode = "inline" | "sheet" | "sidebar" | "embedded"; function getDiffPanelHeaderRowClassName(mode: DiffPanelMode) { const shouldUseDragRegion = isElectron && mode !== "sheet" && mode !== "embedded"; return cn( - "flex items-center justify-between gap-2", + "@container/diff-toolbar flex shrink-0 flex-wrap items-center justify-between gap-x-2 gap-y-1 py-1", mode === "embedded" ? "px-2" : "px-4", shouldUseDragRegion - ? "drag-region h-[var(--workspace-topbar-height)] border-b border-border wco:pr-(--workspace-native-controls-inset)" - : "flex h-10 min-h-10 shrink-0 items-center border-b border-border/60 bg-background in-data-[preview-panel-mode=inline]:mb-3 in-data-[preview-panel-mode=inline]:h-7 in-data-[preview-panel-mode=inline]:min-h-7 in-data-[preview-panel-mode=inline]:border-b-transparent", + ? "drag-region min-h-[var(--workspace-topbar-height)] border-b border-border wco:pr-(--workspace-native-controls-inset)" + : "flex min-h-10 shrink-0 items-center border-b border-border/60 bg-background in-data-[preview-panel-mode=inline]:mb-3 in-data-[preview-panel-mode=inline]:min-h-7 in-data-[preview-panel-mode=inline]:border-b-transparent", ); } diff --git a/apps/web/src/components/diffs/DiffOptionsMenu.tsx b/apps/web/src/components/diffs/DiffOptionsMenu.tsx new file mode 100644 index 0000000000000..89638e54b483c --- /dev/null +++ b/apps/web/src/components/diffs/DiffOptionsMenu.tsx @@ -0,0 +1,85 @@ +import { + Settings2Icon, + PilcrowIcon, + ChevronsUpDownIcon, + ChevronsDownUpIcon, + FlaskConicalOffIcon, +} from "lucide-react"; + +import { Button } from "../ui/button"; +import { + Menu, + MenuCheckboxItem, + MenuItem, + MenuPopup, + MenuSeparator, + MenuTrigger, +} from "../ui/menu"; +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; + +export function DiffOptionsMenu({ + ignoreWhitespace, + onIgnoreWhitespaceChange, + files, + testFiles, +}: { + ignoreWhitespace: boolean; + onIgnoreWhitespaceChange: (value: boolean) => void; + files: { + collapsed: boolean; + onToggleCollapsed: () => void; + } | null; + testFiles: { hidden: boolean; onHiddenChange: (value: boolean) => void } | null; +}) { + return ( +
+ + + + } + aria-label="More diff options" + /> + } + > + + + More diff options + + + + + + Hide whitespace changes + + + {files || testFiles ? : null} + {files ? ( + + {files.collapsed ? ( + + ) : ( + + )} + {files.collapsed ? "Expand all files" : "Collapse all files"} + + ) : null} + {testFiles ? ( + + + + Hide test files + + + ) : null} + + +
+ ); +} diff --git a/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx b/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx index cea33e74ffc99..a3cac75cd626e 100644 --- a/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx +++ b/apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx @@ -152,14 +152,14 @@ it("keeps the diff after a refresh that brings back the same page", async () => const container = document.createElement("div"); container.className = "flex h-[700px] w-[900px]"; await using screen = await render(tab(0), { container }); - await expect.element(screen.getByText("1 file", { exact: true })).toBeVisible(); + await expect.element(screen.getByLabelText("1 file", { exact: true })).toBeVisible(); await screen.rerender(tab(1)); await expect .element(screen.getByText("This pull request has no file changes.")) .not.toBeInTheDocument(); - await expect.element(screen.getByText("1 file", { exact: true })).toBeVisible(); + await expect.element(screen.getByLabelText("1 file", { exact: true })).toBeVisible(); }); function pagedContainer() { @@ -229,7 +229,7 @@ it("never requests the diff of a selected commit the pull request no longer has" { container }, ); - await expect.element(screen.getByText("1 file", { exact: true })).toBeVisible(); + await expect.element(screen.getByLabelText("1 file", { exact: true })).toBeVisible(); await expect .element(screen.getByRole("button", { name: "Diff scope: All commits" })) .toBeVisible(); diff --git a/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx b/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx index a456c84bf5320..667c7c1d85b3b 100644 --- a/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx +++ b/apps/web/src/components/pullRequest/PullRequestCodeTab.tsx @@ -16,6 +16,9 @@ import type { PullRequestThreadCommentsResult, } from "@t3tools/contracts"; import { + CheckIcon, + FilesIcon, + GitCommitHorizontalIcon, ChevronDownIcon, ChevronRightIcon, Columns2Icon, @@ -25,7 +28,6 @@ import { MessageSquareOffIcon, PilcrowIcon, Rows3Icon, - Settings2Icon, TextWrapIcon, TriangleAlertIcon, } from "lucide-react"; @@ -81,6 +83,7 @@ import { pullRequestEnvironment } from "~/state/pullRequests"; import { useEnvironmentQuery } from "~/state/query"; import { useAtomCommand } from "~/state/use-atom-command"; +import { DiffOptionsMenu } from "../diffs/DiffOptionsMenu"; import { DiffPanelLoadingState } from "../DiffPanelShell"; import { useDiffWorkerPool } from "../DiffWorkerPoolProvider"; import { DiffCommentAnnotation } from "../diffs/DiffCommentAnnotation"; @@ -96,12 +99,10 @@ import { Checkbox } from "../ui/checkbox"; import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible"; import { DropdownMenu, - DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, - DropdownMenuSeparator, DropdownMenuTrigger, } from "../ui/menu"; import { toastManager } from "../ui/toast"; @@ -1094,18 +1095,29 @@ function PullRequestCodeTab({ setSelectedLines(null); }; const toolbar = ( -
-
+
+
{orderedCommits.length > 0 ? ( - } - className="min-w-0 max-w-64" - aria-label={`Diff scope: ${scopeLabel}`} - > - {scopeLabel} - - + + } + className="min-w-0 max-w-64" + aria-label={`Diff scope: ${scopeLabel}`} + > + + {scopeLabel} + + {selectedCommit ? selectedCommit.oid.slice(0, 7) : "All"} + + + + } + /> + {scopeLabel} + ) : null} - - - {files.length} {files.length === 1 ? "file" : "files"} + + + + {files.length} {nextCursor === null ? "" : "+"} + + {files.length === 1 ? "file" : "files"} + {hiddenTestFileCount > 0 ? ( - ) : null} {filesViewed.enabled && files.length > 0 ? ( - + + {filePaths.filter(isFileViewed).length} / {files.length} - + {viewedFilesStore === "environment" ? `viewed in ${APP_BASE_NAME}` : "viewed"} {viewedFilesStore === "environment" ? ( @@ -1234,74 +1273,30 @@ function PullRequestCodeTab({ ) : null}
-
- - - } - className="@lg:hidden" - aria-label="Diff options" - /> - } - > - - - Diff options - - - changeIgnoreWhitespace(checked)} - > - Hide whitespace changes - - setWordWrap(checked)} - > - Wrap lines - - - { - if (value === "stacked" || value === "split") { - updateClientSettings({ diffLayout: value }); +
+
+
+ + changeIgnoreWhitespace(Boolean(pressed))} + /> } - }} - > - - Stacked - - - Split - - - - -
- - changeIgnoreWhitespace(Boolean(pressed))} - /> - } - > - - - - {ignoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"} - - + > + + + + {ignoreWhitespace ? "Show whitespace changes" : "Hide whitespace changes"} + + +
+ {fileKeys.length > 0 ? ( +
+ + + } + > + + + + {allFilesCollapsed ? "Expand all files" : "Collapse all files"} + + +
+ ) : null} + {testFileCount > 0 ? ( +
+ + setHideTestFiles(Boolean(pressed))} + /> + } + > + + + + {hideTestFiles ? "Show test files" : "Hide test files"} + + +
+ ) : null} + {fileKeys.length > 0 ? ( + + setFileTreeOpen(Boolean(pressed))} + /> + } + > + + + + {fileTreeOpen ? "Hide file tree" : "Show file tree"} + + + ) : null}
- {fileKeys.length > 0 ? ( - - - } - > - - - - {allFilesCollapsed ? "Expand all files" : "Collapse all files"} - - - ) : null} - {testFileCount > 0 ? ( - - setHideTestFiles(Boolean(pressed))} - /> - } - > - - - - {hideTestFiles ? "Show test files" : "Hide test files"} - - - ) : null} - {fileKeys.length > 0 ? ( - - setFileTreeOpen(Boolean(pressed))} - /> - } - > - - - - {fileTreeOpen ? "Hide file tree" : "Show file tree"} - - - ) : null} + 0 + ? { + collapsed: allFilesCollapsed, + onToggleCollapsed: toggleAllFiles, + } + : null + } + testFiles={ + testFileCount > 0 + ? { + hidden: hideTestFiles, + onHiddenChange: setHideTestFiles, + } + : null + } + />
); @@ -1584,7 +1603,7 @@ function PullRequestCodeTab({ resizeLabel="Resize PR Code files" >