From c1361fde8382e8b1fb9781b4fd468a0ceef89b09 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Thu, 15 Oct 2026 11:13:21 +0000 Subject: [PATCH 1/3] fix(ui): keep the Ask button off the page's buttons The floating Ask button sat on whatever was in the bottom-right corner, such as Import on the Import page. It now finds what it would cover with the browser's own hit testing (a transparent probe just under it) and rises above any control there that scrolling can't carry clear: one in a bar fixed or stuck to the bottom, or with the page at its end. With no room to rise it steps out of sight. Dialogs, drawers and toasts drawn over it don't move it. The clicks survey now fails a journey whose control the Ask button covers, and checks every page scrolled to its end for controls under it. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01KaZgCPYVesfDJhLzGCKJXX --- CHANGELOG.md | 6 + ci/clicks/README.md | 9 +- ci/clicks/meter.mjs | 13 +- ci/clicks/report.mjs | 5 + ci/clicks/survey.mjs | 38 +++- docs/assistant.md | 4 +- docs/frontend.md | 8 +- nextjs-frontend/__tests__/ask-place.test.tsx | 197 ++++++++++++++++ .../components/page-chat/ask-place.ts | 215 ++++++++++++++++++ .../components/page-chat/page-chat.tsx | 43 +++- 10 files changed, 517 insertions(+), 21 deletions(-) create mode 100644 nextjs-frontend/__tests__/ask-place.test.tsx create mode 100644 nextjs-frontend/components/page-chat/ask-place.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d7513f7c..d6d369ef9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ The backend (`fastapi_backend`) and the frontend (`nextjs-frontend`) are version ## Unreleased +- **The Ask button no longer covers buttons.** The floating Ask button at the bottom right used to sit on whatever was + there, such as Import on the Import page. Now, when a button or field is under it and scrolling can't move it clear + (a row of buttons pinned to the bottom of the screen, or the last button on a page scrolled to its end), the Ask + button rises above it, and steps out of sight when there's no room to rise. Dialogs, drawers and toasts drawn over + it don't move it. The clicks survey now fails a journey whose control the Ask button covers, and checks every page + for it ([Chat on any page](docs/assistant.md)). - **The assistant always answers.** When a question used up its tool steps (`ai.max_steps`), the assistant used to stop with "I ran out of steps before finishing". Now it's asked to answer from what it found, with the tools off, and says what it didn't get to check; a reply with nothing in it is asked again the same way. It also knows its step budget up diff --git a/ci/clicks/README.md b/ci/clicks/README.md index 943ed2a92..cb2b5dac1 100644 --- a/ci/clicks/README.md +++ b/ci/clicks/README.md @@ -32,10 +32,13 @@ rclone must be on the PATH, as it is in the Lens image (the Clicks workflow copi navigation). - **Outside the browser**: steps in the terminal, the assistant being connected or the browser's print dialog are counted on the page `(outside the browser)`. -- A step whose control is covered by something else (the floating Ask button) is still one click, marked - "covered" in the steps. +- A step whose control is covered by something else (a toast) is still one click, marked "covered" in the steps. A + control the floating Ask button covers fails the journey: the button rises above controls in its corner, or steps + aside, so that's a bug. - **Per page**: reach is clicks from Home through the sidebar (sections and tabs are two); controls are the buttons, - links and fields in the page's main area on a fresh install, not counting navigation. + links and fields in the page's main area on a fresh install, not counting navigation. Each page is also scrolled to + its end and checked for controls the floating Ask button lies over; any fails the run ("Covered by the Ask button" + in the results). Journeys run in order on the same Lens, each from Home unless it continues the one before (setup does). A journey that can't be done at all (on a phone, say, where a control is hidden) fails with the reason; it is in the baseline diff --git a/ci/clicks/meter.mjs b/ci/clicks/meter.mjs index 4101cd142..effbcb8e9 100644 --- a/ci/clicks/meter.mjs +++ b/ci/clicks/meter.mjs @@ -29,6 +29,13 @@ function hasFocus(el) { return Boolean(el.isContentEditable && active?.contains(el) && caret && el.contains(caret)); } +/** The floating Ask button lies over the middle of `el`, where a click lands. */ +function coveredByAsk(el) { + const r = el.getBoundingClientRect(); + const top = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); + return Boolean(top?.closest("[data-ask-button]")); +} + export class Meter { /** `touch`: a phone, where clicks are taps and bringing a control into view takes a swipe. */ constructor(page, { touch = false } = {}) { @@ -103,9 +110,11 @@ export class Meter { try { await this.tapOrClick(locator, { trial: true, timeout: 2000 }); } catch { - // Something still lies over it (the floating Ask button, a toast). The step notes it; the click still counts - // one, done here with the keyboard so it reaches the control rather than what covers it. + // The floating Ask button rises above controls (or steps aside), so it covering one is a failure. Anything else + // lying over it (a toast) is noted in the step; the click still counts one, done here with the keyboard so it + // reaches the control rather than what covers it. await locator.waitFor({ state: "visible" }); + if (await locator.evaluate(coveredByAsk)) throw new Error(`${what} is covered by the floating Ask button`); const step = this.journey?.steps.at(-1); if (step) step.what += " (covered by something else on the page)"; await locator.focus(); diff --git a/ci/clicks/report.mjs b/ci/clicks/report.mjs index 276a465db..7e34efba1 100644 --- a/ci/clicks/report.mjs +++ b/ci/clicks/report.mjs @@ -100,6 +100,11 @@ export function markdown(result, base) { lines.push( `| **All** | **${result.journeys.length} features** | **${sum.clicks}** | **${sum.keys}** | **${sum.prompts}** |${sw(`**${sum.swipes}**`)} **${sum.clicks + sum.keys + sum.prompts + sum.swipes}** | |`, ); + const covered = (result.pages || []).filter((p) => p.askCovers?.length); + if (covered.length) { + lines.push("", "## Covered by the Ask button", "", "With the page at its end, the floating Ask button lies over these:", ""); + for (const p of covered) lines.push(`- ${p.label} (\`${p.page}\`): ${p.askCovers.join(", ")}`); + } lines.push("", "## Per module", "", `| Module | Features | ${Clicks} | Keys | Prompts |${sw("Swipes")}`, `|---|--:|--:|--:|--:|${sw("--:")}`); for (const m of modules) { const js = result.journeys.filter((x) => x.module === m); diff --git a/ci/clicks/survey.mjs b/ci/clicks/survey.mjs index 4bae8c1bc..d35300a67 100644 --- a/ci/clicks/survey.mjs +++ b/ci/clicks/survey.mjs @@ -87,6 +87,38 @@ async function surveyPages(page, base, phone) { return seen.filter((el) => el.offsetParent !== null && !el.closest("[hidden], nav, details:not([open]) > :not(summary)")).length; }); const settle = () => page.waitForTimeout(1200); + // The controls the floating Ask button covers with the page (and anything scrolling in it) at its end, where + // scrolling can't carry them clear: it should rise above them or step aside, so any is a failure. + const askCovers = async () => { + await page.evaluate(() => { + window.scrollTo(0, document.documentElement.scrollHeight); + for (const el of document.querySelectorAll("main *")) + if (el.scrollHeight > el.clientHeight && /(auto|scroll)/.test(getComputedStyle(el).overflowY)) el.scrollTop = el.scrollHeight; + }); + await page.waitForTimeout(600); // the button moves on the next frame, then slides + return page.evaluate(() => { + const ask = document.querySelector("[data-ask-button]"); + if (!ask || getComputedStyle(ask).visibility === "hidden") return []; + const a = ask.getBoundingClientRect(); + const out = []; + const all = "a[href], button, input:not([type=hidden]), select, textarea, [role=tab], [role=switch], [role=checkbox], [role=radio]"; + for (const el of document.querySelectorAll(all)) { + if (el.closest("[data-ask-button], [data-page-chat]")) continue; + const r = el.getBoundingClientRect(); + if (r.height > innerHeight / 3) continue; // a big field: the button covers a corner of it (ask-place.ts) + const [x0, x1, y0, y1] = [Math.max(r.left, a.left), Math.min(r.right, a.right), Math.max(r.top, a.top), Math.min(r.bottom, a.bottom)]; + if (x1 - x0 < 4 || y1 - y0 < 4) continue; + if (document.elementFromPoint((x0 + x1) / 2, (y0 + y1) / 2)?.closest("[data-ask-button]")) + out.push((el.getAttribute("aria-label") || el.textContent || el.tagName).replace(/\s+/g, " ").trim().slice(0, 60)); + } + return out; + }); + }; + const visit = async (entry) => { + entry.askCovers = await askCovers(); + if (entry.askCovers.length) console.log(`FAIL ${entry.page}: the Ask button covers ${entry.askCovers.join(", ")}`); + pages.push(entry); + }; await page.goto(base + "/", { waitUntil: "domcontentloaded" }); await settle(); if (phone) await page.getByRole("button", { name: "Open navigation" }).tap(); @@ -108,7 +140,7 @@ async function surveyPages(page, base, phone) { await page.waitForLoadState("domcontentloaded"); await settle(); const key = pageKey(page.url()); - pages.push({ page: key, label: item.label, reach: 1 + menu, controls: await controls() }); + await visit({ page: key, label: item.label, reach: 1 + menu, controls: await controls() }); // a second level: settings sections, and tabs that are links (Admin, Sensors, Pipelines) const sub = await page .locator("main") @@ -120,7 +152,7 @@ async function surveyPages(page, base, phone) { if (!s.href || pages.some((p) => p.page === pageKey(base + s.href))) continue; await page.goto(base + s.href, { waitUntil: "domcontentloaded" }); await settle(); - pages.push({ page: pageKey(page.url()), label: `${item.label} › ${s.label}`, reach: 2 + menu, controls: await controls() }); + await visit({ page: pageKey(page.url()), label: `${item.label} › ${s.label}`, reach: 2 + menu, controls: await controls() }); } } return pages; @@ -214,7 +246,7 @@ async function main() { for (const d of worse) console.log(`worse: ${d.id} ${d.what}`); if (worse.length && a.failOnRegression) process.exitCode = 1; } - if (failed) process.exitCode = 1; + if (failed || pages.some((p) => p.askCovers.length)) process.exitCode = 1; } await main(); diff --git a/docs/assistant.md b/docs/assistant.md index b99b1d390..b472f0fe2 100644 --- a/docs/assistant.md +++ b/docs/assistant.md @@ -45,7 +45,9 @@ then. question (up to 12,000 characters of page text and 4,000 of the highlight) as what the person is looking at, not as citable excerpts. The question keeps the page's address, title and highlight, shown above it; the page's text isn't stored. A recording's transcript and document keep their own selection toolbar, whose Ask in chat goes to the - recording's chat. + recording's chat. The Ask button stays clear of the page's own buttons: when one is under it and scrolling can't + move it away (a row of buttons pinned to the bottom of the screen, or the last button with the page at its end), it + rises above them, or steps out of sight when there's no room to rise. - **No model configured:** chat returns the best-matching passages instead. Anyone signed in can see whether a model is set up, and which (`GET /chats/capabilities`), so the app says so before the first question. diff --git a/docs/frontend.md b/docs/frontend.md index f52569b44..da46f64c1 100644 --- a/docs/frontend.md +++ b/docs/frontend.md @@ -56,7 +56,13 @@ four-colour loop (Transcribe blue, Diarize red, Analyze green, Summarize and Rep namespace switcher sits at the top of the menu, Import is an icon in the top bar, settings sections open as a list from the current section's name, tabs wrap, and wide tables (sensors, connections) become cards. A form's main buttons take `phone-actions` (`app/globals.css`) to stay pinned at the bottom of the screen, clear of the floating Ask button; - a Dialog's actions stay in sight on their own. The [clicks + a Dialog's actions stay in sight on their own. +* **The floating Ask button** (`components/page-chat/ask-place.ts`) finds what it would cover with the browser's own + hit testing, through a transparent probe just under it, and rises above any control there that scrolling can't + carry clear (one in a bar that's fixed or stuck to the bottom, or with the page at its end), or steps out of sight + when that would take it past the middle of the screen, so a new page needn't leave room for it (`phone-actions` and + the Settings save row still do, and it stays put there). The clicks survey fails a journey whose control it covers, + and checks every page with the page scrolled to its end. The [clicks survey](https://github.com/adeelahmad/lense/blob/main/ci/clicks/README.md) measures every journey on a phone too. * **The role rule:** actions a person can't take stay visible, disabled, with a tooltip saying who can (`needRole()`); namespaces they have no role in never appear. `useArchive()` gives `can(role, ns)` and the diff --git a/nextjs-frontend/__tests__/ask-place.test.tsx b/nextjs-frontend/__tests__/ask-place.test.tsx new file mode 100644 index 000000000..bf61d2819 --- /dev/null +++ b/nextjs-frontend/__tests__/ask-place.test.tsx @@ -0,0 +1,197 @@ +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { act, render, screen } from "@testing-library/react"; +import "@testing-library/jest-dom"; + +import { Chats } from "@/app/openapi-client"; +import { + AT_REST, + ASK_GAP, + blockersUnder, + controlAround, + placeAsk, + samplePoints, + stuckBar, + type Box, +} from "@/components/page-chat/ask-place"; +import { PageChat } from "@/components/page-chat/page-chat"; +import { TooltipProvider } from "@/components/ui/tooltip"; + +jest.mock("@/app/openapi-client", () => ({ + Chats: { createChat: jest.fn(), getChat: jest.fn(), chatCapabilities: jest.fn(), stopAnswer: jest.fn() }, +})); +jest.mock("next-auth/react", () => ({ useSession: () => ({ data: { accessToken: "t" } }) })); +jest.mock("next/navigation", () => ({ + usePathname: () => "/import", + useSearchParams: () => new URLSearchParams(""), +})); + +// A 1400x900 screen; the button rests 20px from the bottom-right corner, 100x48. +const VIEW = 900; +const box = (top: number, bottom: number, left = 1280, right = 1380): Box => ({ + top, + bottom, + left, + right, + height: bottom - top, +}); +const REST = box(VIEW - 68, VIEW - 20); +/** What getBoundingClientRect gives for a box at (x, y), w by h. */ +const rectAt = (x: number, y: number, w: number, h: number) => + ({ x, y, left: x, top: y, width: w, height: h, right: x + w, bottom: y + h }) as DOMRect; + +describe("placing the Ask button", () => { + it("stays in its corner when nothing is under it", () => { + expect(placeAsk(() => ({ box: REST, blockers: [] }), VIEW)).toEqual(AT_REST); + }); + + it("rises above a row of buttons it would cover, with a gap", () => { + const row = box(VIEW - 70, VIEW); // a sticky Import row, 70px tall + const seen: number[] = []; + const place = placeAsk((lift) => { + seen.push(lift); + const at = box(REST.top - lift, REST.bottom - lift); + return { box: at, blockers: at.bottom > row.top ? [row] : [] }; + }, VIEW); + expect(place).toEqual({ lift: REST.bottom - row.top + ASK_GAP, hidden: false }); + expect(seen).toEqual([0, 62]); // and checks it's clear up there + }); + + it("keeps rising over what it covers next", () => { + const row = box(VIEW - 70, VIEW); + const field = box(VIEW - 130, VIEW - 90); // a field just above the row + const place = placeAsk((lift) => { + const at = box(REST.top - lift, REST.bottom - lift); + return { box: at, blockers: [row, field].filter((b) => at.bottom > b.top && at.top < b.bottom) }; + }, VIEW); + expect(place).toEqual({ lift: REST.bottom - field.top + ASK_GAP, hidden: false }); + }); + + it("steps out of sight rather than rise past the middle of the screen", () => { + const panel = box(VIEW / 2 - 40, VIEW); // controls reaching up past the middle + expect(placeAsk(() => ({ box: REST, blockers: [panel] }), VIEW)).toEqual({ lift: 0, hidden: true }); + }); + + it("samples the whole of its area", () => { + const pts = samplePoints(REST); + expect(pts).toHaveLength(15); + expect(pts[0]).toEqual([REST.left + 3, REST.top + 3]); + expect(pts[14]).toEqual([REST.right - 3, REST.bottom - 3]); + }); +}); + +describe("what counts as covered", () => { + afterEach(() => { + document.body.innerHTML = ""; + }); + + it("knows controls, and clickable rows by their pointer", () => { + // (the word's pointer is the row's, inherited in a browser; jsdom doesn't inherit it) + document.body.innerHTML = `
Row
+

