From aa596f112524fb543ef2470809505d95fd1ec9f7 Mon Sep 17 00:00:00 2001 From: l0ng-ai Date: Wed, 2 Dec 2026 00:25:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(vcs):=20put=20Select=E2=80=A6=20and=20me=20?= =?UTF-8?q?first=20in=20the=20Git=20Log=20User=20filter=20(#7272)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With many authors the Git Log User menu was taller than the window, and Select..., the only way to filter by several users, came last and out of view. The menu now starts with Select... and me, then the recent filters under a Recent header (several users apply in one click), then up to 30 known authors. A click on an author still sets the filter to that author alone. Fixes #7254 --- .../vcs/__tests__/logUserFilter.test.tsx | 76 +++++++++++++++++++ src/features/vcs/log/FilterBar.tsx | 32 ++++---- 2 files changed, 93 insertions(+), 15 deletions(-) create mode 100644 src/features/vcs/__tests__/logUserFilter.test.tsx diff --git a/src/features/vcs/__tests__/logUserFilter.test.tsx b/src/features/vcs/__tests__/logUserFilter.test.tsx new file mode 100644 index 0000000000..c8d617f00b --- /dev/null +++ b/src/features/vcs/__tests__/logUserFilter.test.tsx @@ -0,0 +1,76 @@ +import { fireEvent, render, screen, within } from "@testing-library/react"; +import { beforeEach, describe, expect, it, vi } from "vitest"; + +const authors = Array.from({ length: 40 }, (_, i) => `Author ${String(i).padStart(2, "0")} `); + +vi.mock("@/platform/ipc", async (importOriginal) => { + const real = await importOriginal(); + const ok = (data: T) => Promise.resolve({ status: "ok" as const, data }); + return { + ...real, + commands: { + ...real.commands, + vcsBranches: () => ok([]), + vcsTags: () => ok([]), + vcsLog: () => ok({ commits: [], hasMore: false }), + vcsConfigGet: () => ok(null), + vcsLogUsers: () => ok(authors), + }, + }; +}); + +import { ContextMenuHost } from "@/ui"; +import { FilterBar } from "../log/FilterBar"; +import { fetchLogUsers } from "../log/logUsers"; +import { emptyFilters, useGitLog } from "../logStore"; +import { useVcs } from "../store"; + +describe("Git Log User filter menu (#7254)", () => { + beforeEach(async () => { + localStorage.clear(); + useVcs.setState({ root: "/p", repo: "/p", roots: ["/p"] }); + useGitLog.setState({ filters: emptyFilters() }); + await fetchLogUsers("/p"); + }); + + const openUserMenu = () => { + render( + <> + + + , + ); + fireEvent.click(screen.getByRole("button", { name: /^User/ })); + const menu = screen.getByRole("menu"); + return within(menu) + .getAllByRole("menuitem") + .map((item) => item.textContent?.trim()); + }; + + it("puts Select… and me first, then the recent filters, then the authors", () => { + localStorage.setItem( + "openidea.vcs.logRecent.v1:/p:authors", + JSON.stringify([["Author 03 ", "Author 07 "]]), + ); + const items = openUserMenu(); + expect(items.slice(0, 4)).toEqual([ + "Select…", + "me", + "Author 03 , Author 07 ", + "Author 00 ", + ]); + expect(screen.getByText("Recent")).toBeInTheDocument(); + }); + + it("has no Recent header without recent filters", () => { + const items = openUserMenu(); + expect(items.slice(0, 3)).toEqual(["Select…", "me", "Author 00 "]); + expect(screen.queryByText("Recent")).toBeNull(); + }); + + it("sets the filter to a single author on click", () => { + openUserMenu(); + fireEvent.click(screen.getByRole("menuitem", { name: "Author 05 " })); + expect(useGitLog.getState().filters.authors).toEqual(["Author 05 "]); + }); +}); diff --git a/src/features/vcs/log/FilterBar.tsx b/src/features/vcs/log/FilterBar.tsx index a17b369d09..3e89af6f66 100644 --- a/src/features/vcs/log/FilterBar.tsx +++ b/src/features/vcs/log/FilterBar.tsx @@ -214,22 +214,14 @@ export function FilterBar({ fileHistory = false }: { fileHistory?: boolean }) { a.localeCompare(b), ); const authors = authorsOf(roots.map((repo) => knownLogUsers(repo))); + const recent: MenuItem[] = recentFilterValues("authors").map((authors) => ({ + verbatim: true, + label: authors.join(", "), + run: () => setLogFilters({ authors }), + })); + // IDEA's order: Select… and me first, so both stay in view however many authors follow, + // then the recent filters (several users apply in one click). menuBelow(anchor, [ - ...recentFilterValues("authors").map((authors) => ({ - verbatim: true, - label: authors.join(", "), - run: () => setLogFilters({ authors }), - })), - // A click sets the filter to that user alone, as IDEA does (several users go through Select…), so the - // rows carry no check marks that would read as a multi-select. - { label: ME, run: () => setLogFilters({ authors: [ME] }) }, - ...(authors.length ? [{ kind: "separator" as const }] : []), - ...authors.slice(0, 30).map((a) => ({ - verbatim: true, - label: a, - run: () => setLogFilters({ authors: [a] }), - })), - { kind: "separator" }, { label: "Select…", run: async () => { @@ -242,6 +234,16 @@ export function FilterBar({ fileHistory = false }: { fileHistory?: boolean }) { if (r) setLogFilters({ authors: r }); }, }, + // A click sets the filter to that user alone, as IDEA does (several users go through Select…), so the + // rows carry no check marks that would read as a multi-select. + { label: ME, run: () => setLogFilters({ authors: [ME] }) }, + ...(recent.length ? [{ kind: "header" as const, label: "Recent" }, ...recent] : []), + ...(authors.length ? [{ kind: "separator" as const }] : []), + ...authors.slice(0, 30).map((a) => ({ + verbatim: true, + label: a, + run: () => setLogFilters({ authors: [a] }), + })), ]); };