дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-03 16:51:16 +02:00
fix(welcome): flatten recent project lists across hosts (#7504)
Цей коміт міститься в:
1 джерело
9abe3d7e3c
коміт
ce938df81b
8 files changed
+87
-382
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { expect, stubDesktop, test } from "./fixtures";
|
||||
|
||||
test("keeps the project switcher flat while grouping Welcome and Recent Projects without row overlap", async ({
|
||||
test("keeps local and remote projects flat in all recent-project lists without row overlap", async ({
|
||||
workbench: page,
|
||||
}) => {
|
||||
await page.setViewportSize({ width: 980, height: 740 });
|
||||
@@ -111,7 +111,7 @@ test("keeps the project switcher flat while grouping Welcome and Recent Projects
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(projectPopup).toBeHidden();
|
||||
|
||||
// 2. Recent Projects popup groups by host and never overlaps rows (grouped or 3-line search results).
|
||||
// 2. Recent Projects popup is flat and never overlaps rows, including search results.
|
||||
await page.evaluate(async () => {
|
||||
const popupMod = "/src/features/welcome/RecentProjectsPopup.tsx";
|
||||
const { showRecentProjectsPopup } = await import(/* @vite-ignore */ popupMod);
|
||||
@@ -128,20 +128,28 @@ test("keeps the project switcher flat while grouping Welcome and Recent Projects
|
||||
expect(boxes[i]!.y).toBeGreaterThanOrEqual(boxes[i - 1]!.y + boxes[i - 1]!.height - 0.5);
|
||||
}
|
||||
};
|
||||
await expect(recentDialog.getByRole("option")).toHaveCount(6);
|
||||
await expect(recentDialog.locator("[aria-expanded]")).toHaveCount(0);
|
||||
await expect(recentDialog.locator("[data-remote-badge]")).toHaveCount(4);
|
||||
await assertNoVerticalOverlap();
|
||||
await recentDialog.getByRole("textbox", { name: "Search recent projects" }).fill("openidea_all");
|
||||
await assertNoVerticalOverlap();
|
||||
await page.keyboard.press("Escape");
|
||||
await expect(recentDialog).toBeHidden();
|
||||
|
||||
// 3. Welcome › Projects folds and unfolds host groups.
|
||||
// 3. Welcome › Projects keeps all projects in recency order without host headers.
|
||||
await page.evaluate(async () => {
|
||||
const projectMod = "/src/platform/project.ts";
|
||||
const { useProject } = await import(/* @vite-ignore */ projectMod);
|
||||
useProject.setState({ project: null, lightEdit: false });
|
||||
});
|
||||
const welcomeList = page.getByRole("listbox", { name: "Recent projects" });
|
||||
await expect(welcomeList.getByRole("option")).toHaveCount(11);
|
||||
await welcomeList.getByRole("option").first().click();
|
||||
await expect(welcomeList.getByRole("option")).toHaveCount(9);
|
||||
const welcomeRows = welcomeList.getByRole("option");
|
||||
await expect(welcomeRows).toHaveCount(7);
|
||||
await expect(welcomeList.locator("[aria-expanded]")).toHaveCount(0);
|
||||
await expect(welcomeList.locator("[data-remote-badge]")).toHaveCount(4);
|
||||
await expect(welcomeRows.nth(0)).toContainText("[email protected]:22:/home/coder/git/openidea_all");
|
||||
await expect(welcomeRows.nth(1)).toContainText("dev-mbp1.local:/Users/dev/git/gocommon");
|
||||
await expect(welcomeRows.nth(2)).toContainText("~/git/gocommon");
|
||||
await expect(welcomeRows.nth(3)).toContainText("[email protected]:22:/home/coder/git/gocommon");
|
||||
});
|
||||
@@ -42,3 +42,34 @@ test("Welcome keeps project search and actions on one row at a narrow width", as
|
||||
await expect(more).toBeFocused();
|
||||
await expect(search).toHaveValue("tokio");
|
||||
});
|
||||
|
||||
test("Welcome lists local and remote projects at the same level", async ({ workbench: page }) => {
|
||||
await page.evaluate(async () => {
|
||||
const projectPath = "/src/platform/project.ts";
|
||||
const { useProject } = await import(/* @vite-ignore */ projectPath);
|
||||
useProject.setState({ project: null, lightEdit: false });
|
||||
});
|
||||
const list = page.getByRole("listbox", { name: "Recent projects" });
|
||||
const rows = list.getByRole("option");
|
||||
await expect(rows).toHaveCount(4);
|
||||
await page.evaluate(async () => {
|
||||
const recentPath = "/src/features/welcome/recent.ts";
|
||||
const { useRecent } = await import(/* @vite-ignore */ recentPath);
|
||||
useRecent.setState({
|
||||
groups: [],
|
||||
projects: [
|
||||
{ name: "tty7", path: "ssh://macmini/Users/thomas/repo/tty7", branch: null, openedAtMs: 100 },
|
||||
{ name: "OpenIDEA", path: "/Users/dev/dev/openidea", branch: null, openedAtMs: 90 },
|
||||
{ name: "tty7", path: "/Users/dev/dev/tty7", branch: null, openedAtMs: 80 },
|
||||
],
|
||||
});
|
||||
});
|
||||
await expect(rows).toHaveCount(3);
|
||||
await expect(rows.nth(0)).toContainText("macmini:/Users/thomas/repo/tty7");
|
||||
await expect(rows.nth(1)).toContainText("OpenIDEA");
|
||||
await expect(rows.nth(2)).toContainText("~/dev/tty7");
|
||||
await expect(list.locator("[aria-expanded]")).toHaveCount(0);
|
||||
await expect(list.locator("[data-remote-badge]")).toHaveCount(1);
|
||||
const avatars = await rows.evaluateAll((els) => els.map((el) => el.firstElementChild!.getBoundingClientRect().x));
|
||||
expect(avatars).toEqual([avatars[0], avatars[0], avatars[0]]);
|
||||
});
|
||||
@@ -21,26 +21,8 @@ import {
|
||||
showContextMenu,
|
||||
T,
|
||||
} from "@/ui";
|
||||
import {
|
||||
askRemoveRecent,
|
||||
groupMenu,
|
||||
HostGroupTitle,
|
||||
ProjectBadge,
|
||||
recentMenu,
|
||||
RemoteHostPill,
|
||||
splitRemoteMatch,
|
||||
unavailableTitle,
|
||||
} from "./RecentList";
|
||||
import {
|
||||
openRecent,
|
||||
recentRows,
|
||||
setGroupExpanded,
|
||||
setHostGroupExpanded,
|
||||
useRecent,
|
||||
type HostGroup,
|
||||
type RecentMatch,
|
||||
type RecentRow,
|
||||
} from "./recent";
|
||||
import { askRemoveRecent, groupMenu, ProjectBadge, recentMenu, unavailableTitle } from "./RecentList";
|
||||
import { openRecent, recentRows, setGroupExpanded, useRecent, type RecentMatch, type RecentRow } from "./recent";
|
||||
import { projectWindowOverride } from "@/workbench/projectWindow";
|
||||
import type { RecentProjectGroup } from "@/platform/ipc";
|
||||
import styles from "./Welcome.module.css";
|
||||
@@ -265,51 +247,11 @@ function GroupRow({
|
||||
);
|
||||
}
|
||||
|
||||
/** A host group (`Local` or a remote target): click or Enter folds its projects. */
|
||||
function HostGroupRow({
|
||||
host,
|
||||
count,
|
||||
id,
|
||||
selected,
|
||||
onSelect,
|
||||
}: {
|
||||
host: HostGroup;
|
||||
count: number;
|
||||
id: string;
|
||||
selected: boolean;
|
||||
onSelect: () => void;
|
||||
}) {
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (selected) ref.current?.scrollIntoView?.({ block: "nearest" });
|
||||
}, [selected]);
|
||||
return (
|
||||
<div
|
||||
ref={ref}
|
||||
id={id}
|
||||
role="option"
|
||||
aria-selected={selected}
|
||||
aria-expanded={host.expanded}
|
||||
className={clsx(styles.project, styles.group, selected && styles.projectSelected)}
|
||||
onMouseDown={(e) => e.preventDefault()}
|
||||
onClick={() => {
|
||||
onSelect();
|
||||
setHostGroupExpanded(host.id, !host.expanded);
|
||||
}}
|
||||
>
|
||||
<Icon name={host.expanded ? "chevron-down" : "chevron-right"} size={16} />
|
||||
<HostGroupTitle host={host} iconSize={16} />
|
||||
<span className={styles.groupCount}>{count}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ProjectRow({
|
||||
m,
|
||||
id,
|
||||
selected,
|
||||
nested,
|
||||
hideHost,
|
||||
onSelect,
|
||||
onOpen,
|
||||
}: {
|
||||
@@ -318,8 +260,6 @@ function ProjectRow({
|
||||
selected: boolean;
|
||||
/** Listed under a group. */
|
||||
nested?: boolean;
|
||||
/** Listed under a host group header that already names the remote host. */
|
||||
hideHost?: boolean;
|
||||
onSelect: () => void;
|
||||
/** Its modifier keys pick the window ({@link projectWindowOverride}). */
|
||||
onOpen: (e: MouseEvent<HTMLDivElement>) => void;
|
||||
@@ -330,7 +270,6 @@ function ProjectRow({
|
||||
const stage = progress
|
||||
? tx(stageLabel(progress.stage)) + (progress.fraction == null ? "" : ` ${Math.round(progress.fraction * 100)}%`)
|
||||
: null;
|
||||
const { hostMatch, locationMatch, locationText } = splitRemoteMatch(m);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
useEffect(() => {
|
||||
if (selected) ref.current?.scrollIntoView?.({ block: "nearest" });
|
||||
@@ -372,10 +311,7 @@ function ProjectRow({
|
||||
{stage}
|
||||
</span>
|
||||
) : (
|
||||
<>
|
||||
{!hideHost && m.remote && <RemoteHostPill remote={m.remote} hostMatch={hostMatch} />}
|
||||
<HighlightedText className={styles.projectPath} text={locationText} indices={locationMatch} />
|
||||
</>
|
||||
<HighlightedText className={styles.projectPath} text={m.displayPath} indices={m.pathMatch} />
|
||||
)}
|
||||
{m.project.branch && (
|
||||
<span className={styles.projectBranch}>
|
||||
@@ -423,17 +359,13 @@ export function handleListKey<T>(
|
||||
export function ProjectsPage() {
|
||||
const projects = useRecent((s) => s.projects);
|
||||
const groups = useRecent((s) => s.groups);
|
||||
const collapsedHosts = useRecent((s) => s.collapsedHosts);
|
||||
const loaded = useRecent((s) => s.loaded);
|
||||
const home = useRecent((s) => s.home);
|
||||
const [query, setQuery] = useState("");
|
||||
const [active, setActive] = useState(0);
|
||||
const search = useRef<HTMLInputElement>(null);
|
||||
const baseId = useId();
|
||||
const items = useMemo(
|
||||
() => recentRows(projects, groups, query, home, collapsedHosts),
|
||||
[projects, groups, query, home, collapsedHosts],
|
||||
);
|
||||
const items = useMemo(() => recentRows(projects, groups, query, home), [projects, groups, query, home]);
|
||||
const current = Math.max(0, Math.min(active, items.length - 1));
|
||||
|
||||
if (!loaded) return null;
|
||||
@@ -453,11 +385,6 @@ export function ProjectsPage() {
|
||||
void setGroupExpanded(row.group.name, e.key === "ArrowRight");
|
||||
return;
|
||||
}
|
||||
if (row?.kind === "host") {
|
||||
e.preventDefault();
|
||||
setHostGroupExpanded(row.host.id, e.key === "ArrowRight");
|
||||
return;
|
||||
}
|
||||
}
|
||||
const r = handleListKey(e, { items, current, caretAtEnd });
|
||||
if (!r) {
|
||||
@@ -484,10 +411,6 @@ export function ProjectsPage() {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (match.kind === "host") {
|
||||
if (r.kind === "open") setHostGroupExpanded(match.host.id, !match.host.expanded);
|
||||
return;
|
||||
}
|
||||
if (r.kind === "open") void openRecent(match.m.project, projectWindowOverride(e));
|
||||
else if (r.kind === "remove") void askRemoveRecent(match.m.project);
|
||||
else {
|
||||
@@ -536,23 +459,13 @@ export function ProjectsPage() {
|
||||
selected={i === current}
|
||||
onSelect={() => setActive(i)}
|
||||
/>
|
||||
) : row.kind === "host" ? (
|
||||
<HostGroupRow
|
||||
key={`host:${row.host.id}`}
|
||||
host={row.host}
|
||||
count={row.count}
|
||||
id={optionId(i)}
|
||||
selected={i === current}
|
||||
onSelect={() => setActive(i)}
|
||||
/>
|
||||
) : (
|
||||
<ProjectRow
|
||||
key={row.m.project.path}
|
||||
m={row.m}
|
||||
id={optionId(i)}
|
||||
selected={i === current}
|
||||
nested={row.group !== null || row.hostGroup != null}
|
||||
hideHost={row.hostGroup != null}
|
||||
nested={row.group !== null}
|
||||
onSelect={() => setActive(i)}
|
||||
onOpen={(e) => void openRecent(row.m.project, projectWindowOverride(e))}
|
||||
/>
|
||||
|
||||
@@ -20,7 +20,6 @@ import {
|
||||
IconButton,
|
||||
SearchField,
|
||||
Spinner,
|
||||
T,
|
||||
listNavigate,
|
||||
showContextMenu,
|
||||
type MenuItem,
|
||||
@@ -45,9 +44,7 @@ import {
|
||||
removeRecent,
|
||||
renameGroup,
|
||||
setGroupExpanded,
|
||||
setHostGroupExpanded,
|
||||
useRecent,
|
||||
type HostGroup,
|
||||
type RecentMatch,
|
||||
} from "./recent";
|
||||
import styles from "./Welcome.module.css";
|
||||
@@ -99,64 +96,6 @@ export function ProjectBadge({
|
||||
);
|
||||
}
|
||||
|
||||
/** Splits `pathMatch` of a remote `host:path` display string into host and path highlight indices. */
|
||||
export function splitRemoteMatch(m: Pick<RecentMatch, "remote" | "pathMatch" | "displayPath">) {
|
||||
const { remote, pathMatch } = m;
|
||||
if (!remote) return { hostMatch: null, locationMatch: pathMatch, locationText: m.displayPath };
|
||||
const pathStart = remote.host.length + 1;
|
||||
return {
|
||||
hostMatch: pathMatch ? pathMatch.filter((i) => i < remote.host.length) : null,
|
||||
locationMatch: pathMatch ? pathMatch.filter((i) => i >= pathStart).map((i) => i - pathStart) : null,
|
||||
locationText: remote.path,
|
||||
};
|
||||
}
|
||||
|
||||
/** SSH / WSL / Dev Container host label shown on remote project rows. */
|
||||
export function RemoteHostPill({
|
||||
remote,
|
||||
hostMatch,
|
||||
}: {
|
||||
remote: NonNullable<RecentMatch["remote"]>;
|
||||
hostMatch: number[] | null;
|
||||
}) {
|
||||
return (
|
||||
<span className={styles.remoteHostPill} data-remote-kind={remote.kind}>
|
||||
<Icon name="remote" size={11} />
|
||||
<strong className={styles.remoteKind}>{remote.kindLabel}</strong>
|
||||
<span className={styles.remoteDot} aria-hidden="true">
|
||||
·
|
||||
</span>
|
||||
<HighlightedText className={styles.remoteHostText} text={remote.host} indices={hostMatch} />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
/** Icon and label of a `Local` or remote host group header. */
|
||||
export function HostGroupTitle({ host, iconSize }: { host: HostGroup; iconSize: number }) {
|
||||
if (host.kind === "local") {
|
||||
return (
|
||||
<>
|
||||
<Icon name="folder" size={iconSize} />
|
||||
<span className={styles.hostTitle}>
|
||||
<T>Local</T>
|
||||
</span>
|
||||
</>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<Icon name="remote" size={iconSize} />
|
||||
<span className={styles.hostTitle} data-remote-kind={host.kind}>
|
||||
<span className={styles.hostKind}>{host.kindLabel}</span>
|
||||
<span className={styles.remoteDot} aria-hidden="true">
|
||||
·
|
||||
</span>
|
||||
<span className={styles.hostName}>{host.host}</span>
|
||||
</span>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/** Change Project Icon…: an SVG or PNG for the project, kept in its `.openidea` folder. */
|
||||
async function chooseProjectIcon(root: string) {
|
||||
const file = await openDialog({ filters: [{ name: tx("Image files"), extensions: ["svg", "png"] }] });
|
||||
@@ -314,18 +253,15 @@ function RecentRow({
|
||||
m,
|
||||
active,
|
||||
compact,
|
||||
hideHost,
|
||||
onOpened,
|
||||
}: {
|
||||
m: RecentMatch;
|
||||
active: boolean;
|
||||
compact?: boolean;
|
||||
hideHost?: boolean;
|
||||
onOpened?: () => void;
|
||||
}) {
|
||||
const opening = useRecent((s) => s.opening === m.project.path);
|
||||
const when = relativeTime(m.project.openedAtMs);
|
||||
const { hostMatch, locationMatch, locationText } = splitRemoteMatch(m);
|
||||
return (
|
||||
<div className={styles.recent} title={unavailableTitle(m.project)}>
|
||||
<ProjectBadge name={m.project.name} path={m.project.path} missing={!!m.project.missing} />
|
||||
@@ -344,8 +280,7 @@ function RecentRow({
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
{!hideHost && m.remote && <RemoteHostPill remote={m.remote} hostMatch={hostMatch} />}
|
||||
<HighlightedText className={styles.recentPath} text={locationText} indices={locationMatch} />
|
||||
<HighlightedText className={styles.recentPath} text={m.displayPath} indices={m.pathMatch} />
|
||||
</span>
|
||||
{opening ? (
|
||||
<Spinner size={14} />
|
||||
@@ -387,7 +322,6 @@ export interface RecentListProps {
|
||||
export function RecentList({ exclude, compact, autoFocus, onOpened, className, toolbar }: RecentListProps) {
|
||||
const projects = useRecent((s) => s.projects);
|
||||
const groups = useRecent((s) => s.groups);
|
||||
const collapsedHosts = useRecent((s) => s.collapsedHosts);
|
||||
const home = useRecent((s) => s.home);
|
||||
const [query, setQuery] = useState("");
|
||||
const [active, setActive] = useState(0);
|
||||
@@ -397,10 +331,7 @@ export function RecentList({ exclude, compact, autoFocus, onOpened, className, t
|
||||
() => (exclude ? projects.filter((p) => p.path !== exclude) : projects),
|
||||
[projects, exclude],
|
||||
);
|
||||
const items = useMemo(
|
||||
() => recentRows(visibleProjects, groups, query, home, collapsedHosts),
|
||||
[visibleProjects, groups, query, home, collapsedHosts],
|
||||
);
|
||||
const items = useMemo(() => recentRows(visibleProjects, groups, query, home), [visibleProjects, groups, query, home]);
|
||||
const current = Math.max(0, Math.min(active, items.length - 1));
|
||||
|
||||
useEffect(() => {
|
||||
@@ -421,16 +352,10 @@ export function RecentList({ exclude, compact, autoFocus, onOpened, className, t
|
||||
void setGroupExpanded(row.group.name, e.key === "ArrowRight");
|
||||
return;
|
||||
}
|
||||
if (row?.kind === "host") {
|
||||
e.preventDefault();
|
||||
setHostGroupExpanded(row.host.id, e.key === "ArrowRight");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
if (row?.kind === "group") void setGroupExpanded(row.group.name, !row.group.expanded);
|
||||
else if (row?.kind === "host") setHostGroupExpanded(row.host.id, !row.host.expanded);
|
||||
else if (row?.kind === "project") open(row.m, e);
|
||||
return;
|
||||
}
|
||||
@@ -540,30 +465,7 @@ export function RecentList({ exclude, compact, autoFocus, onOpened, className, t
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (row.kind === "host") {
|
||||
return (
|
||||
<div
|
||||
key={`host:${row.host.id}`}
|
||||
id={optionId(i)}
|
||||
data-recent-index={i}
|
||||
role="option"
|
||||
aria-selected={selected}
|
||||
aria-expanded={row.host.expanded}
|
||||
className={clsx(styles.recentItem, styles.recentGroup, selected && styles.recentSelected)}
|
||||
onMouseDown={(e) => {
|
||||
if (e.button !== 0) return;
|
||||
e.preventDefault();
|
||||
setActive(i);
|
||||
}}
|
||||
onClick={() => setHostGroupExpanded(row.host.id, !row.host.expanded)}
|
||||
>
|
||||
<Icon name={row.host.expanded ? "chevron-down" : "chevron-right"} size={14} />
|
||||
<HostGroupTitle host={row.host} iconSize={14} />
|
||||
<span className={styles.groupCount}>{row.count}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const nested = row.group !== null || row.hostGroup != null;
|
||||
const nested = row.group !== null;
|
||||
return (
|
||||
<div
|
||||
key={row.m.project.path}
|
||||
@@ -584,13 +486,7 @@ export function RecentList({ exclude, compact, autoFocus, onOpened, className, t
|
||||
showContextMenu(e, recentMenu(row.m.project, onOpened, onOpened));
|
||||
}}
|
||||
>
|
||||
<RecentRow
|
||||
m={row.m}
|
||||
active={selected}
|
||||
compact={compact}
|
||||
hideHost={row.hostGroup != null}
|
||||
onOpened={onOpened}
|
||||
/>
|
||||
<RecentRow m={row.m} active={selected} compact={compact} onOpened={onOpened} />
|
||||
</div>
|
||||
);
|
||||
})
|
||||
|
||||
@@ -243,31 +243,6 @@
|
||||
height: 14px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.remoteHostPill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
align-self: flex-start;
|
||||
gap: var(--space-1);
|
||||
max-width: 100%;
|
||||
min-width: 0;
|
||||
color: var(--fg-secondary);
|
||||
--icon-color: var(--fg-muted);
|
||||
font-size: var(--fs-small);
|
||||
}
|
||||
.remoteKind {
|
||||
flex: none;
|
||||
font-weight: normal;
|
||||
}
|
||||
.remoteDot {
|
||||
flex: none;
|
||||
opacity: 0.65;
|
||||
}
|
||||
.remoteHostText {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* A project group: one line, folds its projects. */
|
||||
.group {
|
||||
align-items: center;
|
||||
@@ -283,27 +258,6 @@
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.hostTitle {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
color: var(--fg-strong);
|
||||
font-weight: 600;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.hostKind {
|
||||
flex: none;
|
||||
color: var(--fg-muted);
|
||||
font-weight: 500;
|
||||
}
|
||||
.hostName {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.groupCount {
|
||||
color: var(--fg-faint);
|
||||
}
|
||||
|
||||
@@ -91,16 +91,11 @@ describe("session restore", () => {
|
||||
describe("project groups", () => {
|
||||
const formatRow = (r: ReturnType<typeof recentRows>[number]) => {
|
||||
if (r.kind === "group") return `[${r.group.name} ${r.count}]`;
|
||||
if (r.kind === "host")
|
||||
return `{${r.host.kind === "local" ? "Local" : `${r.host.kindLabel} · ${r.host.host}`} ${r.count}}`;
|
||||
return `${r.group || r.hostGroup ? " " : ""}${r.m.project.name}`;
|
||||
return `${r.group ? " " : ""}${r.m.project.name}`;
|
||||
};
|
||||
const rows = (query = "") =>
|
||||
recentRows(projects, useRecent.getState().groups, query, "/Users/me", useRecent.getState().collapsedHosts).map(
|
||||
formatRow,
|
||||
);
|
||||
const rows = (query = "") => recentRows(projects, useRecent.getState().groups, query, "/Users/me").map(formatRow);
|
||||
afterEach(() => {
|
||||
useRecent.setState({ groups: [], collapsedHosts: [] });
|
||||
useRecent.setState({ groups: [] });
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
@@ -138,7 +133,7 @@ describe("project groups", () => {
|
||||
expect(rows()).toEqual(["acme-api", "openidea-ide", "tokio", "notes"]);
|
||||
});
|
||||
|
||||
it("groups ungrouped projects by Local and remote host when remote entries exist", async () => {
|
||||
it("keeps ungrouped local and remote projects together in recency order", async () => {
|
||||
const mixed = [
|
||||
{ path: "ssh://devbox/srv/acme", name: "acme-remote", openedAtMs: 50, branch: null },
|
||||
...projects,
|
||||
@@ -149,25 +144,12 @@ describe("project groups", () => {
|
||||
expect(recentRows(mixed, useRecent.getState().groups, "", "/Users/me").map(formatRow)).toEqual([
|
||||
"[Pinned 1]",
|
||||
" acme-api",
|
||||
"{SSH · devbox 2}",
|
||||
" acme-remote",
|
||||
" lib-remote",
|
||||
"{Local 3}",
|
||||
" openidea-ide",
|
||||
" tokio",
|
||||
" notes",
|
||||
"{WSL · Ubuntu 1}",
|
||||
" tokio-wsl",
|
||||
]);
|
||||
expect(recentRows(mixed, useRecent.getState().groups, "", "/Users/me", ["local"]).map(formatRow)).toEqual([
|
||||
"[Pinned 1]",
|
||||
" acme-api",
|
||||
"{SSH · devbox 2}",
|
||||
" acme-remote",
|
||||
" lib-remote",
|
||||
"{Local 3}",
|
||||
"{WSL · Ubuntu 1}",
|
||||
" tokio-wsl",
|
||||
"acme-remote",
|
||||
"openidea-ide",
|
||||
"tokio",
|
||||
"notes",
|
||||
"tokio-wsl",
|
||||
"lib-remote",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -32,8 +32,6 @@ interface RecentState {
|
||||
projects: RecentProject[];
|
||||
/** Project groups (New Project Group…), shown above the ungrouped projects. */
|
||||
groups: RecentProjectGroup[];
|
||||
/** Host group ids (`local`, `ssh:…`, `wsl:…`) folded by the user. */
|
||||
collapsedHosts: string[];
|
||||
loaded: boolean;
|
||||
home: string | null;
|
||||
version: string | null;
|
||||
@@ -41,30 +39,9 @@ interface RecentState {
|
||||
opening: string | null;
|
||||
}
|
||||
|
||||
const COLLAPSED_HOSTS_KEY = "openidea.recent.collapsedHosts";
|
||||
|
||||
function readCollapsedHosts(): string[] {
|
||||
try {
|
||||
const raw = JSON.parse(localStorage.getItem(COLLAPSED_HOSTS_KEY) ?? "[]") as unknown;
|
||||
return Array.isArray(raw) ? raw.filter((v): v is string => typeof v === "string") : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function writeCollapsedHosts(ids: string[]) {
|
||||
try {
|
||||
if (ids.length) localStorage.setItem(COLLAPSED_HOSTS_KEY, JSON.stringify(ids));
|
||||
else localStorage.removeItem(COLLAPSED_HOSTS_KEY);
|
||||
} catch {
|
||||
/* storage unavailable */
|
||||
}
|
||||
}
|
||||
|
||||
export const useRecent = create<RecentState>(() => ({
|
||||
projects: [],
|
||||
groups: [],
|
||||
collapsedHosts: readCollapsedHosts(),
|
||||
loaded: false,
|
||||
home: null,
|
||||
version: null,
|
||||
@@ -87,7 +64,6 @@ export async function loadRecent() {
|
||||
if (!isTauri()) {
|
||||
useRecent.setState({
|
||||
projects: SAMPLE,
|
||||
collapsedHosts: readCollapsedHosts(),
|
||||
loaded: true,
|
||||
home: "/Users/dev",
|
||||
version: "0.1.0-dev",
|
||||
@@ -103,7 +79,6 @@ export async function loadRecent() {
|
||||
useRecent.setState({
|
||||
projects: withRemotes(projects),
|
||||
groups,
|
||||
collapsedHosts: readCollapsedHosts(),
|
||||
loaded: true,
|
||||
version: info?.version ?? useRecent.getState().version,
|
||||
home: home ? home.replace(/\/+$/, "") : useRecent.getState().home,
|
||||
@@ -378,43 +353,23 @@ export function setGroupExpanded(name: string, expanded: boolean) {
|
||||
return saveGroups(groups().map((g) => (g.name === name ? { ...g, expanded } : g)));
|
||||
}
|
||||
|
||||
export function setHostGroupExpanded(id: string, expanded: boolean) {
|
||||
const current = useRecent.getState().collapsedHosts;
|
||||
const next = expanded ? current.filter((h) => h !== id) : current.includes(id) ? current : [...current, id];
|
||||
useRecent.setState({ collapsedHosts: next });
|
||||
writeCollapsedHosts(next);
|
||||
}
|
||||
|
||||
export type HostGroup =
|
||||
| { id: "local"; kind: "local"; expanded: boolean }
|
||||
| {
|
||||
id: string;
|
||||
kind: RemoteTarget["kind"];
|
||||
kindLabel: string;
|
||||
host: string;
|
||||
expanded: boolean;
|
||||
};
|
||||
|
||||
export type RecentRow =
|
||||
| { kind: "group"; group: RecentProjectGroup; count: number }
|
||||
| { kind: "host"; host: HostGroup; count: number }
|
||||
| { kind: "project"; m: RecentMatch; group: string | null; hostGroup?: HostGroup | null };
|
||||
| { kind: "project"; m: RecentMatch; group: string | null };
|
||||
|
||||
/**
|
||||
* The rows of the list: without a query, custom groups first (their projects under the expanded
|
||||
* ones, most recent first), then the remaining projects grouped by host (`Local` and each remote
|
||||
* host in MRU order) when any remote project exists, or flat when all projects are local; while
|
||||
* searching, the matches only.
|
||||
* ones, most recent first), then all remaining local and remote projects in recency order.
|
||||
* While searching, the matches only.
|
||||
*/
|
||||
export function recentRows(
|
||||
projects: readonly RecentProject[],
|
||||
groupList: readonly RecentProjectGroup[],
|
||||
query: string,
|
||||
home?: string | null,
|
||||
collapsedHosts: readonly string[] = [],
|
||||
): RecentRow[] {
|
||||
const matches = filterRecent(projects, query, home);
|
||||
if (query.trim()) return matches.map((m) => ({ kind: "project", m, group: null, hostGroup: null }));
|
||||
if (query.trim()) return matches.map((m) => ({ kind: "project", m, group: null }));
|
||||
const rows: RecentRow[] = [];
|
||||
const grouped = new Set<string>();
|
||||
for (const group of groupList) {
|
||||
@@ -422,39 +377,11 @@ export function recentRows(
|
||||
members.forEach((m) => grouped.add(m.project.path));
|
||||
rows.push({ kind: "group", group, count: members.length });
|
||||
if (group.expanded) {
|
||||
rows.push(...members.map((m): RecentRow => ({ kind: "project", m, group: group.name, hostGroup: null })));
|
||||
rows.push(...members.map((m): RecentRow => ({ kind: "project", m, group: group.name })));
|
||||
}
|
||||
}
|
||||
const rest = matches.filter((m) => !grouped.has(m.project.path));
|
||||
if (!rest.some((m) => m.remote !== null)) {
|
||||
for (const m of rest) rows.push({ kind: "project", m, group: null, hostGroup: null });
|
||||
return rows;
|
||||
}
|
||||
const collapsed = new Set(collapsedHosts);
|
||||
const buckets = new Map<string, { host: HostGroup; members: RecentMatch[] }>();
|
||||
for (const m of rest) {
|
||||
const id = m.remote ? `${m.remote.kind}:${m.remote.host}` : "local";
|
||||
let bucket = buckets.get(id);
|
||||
if (!bucket) {
|
||||
const host: HostGroup = m.remote
|
||||
? {
|
||||
id,
|
||||
kind: m.remote.kind,
|
||||
kindLabel: m.remote.kindLabel,
|
||||
host: m.remote.host,
|
||||
expanded: !collapsed.has(id),
|
||||
}
|
||||
: { id: "local", kind: "local", expanded: !collapsed.has("local") };
|
||||
bucket = { host, members: [] };
|
||||
buckets.set(id, bucket);
|
||||
}
|
||||
bucket.members.push(m);
|
||||
}
|
||||
for (const { host, members } of buckets.values()) {
|
||||
rows.push({ kind: "host", host, count: members.length });
|
||||
if (host.expanded) {
|
||||
rows.push(...members.map((m): RecentRow => ({ kind: "project", m, group: null, hostGroup: host })));
|
||||
}
|
||||
for (const m of matches) {
|
||||
if (!grouped.has(m.project.path)) rows.push({ kind: "project", m, group: null });
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
@@ -277,7 +277,7 @@ describe("Welcome › Projects", () => {
|
||||
expect(screen.queryByLabelText("Search projects")).toBeNull();
|
||||
});
|
||||
|
||||
it("groups projects by Local and remote host in MRU order, folds hosts, and flattens on search", async () => {
|
||||
it("shows local and remote projects in one MRU list, ignoring old collapsed hosts", async () => {
|
||||
recent = [
|
||||
{ name: "gocommon", path: "/Users/me/git/gocommon", branch: "main", openedAtMs: 70 },
|
||||
{ name: "openidea_all", path: "/Users/me/git/openidea_all", branch: null, openedAtMs: 40 },
|
||||
@@ -308,32 +308,28 @@ describe("Welcome › Projects", () => {
|
||||
},
|
||||
]),
|
||||
);
|
||||
// Previously collapsed hosts must not hide any projects in the flat list.
|
||||
localStorage.setItem("openidea.recent.collapsedHosts", JSON.stringify(["local", "ssh:dev@devbox:22"]));
|
||||
await renderWelcome();
|
||||
const options = () => screen.getAllByRole("option");
|
||||
expect(options().map((o) => o.textContent)).toEqual([
|
||||
"SSH·dev@devbox:222",
|
||||
expect.stringContaining("openidea_all/home/coder/git/openidea_all"),
|
||||
expect.stringContaining("gocommon/home/coder/git/gocommon"),
|
||||
"Local2",
|
||||
expect.stringContaining("openidea_alldev@devbox:22:/home/coder/git/openidea_all"),
|
||||
expect.stringContaining("gocommon~/git/gocommonmain"),
|
||||
expect.stringContaining("gocommondev@devbox:22:/home/coder/git/gocommon"),
|
||||
expect.stringContaining("openidea_all~/git/openidea_all"),
|
||||
"WSL·Ubuntu1",
|
||||
expect.stringContaining("openidea_all/home/me/git/openidea_all"),
|
||||
expect.stringContaining("openidea_allUbuntu:/home/me/git/openidea_all"),
|
||||
]);
|
||||
// Grouped rows omit the redundant per-row RemoteHostPill while keeping the badge corner.
|
||||
expect(options()[1]!.querySelector("[data-remote-badge]")).not.toBeNull();
|
||||
expect(options()[1]!.querySelector('[data-remote-kind="ssh"]')).toBeNull();
|
||||
expect(options().map((o) => !!o.querySelector("[data-remote-badge]"))).toEqual([true, false, true, false, true]);
|
||||
expect(options().every((o) => !o.hasAttribute("aria-expanded"))).toBe(true);
|
||||
|
||||
// Folding SSH · dev@devbox:22 hides its 2 projects and persists across reloads.
|
||||
fireEvent.click(options()[0]!);
|
||||
expect(options()).toHaveLength(6);
|
||||
expect(JSON.parse(localStorage.getItem("openidea.recent.collapsedHosts") ?? "[]")).toEqual(["ssh:dev@devbox:22"]);
|
||||
|
||||
// Searching flattens the list and restores per-row remote host pills even for folded hosts.
|
||||
const search = screen.getByLabelText("Search projects");
|
||||
fireEvent.change(search, { target: { value: "openidea_all" } });
|
||||
expect(options()).toHaveLength(3);
|
||||
expect(options()[0]!.querySelector('[data-remote-kind="ssh"]')?.textContent).toContain("dev@devbox:22");
|
||||
fireEvent.keyDown(search, { key: "ArrowDown" });
|
||||
expect(options()[1]!.getAttribute("aria-selected")).toBe("true");
|
||||
fireEvent.change(search, { target: { value: "devbox" } });
|
||||
expect(options()).toHaveLength(2);
|
||||
expect(options()[0]!.textContent).toContain("dev@devbox:22:/home/coder/git/openidea_all");
|
||||
fireEvent.change(search, { target: { value: "" } });
|
||||
expect(options()).toHaveLength(5);
|
||||
});
|
||||
|
||||
it("excludes only the active remote location in RecentProjectsPopup, not a local folder at the same path", async () => {
|
||||
@@ -374,9 +370,7 @@ describe("Welcome › Projects", () => {
|
||||
.getAllByRole("option")
|
||||
.map((o) => o.textContent);
|
||||
expect(texts).toEqual([
|
||||
"SSH·mbp.local1",
|
||||
expect.stringContaining("gocommon/Users/me/git/gocommon"),
|
||||
"Local1",
|
||||
expect.stringContaining("gocommonmbp.local:/Users/me/git/gocommon"),
|
||||
expect.stringContaining("openidea_all~/git/openidea_all"),
|
||||
]);
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Заблокувати користувача