Words

`; + const el = (id: string) => document.getElementById(id)!; + expect(controlAround(el("icon"))).toBe(el("b")); + expect(controlAround(el("word"))).toBe(el("row")); + expect(controlAround(el("i"))).toBe(el("i")); + expect(controlAround(el("l"))).toBe(el("l")); + expect(controlAround(el("text"))).toBeNull(); + }); + + it("finds the bar a control stays put in: fixed, or sticky to the bottom and stuck there", () => { + document.body.innerHTML = `
+
+
`; + const el = (id: string) => document.getElementById(id)!; + el("bottom").getBoundingClientRect = () => rectAt(0, VIEW - 60, 1400, 60); + Object.defineProperty(window, "innerHeight", { value: VIEW, configurable: true }); + expect(stuckBar(el("a"))).toBe(el("fixed")); + expect(stuckBar(el("b"))).toBeNull(); + expect(stuckBar(el("c"))).toBe(el("bottom")); + // the same sticky row sitting up the page, where scrolling still moves it, isn't stuck + el("bottom").getBoundingClientRect = () => rectAt(0, 300, 1400, 60); + expect(stuckBar(el("c"))).toBeNull(); + }); + + it("covers only what's drawn under the button, and what scrolling can't carry clear", () => { + document.body.innerHTML = `
+
`; + const el = (id: string) => document.getElementById(id)!; + const rect = (top: number, h: number) => () => rectAt(1200, top, 200, h); + el("bar").getBoundingClientRect = rect(VIEW - 70, 70); + el("import").getBoundingClientRect = rect(VIEW - 56, 40); + el("mid").getBoundingClientRect = rect(VIEW - 60, 40); + Object.defineProperty(window, "innerHeight", { value: VIEW, configurable: true }); + const probe = el("probe"); + const under = (stack: Element[]) => { + document.elementsFromPoint = () => stack; + return blockersUnder(probe, REST); + }; + // the sticky row: the button clears the whole row + expect(under([probe, el("import"), el("bar"), document.body])).toEqual([ + { top: VIEW - 70, bottom: VIEW, left: 1200, right: 1400, height: 70 }, + ]); + // drawn over the button (a toast): not its business + expect(under([el("toast").firstElementChild!, probe, document.body])).toEqual([]); + // a button in the page with more page below it: scrolling carries it clear + Object.defineProperty(document.documentElement, "scrollHeight", { value: 3000, configurable: true }); + Object.defineProperty(document.documentElement, "clientHeight", { value: VIEW, configurable: true }); + expect(under([probe, el("mid"), document.body])).toEqual([]); + // the same button with the page at its end: it's covered + Object.defineProperty(document.documentElement, "scrollHeight", { value: VIEW, configurable: true }); + expect(under([probe, el("mid"), document.body])).toEqual([ + { top: VIEW - 60, bottom: VIEW - 20, left: 1200, right: 1400, height: 40 }, + ]); + }); +}); + +describe("the Ask button on a page", () => { + const original = document.elementsFromPoint; + afterEach(() => { + document.elementsFromPoint = original; + localStorage.clear(); + }); + + it("rises above the page's sticky Import row, and settles back when it goes", async () => { + (Chats.chatCapabilities as jest.Mock).mockReturnValue(new Promise(() => {})); + Object.defineProperty(window, "innerHeight", { value: VIEW, configurable: true }); + let rowShown = true; + const qc = new QueryClient(); + const view = render( + + +
+
+ +
+
+ +
+
, + ); + const row = screen.getByTestId("row"); + const importButton = screen.getByRole("button", { name: "Import 2 files" }); + row.getBoundingClientRect = () => rectAt(0, VIEW - 70, 1400, 70); + importButton.getBoundingClientRect = () => rectAt(1240, VIEW - 55, 140, 40); + const ask = screen.getByRole("button", { name: "Chat about this page" }); + const probe = ask.previousElementSibling as HTMLElement; + // the probe sits where the button would be, raised by whatever it's been moved by + probe.getBoundingClientRect = () => { + const lift = -parseFloat((probe.style.translate || "0 0px").split(" ")[1]); + return rectAt(1280, VIEW - 68 - lift, 100, 48); + }; + document.elementsFromPoint = (_x: number, y: number) => + rowShown && y >= VIEW - 70 ? [probe, importButton, row, document.body] : [probe, document.body]; + + act(() => window.dispatchEvent(new Event("resize"))); + await act(() => new Promise((r) => requestAnimationFrame(r))); + expect(ask).toHaveAttribute("data-place", "raised"); + expect(ask.style.translate).toBe(`0 -${VIEW - 20 - (VIEW - 70) + ASK_GAP}px`); + expect(ask).toBeVisible(); + + rowShown = false; + act(() => window.dispatchEvent(new Event("scroll"))); + await act(() => new Promise((r) => requestAnimationFrame(r))); + expect(ask).toHaveAttribute("data-place", "rest"); + expect(ask.style.translate).toBe(""); + view.unmount(); + }); +}); diff --git a/nextjs-frontend/components/page-chat/ask-place.ts b/nextjs-frontend/components/page-chat/ask-place.ts new file mode 100644 index 000000000..018f2c71c --- /dev/null +++ b/nextjs-frontend/components/page-chat/ask-place.ts @@ -0,0 +1,215 @@ +"use client"; + +import { useEffect, useLayoutEffect, useState, type RefObject } from "react"; + +/** + * Where the floating Ask button sits. It rests in the bottom-right corner, and never on a control people need there: + * when one is under it and scrolling can't carry it clear (a sticky Import or Save row, or the page's last button + * with the page at its end), the button rises above it; with no room to rise (the controls reach past the middle of + * the screen), it steps out of sight until the corner is clear. A transparent probe the button's size, just below it + * in the stacking order, finds what the button would cover with the browser's own hit testing, so whatever is drawn + * over the button (a dialog, a drawer, a toast) never moves it. + */ + +export type AskPlace = { lift: number; hidden: boolean }; +export type Box = { top: number; bottom: number; left: number; right: number; height: number }; + +export const AT_REST: AskPlace = { lift: 0, hidden: false }; +const OUT_OF_SIGHT: AskPlace = { lift: 0, hidden: true }; +/** Between the button and the controls it rises above. */ +export const ASK_GAP = 12; + +/** Things people click or type into. Clickable rows and cards (cursor: pointer) count too. */ +const CONTROL = [ + "a[href]", + "button", + "input:not([type='hidden'])", + "select", + "textarea", + "summary", + "label", + "[contenteditable='true']", + "[contenteditable='']", + ...[ + "button", + "link", + "checkbox", + "radio", + "switch", + "tab", + "menuitem", + "option", + "slider", + "combobox", + "textbox", + ].map((r) => `[role='${r}']`), +].join(", "); + +/** + * The lift that puts the button clear of the controls under it. `under(lift)` says where the button would be, raised + * by `lift` pixels, and what it would cover there; it rises above them, and again over anything it then covers, but + * never past the middle of the screen. + */ +export function placeAsk(under: (lift: number) => { box: Box; blockers: Box[] }, viewHeight: number): AskPlace { + let lift = 0; + for (let tries = 0; tries < 4; tries++) { + const { box, blockers } = under(lift); + if (!blockers.length) return lift ? { lift, hidden: false } : AT_REST; + const rise = box.bottom - Math.min(...blockers.map((b) => b.top)) + ASK_GAP; + if (box.top - rise < viewHeight / 2) return OUT_OF_SIGHT; + lift += rise; + } + return OUT_OF_SIGHT; +} + +/** Points spread over a box (inset from its edges), to find what lies under it. */ +export function samplePoints(b: Box, cols = 5, rows = 3): [number, number][] { + const inset = 3; + const at = (from: number, to: number, i: number, n: number) => from + inset + ((to - from - 2 * inset) * i) / (n - 1); + const out: [number, number][] = []; + for (let r = 0; r < rows; r++) + for (let c = 0; c < cols; c++) out.push([at(b.left, b.right, c, cols), at(b.top, b.bottom, r, rows)]); + return out; +} + +/** The control `el` is, or is part of, if any. */ +export function controlAround(el: Element): Element | null { + const c = el.closest(CONTROL); + if (c) return c; + if (getComputedStyle(el).cursor !== "pointer") return null; + let top = el; // the whole clickable row or card, not the word in it + while ( + top.parentElement && + top.parentElement !== document.body && + getComputedStyle(top.parentElement).cursor === "pointer" + ) + top = top.parentElement; + return top; +} + +const scrolls = (s: CSSStyleDeclaration) => /(auto|scroll|overlay)/.test(s.overflowY); + +/** A bar around `el` that stays put as the page scrolls: fixed, or sticky and stuck to the bottom of its scroller. */ +export function stuckBar(el: Element): Element | null { + for (let a: Element | null = el; a && a !== document.body; a = a.parentElement) { + const s = getComputedStyle(a); + if (s.position === "fixed") return a; + if (s.position !== "sticky") continue; + const offset = parseFloat(s.bottom); + if (Number.isNaN(offset)) continue; // sticky to the top + let port = window.innerHeight; + for (let p = a.parentElement; p && p !== document.body; p = p.parentElement) + if (scrolls(getComputedStyle(p))) { + port = Math.min(port, p.getBoundingClientRect().bottom); + break; + } + if (a.getBoundingClientRect().bottom >= port - offset - 2) return a; + } + return null; +} + +/** How far scrolling down (the page, and anything scrolling inside it) could still carry `el` up the screen. */ +export function scrollRoom(el: Element): number { + let room = 0; + for (let a = el.parentElement; a && a !== document.body && a !== document.documentElement; a = a.parentElement) + if (a.scrollHeight > a.clientHeight && scrolls(getComputedStyle(a))) + room += a.scrollHeight - a.clientHeight - a.scrollTop; + const doc = document.scrollingElement ?? document.documentElement; + return room + Math.max(0, doc.scrollHeight - doc.clientHeight - doc.scrollTop); +} + +const toBox = (r: DOMRect): Box => ({ top: r.top, bottom: r.bottom, left: r.left, right: r.right, height: r.height }); + +/** + * The controls `probe` covers where it is now that scrolling can't carry clear of it: the bar each sits in when it has + * a short one (so the button clears the whole bar), else the control. Big fields and panels (taller than a third of + * the screen) don't count: the button covers a corner of them, and the rest stays usable. + */ +export function blockersUnder(probe: Element, box: Box): Box[] { + const view = window.innerHeight; + const seen = new Set(); + const out: Box[] = []; + for (const [x, y] of samplePoints(box)) { + const stack = document.elementsFromPoint(x, y); + const i = stack.indexOf(probe); + const below = i >= 0 ? stack[i + 1] : undefined; // what's drawn just under the button, not over it + if (!below || below.closest("[data-page-chat], [data-ask-button]")) continue; + const control = controlAround(below); + if (!control || seen.has(control)) continue; + seen.add(control); + const own = toBox(control.getBoundingClientRect()); + if (own.height > view / 3) continue; + const bar = stuckBar(control); + if (!bar && scrollRoom(control) >= own.bottom - box.top) continue; // scrolling on carries it clear + const barBox = bar ? toBox(bar.getBoundingClientRect()) : null; + out.push(barBox && barBox.height <= view / 3 ? barBox : own); + } + return out; +} + +/** Measures where the button goes now, with the probe (normally inert) briefly hit-testable at each spot it tries. */ +export function measureAsk(probe: HTMLElement, button: HTMLElement): AskPlace { + if (typeof document.elementsFromPoint !== "function") return AT_REST; + probe.style.width = `${button.offsetWidth}px`; + probe.style.height = `${button.offsetHeight}px`; + probe.style.pointerEvents = "auto"; + try { + return placeAsk((lift) => { + probe.style.translate = lift ? `0 ${-lift}px` : ""; + const box = toBox(probe.getBoundingClientRect()); + return { box, blockers: blockersUnder(probe, box) }; + }, window.innerHeight); + } finally { + probe.style.pointerEvents = "none"; + probe.style.translate = ""; + } +} + +const useIsoLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect; + +/** The button's place, measured again (once a frame at most) as the page scrolls, resizes or changes. */ +export function useAskPlace(probe: RefObject, button: RefObject): AskPlace { + const [place, setPlace] = useState(AT_REST); + useIsoLayoutEffect(() => { + let frame = 0; + const measure = () => { + frame = 0; + const p = probe.current; + const b = button.current; + if (!p || !b) return; + const next = measureAsk(p, b); + setPlace((now) => (now.lift === next.lift && now.hidden === next.hidden ? now : next)); + }; + const soon = () => { + if (!frame) frame = requestAnimationFrame(measure); + }; + measure(); + window.addEventListener("scroll", soon, { capture: true, passive: true }); + window.addEventListener("resize", soon); + document.addEventListener("transitionend", soon, true); + document.addEventListener("animationend", soon, true); + // the page changing under it (a sticky row appearing, a dialog closing), but not the button moving itself + const mine = (n: Node) => n === probe.current || Boolean(button.current?.contains(n)); + const changes = new MutationObserver((records) => { + if (records.some((r) => !mine(r.target))) soon(); + }); + changes.observe(document.body, { + childList: true, + subtree: true, + attributes: true, + attributeFilter: ["class", "style", "hidden", "open"], + }); + const sizes = typeof ResizeObserver === "function" ? new ResizeObserver(soon) : null; + sizes?.observe(document.body); + return () => { + if (frame) cancelAnimationFrame(frame); + window.removeEventListener("scroll", soon, { capture: true }); + window.removeEventListener("resize", soon); + document.removeEventListener("transitionend", soon, true); + document.removeEventListener("animationend", soon, true); + changes.disconnect(); + sizes?.disconnect(); + }; + }, [probe, button]); + return place; +} diff --git a/nextjs-frontend/components/page-chat/page-chat.tsx b/nextjs-frontend/components/page-chat/page-chat.tsx index e80775e97..59fd28399 100644 --- a/nextjs-frontend/components/page-chat/page-chat.tsx +++ b/nextjs-frontend/components/page-chat/page-chat.tsx @@ -15,6 +15,7 @@ import { useChat, useLlmStatus, useStopAnswer } from "@/components/chat/data"; import { RichText } from "@/components/chat/rich-text"; import { ToolSteps } from "@/components/chat/steps"; import { applyEvent, newTurn, savedSteps, type ToolStep, type TurnState } from "@/components/chat/stream"; +import { useAskPlace } from "@/components/page-chat/ask-place"; import { hiddenOn, INITIAL, @@ -122,22 +123,42 @@ export function PageChat() { focusTick={focusTick} /> ) : ( - + open()} /> )} ); } +/** The floating button that opens the chat. It rises above, or steps aside from, controls it would cover (ask-place). */ +function AskButton({ label, onOpen }: { label: string; onOpen: () => void }) { + const probe = useRef(null); + const button = useRef(null); + const place = useAskPlace(probe, button); + return ( + <> + {/* where the button would be, to find what it covers; drawn just under it */} + + + + ); +} + /** Highlighting text on a page offers "Ask about this", above the words. */ function SelectionAsk({ onAsk }: { onAsk: (quote: string) => void }) { const [sel, setSel] = useState<{ x: number; y: number; text: string } | null>(null); From 991654235d10d9ca5db918d95f3b2f462f1fce44 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Thu, 15 Oct 2026 11:25:10 +0000 Subject: [PATCH 2/3] fix(ui): count only controls drawn under the Ask button, not a label's empty end The survey's page check counted fields a closed fold keeps out of sight; it now checks the control is what lies right under the button. Labels no longer push the button up: their empty end isn't somewhere people tap. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01KaZgCPYVesfDJhLzGCKJXX --- ci/clicks/survey.mjs | 5 ++++- nextjs-frontend/__tests__/ask-place.test.tsx | 2 +- nextjs-frontend/components/page-chat/ask-place.ts | 5 ++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ci/clicks/survey.mjs b/ci/clicks/survey.mjs index d35300a67..3aea07b87 100644 --- a/ci/clicks/survey.mjs +++ b/ci/clicks/survey.mjs @@ -108,7 +108,10 @@ async function surveyPages(page, base, phone) { if (r.height > innerHeight / 3) continue; // a big field: the button covers a corner of it (ask-place.ts) const [x0, x1, y0, y1] = [Math.max(r.left, a.left), Math.min(r.right, a.right), Math.max(r.top, a.top), Math.min(r.bottom, a.bottom)]; if (x1 - x0 < 4 || y1 - y0 < 4) continue; - if (document.elementFromPoint((x0 + x1) / 2, (y0 + y1) / 2)?.closest("[data-ask-button]")) + // the button is on top there, and right under it is this control (not one a closed fold keeps out of sight) + const [top, ...under] = document.elementsFromPoint((x0 + x1) / 2, (y0 + y1) / 2); + const next = under.find((e) => !e.closest("[data-ask-button]")); + if (top?.closest("[data-ask-button]") && next && el.contains(next)) out.push((el.getAttribute("aria-label") || el.textContent || el.tagName).replace(/\s+/g, " ").trim().slice(0, 60)); } return out; diff --git a/nextjs-frontend/__tests__/ask-place.test.tsx b/nextjs-frontend/__tests__/ask-place.test.tsx index bf61d2819..d8c8c68fe 100644 --- a/nextjs-frontend/__tests__/ask-place.test.tsx +++ b/nextjs-frontend/__tests__/ask-place.test.tsx @@ -92,7 +92,7 @@ describe("what counts as covered", () => { expect(controlAround(el("icon"))).toBe(el("b")); expect(controlAround(el("word"))).toBe(el("row")); expect(controlAround(el("i"))).toBe(el("i")); - expect(controlAround(el("l"))).toBe(el("l")); + expect(controlAround(el("l"))).toBeNull(); // the empty end of a label isn't somewhere people tap expect(controlAround(el("text"))).toBeNull(); }); diff --git a/nextjs-frontend/components/page-chat/ask-place.ts b/nextjs-frontend/components/page-chat/ask-place.ts index 018f2c71c..7f5207e8a 100644 --- a/nextjs-frontend/components/page-chat/ask-place.ts +++ b/nextjs-frontend/components/page-chat/ask-place.ts @@ -19,7 +19,7 @@ const OUT_OF_SIGHT: AskPlace = { lift: 0, hidden: true }; /** Between the button and the controls it rises above. */ export const ASK_GAP = 12; -/** Things people click or type into. Clickable rows and cards (cursor: pointer) count too. */ +/** Things people click or type into. Clickable rows and cards (cursor: pointer) count too; a label's empty end doesn't. */ const CONTROL = [ "a[href]", "button", @@ -27,7 +27,6 @@ const CONTROL = [ "select", "textarea", "summary", - "label", "[contenteditable='true']", "[contenteditable='']", ...[ @@ -52,7 +51,7 @@ const CONTROL = [ */ export function placeAsk(under: (lift: number) => { box: Box; blockers: Box[] }, viewHeight: number): AskPlace { let lift = 0; - for (let tries = 0; tries < 4; tries++) { + for (let tries = 0; tries < 8; tries++) { const { box, blockers } = under(lift); if (!blockers.length) return lift ? { lift, hidden: false } : AT_REST; const rise = box.bottom - Math.min(...blockers.map((b) => b.top)) + ASK_GAP; From 3494acf80e8818c1e1a5c85b6f280fb489cbc726 Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Thu, 15 Oct 2026 11:29:45 +0000 Subject: [PATCH 3/3] test(clicks): steady the graph merge and phone chat journeys Both were red on main. The update banner pushed pages that fill the screen (Chat, the graph, a recording) below the fold, so the phone's question box needed a swipe: ported from #393, the banner sets --lens-banner to its height and those pages leave it room. Merging from the graph needs Raspberry Pi linked twice, which takes the second import's analysis: the journey now waits for the jobs to finish, as other journeys wait for background work. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01KaZgCPYVesfDJhLzGCKJXX --- ci/clicks/journeys.mjs | 4 + .../__tests__/update-banner.test.tsx | 29 +++++++ .../components/app-shell/update-banner.tsx | 76 +++++++++++++------ nextjs-frontend/components/chat/chat-app.tsx | 2 +- .../components/graph/graph-page.tsx | 2 +- .../components/home/assistant-home.tsx | 2 +- .../components/recording/audio-layout.tsx | 2 +- .../recording/document/document-layout.tsx | 2 +- .../components/recording/mobile-layout.tsx | 2 +- .../components/recording/skeleton.tsx | 2 +- .../recording/video/video-layout.tsx | 7 +- 11 files changed, 98 insertions(+), 32 deletions(-) create mode 100644 nextjs-frontend/__tests__/update-banner.test.tsx diff --git a/ci/clicks/journeys.mjs b/ci/clicks/journeys.mjs index e42d83845..c8d181513 100644 --- a/ci/clicks/journeys.mjs +++ b/ci/clicks/journeys.mjs @@ -670,6 +670,10 @@ export const JOURNEYS = [ from: "/", async run(ctx) { const { page, meter } = ctx; + // An entity is in the graph once something links it twice (graph.min_edge_weight), which takes import-file's + // pi-episode as well; a slow machine can still be reading it here, so wait for the jobs to finish (not counted) + const idle = page.getByRole("button", { name: /^Activity: (Nothing running|\d+ failed)$/ }); + await madeInBackground(ctx, "/", idle, "/", "the imports' jobs finished"); await go(ctx, "Graph"); const find = page.getByRole("combobox", { name: "Find in graph" }); await page.getByRole("region", { name: "Graph" }).waitFor(); diff --git a/nextjs-frontend/__tests__/update-banner.test.tsx b/nextjs-frontend/__tests__/update-banner.test.tsx new file mode 100644 index 000000000..c3997328f --- /dev/null +++ b/nextjs-frontend/__tests__/update-banner.test.tsx @@ -0,0 +1,29 @@ +import { fireEvent, render, screen } from "@testing-library/react"; +import "@testing-library/jest-dom"; + +import { UpdateBanner } from "@/components/app-shell/update-banner"; + +jest.mock("@/components/settings/updates-panel", () => ({ + useUpdates: () => ({ data: { available: true, current: "0.9.0", latest: { tag: "v0.10.0" }, agent: false } }), +})); + +const room = () => document.documentElement.style.getPropertyValue("--lens-banner"); + +describe("the update banner", () => { + beforeEach(() => localStorage.clear()); + + it("tells pages that fill the screen how much room it takes, and gives it back when dismissed", () => { + render(); + expect(screen.getByText("Lens v0.10.0 is out (this is 0.9.0).")).toBeInTheDocument(); + expect(room()).toMatch(/^\d+px$/); + fireEvent.click(screen.getByRole("button", { name: /dismiss/i })); + expect(screen.queryByText(/is out/)).not.toBeInTheDocument(); + expect(room()).toBe(""); + }); + + it("takes no room for people who aren't admins", () => { + render(); + expect(screen.queryByText(/is out/)).not.toBeInTheDocument(); + expect(room()).toBe(""); + }); +}); diff --git a/nextjs-frontend/components/app-shell/update-banner.tsx b/nextjs-frontend/components/app-shell/update-banner.tsx index b10aca643..ca32df1dc 100644 --- a/nextjs-frontend/components/app-shell/update-banner.tsx +++ b/nextjs-frontend/components/app-shell/update-banner.tsx @@ -1,7 +1,7 @@ "use client"; import Link from "next/link"; -import { useEffect, useState } from "react"; +import { type ReactNode, useEffect, useRef, useState } from "react"; import { useUpdates } from "@/components/settings/updates-panel"; import { Banner } from "@/components/ui/banner"; @@ -12,6 +12,7 @@ const KEY = "lens-update-dismissed"; export function UpdateBanner({ admin }: { admin: boolean }) { const { data: s } = useUpdates(admin); const [dismissed, setDismissed] = useState(null); + const room = useRef(null); useEffect(() => { try { setDismissed(localStorage.getItem(KEY)); @@ -19,35 +20,62 @@ export function UpdateBanner({ admin }: { admin: boolean }) { // private window: shown again next time } }, []); - if (!admin || !s) return null; - const run = s.upgrade; - if (run && ["backing-up", "queued", "running"].includes(run.state) && !run.error) - return ( - + + let banner: ReactNode = null; + const run = s?.upgrade; + const tag = s?.latest?.tag; + if (!admin || !s) banner = null; + else if (run && ["backing-up", "queued", "running"].includes(run.state) && !run.error) + banner = ( + Lens restarts on its own when it’s done.{" "} Follow along ); - const tag = s.latest?.tag; - if (!s.available || !tag || dismissed === tag) return null; + else if (s.available && tag && dismissed !== tag) + banner = ( + { + setDismissed(tag); + try { + localStorage.setItem(KEY, tag); + } catch { + // fine: dismissed for this visit + } + }} + > + + {s.agent ? "See what’s new and install it" : "See what’s new"} + + + ); + + // Pages that fill the screen (Chat, the graph, a recording) leave the banner its room: --lens-banner is its height + const shown = banner != null; + useEffect(() => { + const root = document.documentElement; + const el = room.current; + if (!shown || !el) { + root.style.removeProperty("--lens-banner"); + return; + } + const set = () => root.style.setProperty("--lens-banner", `${el.offsetHeight}px`); + set(); + const watch = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(set); + watch?.observe(el); + return () => { + watch?.disconnect(); + root.style.removeProperty("--lens-banner"); + }; + }, [shown]); + + if (!banner) return null; return ( - { - setDismissed(tag); - try { - localStorage.setItem(KEY, tag); - } catch { - // fine: dismissed for this visit - } - }} - > - - {s.agent ? "See what’s new and install it" : "See what’s new"} - - +
+ {banner} +
); } diff --git a/nextjs-frontend/components/chat/chat-app.tsx b/nextjs-frontend/components/chat/chat-app.tsx index 0aee7f28a..876d5e7a8 100644 --- a/nextjs-frontend/components/chat/chat-app.tsx +++ b/nextjs-frontend/components/chat/chat-app.tsx @@ -568,7 +568,7 @@ export function ChatApp() { return (
diff --git a/nextjs-frontend/components/graph/graph-page.tsx b/nextjs-frontend/components/graph/graph-page.tsx index d1c49f37c..f49615f4a 100644 --- a/nextjs-frontend/components/graph/graph-page.tsx +++ b/nextjs-frontend/components/graph/graph-page.tsx @@ -280,7 +280,7 @@ export function GraphPage() { // an earlier version is for looking: edits go to the graph as it is now const onEdit = asOf ? undefined : setEditing; return ( -
+

Graph