fix(webui): center prompt navigation in the complete chat frame
This commit is contained in:
1 parent
f230409b5a
commit
27ef6fe24f
7 files changed
+84
-15
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { createPortal } from "react-dom";
|
||||
import { MessageBubble } from "@/components/MessageBubble";
|
||||
import { ThreadMessages } from "@/components/thread/ThreadMessages";
|
||||
import { ThreadViewport } from "@/components/thread/ThreadViewport";
|
||||
import { PaneWorkbench } from "@/components/workbench/PaneWorkbench";
|
||||
import { usePromptHistory } from "@/hooks/usePromptHistory";
|
||||
import { ClientProvider } from "@/providers/ClientProvider";
|
||||
import { NanobotClient } from "@/lib/nanobot-client";
|
||||
@@ -82,14 +84,24 @@ function RailFixture() {
|
||||
return () => window.clearInterval(timer);
|
||||
}, [streaming]);
|
||||
const navigation = usePromptHistory(messages.length ? "websocket:rail" : null, version, messages);
|
||||
const composer = <div style={{ height: parameters.has("tall-composer") ? 240 : 100, border: "1px solid #ddd", borderRadius: 20, padding: 20 }}>Message nanobot</div>;
|
||||
const viewport = (external: boolean, navigationFrame?: HTMLElement | null) => <ThreadViewport
|
||||
messages={messages} isStreaming={streaming} conversationKey="websocket:rail"
|
||||
navigation={parameters.has("short") ? undefined : navigation}
|
||||
navigationFrame={navigationFrame} composer={external ? null : composer} />;
|
||||
return <main style={{ height: "100vh", display: "flex", flexDirection: "column" }}>
|
||||
{parameters.has("real") && <div>
|
||||
<button onClick={() => setVersion((value) => value + 1)}>Refresh index</button>
|
||||
<button onClick={() => setStreaming(true)} disabled={streaming}>{streaming ? "Streaming" : "Simulate stream"}</button>
|
||||
</div>}
|
||||
<ThreadViewport messages={messages} isStreaming={streaming} conversationKey="websocket:rail"
|
||||
navigation={parameters.has("short") ? undefined : navigation}
|
||||
composer={<div style={{ height: 100, border: "1px solid #ddd", borderRadius: 20, padding: 20 }}>Message nanobot</div>} />
|
||||
{parameters.has("workbench") ? <PaneWorkbench
|
||||
panes={[{ key: "rail", title: "Rail conversation" }]} activePaneKey="rail" layout="columns" showLayoutControl={false}
|
||||
onActivatePane={() => {}} onAddPane={() => {}} onLayoutChange={() => {}} onPaneOrderChange={() => {}}
|
||||
renderPane={(_pane, context) => <>
|
||||
{viewport(true, context.navigationFrame)}
|
||||
{context.composerPortalTarget && createPortal(composer, context.composerPortalTarget)}
|
||||
</>}
|
||||
/> : viewport(false)}
|
||||
</main>;
|
||||
}
|
||||
await initializeI18n();
|
||||
|
||||
@@ -16,10 +16,17 @@ test("complete rail scrolls independently, jumps to unloaded history and returns
|
||||
has_more_before: start > 0, has_more_after: start + 10 < 2000 } } });
|
||||
});
|
||||
await page.setViewportSize({ width: 1440, height: 900 });
|
||||
await page.goto("/browser/fixture.html?case=rail");
|
||||
await page.goto("/browser/fixture.html?case=rail&workbench=1");
|
||||
const rail = page.getByTestId("prompt-rail-scroll");
|
||||
const body = page.getByTestId("thread-message-region");
|
||||
await expect(rail).toBeVisible();
|
||||
// Center against the complete chat pane, not the rail's own (possibly shifted) box.
|
||||
const expectRailCentered = async () => {
|
||||
const pane = await page.getByRole("region", { name: "Workbench", exact: true }).boundingBox();
|
||||
const bounds = await rail.boundingBox();
|
||||
expect(Math.abs(bounds!.y + bounds!.height / 2 - (pane!.y + pane!.height / 2))).toBeLessThan(2);
|
||||
};
|
||||
await expectRailCentered();
|
||||
await expect.poll(() => rail.evaluate((node) => node.scrollHeight)).toBe(32024);
|
||||
expect(reads).toHaveLength(0);
|
||||
// Lazy markdown and content-visibility can change the scroll range during startup.
|
||||
@@ -64,11 +71,28 @@ test("complete rail scrolls independently, jumps to unloaded history and returns
|
||||
expect(await rail.evaluate((node) => getComputedStyle(node).maskImage)).toContain("linear-gradient");
|
||||
await page.screenshot({ path: "test-results/prompt-rail-long.png" });
|
||||
// Short lists remain centered in the same viewport-relative space.
|
||||
await page.goto("/browser/fixture.html?case=rail&short=1");
|
||||
await page.goto("/browser/fixture.html?case=rail&short=1&workbench=1");
|
||||
const markers = page.getByTestId("prompt-rail-marker");
|
||||
await expect(markers).toHaveCount(5);
|
||||
const bounds = await rail.boundingBox();
|
||||
await expectRailCentered();
|
||||
const bounds = await page.getByRole("region", { name: "Workbench", exact: true }).boundingBox();
|
||||
const middle = await markers.nth(2).boundingBox();
|
||||
expect(Math.abs(middle!.y + middle!.height / 2 - (bounds!.y + bounds!.height / 2))).toBeLessThan(2);
|
||||
await page.screenshot({ path: "test-results/prompt-rail-short.png" });
|
||||
// A taller composer in a shorter window must not push navigation above center.
|
||||
await page.setViewportSize({ width: 1440, height: 640 });
|
||||
await page.goto("/browser/fixture.html?case=rail&short=1&tall-composer=1&workbench=1");
|
||||
await expect(markers).toHaveCount(5);
|
||||
await expectRailCentered();
|
||||
const shortBounds = await page.getByRole("region", { name: "Workbench", exact: true }).boundingBox();
|
||||
const shortMiddle = await markers.nth(2).boundingBox();
|
||||
expect(Math.abs(shortMiddle!.y + shortMiddle!.height / 2 - (shortBounds!.y + shortBounds!.height / 2))).toBeLessThan(2);
|
||||
await expect(markers.first()).toBeInViewport();
|
||||
await expect(markers.last()).toBeInViewport();
|
||||
await page.setViewportSize({ width: 800, height: 900 });
|
||||
await page.goto("/browser/fixture.html?case=rail&short=1&workbench=1");
|
||||
await expect(rail).not.toBeVisible();
|
||||
await page.setViewportSize({ width: 1440, height: 900 });
|
||||
await expect(rail).toBeVisible();
|
||||
await expectRailCentered();
|
||||
});
|
||||
Reference in new issue
Block a user