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 ( +