mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-17 13:54:54 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
94f2df6263 |
@@ -97,18 +97,15 @@ export class ImportSessionFlow {
|
||||
await target.scrollIntoViewIfNeeded();
|
||||
await expect(target).toBeInViewport();
|
||||
}
|
||||
/**
|
||||
* Scrolls the virtualized list, the only one that leaves rows unmounted. A row handle is no way
|
||||
* in: the list unmounts rows as it scrolls, and a detached row has no scroller above it.
|
||||
*/
|
||||
private async scrollList(forward: boolean) {
|
||||
await this.page
|
||||
.locator('[data-testid^="import-session-session-"]')
|
||||
.first()
|
||||
.evaluate((row, advance) => {
|
||||
let element = row.parentElement;
|
||||
while (element && !["auto", "scroll"].includes(getComputedStyle(element).overflowY))
|
||||
element = element.parentElement;
|
||||
if (!element) throw new Error("Import list has no scroll owner");
|
||||
element.scrollTop = advance ? element.scrollTop + element.clientHeight * 0.8 : 0;
|
||||
element.dispatchEvent(new Event("scroll"));
|
||||
}, forward);
|
||||
await this.page.getByTestId("import-session-list").evaluate((list, advance) => {
|
||||
list.scrollTop = advance ? list.scrollTop + list.clientHeight * 0.8 : 0;
|
||||
list.dispatchEvent(new Event("scroll"));
|
||||
}, forward);
|
||||
}
|
||||
async search(query: string) {
|
||||
await this.page.getByTestId("import-session-search").fill(query);
|
||||
@@ -120,11 +117,18 @@ export class ImportSessionFlow {
|
||||
await this.page.getByTestId("import-session-search").fill("");
|
||||
await expect(this.page.getByTestId("import-session-load-more")).toBeVisible();
|
||||
}
|
||||
/** Load more keeps the reader down the list instead of sending them back to the top. */
|
||||
async loadMore() {
|
||||
await this.page.getByTestId("import-session-load-more").click();
|
||||
const loadMore = this.page.getByTestId("import-session-load-more");
|
||||
const topRow = this.page.getByTestId((await this.rowIds())[0]!);
|
||||
await expect(topRow).toBeInViewport();
|
||||
await loadMore.click();
|
||||
// The next page is the last and short, so the button leaves once it lands.
|
||||
await expect(loadMore).toHaveCount(0);
|
||||
await expect(this.page.getByText("Loading sessions...", { exact: true })).toHaveCount(0);
|
||||
await expect(topRow).not.toBeInViewport();
|
||||
await this.revealSession("fixture-root-20");
|
||||
await expect(this.page.getByText("Root session 20", { exact: true })).toBeInViewport();
|
||||
await expect(this.page.getByTestId("import-session-load-more")).toHaveCount(0);
|
||||
}
|
||||
async retryProvider(provider: string, label: string) {
|
||||
await this.expectProviderError(label);
|
||||
|
||||
@@ -17,6 +17,11 @@ export function nextPageLimit(limit: number): number {
|
||||
return PAGE_LIMITS.find((candidate) => candidate > limit) ?? limit;
|
||||
}
|
||||
|
||||
/** The page Load more grew this limit from, or null for the first page. */
|
||||
export function previousPageLimit(limit: number): number | null {
|
||||
return PAGE_LIMITS.findLast((candidate) => candidate < limit) ?? null;
|
||||
}
|
||||
|
||||
export function requiresImportSessionsHostUpgrade(input: {
|
||||
supportsSnapshot: boolean;
|
||||
workspaceId?: string | null;
|
||||
|
||||
@@ -1172,6 +1172,44 @@ describe("ImportSessionSheet", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps the loaded list in place while Load more fetches the next page", async () => {
|
||||
let releaseNextPage: () => void = () => undefined;
|
||||
const nextPage = new Promise<void>((resolve) => {
|
||||
releaseNextPage = resolve;
|
||||
});
|
||||
const fetchRecentProviderSessions = vi.fn(async (options: { limit?: number } | undefined) => {
|
||||
if (options?.limit !== 15) await nextPage;
|
||||
return {
|
||||
requestId: "recent-provider-sessions",
|
||||
entries: createPageOfEntries(options?.limit === 15 ? 15 : 20),
|
||||
};
|
||||
});
|
||||
|
||||
renderSheet(createRecentSessionsClient(fetchRecentProviderSessions, vi.fn()), {
|
||||
cwd: null,
|
||||
snapshot: { supportsSnapshot: true, entries: [createSnapshotEntry("claude")] },
|
||||
});
|
||||
|
||||
fireEvent.click(await screen.findByTestId("import-session-load-more"));
|
||||
// The list the user scrolled to Load more is the one they keep: replacing it would drop
|
||||
// them back at the top, behind a loading state, until the larger page lands.
|
||||
const list = screen.getByTestId("import-session-list");
|
||||
await waitFor(() => {
|
||||
expect(fetchRecentProviderSessions).toHaveBeenCalledWith({
|
||||
providers: ["claude"],
|
||||
limit: 45,
|
||||
});
|
||||
});
|
||||
expect(screen.getByTestId("import-session-list")).toBe(list);
|
||||
expect(screen.queryByText("Loading sessions...")).toBeNull();
|
||||
|
||||
releaseNextPage();
|
||||
await waitFor(() => {
|
||||
expect(screen.queryByTestId("import-session-load-more")).toBeNull();
|
||||
});
|
||||
expect(screen.getByTestId("import-session-list")).toBe(list);
|
||||
});
|
||||
|
||||
it("stops the refresh spinner and retries only the failed provider", async () => {
|
||||
const fetchRecentProviderSessions = vi.fn(
|
||||
async (options: { providers?: string[] } | undefined) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Pressable, type PressableStateCallbackType, Text, View } from "react-native";
|
||||
import { keepPreviousData, useMutation, useQueries, useQueryClient } from "@tanstack/react-query";
|
||||
import { useMutation, useQueries, useQueryClient, type QueryClient } from "@tanstack/react-query";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type {
|
||||
DaemonClient,
|
||||
@@ -40,6 +40,7 @@ import {
|
||||
resolveDirectoryLabel,
|
||||
nextPageLimit,
|
||||
PER_PROVIDER_LIMIT,
|
||||
previousPageLimit,
|
||||
type ProviderErrorRow,
|
||||
resolveImportTarget,
|
||||
resolveProvidersToFetch,
|
||||
@@ -100,11 +101,12 @@ interface SessionsQueryConfig {
|
||||
// Query's default retry would keep the header spinner turning and pile up
|
||||
// in-flight daemon requests behind a dead provider (#2512).
|
||||
retry: false;
|
||||
placeholderData: typeof keepPreviousData;
|
||||
placeholderData: () => RecentSessionsResponse | undefined;
|
||||
queryFn: () => Promise<RecentSessionsResponse>;
|
||||
}
|
||||
|
||||
function buildSessionsQueriesConfig(args: {
|
||||
queryClient: QueryClient;
|
||||
providersToFetch: AgentProvider[] | null;
|
||||
visible: boolean;
|
||||
client: RecentProviderSessionsClient | null;
|
||||
@@ -113,14 +115,24 @@ function buildSessionsQueriesConfig(args: {
|
||||
limit: number;
|
||||
hostDisconnectedMessage?: string;
|
||||
}): SessionsQueryConfig[] {
|
||||
const { providersToFetch, visible, client, cwd, query, limit, hostDisconnectedMessage } = args;
|
||||
const { queryClient, providersToFetch, visible, client, cwd, query, limit } = args;
|
||||
const { hostDisconnectedMessage } = args;
|
||||
if (providersToFetch === null) return [];
|
||||
const enabled = visible && Boolean(client);
|
||||
const previousLimit = previousPageLimit(limit);
|
||||
return providersToFetch.map((provider) => ({
|
||||
queryKey: buildSessionsQueryKey({ cwd, query, limit, provider }),
|
||||
enabled,
|
||||
retry: false as const,
|
||||
placeholderData: keepPreviousData,
|
||||
// While Load more fetches the next page, keep showing the page it grew from. React Query's
|
||||
// keepPreviousData cannot do this here: useQueries gives a changed key a new observer, which
|
||||
// has no previous data, so the rows would vanish and the list would remount at the top.
|
||||
placeholderData: () =>
|
||||
previousLimit === null
|
||||
? undefined
|
||||
: queryClient.getQueryData<RecentSessionsResponse>(
|
||||
buildSessionsQueryKey({ cwd, query, limit: previousLimit, provider }),
|
||||
),
|
||||
queryFn: async () => {
|
||||
if (!client) {
|
||||
throw new Error(hostDisconnectedMessage ?? i18n.t("workspace.terminal.hostDisconnected"));
|
||||
@@ -522,6 +534,7 @@ export function ImportSessionSheet({
|
||||
const queriesConfig = useMemo(
|
||||
() =>
|
||||
buildSessionsQueriesConfig({
|
||||
queryClient,
|
||||
providersToFetch,
|
||||
visible,
|
||||
client,
|
||||
@@ -530,7 +543,7 @@ export function ImportSessionSheet({
|
||||
limit: pageLimit,
|
||||
hostDisconnectedMessage: t("workspace.terminal.hostDisconnected"),
|
||||
}),
|
||||
[providersToFetch, visible, client, scopeCwd, query, pageLimit, t],
|
||||
[queryClient, providersToFetch, visible, client, scopeCwd, query, pageLimit, t],
|
||||
);
|
||||
|
||||
const queries = useQueries({ queries: queriesConfig });
|
||||
|
||||
@@ -6,7 +6,6 @@ import { createMacDockBadgeCountSelector } from "@/utils/desktop-badge-state";
|
||||
import { createFaviconStatusSelector, type FaviconStatus } from "@/utils/favicon-status";
|
||||
import { isNative } from "@/constants/platform";
|
||||
import { useSessionStore } from "@/stores/session-store";
|
||||
import { useSidebarViewStore } from "@/stores/sidebar-view-store";
|
||||
import { useHosts } from "@/runtime/host-runtime";
|
||||
|
||||
type ColorScheme = "dark" | "light";
|
||||
@@ -86,16 +85,8 @@ export function useFaviconStatus() {
|
||||
// The favicon reads the whole fleet, so it has to keep every host's directory loading even
|
||||
// though it no longer subscribes to the agent maps.
|
||||
useAllDirectoryDemand({ serverIds, enabled: !isNative });
|
||||
// Background workspaces count exactly when the sidebar shows them.
|
||||
const showBackground = useSidebarViewStore((state) => state.showBackground);
|
||||
const selectFaviconStatus = useMemo(
|
||||
() => createFaviconStatusSelector({ showBackground }),
|
||||
[showBackground],
|
||||
);
|
||||
const selectMacDockBadgeCount = useMemo(
|
||||
() => createMacDockBadgeCountSelector({ showBackground }),
|
||||
[showBackground],
|
||||
);
|
||||
const selectFaviconStatus = useMemo(createFaviconStatusSelector, []);
|
||||
const selectMacDockBadgeCount = useMemo(createMacDockBadgeCountSelector, []);
|
||||
const status = useSessionStore(selectFaviconStatus);
|
||||
const dockBadgeCount = useSessionStore(selectMacDockBadgeCount);
|
||||
const [colorScheme, setColorScheme] = useState<ColorScheme>(getSystemColorScheme);
|
||||
|
||||
@@ -73,18 +73,6 @@ describe("desktop-badge-state", () => {
|
||||
expect(selectMacDockBadgeCount(state)).toBe(3);
|
||||
});
|
||||
|
||||
it("leaves out background workspaces, which the sidebar hides", () => {
|
||||
const hidden = { ...workspace("a", "attention"), background: true };
|
||||
expect(selectMacDockBadgeCount(stateWith(hidden))).toBeUndefined();
|
||||
expect(selectMacDockBadgeCount(stateWith(hidden, workspace("b", "failed")))).toBe(1);
|
||||
});
|
||||
|
||||
it("counts background workspaces while Show background puts them in the sidebar", () => {
|
||||
const hidden = { ...workspace("a", "attention"), background: true };
|
||||
expect(selectMacDockBadgeCount(stateWith(hidden), { showBackground: true })).toBe(1);
|
||||
expect(createMacDockBadgeCountSelector({ showBackground: true })(stateWith(hidden))).toBe(1);
|
||||
});
|
||||
|
||||
it("recounts only when a workspace map is replaced", () => {
|
||||
const select = createMacDockBadgeCountSelector();
|
||||
const state = stateWith(workspace("a", "attention"));
|
||||
|
||||
@@ -19,21 +19,11 @@ export function isWorkspaceActionableForDesktopBadge(status: DesktopBadgeWorkspa
|
||||
* The macOS dock badge only needs a count, so count here instead of materialising every
|
||||
* workspace status and comparing the whole list on every store write.
|
||||
*/
|
||||
export interface DockBadgeOptions {
|
||||
/** Count background workspaces too, as the sidebar shows them while Show background is on. */
|
||||
showBackground?: boolean;
|
||||
}
|
||||
|
||||
export function selectMacDockBadgeCount(
|
||||
state: WorkspaceStatusSource,
|
||||
options: DockBadgeOptions = {},
|
||||
): number | undefined {
|
||||
export function selectMacDockBadgeCount(state: WorkspaceStatusSource): number | undefined {
|
||||
let actionableCount = 0;
|
||||
for (const session of Object.values(state.sessions)) {
|
||||
if (!session) continue;
|
||||
for (const workspace of session.workspaces.values()) {
|
||||
// A hidden background workspace would leave the badge pointing at nothing in the sidebar.
|
||||
if (workspace.background && !options.showBackground) continue;
|
||||
if (isWorkspaceActionableForDesktopBadge(workspace.status)) actionableCount += 1;
|
||||
}
|
||||
}
|
||||
@@ -41,11 +31,11 @@ export function selectMacDockBadgeCount(
|
||||
}
|
||||
|
||||
/** A session-store selector for the dock badge count that recounts only when a workspace map changes. */
|
||||
export function createMacDockBadgeCountSelector(
|
||||
options: DockBadgeOptions = {},
|
||||
): (state: WorkspaceStatusSource) => number | undefined {
|
||||
export function createMacDockBadgeCountSelector(): (
|
||||
state: WorkspaceStatusSource,
|
||||
) => number | undefined {
|
||||
return memoizeOnSessionMaps<WorkspaceStatusSession, WorkspaceStatusSource, number | undefined>(
|
||||
(session) => [session.workspaces],
|
||||
(state) => selectMacDockBadgeCount(state, options),
|
||||
(session) => session.workspaces,
|
||||
selectMacDockBadgeCount,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { Agent, WorkspaceDescriptor } from "@/stores/session-store";
|
||||
import type { Agent } from "@/stores/session-store";
|
||||
import { createFaviconStatusSelector, deriveFaviconStatus } from "./favicon-status";
|
||||
|
||||
function agent(input: Partial<Agent> & { id: string }): Agent {
|
||||
@@ -14,21 +14,7 @@ function agent(input: Partial<Agent> & { id: string }): Agent {
|
||||
}
|
||||
|
||||
function stateWith(...agents: Agent[]) {
|
||||
return stateWithWorkspaces([], ...agents);
|
||||
}
|
||||
|
||||
function stateWithWorkspaces(
|
||||
workspaces: Array<Pick<WorkspaceDescriptor, "id" | "background">>,
|
||||
...agents: Agent[]
|
||||
) {
|
||||
return {
|
||||
sessions: {
|
||||
srv: {
|
||||
agents: new Map(agents.map((entry) => [entry.id, entry])),
|
||||
workspaces: new Map(workspaces.map((entry) => [entry.id, entry])),
|
||||
},
|
||||
},
|
||||
};
|
||||
return { sessions: { srv: { agents: new Map(agents.map((entry) => [entry.id, entry])) } } };
|
||||
}
|
||||
|
||||
describe("deriveFaviconStatus", () => {
|
||||
@@ -64,37 +50,6 @@ describe("deriveFaviconStatus", () => {
|
||||
),
|
||||
).toBe("none");
|
||||
});
|
||||
|
||||
it("ignores agents in background workspaces, which the sidebar hides", () => {
|
||||
const hidden = { id: "ws-hidden", background: true };
|
||||
expect(
|
||||
deriveFaviconStatus(
|
||||
stateWithWorkspaces(
|
||||
[hidden],
|
||||
agent({ id: "a", workspaceId: "ws-hidden", requiresAttention: true }),
|
||||
agent({ id: "b", workspaceId: "ws-hidden", status: "running" }),
|
||||
),
|
||||
),
|
||||
).toBe("none");
|
||||
expect(
|
||||
deriveFaviconStatus(
|
||||
stateWithWorkspaces(
|
||||
[hidden, { id: "ws-shown", background: false }],
|
||||
agent({ id: "a", workspaceId: "ws-hidden", status: "running" }),
|
||||
agent({ id: "b", workspaceId: "ws-shown", requiresAttention: true }),
|
||||
),
|
||||
),
|
||||
).toBe("attention");
|
||||
});
|
||||
|
||||
it("counts agents in background workspaces while Show background puts them in the sidebar", () => {
|
||||
const state = stateWithWorkspaces(
|
||||
[{ id: "ws-hidden", background: true }],
|
||||
agent({ id: "a", workspaceId: "ws-hidden", requiresAttention: true }),
|
||||
);
|
||||
expect(deriveFaviconStatus(state, { showBackground: true })).toBe("attention");
|
||||
expect(createFaviconStatusSelector({ showBackground: true })(state)).toBe("attention");
|
||||
});
|
||||
});
|
||||
|
||||
describe("createFaviconStatusSelector", () => {
|
||||
@@ -108,18 +63,6 @@ describe("createFaviconStatusSelector", () => {
|
||||
expect(select({ sessions: { ...state.sessions } })).toBe("running");
|
||||
});
|
||||
|
||||
it("rescans when a workspace map is replaced", () => {
|
||||
const select = createFaviconStatusSelector();
|
||||
const state = stateWithWorkspaces(
|
||||
[],
|
||||
agent({ id: "a", workspaceId: "ws-hidden", requiresAttention: true }),
|
||||
);
|
||||
expect(select(state)).toBe("attention");
|
||||
// The agent synced before its workspace; only the workspace map changes.
|
||||
const workspaces = new Map([["ws-hidden", { id: "ws-hidden", background: true }]]);
|
||||
expect(select({ sessions: { srv: { ...state.sessions.srv, workspaces } } })).toBe("none");
|
||||
});
|
||||
|
||||
it("rescans when an agent map is replaced", () => {
|
||||
const select = createFaviconStatusSelector();
|
||||
expect(select(stateWith(agent({ id: "a", status: "running" })))).toBe("running");
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { Agent, WorkspaceDescriptor } from "@/stores/session-store";
|
||||
import type { Agent } from "@/stores/session-store";
|
||||
import { memoizeOnSessionMaps } from "./memoize-on-session-maps";
|
||||
|
||||
export type FaviconStatus = "none" | "running" | "attention";
|
||||
|
||||
interface FaviconAgentSession {
|
||||
agents: ReadonlyMap<string, Agent>;
|
||||
workspaces: ReadonlyMap<string, Pick<WorkspaceDescriptor, "background">>;
|
||||
}
|
||||
|
||||
interface FaviconAgentSource {
|
||||
@@ -17,22 +16,13 @@ interface FaviconAgentSource {
|
||||
* three states here instead of building the aggregated agent list: the list allocates a
|
||||
* projection per agent, deep-compares it and sorts every agent on the host on each update.
|
||||
*/
|
||||
export interface FaviconStatusOptions {
|
||||
/** Count agents in background workspaces too, as the sidebar shows them while Show background is on. */
|
||||
showBackground?: boolean;
|
||||
}
|
||||
|
||||
export function deriveFaviconStatus(
|
||||
state: FaviconAgentSource,
|
||||
options: FaviconStatusOptions = {},
|
||||
): FaviconStatus {
|
||||
export function deriveFaviconStatus(state: FaviconAgentSource): FaviconStatus {
|
||||
let hasAttention = false;
|
||||
let hasNeedsInput = false;
|
||||
for (const session of Object.values(state.sessions)) {
|
||||
if (!session) continue;
|
||||
for (const agent of session.agents.values()) {
|
||||
if (agent.background || agent.archivedAt) continue;
|
||||
if (!options.showBackground && isInBackgroundWorkspace(agent, session)) continue;
|
||||
if (agent.status === "running") return "running";
|
||||
if (agent.requiresAttention) hasAttention = true;
|
||||
if (agent.pendingPermissions.length > 0) hasNeedsInput = true;
|
||||
@@ -41,16 +31,10 @@ export function deriveFaviconStatus(
|
||||
return hasAttention || hasNeedsInput ? "attention" : "none";
|
||||
}
|
||||
|
||||
function isInBackgroundWorkspace(agent: Agent, session: FaviconAgentSession): boolean {
|
||||
return agent.workspaceId ? session.workspaces.get(agent.workspaceId)?.background === true : false;
|
||||
}
|
||||
|
||||
/** A session-store selector for the favicon status that rescans only when an agent or workspace map changes. */
|
||||
export function createFaviconStatusSelector(
|
||||
options: FaviconStatusOptions = {},
|
||||
): (state: FaviconAgentSource) => FaviconStatus {
|
||||
/** A session-store selector for the favicon status that rescans only when an agent map changes. */
|
||||
export function createFaviconStatusSelector(): (state: FaviconAgentSource) => FaviconStatus {
|
||||
return memoizeOnSessionMaps<FaviconAgentSession, FaviconAgentSource, FaviconStatus>(
|
||||
(session) => [session.agents, session.workspaces],
|
||||
(state) => deriveFaviconStatus(state, options),
|
||||
(session) => session.agents,
|
||||
deriveFaviconStatus,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,18 +4,18 @@ interface SessionsSource<TSession> {
|
||||
|
||||
/**
|
||||
* Wraps a whole-store selector so it reruns only when one of the per-session maps it reads has
|
||||
* changed. `pickMaps` returns every map the selector reads from one session. Session-store writes that leave those maps alone (timeline updates, drafts) then cost
|
||||
* changed. Session-store writes that leave those maps alone (timeline updates, drafts) then cost
|
||||
* a reference check per host instead of a walk over every entry.
|
||||
*/
|
||||
export function memoizeOnSessionMaps<TSession, TState extends SessionsSource<TSession>, TResult>(
|
||||
pickMaps: (session: TSession) => readonly unknown[],
|
||||
pickMap: (session: TSession) => unknown,
|
||||
derive: (state: TState) => TResult,
|
||||
): (state: TState) => TResult {
|
||||
let previousMaps: unknown[] | null = null;
|
||||
let previousResult: TResult;
|
||||
return (state) => {
|
||||
const maps = Object.values(state.sessions).flatMap((session) =>
|
||||
session ? pickMaps(session) : [undefined],
|
||||
const maps = Object.values(state.sessions).map((session) =>
|
||||
session ? pickMap(session) : undefined,
|
||||
);
|
||||
if (
|
||||
previousMaps &&
|
||||
|
||||
Reference in New Issue
Block a user