Blocks
Blocks are imported from @protobase/layout. Every block also takes className, Tailwind classes for its outer element. “Record” below means the record of the RecordCard, CardRow card or RecordsIterator entry around a block (see Data); filter is AIP-160, as in the list API, or the builder’s arrow, and sort a list of fields, each with asc or desc if it likes, as the list API’s order_by. The ERP example’s sales overview uses Page, Grid, Card, Stat, Table, RecordCard, CardRow, Field, Chart, Action, ModalForm and Show; of the others, the property portal’s home uses RecordRow, and the Users page Users:
/** @jsxImportSource @protobase/layout */import { Action, Card, CardRow, Chart, Field, Grid, ModalForm, Page, RecordCard, Show, Stat, Table, component, page } from '@protobase/layout'
/** Orders per day for the last `days` days, drawn by protobase.ui.tsx. */export const OrdersPerDay = component<{ days: 7 | 30 | 90 }>('OrdersPerDay')
/** The sales team's start page: what needs attention today, and the leads to follow up. */export const salesOverview = page( 'overview', <Page title="Sales overview" description="What needs attention today: unpaid orders, overdue invoices and new leads."> <Show when="orders.count = 0"> <Card title="No orders yet">Create the first order from Orders; this page fills up as the team sells.</Card> </Show> <Grid columns={4}> <Stat label="Draft orders" resource="orders" filter="status = 'draft'" /> <Stat label="Delivered, not paid" resource="orders" filter="status = 'delivered' AND paid = false" /> <Stat label="Overdue invoices" resource="invoices" filter="status = 'overdue'" /> <Stat label="Open leads" resource="companies" filter="status = 'lead'" /> </Grid> <Grid columns={3}> <RecordCard title="Biggest unpaid delivery" resource="orders" filter="status = 'delivered' AND paid = false" sort={['total desc']} empty="Every delivered order is paid." actions={<Action name="markPaid" variant="primary" />} > <Grid columns={2}> <Field source="number" /> <Field source="total" /> <Field source="company_id" label="Customer" /> <Field source="company_id.city" label="City" /> </Grid> <Show when="company_id.status = 'dormant'">The customer has gone quiet: call before sending a reminder.</Show> </RecordCard> <RecordCard title="Oldest overdue invoice" resource="invoices" filter="status = 'overdue'" sort={['issued_at']} empty="Nothing is overdue." actions={[<Action name="send" label="Send reminder" />, <Action name="recordPayment" variant="primary" />]} > <Grid columns={2}> <Field source="number" /> <Field source="total" /> <Field source="company_id" label="Customer" /> <Field source="due_at" label="Due" /> </Grid> </RecordCard> <Card title="Orders per day" description="The last 30 days."> <OrdersPerDay days={30} /> </Card> </Grid> <Grid columns={2}> <Chart title="Orders by status" resource="orders" groupBy="status" type="donut" /> <Chart title="Revenue by customer" description="Orders not cancelled." resource="orders" groupBy="company_id" sum="total" filter="status != 'cancelled'" limit={5} /> </Grid> <Grid columns={2}> <Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort={['issued_at']} columns={['number', 'company_id', 'due_at', 'total']} limit={5} empty="Nothing is overdue." /> <Table title="Latest orders" resource="orders" sort={['created_at desc']} columns={['number', 'company_id', 'status', 'total']} limit={5} /> </Grid> <CardRow title="New leads" description="Companies that have not ordered yet." resource="companies" filter="status = 'lead'" sort={['created_at desc']} limit={8} actions={<ModalForm mode="create" label="Add lead" resource="companies" fields={['name', 'city', 'country_code', 'email']} values={{ status: 'lead' }} />} > <Field source="name" label={false} /> <Field source="city" /> <Field source="email" /> <ModalForm mode="edit" label="Edit" fields={['name', 'city', 'email', 'phone', 'status']} /> </CardRow> </Page>, { nav: { group: 'Sales', order: 0 }, icon: 'layout-dashboard' },)Layout
Section titled “Layout”The root of every page, and only the root.
| Prop | |
|---|---|
title |
Heading, and the page’s name in the sidebar and breadcrumbs. Required. |
description |
A line under the title. |
actions |
Elements beside the title, such as a ModalForm. |
width |
column, the default, keeps the page in a centred column about 1200px wide; full fills the content pane beside the sidebar, for a dashboard with many blocks. On a phone both look the same. |
<Page title="Today" width="full"> <Grid columns={4}> ... </Grid></Page>Columns that collapse to one on a phone, or to two when the grid holds only Stats. A child’s span (1 to 4) makes it wider.
| Prop | |
|---|---|
columns |
1 to 4; default 2. |
span |
Its own width when it sits in another grid. |
<Grid columns={4}> <Stat label="Draft orders" resource="orders" filter="status = 'draft'" /> ...</Grid>A box with a heading. Text and Links inside it run together as paragraphs.
| Prop | |
|---|---|
title, description |
The heading. |
actions |
Elements in the heading. |
span |
Width in a grid. |
<Card title="No orders yet">Create the first order from Orders; this page fills up as the team sells.</Card>A link in text: to an address in the app, or an href that leaves it (https: opens in a new tab, mailto: in the mail app). It shows its children inline, text, Text as="span"s and field components, or without them where it leads. It cannot hold another Link or a UrlField. With className it drops its own look for those classes.
<Link to={{ kind: 'list', resource: 'invoices', filter: "status = 'overdue'" }}>Overdue invoices</Link>| Prop | |
|---|---|
to |
An address. {{path}} in it is the value of that path through the records around the link, and {{@params.window}} a page parameter, so { kind: 'page', page: 'payouts', params: { window: '{{@params.window}}' } } carries the choice to another page. |
href |
A link that leaves the app. A path in the app is refused when the config loads: give it as to. |
variant |
primary, secondary, danger or ghost: drawn as a button of that variant, still a link. className adds to it, such as w-full. |
One of the two is required. A link to a resource or field the user cannot see is left out of their page.
Box, Row, Column and Text
Section titled “Box, Row, Column and Text”Plain elements for a page too custom for the blocks, drawn by their Tailwind classes alone.
| Element | |
|---|---|
Box |
An element of its own, such as a panel or a banner. No look of its own. |
Row |
Its children side by side: flex. |
Column |
Its children one under another: flex flex-col. |
Text |
Text, Links, Transes, inline Texts and field components in it, nothing else, run as one line. as makes it p (the default), span, strong, em, or a heading h1 to h4; span, strong and em run inline. |
<Row className="items-center gap-3"> <Box className="size-3 rounded-full bg-success" /> <Text as="span" className="font-medium">All systems running</Text></Row>One of the app’s own texts in the reader’s language, as react-i18next’s <Trans>: as a child, it runs inline as text does, and as a title, description, label or empty it reads as that prop’s text. See Texts in the reader’s language.
| Prop | |
|---|---|
i18nKey |
The message’s key in the app’s translations, such as today.open. Required. |
values |
What the message formats by name, { count: 2, name: '{{owner}}' }: text, numbers, booleans and placeholders. |
components |
The element each tag of the message draws, { b: <Text as="strong" /> }, with the tag’s text inside it. As a prop’s text, tags read as their text alone. |
<Trans i18nKey="today.owner" values={{ name: '{{owner}}' }} components={{ b: <Text as="strong" /> }} />Details and Summary
Section titled “Details and Summary”A line that opens to show the rest and closes again, drawn as HTML’s <details> and <summary>, so the browser opens and closes it with no script. A Details takes one Summary, as its first child; the Summary is one line, holding what a Text holds. See Field values.
<Details> <Summary>Brakes, <ChipField source="state" /></Summary> <Text>Pads and cables replaced.</Text></Details>| Prop | |
|---|---|
open |
Details only: starts open. |
Tabs and Tab
Section titled “Tabs and Tab”Tabs splits a page into tabs, each at its own address: the first at the page’s (/<page>), each other at its name below it (/<page>/<name>). Only the shown tab’s elements are drawn, so the others load nothing. On a phone the tabs are a select. Tabs takes no props and holds only Tabs; it sits directly in the Page, once per page, with other elements before or after it if you like.
Tab prop |
|
|---|---|
name |
The tab’s address, after the page’s, and how a link opens it ({ kind: 'page', page, tab }). Lowercase first letter, then letters, digits and dashes; one per tab. Required. |
label |
The tab’s word in the row of tabs, and before the page’s title in the browser tab. Required. |
<Page title="Settings"> <Tabs> <Tab name="general" label="General"> <Card title="Opening hours">Monday to Friday, 8:00 to 17:30.</Card> </Tab> <Tab name="billing" label="Billing"> <Table title="Invoices" resource="invoices" /> </Tab> </Tabs></Page>A tab whose every element a user may not see is left out of their page, and so are tabs left with none. An address with a tab name the page has no tab for (or not for this user) shows the tabs and says so.
One number or value with a label. Exactly one of value, resource and field.
| Prop | |
|---|---|
label |
Required. |
value |
A fixed value. |
resource, filter |
Counts the matching records the user can see; the card links to that filtered list. |
field |
A field of the record, through relations (plan.name). |
format |
Instead of the view’s format, such as badge. |
description |
A line under the value. |
span |
Width in a grid. |
<Stat label="Delivered, not paid" resource="orders" filter="status = 'delivered' AND paid = false" />The first records of a list, drawn the way the resource’s list page draws them: its table, or one of the view’s list displays such as cards, with the same switch between them when the view has several. A row or card opens the record, and View all opens the list with the same filter and order. It opens in the display the viewer picked, which is kept for them in the browser, else in its display, else in the view’s default, on a phone too, a table there showing the phone’s columns; with none of them, a phone opens a view with a cards display in it. On a phone cards sit in one row that scrolls sideways.
| Prop | |
|---|---|
resource, filter, sort |
Which records, in which order; sort defaults to the list’s. Without resource, inside a ReferenceManyField or ReferenceArrayField, it draws that list’s records and reads none of its own, so it takes no filter, sort, limit, display or bulk. |
columns |
Field names for the table, or { name, priority } for a column that matters on a phone, 1 the most important; default the view’s list columns. See Columns on a phone. |
button |
A button on each row to an address the row’s fields name, or to the outside page a field holds; a list of these gives each row the first whose fields it holds. |
bulk |
true: rows can be selected, and the view’s bulk actions run on the selected rows, as on the list page; see signing several records off. |
limit |
How many records it shows; default 10. It has no pages: the rest are in the list. Before 0.13 this was pageSize, rows per page; rename it. |
display |
The display it opens in, such as cards; default the list’s. |
select |
The page parameter a row’s choice sets, such as claim: each row links to the page with its key there (?claim=11) instead of to its record, whose page its menu still opens, and the table’s children draw under it inside the chosen row, or nothing while none is chosen. With it, the table shows no other display. |
title, description, actions |
The heading. |
empty |
Text when nothing matches; default “Nothing here yet.”. |
span |
Width in a grid. |
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort={['issued_at']} columns={['number', 'company_id', 'due_at', 'total']} limit={5} empty="Nothing is overdue." />Columns on a phone
Section titled “Columns on a phone”At mobile width, below the sm breakpoint (640px), a table shows at most three of its columns, so the ones that matter fit on screen without scrolling sideways; at wider widths it shows them all. Give a column a priority to choose it: when any column has one, a phone shows only the columns with a priority, the three lowest numbers. Without priorities, the default comes from the columns themselves: the record’s title first, then badge columns such as enums, then the others in the table’s order. The columns keep their order in the table.
<Table title="Objectives" resource="objectives" columns={['rank', { name: 'title', priority: 2 }, 'points', { name: 'verdict', priority: 1 }]} />On a phone this table shows Title and Verdict; on a wider screen Rank, Title, Points and Verdict. Its text form is a Markdown table with its columns in the same order of importance.
Row buttons
Section titled “Row buttons”button: { label, to } adds a last column with a button on each row: a link, drawn as a button, to to, an address in the app, such as a record on one of its tabs. {{field}} in the address or the label is replaced by the row’s value, the label’s as the record page shows it (an enum value by its label), so each row can name its own next step. The column is as wide as the longest label among the first rows shown, up to 18rem, past which a label shortens and shows whole on hover. Below the md breakpoint (768px), where a table keeps its columns whole and scrolls sideways, the button sits under the text of the row’s first cell instead, so it is on screen without scrolling. A row with no value for a field the button names shows no button. The button is checked when the config loads, and /meta gives it, on the block or the related section, to callers who can read the fields it names and follow its address, and leaves it out for the others. A related section takes the same button, on its table’s rows or its cards.
<Table title="Waiting on you" resource="holds" filter="state = 'open'" columns={['reason', 'task_id']} button={{ label: '{{verb}}', to: { kind: 'record', resource: 'tasks', key: '{{task_id}}', tab: 'Review' } }}/>Each row can decide where its button goes:
- A record’s tab from a field:
tab: '{{tab}}'opens the tab the row’stabfield names; a name the record page has no tab for opens its first tab. - A filtered list:
{ kind: 'list', resource: 'holds', filter: 'task_id = {{task_id}} AND state = "{{state}}"' }opens the list with a filter built from the row. A text value goes in quotes, on its own, escaped so a title with quotes in it stays one value; a{{field}}inside a longer quoted value, such as're {{verb}}', is refused when the config loads; a value outside quotes must be a number ortrue/false, and a row with any other value there shows no button. The filter’s fields must be filterable, as in any address. - A list the row holds:
{ kind: 'list', resource: '{{lever_resource}}', filter: '{{lever_filter}}' }opens the list whose resource and whole filter, such asstatus = "parked" AND repo = "web", the row’s fields hold; a fixed resource takes a filter from the row the same way. The filter is checked as each row draws its button, against the resource as/metagives it to the caller, and a row whose filter does not parse, names a field that resource lacks or names one the caller cannot filter shows no button. The list still applies its own access rules when it opens. Beside a resource from the row, the filter is that one field or none, and the address takes no order. - An outside page:
{ label: 'Error report', href: '{{report_url}}' }opens the page the row’sreport_urlfield holds, in a new tab without the referrer, and the button carries the outside-link mark, which screen readers hear as “opens in a new tab”. Thehrefis one field, never a URL put together from parts, and a row whose field holds nohttps:URL shows no button. - A different kind per row:
buttontakes a list of these, and each row shows the first whose fields it holds, so one list can hold items that each need a different act. A row whose first such choice leads nowhere, such as anhreffield without anhttps:URL, shows no button rather than the next choice. A caller who cannot read a choice’s fields or follow its address gets the list without it.
<Table title="Needs attention" resource="alerts" columns={['summary']} button={[ { label: 'Open the error report', href: '{{report_url}}' }, { label: '{{verb}}', to: { kind: 'record', resource: 'tasks', key: '{{task_id}}', tab: '{{tab}}' } }, { label: 'See its failed jobs', to: { kind: 'list', resource: 'failed_jobs', filter: 'alert_id = {{id}}' } }, ]}/>Signing several records off
Section titled “Signing several records off”Records that wait on the same act, such as several steps one approval unlocks, are signed off together: select them in the list, or in a Table with bulk, and press the action, such as Approve (3). Its dialog names the records and shows a checklist, and the action runs only once every box is ticked. The checklist is an input, i.checklist, of an action with bulk:
.actions((a) => [ a.update('approve', { label: 'Approve', bulk: true, when: "state = 'waiting'", confirm: 'Tick each detail you confirm.', inputs: (i) => [i.checklist('checked', { label: 'What you checked', from: 'checklist' })], set: { checked: '{{checked}}', state: 'approved' }, }),])<Table title="Waiting on you" resource="approvals" filter="state = 'waiting'" bulk />With from, each record brings its own boxes from that JSON field, a list of texts, and the dialog shows each box once, however many of the records hold it. Each record then gets the boxes it holds as its answer, so '{{checked}}' writes what was signed off for that record; a record that holds no boxes needs none ticked. With items, every record shows and gets the same boxes. The record page’s button for the action opens the same dialog with that record’s boxes.
Access is checked per record: a record the person may not change, by its permissions or by the API’s answer, is refused while the others are signed off, and the toast names it, such as Approve: done on 2, refused on 1 with “Not done on “Rotate the signing key”: you may not change it.”. protobase build refuses a from that is no JSON field of the resource, and /api/meta leaves the action out for someone who cannot read that field.
RecordCard
Section titled “RecordCard”One record and what is inside it: the one recordKey names (the key as the record’s URL has it), else the first that matches filter in sort order. Its children and its heading actions work on that record.
| Prop | |
|---|---|
resource, filter, sort |
Which record. resource is required. |
recordKey |
A fixed record instead. |
title, description, actions |
The heading. |
empty |
Text when no record matches. |
span |
Width in a grid. |
<RecordCard title="Biggest unpaid delivery" resource="orders" filter="status = 'delivered' AND paid = false" sort={['total desc']} actions={<Action name="markPaid" variant="primary" />}> <Field source="number" /> <Field source="company_id.city" label="City" /></RecordCard>CardRow
Section titled “CardRow”Up to limit records side by side, each a small card made from the children, which work on that card’s record. The heading’s actions do not have a record: use them for a ModalForm mode="create".
| Prop | |
|---|---|
resource, filter, sort |
Which records, in which order. resource is required. |
limit |
How many; default 12. |
title, description, actions |
The heading. |
empty |
Text when nothing matches. |
span |
Width in a grid. |
RecordRow
Section titled “RecordRow”What a filter finds, the way a home page shows it: the filter’s chips, as the list’s filter panel names them, how many records match, the records as the cards of the resource’s cards display in one row, and View all, which opens the list with the same filter and order. The row scrolls sideways by touch, trackpad or its arrow buttons and snaps each card, 256px wide but never wider than the row, to its left edge; only the cards near the view are drawn, and the records load through the list API in pages as it scrolls. Each card opens its record. A resource without a cards display gets cards of the title alone.
It follows the resource’s view as its list page does. Of a resource whose view has listOf, such as favorites, it shows the records the user’s saved ones point at, as their own resource’s cards, and View all opens the favorites. Of one whose view has searchesOf, it shows a row for each of the user’s saved searches, under its name or its filters, with the records new to them marked New and View all results, as their list page shows them. filter and sort do not apply to those two.
| Prop | |
|---|---|
resource, filter, sort |
Which records, in which order. resource is required; sort defaults to the list’s. |
limit |
How many records it shows at most; default every one that matches. |
display |
The cards display whose cards it draws; default the view’s first. |
title, description, actions |
The heading. |
empty |
Text when nothing matches; default “No … match.”, with the view’s plural. |
span |
Width in a grid. |
<RecordRow title="For rent" resource="listings" filter="for_rent = true AND status = 'available'" sort={['published_at desc']} />RecordCards
Section titled “RecordCards”What a filter finds as the cards of a record page’s related records as cards, stacked full width under a heading that has no card around it, so the page shows no card inside another: each record’s title linking to its page, its fields under their labels, a value taller than a few lines cut short with Show more, and a button for each of cardActions, run as on the record page. Below the cards, View all opens the list with the same filter and order, beside a note such as “The first 10 of 37.” when there are more.
With layout="carousel" the cards sit side by side in one row that scrolls sideways, by touch, trackpad, mouse wheel, its scrollbar or, with a mouse, its arrow buttons, as a RecordRow does, and snaps each card to its left edge. Each card is cardWidth of the block’s width, so the next one peeks in, but never narrower than 12rem, so narrow cards stay readable on a phone. The cards in a row are as tall as its tallest and keep their fields and buttons.
| Prop | |
|---|---|
resource, filter, sort |
Which records, in which order. resource is required; sort defaults to the list’s. |
layout |
stack (default) or carousel. |
cardWidth |
In a carousel, the width of each card as a share of the block’s: 1/4, 1/3, 1/2 or 2/3 (default). |
fields |
The fields each card shows, through relations too (task_id.title); default the list’s columns. |
cardActions |
Named actions of the resource’s view, as buttons on each card. |
limit |
How many; default 10. |
display |
The list display View all opens; default the list’s. |
title, description, actions |
The heading. |
empty |
Text when nothing matches. |
span |
Width in a grid. |
<RecordCards title="Waiting on you" resource="task_preconditions" filter="state = 'waiting'" fields={['task_id', 'plan']} cardActions={['approve', 'request_changes']} /><RecordCards title="Runners" resource="runners" layout="carousel" cardWidth="1/4" fields={['state']} />A label over a value of the record, formatted as on the record page: statuses as badges with the view’s value labels, relations as the related record’s name (linked), the view’s prefix and decimals.
| Prop | |
|---|---|
source |
A field, through relations (company_id.city), named as react-admin’s fields name it. Required. |
label |
Default: the view’s label, else the path in words. false shows the value alone. |
format |
Instead of the view’s format. |
Field components
Section titled “Field components”TextField, NumberField, DateField, BooleanField, UrlField and ChipField show one value of the record inline, in a Text, a Link or a Summary, as react-admin’s field components do. Each takes source and emptyText; see Field values for their props and where they differ from react-admin’s.
<Text>Due <DateField source="due_at" format="relative" />, quoted at <NumberField source="quote" options={{ style: 'currency', currency: 'EUR' }} /></Text>Progress
Section titled “Progress”A bar for value out of max, with both numbers. It turns amber from 90%.
| Prop | |
|---|---|
value |
A number, or the name of a field of the record. Required. |
max |
A number or a field; default 100. |
label, span |
<Progress label="Seats" value="seats_used" max="plan.seats" />A unified patch the record holds in a text field, as diff -u and git diff write it: each file under its name, a name git quotes read as the name it stands for, with the counts of added and removed lines, then its changes, numbered by the patch’s @@ lines. From the md breakpoint (768px) up, the old lines stand on the left and the new ones beside them; below it, both run in one column. Text that is not a unified patch shows as it is, in a code font, and text before the first file, such as a mailed patch’s message, is left out.
| Prop | |
|---|---|
source |
The text field holding the patch, a path as a field component’s source is. Required. |
emptyText |
Shown when the field is empty; nothing is shown without it. |
<RecordCard resource="changes" recordKey="42" title="Proposed change"> <Diff source="patch" emptyText="No changes yet" /></RecordCard>In the text form it reads as the patch in a fenced diff code block, its fence longer than any run of backticks the patch holds, so a patch of a Markdown file cannot end it early.
A fixed picture at src, or one an API function draws.
A fixed picture is an https: URL or a path on the app’s own origin, such as /logo.svg, with an alt it needs: what it shows, or alt="" when it only decorates. It is drawn as a plain image at its width and height, never wider than its space; with className its classes are its whole look instead. Every reader gets it, and it takes no refresh.
<Image src="/logo.svg" alt="Acme" className="size-12 rounded-full" />A function’s picture, such as a system map: the block calls GET /api/functions/<function> with the reader’s token, and draws the image it answers with, such as a PNG. The query says what to draw:
| Query | |
|---|---|
width |
The width the client draws it at, in CSS pixels: the block’s width, else the width of its space, rounded up to a multiple of 100 so resizing the window asks again only now and then. |
height |
The block’s height, when it has one. Without it the query names no height, and the picture’s own proportions decide. |
theme |
light or dark, the theme the page is drawn in. |
| Prop | |
|---|---|
function |
The function’s name, as in functions/<function>.ts; the server stops at startup when the app has no such function. |
src |
A fixed picture instead. One of function and src is required. |
alt |
What the picture shows, for screen readers and for clients that draw no images. |
width, height |
The size it is drawn at, in CSS pixels. |
refresh |
Every how many seconds the client asks for the picture again, keeping the last one on screen while the next loads; once when omitted. Regaining window focus never asks again. |
<Image function="system-map" alt="The servers and the links between them" height={320} refresh={60} />import { defineFunction } from '@protobase/server'import { drawSystemMap } from './_shared/system-map'
export default defineFunction({ roles: ['admin', 'support'] }, async (request, { records }) => { const query = new URL(request.url).searchParams const { items } = await records.list('servers') const png = await drawSystemMap(items, { width: Number(query.get('width')), height: Number(query.get('height')) || undefined, dark: query.get('theme') === 'dark' }) return new Response(png, { headers: { 'content-type': 'image/png' } })})The function reads records as the caller, so the picture shows only what they may see. A reader the function’s roles or capability leave out gets the page without the block. So does a visitor without a token, unless the function is public, since only a public function takes a call without one. A client that draws no images, such as one that shows text only, shows alt in its place, or nothing without it; the admin app does the same when the function refuses, answers no image or one the browser cannot draw, also when a later request fails after an earlier one drew a picture.
Counts, sums or averages of the records that match filter, per value of a field or per hour, day, week, month or year of a date field, in a card. It reads :aggregate, so only what the user may see is counted, and the grouped field needs an index (scan guard).
| Prop | |
|---|---|
resource, filter |
The records it counts. resource is required. |
groupBy |
A filterable field. Values, such as an enum, a boolean or a relation (named by the related record), are ranked bars or a donut, each linking to its records; a date or timestamp field is a bar or line per bucket, empty ones included. Required. |
splitBy |
With a date groupBy: a field of values that splits each bucket, as stacked bars or a line per value; its 8 largest values over the range, the rest as Other for a count or sum. An index must serve it. A stacked bar takes no average. |
type |
bar (the default), line for a date groupBy, donut for one of values. |
sum, average |
A numeric field each group adds up or averages, with its prefix, suffix and decimals, instead of counting. One of the two; a donut takes no average. |
granularity, range |
A date groupBy’s bucket, hour to year (default day), and how far back it reaches: 7d, 30d (the default), 90d, 1y or all. |
limit |
How many values it shows, the largest; default 10. |
title, description, actions, empty, span |
As on Table. |
<Chart title="Orders by status" resource="orders" groupBy="status" type="donut" /><Chart title="Revenue by customer" resource="orders" groupBy="company_id" sum="total" filter="status != 'cancelled'" limit={5} /><Chart title="Invoiced per month" resource="invoices" groupBy="issued_at" granularity="month" range="1y" type="line" sum="total" /><Chart title="Revenue per day by status" resource="orders" groupBy="created_at" splitBy="status" sum="total" />Each value takes its colour from the view’s valueColors, else an enum value’s place among its values, from the chart tokens. A chart whose field the user cannot read is left out of their page, and a field it cannot group or add up stops the server at startup. On a time rollup it adds up the stored buckets, such as average="watts_sum", and gives what the source’s records give.
Timeline
Section titled “Timeline”Records of resource that match filter as a timeline, a Gantt chart for projects, orders or work: a lane per value of lane, a bar per value of bar in it, and each record a segment of its bar from start to end, coloured by its color value. A record without an end runs to now. The time axis runs from the earliest start to the latest end and always fits the page’s width, so a phone shows the same time compressed, its lanes stacked under their names, and the page never scrolls sideways. Bars that overlap in time get rows of their own in their lane. Pointing at a bar, or moving focus to it, shows its times and each segment’s under the lanes, which a screen reader reads from the bar too, a relation’s bar by the name of the record it points at.
| Prop | |
|---|---|
resource, filter |
The records it draws, every one the filter matches, read page after page. resource is required. |
lane |
The field whose values each get a lane, in the order they first start, such as a project. Required. |
bar |
The field whose values each get a bar in their lane, its records the bar’s segments, such as a task; the record’s own key gives a bar per record. Required. |
start, end |
Date or timestamp fields where a segment starts and ends. Required. |
color |
An enum field: a segment takes its value’s tone or colour from the view’s valueColors, else the chart token of its place among the enum’s values, and is striped for a value the view marks with .waitingValues(...). A legend names the values the bars hold. Required. |
select |
The page parameter a bar’s choice sets, such as task: each bar links to the page with its bar value there (?task=42), the chosen bar is marked aria-current, and the timeline’s children draw under it inside the chosen bar’s first record, or nothing while none is chosen. |
limit |
How many records it reads at most, from 1 to 100,000; default 20,000. When more match, it draws the latest by start and a line under the lanes says how many it shows. |
title, description, actions, empty, span |
As on Table. |
<Timeline title="Where the time went" resource="phases" lane="project" bar="task_id" start="started_at" end="ended_at" color="phase" select="task"> <ReferenceField source="task_id" reference="tasks" /></Timeline>view<typeof phases>('phases').fields((r) => ({ phase: r.phase.valueLabels({ build: 'Building', ci: 'Waiting for CI' }).valueColors({ build: 'blue', ci: 'amber' }).waitingValues(['ci']),}))Its text form is a Markdown table with a row per segment of its latest 500, the earliest first: its lane, bar, value, start and end under the fields’ labels. A timeline whose fields the user cannot read is left out of their page, and a field it cannot draw, such as a start that is no date, stops the server at startup.
The records of nodes as boxes and the records of edges as arrows between them, from the node an edge’s source holds the key of to the one its target holds, such as services and the links between them, or tasks and what blocks them. Each node sits in the region of its group, coloured by its status, and draws its label and status, or contents of the layout’s own; each edge can carry a label, a status colour and a moving, dashed or dotted line. With select, the chosen node’s details draw beside the graph. Its drawing code loads only on a page with a graph, and it is laid out in a worker of its own, so a large graph never holds up the page.
| Prop | |
|---|---|
nodes, edges |
The resources whose records are the nodes and the edges. A node is found by its key, which must be one field: a resource with a key of several fields stops the server at startup. An edge whose source or target is not among the nodes is left out. Required. |
source, target |
The fields of an edge that hold the keys of the nodes it runs from and to. Required. |
label |
The field of a node that names it: its text where it draws no node, the name of its link and its line in the text form. Required. |
group |
The field of a node whose value puts it in a region with the nodes that hold the same, the value at the region’s top; a node without one stands outside every region. |
status |
An enum field of a node, shown under its label and colouring its left edge, as the view’s valueColors give each value. |
node |
What each node draws, inside its record: placeholders, Fields, Shows and the other blocks that show a record, but no block that reads records of its own, which would read once per node. In a typed layout it is a function of the node’s record, (service) => <Text>{service.owner}</Text>. A node that draws one is 224 pixels wide and as tall as it draws. |
filter, edgeFilter |
Which nodes and which edges it shows, AIP-160 or the builder’s arrow. |
edgeLabel |
A field of an edge shown on its middle, by its value label if the edges’ view gives one. |
edgeStatus |
An enum field of an edge that colours its line and arrow, as the edges’ view’s valueColors give each value. |
animated, dashed, dotted |
Conditions on an edge, AIP-160 or the builder’s arrow of the edge’s fields, (link) => link.state.eq('busy'), under which its line moves, as for work running along it, is dashed or is dotted; dotted wins over dashed. Each is evaluated for each edge as the graph draws, now() included. |
layout |
layered (the default), the nodes in layers along their edges, or force, linked nodes pulled near each other and the others pushed apart, for a graph that has no direction. |
direction |
Which way a layered graph’s edges run: down (the default), which keeps it narrow on a phone, or right. |
x, y |
Two number fields of a node that place its top left corner, in pixels at the graph’s normal size. A node with both stands there, and the nodes without are laid out under the placed ones; when every node has them, nothing is laid out. |
select |
The page parameter that holds the chosen node’s key: each node links to the page with it chosen, a node that draws its own node as a whole, and the Graph’s children draw beside the graph, inside that node’s record, or under it on a narrow screen. |
empty |
What it shows without nodes. |
fallback |
What draws in its place where it cannot draw, as when its records cannot be read, such as the picture one of the app’s API functions draws of the same graph. Without one, it shows the error. |
export const serviceMap = page('service-map', layout(() => ( <Page title="Services" width="full"> <Card title="Service map"> <Graph nodes="services" edges="links" source="from_id" target="to_id" label="name" group="area" status="health" select="service" node={(service) => ( <> <Text as="strong">{service.name}</Text> <Text>{`Owned by ${service.owner}`}</Text> </> )} edgeLabel="protocol" edgeStatus="state" animated={(link) => link.state.eq('busy')} dashed={(link) => link.optional.eq(true)} fallback={<Image function="service_map" alt="The services and the links between them" />} > <Field source="owner" /> <Field source="health" /> </Graph> </Card> </Page>)))The page’s read plan reads the nodes, with the fields they and their node draw, and the edges, with the fields their label, colour and conditions read, with the rest of the page as it opens. The same records always make the same picture: groups, nodes and edges are laid out in the order of their keys, and a force layout from a fixed seed. The graph is as wide as its place and as tall as its shape asks, up to most of the screen; it fits in that box unless that would make it too small to read, as on a phone, where you drag to pan. Pinch or the zoom buttons zoom it, the fit button shows all of it, and the mouse wheel scrolls the page past it. x and y from the graph is not implemented; store them from elsewhere, such as an action.
Its text form lists each group with its nodes and their status, the nodes in no group, then each edge as a → b with its label, from the records of the page’s plan, or its fallback without them. A graph whose resources, label or ends the user cannot read is left out of their page, and its other props that name fields they cannot read are dropped.
Related records
Section titled “Related records”The blocks that repeat over a record’s related records, as related records explains, with the names, props and defaults of react-admin’s components. ReferenceManyField, ReferenceArrayField and ArrayField hold a list and draw nothing of their own; a RecordsIterator or a Table without resource inside one draws it. Each sits inside a record, whose field it reads.
ReferenceManyField
Section titled “ReferenceManyField”The records of reference whose target holds the record’s source, as react-admin’s ReferenceManyField.
| Prop | |
|---|---|
reference |
The resource it reads. Required. |
target |
The field of reference that points at the record. Required. |
source |
The field of the record it matches; default id, of the nearest record. A path, such as ../id. |
filter |
More conditions, as AIP-160 text or the builder’s arrow, ANDed with the target’s. |
sort |
A list of fields, each with asc or desc if it likes, ['claimed_at desc']; default the key, descending. |
perPage |
How many records it reads, at most 500; default 25. |
pagination |
more: a Load more button reads the next perPage records into the same list. |
empty |
Text instead of the children when no record matches. |
<ReferenceManyField reference="task_claims" target="task_id" filter="status = 'open'" sort={['claimed_at desc']} pagination="more"> <Table title="Open claims" columns={['worker_id', 'claimed_at']} /></ReferenceManyField>ReferenceArrayField
Section titled “ReferenceArrayField”The records of reference whose keys the record’s source, a JSON list of keys, holds, as react-admin’s ReferenceArrayField.
| Prop | |
|---|---|
source |
A JSON field of the record holding the keys. Required. |
reference |
The resource the keys belong to. Required. |
filter, sort |
As ReferenceManyField’s. |
perPage |
How many records it reads; default and at most 500, the API’s largest page. |
empty |
Text instead of the children when no record matches. |
ArrayField
Section titled “ArrayField”The items of the record’s source, a JSON list, as react-admin’s ArrayField. An object item is read by its keys, and a text item as this: <Field source="this" />.
| Prop | |
|---|---|
source |
A JSON field of the record. Required. |
ArrayField cannot filter, sort or page its items because react-admin’s filter, sort and perPage on it are not implemented.RecordsIterator
Section titled “RecordsIterator”Its children once per entry of the list around it, each inside that record or item, with nothing drawn around them, as react-admin’s RecordsIterator. It takes no props.
<ArrayField source="labels"> <RecordsIterator> <Field source="this" label={false} /> </RecordsIterator></ArrayField>ReferenceField
Section titled “ReferenceField”The record of reference the record’s source points at, as react-admin’s ReferenceField: its children inside that record, or without children its title, as a link to the record’s page.
| Prop | |
|---|---|
source |
The field holding the key, such as a relation. Required. |
reference |
The resource it points at. Required. |
link |
edit (default) or show links to the record’s page, false does not. |
empty |
Text when the field holds no key. |
Conversation
Section titled “Conversation”A chat declared in the layout like any other block: a Thread lists the messages of a resource and a Composer beneath it sends one, so /meta describes the conversation and every client can draw it, with no component of the app’s own. On a record page, l.thread and l.composer hold the conversation of that record.
<Card title="General"> <Thread resource="messages" filter="room = 'general'" sender="author_id" time="sent_at" text="body" /> <Composer resource="messages" field="body" values={{ room: 'general' }} placeholder="Message General" /></Card>A message resource marks its sender with .author(), which every create sets to the signed-in user, so a message is never sent in someone else’s name.
Thread
Section titled “Thread”The latest messages that match filter, oldest first, each under its sender’s name and the time it was sent, with a line between days and a sender’s next message that day drawn under the first. Load earlier messages at the top reads the ones before. The thread opens at the newest message and scrolls in a box of its own, so it follows what arrives while the reader is at the end and keeps their place when they scrolled back, until their own message arrives; new messages arrive by themselves only when the message resource is .live(), otherwise when the page reads the thread again, and screen readers announce them politely. It is left out of the page of a user who cannot read its sender, time or text.
| Prop | |
|---|---|
resource, filter |
Which messages. resource is required. |
sender |
Who wrote each message: a relation, named as the record it points at, or a text field. Without it, the thread is one author’s, such as a log: each message shows under the time it was sent, with no name or avatar. |
time |
When each was sent: a date or timestamp field the API can sort by, which orders them. Required. |
text |
The message; shown rendered when the message resource’s view marks it .markdown(). Required. |
status |
A short line under each message, such as whether it was delivered: a text or enum field, shown with its view’s value labels, in red for a value it colours red; a message without a value shows none. Left out for a user who cannot read it. Experimental, see Message status and a working indicator. |
working |
A condition on the record around the thread, as Show takes, such as state = 'working': while it holds, the thread ends in a working indicator. Left out for a user who cannot read what it names. Experimental. |
calls |
Tool calls shown between the messages in time order, from a resource of their own; see Tool calls. Left out for a user who cannot read their name, time or status. |
limit |
How many of the latest messages it shows at first, and of the latest tool calls, and how many each Load earlier messages adds: 1 to 500, the API’s largest page; default 50. |
title, description, actions |
The heading; no card is drawn around the thread, so it can sit in a Card with its composer. |
empty |
Text while there are no messages. |
span |
Width in a grid. |
Tool calls
Section titled “Tool calls”A thread with an assistant in it can show what the assistant did between its messages: each tool call it made, in time order, with the tool’s name and its status, which opens to what the tool was called with, what it gave back and why it failed. calls names the resource that holds the calls and the fields the thread reads of each:
<Thread resource="messages" filter="chat_id = 1" sender="author_id" time="sent_at" text="body" calls={{ resource: 'tool_calls', filter: 'chat_id = 1', name: 'tool', time: 'called_at', status: 'state', input: 'input', result: 'output', error: 'failure' }}/>calls key |
|
|---|---|
resource, filter |
Which calls. resource is required. |
name |
The tool’s name: a text field. Required. |
time |
When it was called: a date or timestamp field the API can sort by, which places it among the messages. A call at the same time as a message shows after it. Required. |
status |
A text or enum field: done shows a check, running a spinner and error an alert icon in red, each beside the value’s label from the view; any other value shows its label without a mark, and a call without a value shows none. Required. |
input, result |
What the tool was called with and what it gave back, shown as indented JSON; a text that holds JSON shows as the value it holds. |
error |
Why the call failed: a text field. |
Each call is a line under the messages before it, closed at first; a call with an input, result or error opens and closes with a click on its line. The thread reads the latest calls as it reads the latest messages, limit at a time, newest first by time, so that read needs an index on the filter’s field and time, which protobase doctor checks, and Load earlier messages loads the earlier calls with the earlier messages, keeping them in time order. A user who cannot read the calls’ name, time or status gets the thread without its calls, and one who cannot read input, result or error gets the calls without that part.
Clients that cannot draw the calls get their simpler forms from @protobase/layout: threadLines(items) gives one short line per item, a message as its sender, when it has one, and first line and a call as its name and status, and threadMarkdown(items, words) gives the thread as Markdown, for clients that read text, such as an MCP client or a language model: each message under its sender in bold, or one author’s under its time alone, each call as its name and status with its input and result as JSON and its error in fenced code blocks. A message’s text is escaped so it reads as written, unless its item sets markdown: true. The Markdown comes from renderText, the text form every block renders through: threadItemNodes(items, words) gives the items as elements, and a Thread element holding them as its children reads as its heading with its items under it, so a page’s text can include its thread.
Composer
Section titled “Composer”A text box that grows with its text: Enter or the send button creates a record of resource with the text in field and the values, and Shift+Enter starts a new line. The text stays in the box until the server took it, so a message it refuses is still there to send again, under the reason. It is not shown to a user who may not create a record of resource or write its fields.
| Prop | |
|---|---|
resource |
Where a message is created. Required. |
field |
The writable text field the message goes in. Required. |
values |
Sent with every message, such as the room or the parent record’s key. Only writable fields: a read-only field, the tenant or the author stops the server at startup, since the server sets those itself. Before 0.92 these were accepted; remove them from values. |
placeholder |
The box’s text while empty. |
span |
Width in a grid. |
Behaviour
Section titled “Behaviour”Action
Section titled “Action”A button for a named action of the view, on the record around it, or, directly in a ReferenceManyField or ReferenceArrayField, on every record of that list (actions in a list).
| Prop | |
|---|---|
name |
The action’s name in the view. Required. |
resource |
Outside a record and a list: the resource whose view declares it. |
label |
Default: the action’s label. |
variant |
primary, secondary (default), danger or ghost. |
ModalForm
Section titled “ModalForm”A button that opens a form in a dialog. create makes a record of resource; edit changes the record around it (or resource with recordKey), sending only the changed fields with the record’s ETag. The editors are the record page’s, and errors from the server show on their fields. It is not shown to a user who may not create or update, and it keeps only the fields they may write.
| Prop | |
|---|---|
mode |
create or edit. Required. |
label |
The button. Required. |
fields |
The fields of the form, writable ones only. Required. |
resource |
Default: the record’s resource. |
recordKey |
Edit this record. |
title |
The dialog’s title; default the label. |
values |
Sent with every create, such as { status: 'lead' } or a parent’s key. |
variant |
As for Action. |
<ModalForm mode="create" label="Add lead" resource="companies" fields={['name', 'city', 'country_code', 'email']} values={{ status: 'lead' }} />SelectInput
Section titled “SelectInput”A choice of a page parameter, as react-admin’s SelectInput takes it, written into the page’s address instead of a form: a select whose choices are each a link to the page with that choice, ?<source>=<id>, the default leaving it out. The layout reads it as @params.<source>.
| Prop | |
|---|---|
source |
The parameter’s name, such as window. Required. |
choices |
{ id, name } objects: id the value the address holds, text or a number, name what the select shows. Without them, it shows the address’s value as text, which no read may take. |
label |
Shown beside the select; default the source. |
defaultValue |
The choice’s id while the address names none of the choices. |
<SelectInput source="window" label="Window" defaultValue="7d" choices={[{ id: '7d', name: 'Last 7 days' }, { id: '30d', name: 'Last 30 days' }]} />Its children while when holds, else its fallback, as SolidJS’s <Show>. Its text form is what it draws.
| Prop | |
|---|---|
when |
A condition. Required. |
fallback |
Text or elements drawn while when does not hold. |
<Show when="orders.count = 0" fallback={<Text>Orders are coming in.</Text>}> <Card title="No orders yet">...</Card></Show>Switch and Match
Section titled “Switch and Match”The first Match whose when holds, else the Switch’s fallback, as SolidJS’s <Switch> and <Match>. A Switch holds Matches only. Its text form is the branch it draws.
| Prop | |
|---|---|
Switch fallback |
Text or elements drawn while no Match holds. |
Match when |
A condition. Required. |
<Switch fallback={<Text>Not started</Text>}> <Match when="status = 'done'"><Text>Done</Text></Match> <Match when="claims.count > 0"><Text>Claimed</Text></Match></Switch>Accounts
Section titled “Accounts”Everyone who can sign in, for admins: find them by address, tick their roles, block or unblock them, invite someone by email and add an account. It takes no props or children. The Users page is a Page with it alone; a page of your own can put it beside other blocks, with roles: ['admin'], since the server refuses everyone else.
<Page title="People"> <Users /></Page>Account blocks
Section titled “Account blocks”Profile, Password, Passkeys, TwoFactor, ConnectedAccounts, PersonalMail, Connections, Devices, ConnectedApps, PersonalAccessTokens and DeleteAccount are the parts of the signed-in person’s own account: their name and address (which they can change, the address with an emailed code), their password (changed, or set for the first time), their passkeys, two-factor authentication, the sign-in providers they linked, the mailbox they linked for the app to send mail from, the accounts they connected for their workflows, the devices signed in as them (each one but this one to sign out), the apps such as MCP clients they allowed to act as them, below the app’s MCP address to connect one, their personal access tokens for scripts, and the deletion of their account. Each takes no props or children, reads its own data, and leaves itself out where it does not apply: ConnectedAccounts without an OAuth sign-in provider, PersonalMail without auth.personalMail, Connections when no workflow plugin declares a connection, ConnectedApps without MCP, PersonalAccessTokens without auth.personalAccessTokens, DeleteAccount with auth.accountDeletion: false. They act on whoever is signed in, so they are allowed on the page named account alone; anywhere else stops the config. That page is the account page at /-/account, which accountTabs helps build from the standard tabs.
export const account = page('account', <Page title="Account"> <Profile /> <Passkeys /> <TwoFactor /> </Page>)Settings
Section titled “Settings”The signed-in person’s own record of resource as settings, one field under the other with its label and help: a switch for a boolean, a select for an enum, an input for the other types. A switch or a select saves as soon as it changes; typed values save with Save, or Enter. Until the person saves for the first time there is no record, and each field shows its .default(...); the first save creates the record, owned by them, and later saves update it with its ETag. Errors from the server show on their fields.
| Prop | |
|---|---|
resource |
A resource whose .owner(...) field is its key, so each person has one record. Required. |
fields |
The fields it shows; default every field a person can set: not the key, read-only, sensitive or file fields. |
title, description |
Its heading. |
span |
As for Card. |
Each person’s own, admins too. Every caller of the API, an admin holding * included, reads and writes only the records of the resource they own, wherever they ask: the block, the resource’s list and record pages, exports, the API and API functions. A caller without a token gets nothing of it. Only SQL of your own and the built-in assistant’s SQL tools, which run outside the access rules for every resource, read every row. The roles still decide who has settings at all: give each role that should <resource>.read.own, .create.own and .update.own. Someone who may read but not write sees the values, not controls; someone who may not read gets no block, and a field they may not read is left out.
The startup check stops the config when the resource has no .owner(...), when its owner is not its whole key, when it has a tenant (settings are each person’s own, not an organization’s), when it has no field a person can set, and when fields names an unknown, key, sensitive or file field.
A person’s notification choices, in a tab of the account page; the guide Add a personal setting walks through the ERP example’s. The table has one row per person, keyed by their user id, which is text with Better Auth:
-- db/migrations/012_preferences.sqlcreate table preferences ( user_id text primary key, digest text not null default 'weekly' check (digest in ('daily', 'weekly', 'never')), mentions boolean not null default true);export const preferences = resource('preferences') .table('preferences') .fields({ user_id: f.text(), digest: f.enum(['daily', 'weekly', 'never']).default('weekly'), mentions: f.boolean().default(true) }) .primaryKey((r) => r.user_id) .owner((r) => r.user_id)
// config/preferences/ui.ts: labels, help and the values' words, and no sidebar entryexport const preferencesView = view<typeof preferences>('preferences') .nav({ hidden: true }) .fields((r) => ({ digest: r.digest.label('Email digest').help('A summary of what changed in your orders.').valueLabels({ daily: 'Every day', weekly: 'Every week', never: 'Never' }), mentions: r.mentions.label('Email me when someone mentions me'), }))
// roles: everyone who signs in has their ownmember: ['preferences.read.own', 'preferences.create.own', 'preferences.update.own', ...]export const account = page('account', <Page title="Account"> <Tabs> {accountTabs.profile} {accountTabs.security} <Tab name="notifications" label="Notifications"> <Settings resource="preferences" title="Notifications" description="What we email you about." /> </Tab> </Tabs> </Page>)Other code reads the choices with SQL, such as a job that sends the digest: select user_id from preferences where digest = 'daily'. Someone who never saved has no row, so it reads the default for them: coalesce(digest, 'weekly') over a left join from the users.