fix(layout): address PR review — narrow viewport, hidden sidebar, e2e flake
Bot-review fixups for #1005: - caps: bound runtime caps by `viewport - VIEWPORT_RESERVE_PX` so the 800px right-cap floor can't collapse the center column on narrow screens (Cubic P1). - applier: respect `column.maxWidth` on the sidebar too, so the `compact` preset's 260px cap is honored at runtime (Cubic P2). - dockview-store: skip the pinned-defaults mirror when the column is hidden — auto-sync infers sidebar from grid index 0, which is the center when sidebar is hidden, so an unguarded mirror would persist the center's width as the sidebar's (Greptile/Cubic P1). - trackPinnedWidths: gate the auto-sync on `sidebarVisible` / `rightPanelsVisible` for the same reason. - sizing: use `LAYOUT_RIGHT_RATIO` for non-sidebar columns instead of silently reusing the sidebar ratio (Greptile P2). - e2e: tablet viewport bumped from 1024 → 700 (≥1024 is desktop, not tablet — the old viewport never rendered the tablet layout and every assertion timed out). Tests now also verify rendered panel proportions, not just the localStorage echo (CodeRabbit #2/#3). - e2e helpers: throw on missing `.dv-sash` instead of returning `-1` (CodeRabbit #1); shared `openWideTask` extracted from three spec files (CodeRabbit #5); silent `return` in evaluate blocks replaced with `throw` for fail-fast (CodeRabbit #4).
This commit is contained in:
@@ -41,25 +41,36 @@ function applyDynamicConstraints(api: DockviewReadyEvent["api"]): void {
|
||||
}
|
||||
|
||||
function trackPinnedWidths(api: DockviewReadyEvent["api"]): void {
|
||||
if (useDockviewStore.getState().isRestoringLayout) return;
|
||||
if (api.hasMaximizedGroup() || useDockviewStore.getState().preMaximizeLayout !== null) return;
|
||||
const store = useDockviewStore.getState();
|
||||
if (store.isRestoringLayout) return;
|
||||
if (api.hasMaximizedGroup() || store.preMaximizeLayout !== null) return;
|
||||
const sv = getRootSplitview(api);
|
||||
if (!sv || sv.length < 2) return;
|
||||
try {
|
||||
const sidebarW = sv.getViewSize(0);
|
||||
if (sidebarW > 50) {
|
||||
const current = useDockviewStore.getState().pinnedWidths.get("sidebar");
|
||||
if (current !== sidebarW) {
|
||||
useDockviewStore.getState().setPinnedWidth("sidebar", sidebarW);
|
||||
// Sidebar is grid index 0 *only when sidebar is visible*. Without the
|
||||
// visibility guard, hiding the sidebar makes index 0 the center column,
|
||||
// and we'd persist the center width as the sidebar's preferred width.
|
||||
if (store.sidebarVisible) {
|
||||
const sidebarW = sv.getViewSize(0);
|
||||
if (sidebarW > 50) {
|
||||
const current = store.pinnedWidths.get("sidebar");
|
||||
if (current !== sidebarW) {
|
||||
store.setPinnedWidth("sidebar", sidebarW);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sv.length >= 3) {
|
||||
// Right column is the last grid index when present. Skip when there is
|
||||
// no right column (compact preset, sv.length < 2 after sidebar check,
|
||||
// or rightPanelsVisible=false).
|
||||
if (store.rightPanelsVisible) {
|
||||
const rightIdx = sv.length - 1;
|
||||
// Same index as sidebar when sv.length == 1 (degenerate) — bail.
|
||||
if (rightIdx === 0 && store.sidebarVisible) return;
|
||||
const rightW = sv.getViewSize(rightIdx);
|
||||
if (rightW > 50) {
|
||||
const current = useDockviewStore.getState().pinnedWidths.get("right");
|
||||
const current = store.pinnedWidths.get("right");
|
||||
if (current !== rightW) {
|
||||
useDockviewStore.getState().setPinnedWidth("right", rightW);
|
||||
store.setPinnedWidth("right", rightW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,41 @@
|
||||
import { expect, type Page } from "@playwright/test";
|
||||
import type { SeedData } from "../fixtures/test-base";
|
||||
import type { ApiClient } from "../helpers/api-client";
|
||||
import { SessionPage } from "../pages/session-page";
|
||||
|
||||
/** Bounding-box info Playwright returns. Re-declared to avoid pulling the
|
||||
* full Locator type just for one shape. */
|
||||
type Box = { x: number; y: number; width: number; height: number };
|
||||
|
||||
export const WIDE_VIEWPORT = { width: 1600, height: 900 };
|
||||
|
||||
/** Open a fresh task at the wide viewport and wait for the desktop dockview
|
||||
* layout to settle. Shared by every pane-resize spec. */
|
||||
export async function openWideTask(
|
||||
page: Page,
|
||||
apiClient: ApiClient,
|
||||
seedData: SeedData,
|
||||
title: string,
|
||||
): Promise<SessionPage> {
|
||||
await page.setViewportSize(WIDE_VIEWPORT);
|
||||
const task = await apiClient.createTaskWithAgent(
|
||||
seedData.workspaceId,
|
||||
title,
|
||||
seedData.agentProfileId,
|
||||
{
|
||||
description: "/e2e:simple-message",
|
||||
workflow_id: seedData.workflowId,
|
||||
workflow_step_id: seedData.startStepId,
|
||||
repository_ids: [seedData.repositoryId],
|
||||
},
|
||||
);
|
||||
await page.goto(`/t/${task.id}`);
|
||||
const session = new SessionPage(page);
|
||||
await session.waitForLoad();
|
||||
await session.waitForDockviewReady();
|
||||
return session;
|
||||
}
|
||||
|
||||
/** Read the live pixel width of a dockview group containing a given panel. */
|
||||
export async function getDockviewGroupWidth(page: Page, panelId: string): Promise<number> {
|
||||
return page.evaluate((id) => {
|
||||
@@ -46,7 +78,7 @@ async function sashBoxAt(page: Page, index: number): Promise<Box> {
|
||||
/**
|
||||
* Drag a horizontal-direction sash (between two columns) by deltaX pixels.
|
||||
* sashIndex is the dockview sash order (0 = left-most). Uses many small mouse
|
||||
* moves so dockview's drag listener fires through-out the drag, mirroring real
|
||||
* moves so dockview's drag listener fires throughout the drag, mirroring real
|
||||
* user motion.
|
||||
*/
|
||||
export async function dragHorizontalSash(
|
||||
@@ -75,7 +107,9 @@ export async function dragHorizontalSash(
|
||||
export async function getColumnSashIndex(page: Page, column: "sidebar" | "right"): Promise<number> {
|
||||
if (column === "sidebar") return 0;
|
||||
return page.evaluate(() => {
|
||||
return document.querySelectorAll(".dv-sash").length - 1;
|
||||
const count = document.querySelectorAll(".dv-sash").length;
|
||||
if (count === 0) throw new Error("no .dv-sash elements found");
|
||||
return count - 1;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { type Page } from "@playwright/test";
|
||||
import { type Page, expect as pwExpect } from "@playwright/test";
|
||||
import { test, expect } from "../../fixtures/test-base";
|
||||
import type { SeedData } from "../../fixtures/test-base";
|
||||
import type { ApiClient } from "../../helpers/api-client";
|
||||
import { SessionPage } from "../../pages/session-page";
|
||||
|
||||
const TABLET_VIEWPORT = { width: 1024, height: 800 };
|
||||
// The responsive breakpoint logic treats width < 768 with fine pointer as
|
||||
// "tablet"; width >= 768 with fine pointer is compactDesktop. Headless
|
||||
// Chromium reports fine pointer, so a true tablet layout needs width < 768.
|
||||
const TABLET_VIEWPORT = { width: 700, height: 900 };
|
||||
|
||||
async function openTabletTask(
|
||||
page: Page,
|
||||
@@ -31,15 +34,22 @@ async function openTabletTask(
|
||||
return session;
|
||||
}
|
||||
|
||||
async function readStoredLayout(page: Page, id: string): Promise<unknown | null> {
|
||||
async function readStoredLayout(page: Page, id: string): Promise<Record<string, number> | null> {
|
||||
return page.evaluate((key) => {
|
||||
const raw = window.localStorage.getItem(key);
|
||||
return raw ? JSON.parse(raw) : null;
|
||||
return raw ? (JSON.parse(raw) as Record<string, number>) : null;
|
||||
}, id);
|
||||
}
|
||||
|
||||
async function readPanelWidth(page: Page, panelId: string): Promise<number> {
|
||||
return page.evaluate((id) => {
|
||||
const el = document.querySelector(`[data-panel-id="${id}"]`);
|
||||
return el ? Math.round(el.getBoundingClientRect().width) : 0;
|
||||
}, panelId);
|
||||
}
|
||||
|
||||
test.describe("Tablet pane persistence", () => {
|
||||
test("tablet left/right split persists to localStorage", async ({
|
||||
test("tablet left/right split persists across reload", async ({
|
||||
testPage,
|
||||
apiClient,
|
||||
seedData,
|
||||
@@ -49,39 +59,55 @@ test.describe("Tablet pane persistence", () => {
|
||||
// Drive the resize-panels library directly by overwriting the stored
|
||||
// layout — the underlying drag handle is a complex pointer-events target
|
||||
// that's flaky to grab in headless. The stored layout drives the next
|
||||
// render; this test verifies the round-trip persistence contract.
|
||||
// render; this test verifies the round-trip persistence contract AND
|
||||
// that the rendered panels match the stored proportions.
|
||||
await testPage.evaluate(() => {
|
||||
window.localStorage.setItem("task-layout-tablet-v1", JSON.stringify({ left: 70, right: 30 }));
|
||||
window.localStorage.setItem("task-layout-tablet-v1", JSON.stringify({ left: 65, right: 35 }));
|
||||
});
|
||||
await testPage.reload();
|
||||
await session.waitForLoad();
|
||||
await expect(testPage.getByTestId("tablet-task-layout")).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
const stored = (await readStoredLayout(testPage, "task-layout-tablet-v1")) as Record<
|
||||
string,
|
||||
number
|
||||
>;
|
||||
expect(stored.left).toBe(70);
|
||||
expect(stored.right).toBe(30);
|
||||
// localStorage round-trip: react-resizable-panels writes its own
|
||||
// normalized version on layout, so allow a small tolerance.
|
||||
const stored = await readStoredLayout(testPage, "task-layout-tablet-v1");
|
||||
pwExpect(stored).not.toBeNull();
|
||||
pwExpect(Math.abs((stored?.left ?? 0) - 65)).toBeLessThanOrEqual(2);
|
||||
pwExpect(Math.abs((stored?.right ?? 0) - 35)).toBeLessThanOrEqual(2);
|
||||
|
||||
// Rendered widths should match the stored proportions (verifies the
|
||||
// app actually applied the stored layout, not just echoed localStorage).
|
||||
const leftWidth = await readPanelWidth(testPage, "left");
|
||||
const rightWidth = await readPanelWidth(testPage, "right");
|
||||
const totalWidth = leftWidth + rightWidth;
|
||||
pwExpect(totalWidth).toBeGreaterThan(0);
|
||||
const leftPct = (leftWidth / totalWidth) * 100;
|
||||
pwExpect(Math.abs(leftPct - 65)).toBeLessThanOrEqual(4);
|
||||
});
|
||||
|
||||
test("invalid stored layout falls back to default", async ({ testPage, apiClient, seedData }) => {
|
||||
test("invalid stored layout is replaced with a valid default", async ({
|
||||
testPage,
|
||||
apiClient,
|
||||
seedData,
|
||||
}) => {
|
||||
await testPage.setViewportSize(TABLET_VIEWPORT);
|
||||
await testPage.goto("/");
|
||||
await testPage.evaluate(() => {
|
||||
window.localStorage.setItem("task-layout-tablet-v1", '{"left":2}');
|
||||
});
|
||||
const session = await openTabletTask(testPage, apiClient, seedData, "Tablet fallback");
|
||||
await expect(testPage.getByTestId("tablet-task-layout")).toBeVisible();
|
||||
|
||||
// Default layout still renders both panels — the broken stored layout
|
||||
// is rejected by `isLayoutValid` (panel "right" is missing) and the
|
||||
// base layout takes over.
|
||||
const tabletLayout = testPage.getByTestId("tablet-task-layout");
|
||||
await expect(tabletLayout).toBeVisible();
|
||||
void session;
|
||||
|
||||
// After load, onLayoutChanged replaces the invalid stub with the
|
||||
// rendered (valid) layout. Verify the persisted value is now valid:
|
||||
// both panel IDs present and >= MIN_PANEL_PERCENT (5).
|
||||
const stored = await readStoredLayout(testPage, "task-layout-tablet-v1");
|
||||
pwExpect(stored).not.toBeNull();
|
||||
pwExpect(stored?.left).toBeGreaterThanOrEqual(5);
|
||||
pwExpect(stored?.right).toBeGreaterThanOrEqual(5);
|
||||
});
|
||||
|
||||
test("tablet right-panel top/bottom shrinks below the old 30% floor", async ({
|
||||
test("tablet right-panel inner split accepts values below the old 30% floor", async ({
|
||||
testPage,
|
||||
apiClient,
|
||||
seedData,
|
||||
@@ -89,19 +115,17 @@ test.describe("Tablet pane persistence", () => {
|
||||
await openTabletTask(testPage, apiClient, seedData, "Tablet top shrink");
|
||||
|
||||
// The right-panel internal split now allows minSize=15. Round-trip via
|
||||
// localStorage: write a 20/80 layout (below the old 30% floor), reload,
|
||||
// assert the layout was accepted (would have been rejected before).
|
||||
// localStorage: write a 20/80 layout (below the old 30% floor) and
|
||||
// verify it survives the reload — would have been rejected before.
|
||||
await testPage.evaluate(() => {
|
||||
window.localStorage.setItem("task-layout-right-v2", JSON.stringify({ top: 20, bottom: 80 }));
|
||||
});
|
||||
await testPage.reload();
|
||||
await expect(testPage.getByTestId("tablet-task-layout")).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
const stored = (await readStoredLayout(testPage, "task-layout-right-v2")) as Record<
|
||||
string,
|
||||
number
|
||||
>;
|
||||
expect(stored.top).toBe(20);
|
||||
expect(stored.bottom).toBe(80);
|
||||
const stored = await readStoredLayout(testPage, "task-layout-right-v2");
|
||||
pwExpect(stored).not.toBeNull();
|
||||
pwExpect(Math.abs((stored?.top ?? 0) - 20)).toBeLessThanOrEqual(2);
|
||||
pwExpect(Math.abs((stored?.bottom ?? 0) - 80)).toBeLessThanOrEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,42 +1,13 @@
|
||||
import { type Page } from "@playwright/test";
|
||||
import { test, expect } from "../../fixtures/test-base";
|
||||
import type { SeedData } from "../../fixtures/test-base";
|
||||
import type { ApiClient } from "../../helpers/api-client";
|
||||
import { SessionPage } from "../../pages/session-page";
|
||||
import {
|
||||
WIDE_VIEWPORT,
|
||||
openWideTask,
|
||||
dragHorizontalSash,
|
||||
expectApproxWidth,
|
||||
getColumnSashIndex,
|
||||
getDockviewGroupWidth,
|
||||
} from "../../helpers/dockview-resize";
|
||||
|
||||
const WIDE_VIEWPORT = { width: 1600, height: 900 };
|
||||
|
||||
async function openWideTask(
|
||||
page: Page,
|
||||
apiClient: ApiClient,
|
||||
seedData: SeedData,
|
||||
title: string,
|
||||
): Promise<SessionPage> {
|
||||
await page.setViewportSize(WIDE_VIEWPORT);
|
||||
const task = await apiClient.createTaskWithAgent(
|
||||
seedData.workspaceId,
|
||||
title,
|
||||
seedData.agentProfileId,
|
||||
{
|
||||
description: "/e2e:simple-message",
|
||||
workflow_id: seedData.workflowId,
|
||||
workflow_step_id: seedData.startStepId,
|
||||
repository_ids: [seedData.repositoryId],
|
||||
},
|
||||
);
|
||||
await page.goto(`/t/${task.id}`);
|
||||
const session = new SessionPage(page);
|
||||
await session.waitForLoad();
|
||||
await session.waitForDockviewReady();
|
||||
return session;
|
||||
}
|
||||
|
||||
test.describe("Pane resize edge cases", () => {
|
||||
test("double-click on sidebar sash does not crash dockview", async ({
|
||||
testPage,
|
||||
@@ -84,23 +55,14 @@ test.describe("Pane resize edge cases", () => {
|
||||
// Maximize the files group, then exit. The pre-maximize layout is the
|
||||
// source of truth; the new cap should not have squashed it.
|
||||
await testPage.evaluate(() => {
|
||||
type Group = { id: string; panels: { id: string }[] };
|
||||
type Api = { groups: Group[] };
|
||||
const fileWindow = window as unknown as {
|
||||
__dockviewApi__?: Api;
|
||||
__testMaximize__?: (gid: string) => void;
|
||||
};
|
||||
const api = fileWindow.__dockviewApi__;
|
||||
if (!api) return;
|
||||
const group = api.groups.find((g) => g.panels.some((p) => p.id === "files"));
|
||||
if (!group) return;
|
||||
// Use the store action via the keyboard shortcut path is brittle; just
|
||||
// call the API's own maximize for the smoke check.
|
||||
type GroupApi = { maximize: () => void };
|
||||
type ApiWithMax = { groups: (Group & { api: GroupApi })[] };
|
||||
const apiMax = fileWindow.__dockviewApi__ as unknown as ApiWithMax;
|
||||
const matching = apiMax.groups.find((g) => g.panels.some((p) => p.id === "files"));
|
||||
matching?.api.maximize();
|
||||
type Group = { id: string; panels: { id: string }[]; api: GroupApi };
|
||||
type Api = { groups: Group[] };
|
||||
const api = (window as unknown as { __dockviewApi__?: Api }).__dockviewApi__;
|
||||
if (!api) throw new Error("dockview api not exposed");
|
||||
const matching = api.groups.find((g) => g.panels.some((p) => p.id === "files"));
|
||||
if (!matching) throw new Error("files group not found");
|
||||
matching.api.maximize();
|
||||
});
|
||||
await testPage.waitForTimeout(150);
|
||||
await testPage.evaluate(() => {
|
||||
@@ -108,8 +70,10 @@ test.describe("Pane resize edge cases", () => {
|
||||
type Group = { id: string; panels: { id: string }[]; api: GroupApi };
|
||||
type Api = { groups: Group[] };
|
||||
const api = (window as unknown as { __dockviewApi__?: Api }).__dockviewApi__;
|
||||
const matching = api?.groups.find((g) => g.panels.some((p) => p.id === "files"));
|
||||
matching?.api.exitMaximized();
|
||||
if (!api) throw new Error("dockview api not exposed");
|
||||
const matching = api.groups.find((g) => g.panels.some((p) => p.id === "files"));
|
||||
if (!matching) throw new Error("files group not found");
|
||||
matching.api.exitMaximized();
|
||||
});
|
||||
await session.waitForDockviewReady();
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { type Page } from "@playwright/test";
|
||||
import { test, expect } from "../../fixtures/test-base";
|
||||
import type { SeedData } from "../../fixtures/test-base";
|
||||
import type { ApiClient } from "../../helpers/api-client";
|
||||
import { SessionPage } from "../../pages/session-page";
|
||||
import {
|
||||
WIDE_VIEWPORT,
|
||||
openWideTask,
|
||||
dragHorizontalSash,
|
||||
expectApproxWidth,
|
||||
getColumnSashIndex,
|
||||
@@ -11,33 +10,6 @@ import {
|
||||
readPinnedDefaultsFromStorage,
|
||||
} from "../../helpers/dockview-resize";
|
||||
|
||||
const WIDE_VIEWPORT = { width: 1600, height: 900 };
|
||||
|
||||
async function openWideTask(
|
||||
page: Page,
|
||||
apiClient: ApiClient,
|
||||
seedData: SeedData,
|
||||
title: string,
|
||||
): Promise<SessionPage> {
|
||||
await page.setViewportSize(WIDE_VIEWPORT);
|
||||
const task = await apiClient.createTaskWithAgent(
|
||||
seedData.workspaceId,
|
||||
title,
|
||||
seedData.agentProfileId,
|
||||
{
|
||||
description: "/e2e:simple-message",
|
||||
workflow_id: seedData.workflowId,
|
||||
workflow_step_id: seedData.startStepId,
|
||||
repository_ids: [seedData.repositoryId],
|
||||
},
|
||||
);
|
||||
await page.goto(`/t/${task.id}`);
|
||||
const session = new SessionPage(page);
|
||||
await session.waitForLoad();
|
||||
await session.waitForDockviewReady();
|
||||
return session;
|
||||
}
|
||||
|
||||
test.describe("Right pane resize — viewport-proportional cap", () => {
|
||||
test("resizes past the old 450px hard cap", async ({ testPage, apiClient, seedData }) => {
|
||||
await openWideTask(testPage, apiClient, seedData, "Right resize past old cap");
|
||||
|
||||
@@ -1,42 +1,13 @@
|
||||
import { type Page } from "@playwright/test";
|
||||
import { test, expect } from "../../fixtures/test-base";
|
||||
import type { SeedData } from "../../fixtures/test-base";
|
||||
import type { ApiClient } from "../../helpers/api-client";
|
||||
import { SessionPage } from "../../pages/session-page";
|
||||
import {
|
||||
openWideTask,
|
||||
dragHorizontalSash,
|
||||
expectApproxWidth,
|
||||
getColumnSashIndex,
|
||||
getDockviewGroupWidth,
|
||||
} from "../../helpers/dockview-resize";
|
||||
|
||||
const WIDE_VIEWPORT = { width: 1600, height: 900 };
|
||||
|
||||
async function openWideTask(
|
||||
page: Page,
|
||||
apiClient: ApiClient,
|
||||
seedData: SeedData,
|
||||
title: string,
|
||||
): Promise<SessionPage> {
|
||||
await page.setViewportSize(WIDE_VIEWPORT);
|
||||
const task = await apiClient.createTaskWithAgent(
|
||||
seedData.workspaceId,
|
||||
title,
|
||||
seedData.agentProfileId,
|
||||
{
|
||||
description: "/e2e:simple-message",
|
||||
workflow_id: seedData.workflowId,
|
||||
workflow_step_id: seedData.startStepId,
|
||||
repository_ids: [seedData.repositoryId],
|
||||
},
|
||||
);
|
||||
await page.goto(`/t/${task.id}`);
|
||||
const session = new SessionPage(page);
|
||||
await session.waitForLoad();
|
||||
await session.waitForDockviewReady();
|
||||
return session;
|
||||
}
|
||||
|
||||
test.describe("Sidebar resize — viewport-proportional cap", () => {
|
||||
test("resizes past the old 350px hard cap", async ({ testPage, apiClient, seedData }) => {
|
||||
await openWideTask(testPage, apiClient, seedData, "Sidebar past cap");
|
||||
|
||||
@@ -786,10 +786,17 @@ export const useDockviewStore = create<DockviewStore>((set, get) => ({
|
||||
// Mirror sidebar / right widths into sessionStorage so brand-new envs
|
||||
// (no saved per-env layout yet) open at the user's preferred widths
|
||||
// instead of the ratio-based default.
|
||||
if (columnId === "sidebar" || columnId === "right") {
|
||||
const current = getPinnedDefaults();
|
||||
setPinnedDefaults({ ...current, [columnId]: width });
|
||||
}
|
||||
//
|
||||
// Skip when the column is hidden — auto-sync infers the sidebar slot
|
||||
// from grid index 0, which is the *center* column when the sidebar is
|
||||
// hidden. Without this guard, a center-column resize would overwrite
|
||||
// the user's stored sidebar width.
|
||||
if (columnId !== "sidebar" && columnId !== "right") return;
|
||||
const live = get();
|
||||
const visible = columnId === "sidebar" ? live.sidebarVisible : live.rightPanelsVisible;
|
||||
if (!visible) return;
|
||||
const current = getPinnedDefaults();
|
||||
setPinnedDefaults({ ...current, [columnId]: width });
|
||||
},
|
||||
userDefaultLayout: null,
|
||||
setUserDefaultLayout: (layout) => set({ userDefaultLayout: layout }),
|
||||
|
||||
@@ -73,12 +73,16 @@ export function applyLayout(
|
||||
|
||||
// Lock sidebar group and enforce max/min-width constraints.
|
||||
// Constraints are not serialized with layouts, so we must reapply after fromJSON.
|
||||
// column.maxWidth wins so presets like `compact` (maxWidth=260) keep their
|
||||
// tight cap; otherwise inherit the runtime sidebar cap.
|
||||
const sidebarCol = state.columns.find((c) => c.id === "sidebar");
|
||||
const sidebarCap = sidebarCol?.maxWidth ?? computePinnedMaxPxFor("sidebar");
|
||||
const sb = api.getPanel("sidebar");
|
||||
if (sb) {
|
||||
sb.group.locked = SIDEBAR_LOCK;
|
||||
sb.group.header.hidden = false;
|
||||
sb.group.api.setConstraints({
|
||||
maximumWidth: computePinnedMaxPxFor("sidebar"),
|
||||
maximumWidth: sidebarCap,
|
||||
minimumWidth: LAYOUT_PINNED_MIN_PX,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ describe("computeSidebarMaxPx", () => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("floors at 350px on narrow viewports", () => {
|
||||
expect(computeSidebarMaxPx(800)).toBe(350);
|
||||
expect(computeSidebarMaxPx(100)).toBe(350);
|
||||
it("hits the 350px floor on roomy viewports", () => {
|
||||
// vw=1000 → 30%=300 < floor 350; viewport reserve = 700 (plenty).
|
||||
expect(computeSidebarMaxPx(1000)).toBe(350);
|
||||
});
|
||||
|
||||
it("scales to viewport * 0.3 above the floor", () => {
|
||||
@@ -21,9 +21,17 @@ describe("computeSidebarMaxPx", () => {
|
||||
expect(computeSidebarMaxPx(3000)).toBe(900);
|
||||
});
|
||||
|
||||
it("never exceeds viewport - reserve so the center column survives", () => {
|
||||
// vw=500 → 30%=150 < floor 350; viewport reserve = 200. So 350 clamps to 200.
|
||||
// floor below LAYOUT_PINNED_MIN_PX is also enforced.
|
||||
expect(computeSidebarMaxPx(500)).toBeLessThanOrEqual(500 - 300);
|
||||
expect(computeSidebarMaxPx(500)).toBeGreaterThanOrEqual(LAYOUT_PINNED_MIN_PX);
|
||||
});
|
||||
|
||||
it("uses 1440 fallback when window is undefined", () => {
|
||||
vi.stubGlobal("window", undefined);
|
||||
expect(computeSidebarMaxPx()).toBe(Math.round(1440 * 0.3));
|
||||
// vw=1440 → 30%=432 > floor 350.
|
||||
expect(computeSidebarMaxPx()).toBe(432);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -32,16 +40,22 @@ describe("computeRightMaxPx", () => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it("floors at 800px on narrow viewports", () => {
|
||||
expect(computeRightMaxPx(1024)).toBe(800);
|
||||
expect(computeRightMaxPx(100)).toBe(800);
|
||||
it("hits the 800px floor on mid viewports", () => {
|
||||
// vw=1024 → 70%=716 < floor 800; viewport reserve = 724. Clamp 800 → 724.
|
||||
// (The viewport reserve protects narrow screens from over-allocation.)
|
||||
expect(computeRightMaxPx(1024)).toBeLessThan(800);
|
||||
});
|
||||
|
||||
it("scales to viewport * 0.7 above the floor", () => {
|
||||
it("scales to viewport * 0.7 above the floor on roomy viewports", () => {
|
||||
expect(computeRightMaxPx(2000)).toBe(1400);
|
||||
expect(computeRightMaxPx(3000)).toBe(2100);
|
||||
});
|
||||
|
||||
it("never collapses the center column on narrow viewports", () => {
|
||||
// vw=900 → 70%=630 < floor 800; reserve 300 → viewport bound 600.
|
||||
expect(computeRightMaxPx(900)).toBe(600);
|
||||
});
|
||||
|
||||
it("reads window.innerWidth when no argument passed", () => {
|
||||
vi.stubGlobal("window", { innerWidth: 1800 } as Window);
|
||||
expect(computeRightMaxPx()).toBe(Math.round(1800 * 0.7));
|
||||
|
||||
@@ -18,18 +18,35 @@ const SIDEBAR_FLOOR_PX = 350;
|
||||
const RIGHT_RATIO = 0.7;
|
||||
const RIGHT_FLOOR_PX = 800;
|
||||
|
||||
/** Pixels reserved for the center column + opposite pinned column so the cap
|
||||
* never grows past `viewport - VIEWPORT_RESERVE_PX`. Without this, an 800px
|
||||
* right-cap floor on a 900px viewport would collapse the center to 0. */
|
||||
const VIEWPORT_RESERVE_PX = 300;
|
||||
|
||||
/** Minimum pixel width for any pinned column. Below this the panel becomes
|
||||
* unusable (icons clipped, scrollbars stacked). */
|
||||
export const LAYOUT_PINNED_MIN_PX = 180;
|
||||
|
||||
function getViewport(viewportWidth?: number): number {
|
||||
return viewportWidth ?? (typeof window !== "undefined" ? window.innerWidth : FALLBACK_VIEWPORT);
|
||||
}
|
||||
|
||||
/** Sidebar max width: max(350, viewportWidth * 0.3). */
|
||||
export function computeSidebarMaxPx(viewportWidth?: number): number {
|
||||
return Math.max(SIDEBAR_FLOOR_PX, Math.round(getViewport(viewportWidth) * SIDEBAR_RATIO));
|
||||
function viewportBound(value: number, viewportWidth: number): number {
|
||||
// Always leave at least `VIEWPORT_RESERVE_PX` for the rest of the layout,
|
||||
// and never go below the per-column min — even on absurdly narrow viewports.
|
||||
return Math.max(LAYOUT_PINNED_MIN_PX, Math.min(value, viewportWidth - VIEWPORT_RESERVE_PX));
|
||||
}
|
||||
|
||||
/** Right pane max width: max(800, viewportWidth * 0.7). */
|
||||
/** Sidebar max width: max(350, viewportWidth * 0.3), bounded by viewport. */
|
||||
export function computeSidebarMaxPx(viewportWidth?: number): number {
|
||||
const vw = getViewport(viewportWidth);
|
||||
return viewportBound(Math.max(SIDEBAR_FLOOR_PX, Math.round(vw * SIDEBAR_RATIO)), vw);
|
||||
}
|
||||
|
||||
/** Right pane max width: max(800, viewportWidth * 0.7), bounded by viewport. */
|
||||
export function computeRightMaxPx(viewportWidth?: number): number {
|
||||
return Math.max(RIGHT_FLOOR_PX, Math.round(getViewport(viewportWidth) * RIGHT_RATIO));
|
||||
const vw = getViewport(viewportWidth);
|
||||
return viewportBound(Math.max(RIGHT_FLOOR_PX, Math.round(vw * RIGHT_RATIO)), vw);
|
||||
}
|
||||
|
||||
/** Pick the runtime cap appropriate for a given column ID. Non-sidebar
|
||||
@@ -39,7 +56,3 @@ export function computePinnedMaxPxFor(columnId: string, viewportWidth?: number):
|
||||
? computeSidebarMaxPx(viewportWidth)
|
||||
: computeRightMaxPx(viewportWidth);
|
||||
}
|
||||
|
||||
/** Minimum pixel width for any pinned column. Below this the panel becomes
|
||||
* unusable (icons clipped, scrollbars stacked). */
|
||||
export const LAYOUT_PINNED_MIN_PX = 180;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { LayoutColumn, LayoutGroup } from "./types";
|
||||
import { LAYOUT_SIDEBAR_RATIO } from "./constants";
|
||||
import { LAYOUT_SIDEBAR_RATIO, LAYOUT_RIGHT_RATIO } from "./constants";
|
||||
import { computePinnedMaxPxFor, LAYOUT_PINNED_MIN_PX } from "./caps";
|
||||
|
||||
// Legacy hard caps used to clamp the *initial* default width. Users can still
|
||||
@@ -27,7 +27,8 @@ export function getPinnedWidth(
|
||||
if (override !== undefined) {
|
||||
return Math.max(min, Math.min(override, runtimeMax));
|
||||
}
|
||||
const ratioWidth = Math.round(totalWidth * LAYOUT_SIDEBAR_RATIO);
|
||||
const ratio = column.id === "sidebar" ? LAYOUT_SIDEBAR_RATIO : LAYOUT_RIGHT_RATIO;
|
||||
const ratioWidth = Math.round(totalWidth * ratio);
|
||||
const initialCap =
|
||||
column.maxWidth ??
|
||||
(column.id === "sidebar" ? LEGACY_SIDEBAR_INITIAL_CAP : LEGACY_RIGHT_INITIAL_CAP);
|
||||
|
||||
Reference in New Issue
Block a user