fix(vcs): put Select… and me first in the Git Log User filter (#7272)

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
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-02 00:25:00 +08:00
1 джерело 6927b787b2
коміт aa596f1125
2 files changed
+93 -15

No files matched your search

+76
Переглянути файл
@@ -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")} <a${i}@example.com>`);
vi.mock("@/platform/ipc", async (importOriginal) => {
const real = await importOriginal<typeof import("@/platform/ipc")>();
const ok = <T,>(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(
<>
<FilterBar />
<ContextMenuHost />
</>,
);
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 <[email protected]>", "Author 07 <[email protected]>"]]),
);
const items = openUserMenu();
expect(items.slice(0, 4)).toEqual([
"Select…",
"me",
"Author 03 <[email protected]>, Author 07 <[email protected]>",
"Author 00 <[email protected]>",
]);
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 <[email protected]>"]);
expect(screen.queryByText("Recent")).toBeNull();
});
it("sets the filter to a single author on click", () => {
openUserMenu();
fireEvent.click(screen.getByRole("menuitem", { name: "Author 05 <[email protected]>" }));
expect(useGitLog.getState().filters.authors).toEqual(["Author 05 <[email protected]>"]);
});
});
+17 -15
Переглянути файл
@@ -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] }),
})),
]);
};