From 29724b493c896bf138a552bf5546e83395e76178 Mon Sep 17 00:00:00 2001 From: CJ Brewer Date: Fri, 4 Dec 2026 07:56:07 -0700 Subject: [PATCH] fix(ui): draw alerts in the top right corner, clear of the foot of the page An alert that stays (danger, working, stays) sat over the bottom centre of the page until it was dismissed: a form's buttons, a panel pinned to the bottom, the last rows of a list. The stack is now under the top bar on the right, and narrower. A browser test raises a staying alert from a button held at the foot of a page, then presses that button and reaches the last row of the list without dismissing it. Co-Authored-By: Claude Fable 5.2 --- .changeset/alerts-clear-of-controls.md | 8 +++++ apps/docs/src/docs-manifest.json | 4 +-- apps/starter/e2e/layouts.ts | 2 +- apps/starter/e2e/spool.ui.tsx | 45 +++++++++++++++++++++++++- apps/starter/e2e/tests/alerts.e2e.ts | 29 +++++++++++++++++ docs/alerts.md | 14 ++++++-- packages/spools/src/crm/ui/alerts.tsx | 9 ++++-- 7 files changed, 102 insertions(+), 9 deletions(-) create mode 100644 .changeset/alerts-clear-of-controls.md diff --git a/.changeset/alerts-clear-of-controls.md b/.changeset/alerts-clear-of-controls.md new file mode 100644 index 0000000..7edeb2f --- /dev/null +++ b/.changeset/alerts-clear-of-controls.md @@ -0,0 +1,8 @@ +--- +'@swirls/spools': patch +--- + +Alerts are drawn in the top right corner of the page, under the top bar, and are narrower. +At the bottom of the page an alert that stays (`danger`, `working`, `stays`) sat over a +form's buttons, a panel pinned to the bottom and the last rows of a list until it was +dismissed. diff --git a/apps/docs/src/docs-manifest.json b/apps/docs/src/docs-manifest.json index bc3db8d..94e9faf 100644 --- a/apps/docs/src/docs-manifest.json +++ b/apps/docs/src/docs-manifest.json @@ -723,7 +723,7 @@ { "path": "/docs/alerts", "title": "Alerts", - "description": "Alerts are how the CRM tells whoever is using it what is happening: a save the server refused, an action that finished, work that is taking a while. They are drawn in one place, over the bottom of the page, by the CRM's shell. The CRM's own parts raise them, and so can your layouts, your components and your modules.", + "description": "Alerts are how the CRM tells whoever is using it what is happening: a save the server refused, an action that finished, work that is taking a while. They are drawn in one place by the CRM's shell: the top right corner of the page, under the top bar. The CRM's own parts raise them, and so can your layouts, your components and your modules.", "sections": [ { "id": "what-the-crm-raises-on-its-own", @@ -751,7 +751,7 @@ "level": 2 } ], - "text": "Alerts Alerts are how the CRM tells whoever is using it what is happening: a save the server refused, an action that finished, work that is taking a while. They are drawn in one place, over the bottom of the page, by the CRM's shell. The CRM's own parts raise them, and so can your layouts, your components and your modules. What the CRM raises on its own When What is said A field changed in place is refused by the server \"Value was not saved\", and what the server said A step of Stages is refused \"Stage was not changed\", and what the server said A record action ( actions in the config) runs for a while The action's label, with a spinner A record action ends The action's message, or why it failed A save that works says nothing: the new value on the page is the news. From a layout @Alert(text, tone?) is an action, beside @Navigate and @Refresh: The steps of an Action run in order and stop at a Mutation that fails, so an alert after @Run is raised only when the Mutation worked. tone is info (when left out), success, warning or danger. From a component useAlerts() works in any component drawn inside the CRM: a layout component ( defineLayoutComponent), a module's panel, a page of your own under src/routes/_crm. Call What it does alerts.show(alert) Raises an alert and gives its id. alerts.change(id, alert) Replaces an alert that is up. alerts.dismiss(id) Takes one down. alerts.during(work, says) Says doing if the promise is still going after a moment, then done or failed. Gives the promise's own result, and fails when it does. An alert is { text, tone?, detail?, link?, stays? }: tone: info, success, warning, danger, or working (a spinner). detail: a second line, such as why it failed. link: { label, to }, somewhere in the CRM to go from here. stays: keeps it up until it is dismissed. danger and working alerts always stay; the rest go after five seconds. during leaves out done to say nothing when the work succeeds, and waits a moment before announcing work, so something quick never flashes a spinner. At most four alerts are up at once: the oldest that would have gone on its own makes room. Outside the CRM's shell (a public page, a unit test) useAlerts() draws nothing and during still runs the work. Hearing every alert onAlert in defineSpoolUi is called with every alert as it is raised or changed, the CRM's own included. Use it to log them or to send them somewhere of your own. What alerts are not Alerts are for the person at the page, about what they just did. They are not kept, and nobody else sees them. To tell a teammate something later, make a task or use an automation (see configuration.md)." + "text": "Alerts Alerts are how the CRM tells whoever is using it what is happening: a save the server refused, an action that finished, work that is taking a while. They are drawn in one place by the CRM's shell: the top right corner of the page, under the top bar. The CRM's own parts raise them, and so can your layouts, your components and your modules. That corner keeps alerts off the foot of the page: a form's buttons, a panel pinned to the bottom and the last rows of a list stay within reach while an alert is up, one that stays until it is dismissed included. What an alert can be over is the right end of whatever is directly under the top bar (a list's search and its \"New\" button, the last tabs of a record), until it goes or is dismissed. An alert raised while a dialog is open is drawn behind it, and is there when the dialog closes: say what a dialog's own form got wrong in the dialog. What the CRM raises on its own When What is said A field changed in place is refused by the server \"Value was not saved\", and what the server said A step of Stages is refused \"Stage was not changed\", and what the server said A record action ( actions in the config) runs for a while The action's label, with a spinner A record action ends The action's message, or why it failed A save that works says nothing: the new value on the page is the news. From a layout @Alert(text, tone?) is an action, beside @Navigate and @Refresh: The steps of an Action run in order and stop at a Mutation that fails, so an alert after @Run is raised only when the Mutation worked. tone is info (when left out), success, warning or danger. From a component useAlerts() works in any component drawn inside the CRM: a layout component ( defineLayoutComponent), a module's panel, a page of your own under src/routes/_crm. Call What it does alerts.show(alert) Raises an alert and gives its id. alerts.change(id, alert) Replaces an alert that is up. alerts.dismiss(id) Takes one down. alerts.during(work, says) Says doing if the promise is still going after a moment, then done or failed. Gives the promise's own result, and fails when it does. An alert is { text, tone?, detail?, link?, stays? }: tone: info, success, warning, danger, or working (a spinner). detail: a second line, such as why it failed. link: { label, to }, somewhere in the CRM to go from here. stays: keeps it up until it is dismissed. danger and working alerts always stay; the rest go after five seconds. during leaves out done to say nothing when the work succeeds, and waits a moment before announcing work, so something quick never flashes a spinner. At most four alerts are up at once: the oldest that would have gone on its own makes room. Outside the CRM's shell (a public page, a unit test) useAlerts() draws nothing and during still runs the work. Hearing every alert onAlert in defineSpoolUi is called with every alert as it is raised or changed, the CRM's own included. Use it to log them or to send them somewhere of your own. What alerts are not Alerts are for the person at the page, about what they just did. They are not kept, and nobody else sees them. To tell a teammate something later, make a task or use an automation (see configuration.md)." }, { "path": "/docs/integrations", diff --git a/apps/starter/e2e/layouts.ts b/apps/starter/e2e/layouts.ts index 1e140c7..33aa707 100644 --- a/apps/starter/e2e/layouts.ts +++ b/apps/starter/e2e/layouts.ts @@ -12,7 +12,7 @@ import { TAGGER } from './sections' export const PIPELINE_PAGE = [ - 'root = Page([stats, Card([Funnel(byStage.groups, "deals", "currency", ["closeDate"])], "By stage"), Row([Input("q", "Search deals", "search", $q), NewRecord("deals")], "between"), Card([Records("deals", deals.rows, ["value", "stage", "closeDate"], "No deals match.")], "Deals")], "wide")', + 'root = Page([stats, Card([Funnel(byStage.groups, "deals", "currency", ["closeDate"])], "By stage"), Row([Input("q", "Search deals", "search", $q), NewRecord("deals")], "between"), Card([Records("deals", deals.rows, ["value", "stage", "closeDate"], "No deals match.")], "Deals"), SignOff()], "wide")', '$q = ""', 'deals = Query("records", {object: "deals", q: $q, sort: {field: "closeDate", dir: "asc"}}, {rows: [], total: 0})', 'won = Query("records", {object: "deals", where: {stage: "won"}, limit: 1}, {rows: [], total: 0})', diff --git a/apps/starter/e2e/spool.ui.tsx b/apps/starter/e2e/spool.ui.tsx index f761aa6..b72f04a 100644 --- a/apps/starter/e2e/spool.ui.tsx +++ b/apps/starter/e2e/spool.ui.tsx @@ -1,3 +1,4 @@ +import { useState } from 'react' import { z } from 'zod' import { devAuthClient } from '@swirls/spools/auth/dev/ui' @@ -41,6 +42,48 @@ const Nudge = defineLayoutComponent({ }, }) +/** + * A component of the app's own that stays at the bottom of the page, as a panel with a form's + * button in it does, and whose every press is refused: the alert saying so stays up, and the + * button has to be reachable all the same (e2e/tests/alerts.e2e.ts). + */ +const SignOff = defineLayoutComponent({ + name: 'SignOff', + description: 'A button at the bottom of the page that is refused, and says so.', + props: z.object({}), + Component: () => { + const alerts = useAlerts() + const [tries, setTries] = useState(0) + + const signOff = () => { + setTries((now) => now + 1) + alerts.show({ tone: 'danger', text: 'Not signed off', detail: 'A deal is still open.' }) + } + + return ( +
+ +
+ ) + }, +}) + /** * The example Approvals module's panels and sidebar link. One build serves * every server of the browser tests, so it is here for all of them; it shows @@ -49,7 +92,7 @@ const Nudge = defineLayoutComponent({ */ export const ui = defineSpoolUi({ modules: [approvalsUi], - components: [DealCount, Nudge], + components: [DealCount, Nudge, SignOff], // Every alert the CRM raises is heard here: the tests read what was (e2e/tests/alerts.e2e.ts). onAlert: (alert) => { const heard = document.documentElement.dataset['alertsHeard'] diff --git a/apps/starter/e2e/tests/alerts.e2e.ts b/apps/starter/e2e/tests/alerts.e2e.ts index b19b440..410f434 100644 --- a/apps/starter/e2e/tests/alerts.e2e.ts +++ b/apps/starter/e2e/tests/alerts.e2e.ts @@ -87,3 +87,32 @@ test('a field the server will not save says so, by name, and stays until dismiss await alert.getByRole('button', { name: 'Dismiss' }).click() await expect(alert).toHaveCount(0) }) + +test('an alert that stays leaves a button at the bottom of the page within reach', async ({ + page, +}) => { + // Shorter than the page, so the button is held at the foot of the window, as a pinned panel's is. + const height = 560 + + await page.setViewportSize({ width: 1280, height }) + await page.goto('/pages/pipeline') + + const signOff = page.locator('[data-own="sign-off"]') + const box = await signOff.boundingBox() + + expect(box && height - (box.y + box.height)).toBeLessThan(80) + + await signOff.click() + + const alert = alerts(page).getByRole('alert') + + await expect(alert).toContainText('Not signed off') + + // Pressed again with the alert still up: nothing of the alert is over it. + await signOff.click({ timeout: 3000 }) + await expect(signOff).toHaveAttribute('data-tries', '2') + await expect(alert).toHaveCount(2) + + // Nor over the last of the list above it. + await page.getByRole('main').getByRole('link').last().click({ timeout: 3000, trial: true }) +}) diff --git a/docs/alerts.md b/docs/alerts.md index 554dff1..44b55b1 100644 --- a/docs/alerts.md +++ b/docs/alerts.md @@ -1,9 +1,17 @@ # Alerts Alerts are how the CRM tells whoever is using it what is happening: a save the server -refused, an action that finished, work that is taking a while. They are drawn in one place, -over the bottom of the page, by the CRM's shell. The CRM's own parts raise them, and so can -your layouts, your components and your modules. +refused, an action that finished, work that is taking a while. They are drawn in one place +by the CRM's shell: the top right corner of the page, under the top bar. The CRM's own parts +raise them, and so can your layouts, your components and your modules. + +That corner keeps alerts off the foot of the page: a form's buttons, a panel pinned to the +bottom and the last rows of a list stay within reach while an alert is up, one that stays +until it is dismissed included. What an alert can be over is the right end of whatever is +directly under the top bar (a list's search and its "New" button, the last tabs of a +record), until it goes or is dismissed. An alert raised while a dialog is open is drawn +behind it, and is there when the dialog closes: say what a dialog's own form got wrong in +the dialog. ## What the CRM raises on its own diff --git a/packages/spools/src/crm/ui/alerts.tsx b/packages/spools/src/crm/ui/alerts.tsx index bb54d64..f175435 100644 --- a/packages/spools/src/crm/ui/alerts.tsx +++ b/packages/spools/src/crm/ui/alerts.tsx @@ -108,7 +108,7 @@ function trimmed(raised: readonly Raised[]): readonly Raised[] { return trimmed(raised.filter((one) => one !== passing)) } -/** Holds the alerts that are up and draws them over the page. The shell has one. */ +/** Holds the alerts that are up and draws them over a corner of the page. The shell has one. */ export function AlertsProvider({ children }: { children: ReactNode }) { const [raised, setRaised] = useState([]) const { onAlert } = useSpoolUi() @@ -187,10 +187,15 @@ export function AlertsProvider({ children }: { children: ReactNode }) { return ( {children} + {/* + In the top right corner, under the top bar: most of what people act on is at the foot of a + page (a form's buttons, a pinned panel, the last rows of a list, the bar of a selection) and + down its middle, and an alert that stays must not be over any of it. + */}
{raised.map(({ id, alert }) => ( alerts.dismiss(id)} />