Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 1afb73136a feat(welcome): show project groups in the title bar's recent projects
The title bar project popup listed recent projects flat even when the
Welcome screen sorted them into groups, so similarly named projects were
easy to mix up. Its Recent Projects section now lists each group's name
above its projects (whether the group is collapsed on the Welcome screen
or not), then the ungrouped projects after a separator; a search stays a
flat list of matches.
2026-11-19 18:22:42 +08:00
3 змінених файлів з 77 додано та 8 видалено

No files matched your search

+10
Переглянути файл
@@ -68,6 +68,16 @@
font-size: var(--fs-small);
font-weight: 600;
}
.groupHeader {
display: flex;
align-items: center;
gap: var(--space-1-5);
padding: 6px 16px 2px;
color: var(--fg);
font-weight: 600;
white-space: nowrap;
--icon-color: var(--fg-muted);
}
.badge {
align-self: flex-start;
margin-top: 1px;
+33 -2
Переглянути файл
@@ -1,12 +1,13 @@
import { describe, expect, it, vi } from "vitest";
import { createRef } from "react";
import { render, screen, within } from "@testing-library/react";
import type { OpenProject, RecentProject } from "@/platform/ipc";
import type { OpenProject, RecentProject, RecentProjectGroup } from "@/platform/ipc";
import { remoteLocation } from "@/platform/remote";
const wsl = { kind: "wsl", distro: "Ubuntu-24.04" } as const;
let open: OpenProject[] = [];
let recent: RecentProject[] = [];
let groups: RecentProjectGroup[] = [];
vi.mock("@/platform/ipc", async (importOriginal) => {
const real = await importOriginal<typeof import("@/platform/ipc")>();
@@ -16,7 +17,7 @@ vi.mock("@/platform/ipc", async (importOriginal) => {
commands: {
...real.commands,
recentProjects: async () => recent,
recentProjectGroups: async () => [],
recentProjectGroups: async () => groups,
windowOpenProjects: async () => ({ status: "ok", data: open }),
},
};
@@ -56,4 +57,34 @@ describe("ProjectPopup", () => {
expect(text.indexOf("Recent Projects")).toBeLessThan(text.indexOf("other"));
expect(within(list).getAllByText("FastAPIProject")).toHaveLength(1);
});
it("lists recent projects under the Welcome screen's groups, collapsed or not, then the ungrouped ones", async () => {
open = [{ name: "current", root: "/w/current", current: true, remote: null }];
const project = (name: string, at: number): RecentProject => ({
path: `/w/${name}`,
name,
openedAtMs: at,
branch: null,
});
recent = [project("current", 9), project("example-web", 5), project("loose", 4), project("example-api", 3)];
groups = [
{ name: "Frontend", paths: ["/w/example-web"], expanded: true },
{ name: "Backend", paths: ["/w/example-api", "/w/current"], expanded: false },
];
const anchor = createRef<HTMLButtonElement>();
render(
<>
<button ref={anchor} />
<ProjectPopup anchor={anchor} onClose={() => {}} />
</>,
);
await screen.findByText("Frontend");
const text = screen.getByRole("listbox").textContent ?? "";
const order = ["Recent Projects", "Frontend", "example-web", "Backend", "example-api", "loose"];
expect(order.map((t) => text.indexOf(t))).toEqual([...order.map((t) => text.indexOf(t))].sort((a, b) => a - b));
expect(order.every((t) => text.includes(t))).toBe(true);
// The open project stays under Open Projects only.
expect(within(screen.getByRole("listbox")).getAllByText("current")).toHaveLength(1);
expect(screen.getAllByRole("option").map((o) => o.textContent)).not.toContain("Frontend");
});
});
+34 -6
Переглянути файл
@@ -5,14 +5,14 @@ import { call, commands, isTauri, type OpenProject, type RecentProject } from "@
import { HighlightedText, Icon, Popup, showContextMenu, type IconName, T } from "@/ui";
import type { ProjectPopupProps } from "@/workbench/contributions";
import { askRemoveRecent, ProjectBadge, recentMenu, unavailableTitle } from "./RecentList";
import { filterRecent, loadRecent, openRecent, useRecent, type RecentMatch } from "./recent";
import { filterRecent, loadRecent, openRecent, recentRows, useRecent, type RecentMatch } from "./recent";
import styles from "./ProjectPopup.module.css";
import { tx } from "@/platform/i18n";
import { parseRemoteLocation, remoteLocation } from "@/platform/remote";
type Entry =
| { kind: "action"; id: string; label: string; icon: IconName }
| { kind: "project"; open: boolean; m: RecentMatch };
| { kind: "project"; open: boolean; m: RecentMatch; group?: string | null };
const ACTIONS: { id: string; label: string; icon: IconName }[] = [
{ id: "file.newProject", label: "New Project…", icon: "plus" },
@@ -36,10 +36,14 @@ function useOpenProjects(): OpenProject[] {
return open;
}
/** The title bar project widget's popup, after IDEA's ProjectWidget: actions, open projects, recent projects; type to filter. */
/**
* The title bar project widget's popup, after IDEA's ProjectWidget: actions, open projects, recent
* projects (under the Welcome screen's project groups, then the ungrouped ones); type to filter.
*/
export function ProjectPopup({ anchor, onClose }: ProjectPopupProps) {
const actions = useActions((s) => s.actions);
const recent = useRecent((s) => s.projects);
const groups = useRecent((s) => s.groups);
const home = useRecent((s) => s.home);
const openProjects = useOpenProjects();
const [query, setQuery] = useState("");
@@ -60,14 +64,17 @@ export function ProjectPopup({ anchor, onClose }: ProjectPopupProps) {
open: true,
m,
}));
const rest = filterRecent(
// Every group lists its projects here, collapsed on the Welcome screen or not; a search is flat.
const expanded = groups.map((g) => ({ ...g, expanded: true }));
const rest = recentRows(
recent.filter((r) => !openPaths.has(r.path)),
expanded,
query,
home,
).map((m) => ({ kind: "project" as const, open: false, m }));
).flatMap((r) => (r.kind === "project" ? [{ kind: "project" as const, open: false, m: r.m, group: r.group }] : []));
const acts = query ? [] : ACTIONS.filter((a) => actions.has(a.id)).map((a) => ({ kind: "action" as const, ...a }));
return [...acts, ...open, ...rest];
}, [actions, recent, home, openProjects, query]);
}, [actions, recent, groups, home, openProjects, query]);
const current = Math.min(active, entries.length - 1);
useEffect(() => {
@@ -150,6 +157,7 @@ export function ProjectPopup({ anchor, onClose }: ProjectPopupProps) {
<T>Recent Projects</T>
</Header>
)}
{e.kind === "project" && !e.open && <GroupBoundary entry={e} previous={entries[i - 1]} />}
<div
role="option"
aria-selected={i === current}
@@ -194,6 +202,26 @@ function Header({ first, children }: { first: boolean; children: ReactNode }) {
);
}
/** A project group's name above its first project; a separator where the ungrouped projects start. */
function GroupBoundary({
entry,
previous,
}: {
entry: Extract<Entry, { kind: "project" }>;
previous: Entry | undefined;
}) {
const before = previous?.kind === "project" && !previous.open ? (previous.group ?? null) : null;
const group = entry.group ?? null;
if (group === before) return null;
if (group === null) return <div className={styles.separator} role="separator" />;
return (
<div className={styles.groupHeader}>
<Icon name="folder" size={14} />
<span className={styles.label}>{group}</span>
</div>
);
}
function ProjectRow({ m, active }: { m: RecentMatch; active: boolean }) {
return (
<>