@protobase/cli 0.100.24 → 0.101.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/layout-check.js +15 -4
- package/dist/cli/package.js +1 -1
- package/dist/project/project-admin.js +2 -1
- package/dist/project/project-types.js +29 -6
- package/package.json +8 -8
- package/skills/protobase/references/features/compatibility.md +1 -1
- package/skills/protobase/references/features/composed-pages.md +3 -1
- package/skills/protobase/references/features/look-and-language.md +1 -0
- package/skills/protobase/references/features/workflows.md +2 -1
- package/skills/protobase/references/guides/billing-page.md +5 -5
- package/skills/protobase/references/guides/first-composed-page.md +10 -10
- package/skills/protobase/references/reference/blocks.md +27 -13
- package/skills/protobase/references/reference/cli.md +3 -1
- package/skills/protobase/references/reference/languages.md +36 -2
- package/skills/protobase/references/reference/layouts.md +71 -6
- package/skills/protobase/references/reference/workflows.md +6 -4
- package/skills/protobase/workflows.md +5 -5
|
@@ -12,6 +12,17 @@ const what = (expression) => {
|
|
|
12
12
|
if (ts.isClassExpression(inner)) return "a class";
|
|
13
13
|
if (ts.isNewExpression(inner)) return `a new ${inner.expression.getText()}`;
|
|
14
14
|
};
|
|
15
|
+
const recordChildBlocks = /* @__PURE__ */ new Set([
|
|
16
|
+
"RecordCard",
|
|
17
|
+
"CardRow",
|
|
18
|
+
"ReferenceField",
|
|
19
|
+
"RecordsIterator"
|
|
20
|
+
]);
|
|
21
|
+
const unwrapped = (expression) => ts.isParenthesizedExpression(expression) ? expression.expression : expression;
|
|
22
|
+
const isExpressionArrow = (expression) => {
|
|
23
|
+
const inner = unwrapped(expression);
|
|
24
|
+
return ts.isArrowFunction(inner) && !ts.isBlock(inner.body);
|
|
25
|
+
};
|
|
15
26
|
const isHookCall = (node) => ts.isCallExpression(node) && /^use[A-Z]/.test(ts.isPropertyAccessExpression(node.expression) ? node.expression.name.text : node.expression.getText());
|
|
16
27
|
/** Every place in a layout file where JSX gets a value that cannot be static, and every hook call. */
|
|
17
28
|
const layoutProblems = (code, file) => {
|
|
@@ -23,12 +34,12 @@ const layoutProblems = (code, file) => {
|
|
|
23
34
|
};
|
|
24
35
|
const visit = (node) => {
|
|
25
36
|
if (ts.isJsxAttribute(node) && node.initializer && ts.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
26
|
-
const kind = what(node.initializer.expression);
|
|
27
|
-
if (kind) problems.push(`${at(node)}: <${elementName(node)} ${node.name.getText()}> is ${kind}; layout props must be static data. Use <Action name="..."> for behaviour, or a custom component for React code.`);
|
|
37
|
+
const kind = node.name.getText() === "filter" && isExpressionArrow(node.initializer.expression) ? void 0 : what(node.initializer.expression);
|
|
38
|
+
if (kind) problems.push(`${at(node)}: <${elementName(node)} ${node.name.getText()}> is ${kind}; layout props must be static data, a filter may be one arrow of the builder. Use <Action name="..."> for behaviour, or a custom component for React code.`);
|
|
28
39
|
}
|
|
29
40
|
if (ts.isJsxExpression(node) && node.expression && (ts.isJsxElement(node.parent) || ts.isJsxFragment(node.parent))) {
|
|
30
|
-
const kind = what(node.expression);
|
|
31
|
-
if (kind) problems.push(`${at(node)}: a child of <${ts.isJsxElement(node.parent) ? node.parent.openingElement.tagName.getText() : ""}> is ${kind}; layout children must be elements or text.`);
|
|
41
|
+
const kind = ts.isJsxElement(node.parent) && recordChildBlocks.has(node.parent.openingElement.tagName.getText().replace(/<.*$/, "")) && isExpressionArrow(node.expression) ? void 0 : what(node.expression);
|
|
42
|
+
if (kind) problems.push(`${at(node)}: a child of <${ts.isJsxElement(node.parent) ? node.parent.openingElement.tagName.getText() : ""}> is ${kind}; layout children must be elements or text, or for a ${[...recordChildBlocks].join(", ")} one arrow of its record.`);
|
|
32
43
|
}
|
|
33
44
|
if (isHookCall(node)) problems.push(`${at(node)}: ${node.expression.getText()}() is a hook; layouts have no state. Put stateful UI in a custom component.`);
|
|
34
45
|
ts.forEachChild(node, visit);
|
package/dist/cli/package.js
CHANGED
|
@@ -10,7 +10,7 @@ import { configExports, createAdmin } from "@protobase/server";
|
|
|
10
10
|
* beside the config's resources (see `readUserTables`). `report` is what the admin does with an unhandled error.
|
|
11
11
|
*/
|
|
12
12
|
const projectAdmin = (project, db, ui, reporter, upgradeWebSocket, userTables) => {
|
|
13
|
-
const { resources, views, pages, userMenu, bottomBars, subscriptions } = configExports(project.config);
|
|
13
|
+
const { resources, views, pages, translations, userMenu, bottomBars, subscriptions } = configExports(project.config);
|
|
14
14
|
const unhandled = project.options?.onUnhandledError ?? ((error) => console.error(error));
|
|
15
15
|
const report = (error, request) => {
|
|
16
16
|
reporter?.report(error, request);
|
|
@@ -21,6 +21,7 @@ const projectAdmin = (project, db, ui, reporter, upgradeWebSocket, userTables) =
|
|
|
21
21
|
views,
|
|
22
22
|
...userTables && { userTables },
|
|
23
23
|
pages,
|
|
24
|
+
...translations && { translations },
|
|
24
25
|
...userMenu && { userMenu },
|
|
25
26
|
bottomBars,
|
|
26
27
|
db,
|
|
@@ -48,10 +48,30 @@ const cliTypePaths = (ownDir = cliDir) => Object.fromEntries(typedPackages.flatM
|
|
|
48
48
|
const dir = findPackageDirSync(name, ownDir) ?? findPackageDirSync(name, uiPackageDir);
|
|
49
49
|
return dir ? packagePaths(name, dir).map(([id, file]) => [id, [file]]) : [];
|
|
50
50
|
}));
|
|
51
|
+
/** The declarations that register the project's config module, which typed layouts read their resources and texts from. */
|
|
52
|
+
const registerFile = path.join(protobaseFolder, "register.d.ts");
|
|
53
|
+
const register = [
|
|
54
|
+
"// Written by protobase: the project's config module, which layout(), recordLayout() and <Trans> read the app's",
|
|
55
|
+
"// resources, fields and texts from. Wrap a typed layout in page() or a view; a layout exported bare refers to itself.",
|
|
56
|
+
"import type * as app from '../config/index'",
|
|
57
|
+
"",
|
|
58
|
+
"declare module '@protobase/layout' {",
|
|
59
|
+
" interface Register {",
|
|
60
|
+
" app: typeof app",
|
|
61
|
+
" }",
|
|
62
|
+
"}",
|
|
63
|
+
""
|
|
64
|
+
].join("\n");
|
|
65
|
+
const writeChanged = async (file, content) => {
|
|
66
|
+
if (existsSync(file) && readFileSync(file, "utf8") === content) return;
|
|
67
|
+
await writeFile(file, content);
|
|
68
|
+
};
|
|
51
69
|
/**
|
|
52
70
|
* Writes `.protobase/tsconfig.json` in `projectDir`, which the project's tsconfig.json extends: in a bundled project
|
|
53
71
|
* its `paths` give the @protobase packages and those the serve runtime supplies the types of the CLI that builds the
|
|
54
|
-
* app, with nothing installed; a locked project's installed packages type themselves, so it holds no paths.
|
|
72
|
+
* app, with nothing installed; a locked project's installed packages type themselves, so it holds no paths. With a
|
|
73
|
+
* `config/index.ts` it also writes `.protobase/register.d.ts`, which types the layouts by the app's resources and texts,
|
|
74
|
+
* and includes it beside the project's files; a project tsconfig.json with an `include` of its own lists it there. The
|
|
55
75
|
* folder ignores itself in git, since the paths are this machine's. An unchanged file is left alone: Vite reloads every
|
|
56
76
|
* module on any write to a tsconfig.json, so another command rewriting it would rebuild a running dev server's API.
|
|
57
77
|
*/
|
|
@@ -61,10 +81,13 @@ const writeProjectTypes = async (projectDir) => {
|
|
|
61
81
|
const ignore = path.join(folder, ".gitignore");
|
|
62
82
|
if (!existsSync(ignore)) await writeFile(ignore, "*\n");
|
|
63
83
|
const compilerOptions = projectPackages(projectDir).mode === "bundled" ? { paths: cliTypePaths() } : {};
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
await
|
|
84
|
+
const registered = existsSync(path.join(projectDir, "config", "index.ts"));
|
|
85
|
+
if (registered) await writeChanged(path.join(projectDir, registerFile), register);
|
|
86
|
+
const include = registered ? { include: ["../**/*", "register.d.ts"] } : {};
|
|
87
|
+
await writeChanged(path.join(projectDir, typesFile), `${JSON.stringify({
|
|
88
|
+
compilerOptions,
|
|
89
|
+
...include
|
|
90
|
+
}, null, 2)}\n`);
|
|
68
91
|
};
|
|
69
92
|
//#endregion
|
|
70
|
-
export { cliTypePaths, typesFile, writeProjectTypes };
|
|
93
|
+
export { cliTypePaths, registerFile, typesFile, writeProjectTypes };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.101.0",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@better-auth/core": "^1.7.12",
|
|
45
45
|
"@hono/node-server": "^2.1.3",
|
|
46
|
-
"@protobase/config": "0.
|
|
47
|
-
"@protobase/layout": "0.
|
|
48
|
-
"@protobase/query": "0.
|
|
49
|
-
"@protobase/schema": "0.
|
|
50
|
-
"@protobase/server": "0.
|
|
51
|
-
"@protobase/ui": "0.
|
|
52
|
-
"@protobase/workflows": "0.
|
|
46
|
+
"@protobase/config": "0.101.0",
|
|
47
|
+
"@protobase/layout": "0.101.0",
|
|
48
|
+
"@protobase/query": "0.101.0",
|
|
49
|
+
"@protobase/schema": "0.101.0",
|
|
50
|
+
"@protobase/server": "0.101.0",
|
|
51
|
+
"@protobase/ui": "0.101.0",
|
|
52
|
+
"@protobase/workflows": "0.101.0",
|
|
53
53
|
"@react-email/render": "^2.1.0",
|
|
54
54
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
55
55
|
"@sentry/vite-plugin": "^11.10.0",
|
|
@@ -26,7 +26,7 @@ Apps written for other systems that keep working on Protobase, and moving their
|
|
|
26
26
|
## react-admin
|
|
27
27
|
|
|
28
28
|
- [Related records](../reference/layouts.md#related-records) (beta): Layouts take react-admin's `ReferenceManyField`, `ReferenceArrayField`, `ArrayField`, `RecordsIterator` and `ReferenceField` with their names, props and defaults: `sort` is the key descending, and a `ReferenceManyField`'s `source` is `id` and its `perPage` 25.
|
|
29
|
-
- [
|
|
29
|
+
- [Filters and sorts on related records](../reference/layouts.md#related-records) (beta): `filter` is AIP-160 text or the condition builder's arrow, since an object cannot say `OR`, and `sort` a list of fields, `['claimed_at desc']`; react-admin's `{ field: value }` and `{ field, order }` objects are not taken.
|
|
30
30
|
- [Page size of related records](../reference/layouts.md#related-records) (beta): A list reads at most 500 records, the API's largest page, which is also a `ReferenceArrayField`'s `perPage` where react-admin's is 1000.
|
|
31
31
|
- [Items of an ArrayField](../reference/layouts.md#related-records) (beta): A text item of an `ArrayField` is read as `this`. An `ArrayField` takes no `filter`, `sort` or `perPage` yet.
|
|
32
32
|
- [RecordsIterator without functions](../reference/layouts.md#related-records) (beta): `RecordsIterator` takes no `render`, `data`, `total` or `isPending`, as a layout holds no functions and the list around it gives the rest.
|
|
@@ -7,7 +7,9 @@ Pages of your own, built from blocks in a JSX layout.
|
|
|
7
7
|
- [Composed pages](../reference/layouts.md#setup): Pages built from a JSX layout, with their own address, sidebar entry and role limits, reading the API under the same access rules as the lists.
|
|
8
8
|
- [Layout checks](../reference/layouts.md#what-a-layout-may-hold): The build refuses a layout with code, unknown props or unknown fields, and names the file and place.
|
|
9
9
|
- [Page parameters](../reference/layouts.md#page-parameters) (beta): A page holds a choice in its address with `SelectInput`, reads it in its layout, and shows the details of a row chosen in a table.
|
|
10
|
-
- [Conditions](../reference/layouts.md#conditions): Part of a page shows only while a condition on a record
|
|
10
|
+
- [Conditions](../reference/layouts.md#conditions): Part of a page shows only while a condition on a record, a count or the time, `now() + 7d`, holds.
|
|
11
|
+
- [Typed layouts](../reference/layouts.md#typed-layouts) (beta): `layout()` and `recordLayout()` write a page's tree with the record and the app's tables in hand, so TypeScript checks every resource, column, sort and field against the app, and record blocks take a function of their record.
|
|
12
|
+
- [The condition builder](../reference/layouts.md#the-condition-builder) (beta): A filter is an arrow, `(f) => f.status.eq('open').and(f.due_at.lt(now().plus('7d')))`, and a condition the same builder's, written as AIP-160 for you.
|
|
11
13
|
- [Paths and scopes](../reference/layouts.md#paths-and-scopes) (beta): Layout values resolve through the records around them with paths relative to those records, such as `../name`, `this.name` and `@index`; typos and reads that would wait on other reads fail the build, and `Show`, `Switch` and `Match` choose what is drawn.
|
|
12
14
|
- [Field values and expanding lines](../reference/layouts.md#field-values) (beta): Layouts show a record's values inline in text and links with react-admin's field components, such as `DateField` and `NumberField`, and a line that opens to show more with `Details` and `Summary`.
|
|
13
15
|
- [App addresses](../reference/layouts.md#addresses): Links to lists, records, create forms and pages are typed addresses that can carry filters and prefilled values.
|
|
@@ -11,6 +11,7 @@ The app's colours, name, icon, language and installation.
|
|
|
11
11
|
- [Logo and favicon](../reference/theme.md#logo-and-favicon): Your own favicon or logo replaces Protobase's.
|
|
12
12
|
- [Named icons](../reference/layouts.md#named-actions): Actions, key facts and card meta show an icon picked by name from a set, such as `play`, `bed` or `cpu`.
|
|
13
13
|
- [English and Dutch](../reference/languages.md): The built-in screens come in English and Dutch, with numbers and dates written to match.
|
|
14
|
+
- [The app's own texts](../reference/languages.md#your-own-texts) (beta): Pages and labels come in each language the app has translations for, ICU messages shown with `<Trans>`, in the reader's language, and the server refuses to start on a missing text.
|
|
14
15
|
- [Installable app](../reference/installable-app.md): The admin installs as an app on phones and computers, and says when the server cannot be reached.
|
|
15
16
|
- [Start from the last pages seen](../reference/installable-app.md#starting-from-the-last-pages-seen): Someone signed in opens the app on what it showed last time, muted with a spinner by the title until it is refreshed in the background.
|
|
16
17
|
|
|
@@ -11,7 +11,8 @@ Graphs of steps the server runs along their edges, written in a language a model
|
|
|
11
11
|
- [One page per workflow](../reference/workflows.md#the-workflows-page) (beta): A workflow's focus page is its graph, with Add step, Test run, Runs and Publish beside it in a panel, so you build, test and debug without leaving it; in the sidebar, Workflows lists the workflows.
|
|
12
12
|
- [Pins and wires](../reference/workflows.md#the-workflows-page) (beta): A step's inputs and the values it gives are pins coloured by type; drag an output pin to an input to read that value there, and a wire that does not fit is refused, saying why.
|
|
13
13
|
- [Break and Make](../reference/workflows.md#the-workflows-page) (beta): Take an object apart into a pin for each field, such as a record's fields, or build one from a pin per field, with no extra step to run.
|
|
14
|
-
- [Condition nodes](../reference/workflows.md#the-workflows-page) (beta): In data order, build when a step runs from Equals, Not equals, Greater and
|
|
14
|
+
- [Condition nodes](../reference/workflows.md#the-workflows-page) (beta): In data order, build when a step runs from Equals, Not equals, Greater, Less and Matches, All of, Any of and Not on the graph, or drop a step's status on another step's Only when pin to run it once the first succeeded; any other condition is one Expression node, kept as you wrote it.
|
|
15
|
+
- [Select](../reference/workflows.md#the-workflows-page) (beta): Choose an argument by another value on the graph, such as a mail's address by a form's topic, a value per case and one otherwise.
|
|
15
16
|
- [Move nodes by hand](../reference/workflows.md#the-workflows-page) (beta): Drag a node of the graph where you want it; it stays there, marked, for everyone who edits the workflow, and the rest lays itself out around it until you unpin it or tidy up. Pins and Simple each keep their own places, and moving nodes makes no new version.
|
|
16
17
|
- [Pins or Simple](../reference/workflows.md#the-workflows-page) (beta): Draw the graph with every pin and wire, or with only the steps and the lines between them, and switch at any time; nothing saved changes.
|
|
17
18
|
- [Build on the graph](../reference/workflows.md#the-workflows-page) (beta): Click a step's handle to add a step right there, or drag from it to another step to connect them; the wheel and a pinch zoom the graph, and dragging pans it.
|
|
@@ -161,7 +161,7 @@ export const billing = page(
|
|
|
161
161
|
<CardRow
|
|
162
162
|
title="Payment methods"
|
|
163
163
|
resource="payment_methods"
|
|
164
|
-
sort=
|
|
164
|
+
sort={['is_default desc', 'id']}
|
|
165
165
|
actions={<ModalForm mode="create" label="Add card" resource="payment_methods" fields={['brand', 'last4', 'expires']} />}
|
|
166
166
|
>
|
|
167
167
|
<Field source="brand" label={false} />
|
|
@@ -178,7 +178,7 @@ export const billing = page(
|
|
|
178
178
|
)
|
|
179
179
|
```
|
|
180
180
|
|
|
181
|
-
The cards sit side by side in a `CardRow`, the default card first (`sort=
|
|
181
|
+
The cards sit side by side in a `CardRow`, the default card first (`sort={['is_default desc', 'id']}`). Two `Show` blocks split the card on its own `is_default` field: the default card says so, the others get "Make default" and "Remove". Those are again view actions, `a.update('makeDefault', ...)` and `a.remove('remove', ...)` in the views above.
|
|
182
182
|
|
|
183
183
|
Making a card the default unsets the others in the database (a trigger or a write hook); the row reloads after every action, so the order follows. "Add card" is a `ModalForm mode="create"` in the row's header. In the story, make the Mastercard the default, remove the Visa and add a card.
|
|
184
184
|
|
|
@@ -226,7 +226,7 @@ export const billing = page(
|
|
|
226
226
|
<CardRow
|
|
227
227
|
title="Payment methods"
|
|
228
228
|
resource="payment_methods"
|
|
229
|
-
sort=
|
|
229
|
+
sort={['is_default desc', 'id']}
|
|
230
230
|
actions={<ModalForm mode="create" label="Add card" resource="payment_methods" fields={['brand', 'last4', 'expires']} />}
|
|
231
231
|
>
|
|
232
232
|
<Field source="brand" label={false} />
|
|
@@ -239,10 +239,10 @@ export const billing = page(
|
|
|
239
239
|
</Show>
|
|
240
240
|
</CardRow>
|
|
241
241
|
<Grid columns={3}>
|
|
242
|
-
<Table title="Invoices" resource="invoices" sort=
|
|
242
|
+
<Table title="Invoices" resource="invoices" sort={['issued_at desc']} limit={5} span={2} />
|
|
243
243
|
<Grid columns={1}>
|
|
244
244
|
<Stat label="Open invoices" resource="invoices" filter="status = 'open'" />
|
|
245
|
-
<RecordCard title="Latest invoice" resource="invoices" sort=
|
|
245
|
+
<RecordCard title="Latest invoice" resource="invoices" sort={['issued_at desc']} actions={<Action name="download" />}>
|
|
246
246
|
<Grid columns={2}>
|
|
247
247
|
<Field source="number" />
|
|
248
248
|
<Field source="total" />
|
|
@@ -59,15 +59,15 @@ export const overview = page(
|
|
|
59
59
|
<Stat label="Open leads" resource="companies" filter="status = 'lead'" />
|
|
60
60
|
</Grid>
|
|
61
61
|
<Grid columns={2}>
|
|
62
|
-
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort=
|
|
63
|
-
<Table title="Latest orders" resource="orders" sort=
|
|
62
|
+
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort={['issued_at']} columns={['number', 'company_id', 'due_at', 'total']} limit={2} empty="Nothing is overdue." />
|
|
63
|
+
<Table title="Latest orders" resource="orders" sort={['created_at desc']} columns={['number', 'company_id', 'status', 'total']} limit={5} />
|
|
64
64
|
</Grid>
|
|
65
65
|
</Page>,
|
|
66
66
|
{ nav: { group: 'Sales', order: 0 }, icon: 'layout-dashboard' },
|
|
67
67
|
)
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
A `Table` takes the same `resource`, `filter` and `sort` (
|
|
70
|
+
A `Table` takes the same `resource`, `filter` and `sort` (a list of fields, like `?order_by=` one entry at a time), plus the `columns` to show and a `limit`. Relations such as `company_id` show the company's name, a row opens the record, and **View all** opens the list with the same filter and order. Try it on the overdue invoices: there are three, and the table shows two.
|
|
71
71
|
|
|
72
72
|
## 3. One order to chase
|
|
73
73
|
|
|
@@ -90,7 +90,7 @@ export const overview = page(
|
|
|
90
90
|
title="Biggest unpaid delivery"
|
|
91
91
|
resource="orders"
|
|
92
92
|
filter="status = 'delivered' AND paid = false"
|
|
93
|
-
sort=
|
|
93
|
+
sort={['total desc']}
|
|
94
94
|
empty="Every delivered order is paid."
|
|
95
95
|
actions={<Action name="markPaid" variant="primary" />}
|
|
96
96
|
>
|
|
@@ -103,8 +103,8 @@ export const overview = page(
|
|
|
103
103
|
<Show when="company_id.status = 'dormant'">The customer has gone quiet: call before sending a reminder.</Show>
|
|
104
104
|
</RecordCard>
|
|
105
105
|
<Grid columns={2}>
|
|
106
|
-
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort=
|
|
107
|
-
<Table title="Latest orders" resource="orders" sort=
|
|
106
|
+
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort={['issued_at']} columns={['number', 'company_id', 'due_at', 'total']} limit={2} empty="Nothing is overdue." />
|
|
107
|
+
<Table title="Latest orders" resource="orders" sort={['created_at desc']} columns={['number', 'company_id', 'status', 'total']} limit={5} />
|
|
108
108
|
</Grid>
|
|
109
109
|
</Page>,
|
|
110
110
|
{ nav: { group: 'Sales', order: 0 }, icon: 'layout-dashboard' },
|
|
@@ -187,7 +187,7 @@ export const overview = page(
|
|
|
187
187
|
title="Biggest unpaid delivery"
|
|
188
188
|
resource="orders"
|
|
189
189
|
filter="status = 'delivered' AND paid = false"
|
|
190
|
-
sort=
|
|
190
|
+
sort={['total desc']}
|
|
191
191
|
empty="Every delivered order is paid."
|
|
192
192
|
actions={<Action name="markPaid" variant="primary" />}
|
|
193
193
|
>
|
|
@@ -200,15 +200,15 @@ export const overview = page(
|
|
|
200
200
|
<Show when="company_id.status = 'dormant'">The customer has gone quiet: call before sending a reminder.</Show>
|
|
201
201
|
</RecordCard>
|
|
202
202
|
<Grid columns={2}>
|
|
203
|
-
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort=
|
|
204
|
-
<Table title="Latest orders" resource="orders" sort=
|
|
203
|
+
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort={['issued_at']} columns={['number', 'company_id', 'due_at', 'total']} limit={2} empty="Nothing is overdue." />
|
|
204
|
+
<Table title="Latest orders" resource="orders" sort={['created_at desc']} columns={['number', 'company_id', 'status', 'total']} limit={5} />
|
|
205
205
|
</Grid>
|
|
206
206
|
<CardRow
|
|
207
207
|
title="New leads"
|
|
208
208
|
description="Companies that have not ordered yet."
|
|
209
209
|
resource="companies"
|
|
210
210
|
filter="status = 'lead'"
|
|
211
|
-
sort=
|
|
211
|
+
sort={['created_at desc']}
|
|
212
212
|
actions={<ModalForm mode="create" label="Add lead" resource="companies" fields={['name', 'city', 'email']} values={{ status: 'lead' }} />}
|
|
213
213
|
>
|
|
214
214
|
<Field source="name" label={false} />
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Every built-in layout block, its props and what it does, with examples from the ERP's sales overview.
|
|
6
6
|
|
|
7
|
-
Blocks are imported from `@protobase/layout`. Every block also takes [`className`](layouts.md#tailwind-classes), Tailwind classes for its outer element. "Record" below means the record of the `RecordCard`, `CardRow` card or `RecordsIterator` entry around a block (see [Data](layouts.md#data)); `filter` is AIP-160 and `sort`
|
|
7
|
+
Blocks are imported from `@protobase/layout`. Every block also takes [`className`](layouts.md#tailwind-classes), Tailwind classes for its outer element. "Record" below means the record of the `RecordCard`, `CardRow` card or `RecordsIterator` entry around a block (see [Data](layouts.md#data)); `filter` is AIP-160, as in the list API, or the [builder's arrow](layouts.md#the-condition-builder), 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](auth.md#users-page) `Users`:
|
|
8
8
|
|
|
9
9
|
```tsx title="tests/apps/erp/config/overview/page.tsx"
|
|
10
10
|
/** @jsxImportSource @protobase/layout */
|
|
@@ -31,7 +31,7 @@ export const salesOverview = page(
|
|
|
31
31
|
title="Biggest unpaid delivery"
|
|
32
32
|
resource="orders"
|
|
33
33
|
filter="status = 'delivered' AND paid = false"
|
|
34
|
-
sort=
|
|
34
|
+
sort={['total desc']}
|
|
35
35
|
empty="Every delivered order is paid."
|
|
36
36
|
actions={<Action name="markPaid" variant="primary" />}
|
|
37
37
|
>
|
|
@@ -47,7 +47,7 @@ export const salesOverview = page(
|
|
|
47
47
|
title="Oldest overdue invoice"
|
|
48
48
|
resource="invoices"
|
|
49
49
|
filter="status = 'overdue'"
|
|
50
|
-
sort=
|
|
50
|
+
sort={['issued_at']}
|
|
51
51
|
empty="Nothing is overdue."
|
|
52
52
|
actions={[<Action name="send" label="Send reminder" />, <Action name="recordPayment" variant="primary" />]}
|
|
53
53
|
>
|
|
@@ -67,15 +67,15 @@ export const salesOverview = page(
|
|
|
67
67
|
<Chart title="Revenue by customer" description="Orders not cancelled." resource="orders" groupBy="company_id" sum="total" filter="status != 'cancelled'" limit={5} />
|
|
68
68
|
</Grid>
|
|
69
69
|
<Grid columns={2}>
|
|
70
|
-
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort=
|
|
71
|
-
<Table title="Latest orders" resource="orders" sort=
|
|
70
|
+
<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." />
|
|
71
|
+
<Table title="Latest orders" resource="orders" sort={['created_at desc']} columns={['number', 'company_id', 'status', 'total']} limit={5} />
|
|
72
72
|
</Grid>
|
|
73
73
|
<CardRow
|
|
74
74
|
title="New leads"
|
|
75
75
|
description="Companies that have not ordered yet."
|
|
76
76
|
resource="companies"
|
|
77
77
|
filter="status = 'lead'"
|
|
78
|
-
sort=
|
|
78
|
+
sort={['created_at desc']}
|
|
79
79
|
limit={8}
|
|
80
80
|
actions={<ModalForm mode="create" label="Add lead" resource="companies" fields={['name', 'city', 'country_code', 'email']} values={{ status: 'lead' }} />}
|
|
81
81
|
>
|
|
@@ -165,7 +165,7 @@ Plain elements for a page too custom for the blocks, drawn by their [Tailwind cl
|
|
|
165
165
|
| `Box` | An element of its own, such as a panel or a banner. No look of its own. |
|
|
166
166
|
| `Row` | Its children side by side: `flex`. |
|
|
167
167
|
| `Column` | Its children one under another: `flex flex-col`. |
|
|
168
|
-
| `Text` | Text, `Link`s, `
|
|
168
|
+
| `Text` | Text, `Link`s, `Trans`es, inline `Text`s and [field components](#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. |
|
|
169
169
|
|
|
170
170
|
```tsx
|
|
171
171
|
<Row className="items-center gap-3">
|
|
@@ -174,6 +174,20 @@ Plain elements for a page too custom for the blocks, drawn by their [Tailwind cl
|
|
|
174
174
|
</Row>
|
|
175
175
|
```
|
|
176
176
|
|
|
177
|
+
### Trans
|
|
178
|
+
|
|
179
|
+
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](layouts.md#texts-in-the-readers-language).
|
|
180
|
+
|
|
181
|
+
| Prop | |
|
|
182
|
+
| --- | --- |
|
|
183
|
+
| `i18nKey` | The message's key in the app's [translations](languages.md#your-own-texts), such as `today.open`. Required. |
|
|
184
|
+
| `values` | What the message formats by name, `{ count: 2, name: '{{owner}}' }`: text, numbers, booleans and placeholders. |
|
|
185
|
+
| `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. |
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
<Trans i18nKey="today.owner" values={{ name: '{{owner}}' }} components={{ b: <Text as="strong" /> }} />
|
|
189
|
+
```
|
|
190
|
+
|
|
177
191
|
### Details and Summary
|
|
178
192
|
|
|
179
193
|
A line that opens to show the rest and closes again, drawn as HTML's [`<details>` and `<summary>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details), 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](layouts.md#field-values).
|
|
@@ -251,7 +265,7 @@ The first records of a list, drawn the way the resource's list page draws them:
|
|
|
251
265
|
| `span` | Width in a grid. |
|
|
252
266
|
|
|
253
267
|
```tsx
|
|
254
|
-
<Table title="Overdue invoices" resource="invoices" filter="status = 'overdue'" sort=
|
|
268
|
+
<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." />
|
|
255
269
|
```
|
|
256
270
|
|
|
257
271
|
#### Columns on a phone
|
|
@@ -349,7 +363,7 @@ One record and what is inside it: the one `recordKey` names (the key as the reco
|
|
|
349
363
|
| `span` | Width in a grid. |
|
|
350
364
|
|
|
351
365
|
```tsx
|
|
352
|
-
<RecordCard title="Biggest unpaid delivery" resource="orders" filter="status = 'delivered' AND paid = false" sort=
|
|
366
|
+
<RecordCard title="Biggest unpaid delivery" resource="orders" filter="status = 'delivered' AND paid = false" sort={['total desc']} actions={<Action name="markPaid" variant="primary" />}>
|
|
353
367
|
<Field source="number" />
|
|
354
368
|
<Field source="company_id.city" label="City" />
|
|
355
369
|
</RecordCard>
|
|
@@ -383,7 +397,7 @@ It follows the resource's view as its list page does. Of a resource whose view h
|
|
|
383
397
|
| `span` | Width in a grid. |
|
|
384
398
|
|
|
385
399
|
```tsx
|
|
386
|
-
<RecordRow title="For rent" resource="listings" filter="for_rent = true AND status = 'available'" sort=
|
|
400
|
+
<RecordRow title="For rent" resource="listings" filter="for_rent = true AND status = 'available'" sort={['published_at desc']} />
|
|
387
401
|
```
|
|
388
402
|
|
|
389
403
|
### RecordCards
|
|
@@ -582,14 +596,14 @@ The records of `reference` whose `target` holds the record's `source`, as [react
|
|
|
582
596
|
| `reference` | The resource it reads. Required. |
|
|
583
597
|
| `target` | The field of `reference` that points at the record. Required. |
|
|
584
598
|
| `source` | The field of the record it matches; default `id`, of the nearest record. A [path](layouts.md#paths-and-scopes), such as `../id`. |
|
|
585
|
-
| `filter` | More conditions, as AIP-160 text or
|
|
586
|
-
| `sort` |
|
|
599
|
+
| `filter` | More conditions, as AIP-160 text or the [builder's arrow](layouts.md#the-condition-builder), ANDed with the target's. |
|
|
600
|
+
| `sort` | A list of fields, each with `asc` or `desc` if it likes, `['claimed_at desc']`; default the key, descending. |
|
|
587
601
|
| `perPage` | How many records it reads, at most 500; default 25. |
|
|
588
602
|
| `pagination` | `more`: a **Load more** button reads the next `perPage` records into the same list. |
|
|
589
603
|
| `empty` | Text instead of the children when no record matches. |
|
|
590
604
|
|
|
591
605
|
```tsx
|
|
592
|
-
<ReferenceManyField reference="task_claims" target="task_id" filter=
|
|
606
|
+
<ReferenceManyField reference="task_claims" target="task_id" filter="status = 'open'" sort={['claimed_at desc']} pagination="more">
|
|
593
607
|
<Table title="Open claims" columns={['worker_id', 'claimed_at']} />
|
|
594
608
|
</ReferenceManyField>
|
|
595
609
|
```
|
|
@@ -359,11 +359,13 @@ docker run --rm -p 127.0.0.1:8787:8787 -e DATABASE_URL -e PROTOBASE_URL -e PROTO
|
|
|
359
359
|
## `types`
|
|
360
360
|
|
|
361
361
|
```sh
|
|
362
|
-
protobase types # writes .protobase/tsconfig.json; dev, build and every command that loads the config write
|
|
362
|
+
protobase types # writes .protobase/tsconfig.json and register.d.ts; dev, build and every command that loads the config write them too
|
|
363
363
|
```
|
|
364
364
|
|
|
365
365
|
Writes `.protobase/tsconfig.json`, which the project's `tsconfig.json` extends (`"extends": "./.protobase/tsconfig.json"`). In a bundled project its `paths` point each `@protobase` package and each package the serve runtime supplies, by name and by each of its exports (`@protobase/layout/jsx-runtime`, `kysely`, `zod`, ...), at the declarations of the CLI that builds the app, so the editor and `tsc` see the version that runs with nothing installed. There is no catch-all, so a package the project imports and lacks still fails as missing. React carries no types of its own, so the project keeps `@types/react`, as it keeps `@types/node`. A locked project's installed packages type themselves, so its file holds no `paths`. A `paths` of the project's own `tsconfig.json` replaces the generated one, as `extends` does with any option.
|
|
366
366
|
|
|
367
|
+
With a `config/index.ts`, it also writes `.protobase/register.d.ts`, which registers that module's type with `@protobase/layout`, so [typed layouts](layouts.md#typed-layouts) and `<Trans>` check the app's resource names, fields and text keys, and the generated `tsconfig.json` includes it beside the project's own files (`"include": ["../**/*", "register.d.ts"]`). A project `tsconfig.json` with an `include` of its own replaces that one, so it lists `.protobase/register.d.ts` there too.
|
|
368
|
+
|
|
367
369
|
`.protobase/` ignores itself in git: the paths are this machine's. Write the file again after installing another CLI; `dev` and `build` do it on every run.
|
|
368
370
|
|
|
369
371
|
## `run`
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# Languages
|
|
4
4
|
|
|
5
|
-
The admin app's built-in screens come in English and Dutch, chosen by the app or by each user's browser, with numbers and dates written to match.
|
|
5
|
+
The admin app's built-in screens come in English and Dutch, chosen by the app or by each user's browser, with numbers and dates written to match, and the app's own texts in any language it has translations for.
|
|
6
6
|
|
|
7
|
-
The admin app's own texts and its numbers and dates come in English and Dutch. The texts you write yourself, such as resource names, labels and enum value labels, show as you write them, in any language.
|
|
7
|
+
The admin app's own texts and its numbers and dates come in English and Dutch. The texts you write yourself, such as resource names, labels and enum value labels, show as you write them, in any language, unless the app's [translations](#your-own-texts) give them in the reader's.
|
|
8
8
|
|
|
9
9
|
## Choosing the language
|
|
10
10
|
|
|
@@ -22,6 +22,40 @@ The value is `'en'` or `'nl'`, and the server refuses to start with any other va
|
|
|
22
22
|
|
|
23
23
|
Numbers, amounts and dates use the conventions of the language: English as written in Britain (`6 Oct 2026`, `€1,234.56`), and Dutch as written in the Netherlands (`6 okt 2026`, `€ 1.234,56`). Typing a decimal number in a form uses the same decimal mark. Times show in the viewer's time zone in both languages.
|
|
24
24
|
|
|
25
|
+
## Your own texts
|
|
26
|
+
|
|
27
|
+
The app's own texts, its pages' and its labels, come in every language it has translations for: one JSON file per language, its messages ICU, as `intl-messageformat` reads them, exported from `config/index.ts` with `translations`:
|
|
28
|
+
|
|
29
|
+
```ts title="config/index.ts"
|
|
30
|
+
import { translations } from '@protobase/layout'
|
|
31
|
+
import en from './texts/en.json'
|
|
32
|
+
import nl from './texts/nl.json'
|
|
33
|
+
|
|
34
|
+
export const texts = translations({ en, nl })
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```json title="config/texts/nl.json"
|
|
38
|
+
{
|
|
39
|
+
"today": {
|
|
40
|
+
"title": "Vandaag",
|
|
41
|
+
"open": "{count, plural, one {# open taak} other {# open taken}}",
|
|
42
|
+
"owner": "Van <b>{name}</b>"
|
|
43
|
+
},
|
|
44
|
+
"resources": {
|
|
45
|
+
"tasks": {
|
|
46
|
+
"names": { "singular": "Taak", "plural": "Taken" },
|
|
47
|
+
"fields": { "status": { "label": "Staat", "values": { "done": "Klaar" } } }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
A layout shows a message with [`<Trans i18nKey="today.open" values={{ count: 2 }} />`](layouts.md#texts-in-the-readers-language), and a page whose `title` is one is named by it in the sidebar too. A view's labels take their key from where they sit, under `resources.<resource>`: `names.singular` and `names.plural`, `help`, `fields.<field>.label`, `.help` and `.values.<value>`, `layout.<index>.title`, `.help` and `.empty` (a tab's items under `layout.<index>.items.<index>`), and `actions.<action>.label` and `.confirm`. A label the translations leave out shows as the view writes it.
|
|
54
|
+
|
|
55
|
+
Each reader gets the app's own `locale` when it sets one the translations have, else the first of their browser's languages the translations have, by its tag or its language (`nl-BE` reads `nl`), else English, else the first language. A language is any BCP 47 tag, such as `de` or `pt-BR`, while the built-in screens stay in English or Dutch. `/meta` serves the reader's language and only the messages their pages name, as `texts: { locale, messages }`, with the page titles and labels already in it.
|
|
56
|
+
|
|
57
|
+
The config fails to load when a message is not ICU or a language lacks a key another has, and the server refuses to start when a layout names a key no language has, leaves out a value its message formats in some language, or has a tag with no element in `components`, naming the page or view.
|
|
58
|
+
|
|
25
59
|
## What is translated
|
|
26
60
|
|
|
27
61
|
Every built-in screen is translated: the shell with its sidebar, top bar, search, notification bell, profile menu and bottom bar; the list page with all its displays (table, cards, board, calendar, timeline and map), filters, search, sort, imports and exports; the record page with its actions, related lists, history, comments, gallery, saving, conflicts and deleting; the create page and composed pages; saved searches and favorites; the sign-in, sign-up and two-factor screens, the account and sign-in policy pages, and the organization, people and invitation pages; public forms; the assistant's dock and a record's [lines](ui-config.md#record-lines); the notice naming a plugin that is off and why; and the messages, toasts and confirmations around them. The parts `@protobase/ui` gives your own components, such as the [form parts](custom-components.md#form-parts), the [chat parts](custom-components.md#chat-parts) and the markdown editor, come in the app's language too. So are counts, relative times ("5 minutes ago"), yes, no and the other values the app writes itself, and the notices shown while the app loads.
|
|
@@ -119,14 +119,14 @@ It takes the options of `renderText` but `records`, `tables` and `planned`, and
|
|
|
119
119
|
|
|
120
120
|
A prop is a string, a finite number, a boolean, `null`, or an array or plain object of those (elements included). It is JSON in the end, so the rules are checked twice:
|
|
121
121
|
|
|
122
|
-
- **At build time.** `protobase build` and `protobase dev` read every file with the `@jsxImportSource @protobase/layout` comment and refuse a function, class or `new` value in a prop or child, and any call to a hook (`useState`, ...), with the file, line and column. No project code runs for this.
|
|
122
|
+
- **At build time.** `protobase build` and `protobase dev` read every file with the `@jsxImportSource @protobase/layout` comment and refuse a function, class or `new` value in a prop or child, and any call to a hook (`useState`, ...), with the file, line and column. Two arrows are data and pass: a [filter's arrow](#the-condition-builder) and a record block's child arrow in a [typed layout](#typed-layouts), each one expression, never a body of statements. No project code runs for this.
|
|
123
123
|
- **When the config loads.** The JSX runtime refuses anything else that is not plain data (a function in a variable, a `Date`, a `Map`, `NaN`), `page()` checks every element's props against its block (unknown, missing and mistyped props, children where none are allowed, elements that need a record outside one), and `createAdmin` checks every resource, field, filter, sort, action and condition against the models. Each problem names its place, such as `Page "overview": <Page> › <Table resource="invoices">: unknown column "amount" on invoices`.
|
|
124
124
|
|
|
125
125
|
Behaviour comes from [named actions](#named-actions); React code from [custom components](custom-components.md).
|
|
126
126
|
|
|
127
127
|
## Data
|
|
128
128
|
|
|
129
|
-
`Stat`, `RecordCard`, `Table`, `CardRow`, `RecordRow`, `RecordCards` and `Thread` read records of a `resource`. `filter` is AIP-160
|
|
129
|
+
`Stat`, `RecordCard`, `Table`, `CardRow`, `RecordRow`, `RecordCards` and `Thread` read records of a `resource`. `filter` is AIP-160, exactly as the list API's `filter`, so a filter that works in the list's URL works here, or [the builder's arrow](#the-condition-builder), `filter={(f) => f.status.eq('open')}`, which writes that text. `sort` is a list of fields, each with `asc` or `desc` if it likes, `sort={['due_at', 'total desc']}`, the list API's `order_by` one entry at a time. `Thread` takes no `sort`: it orders its messages by its `time` field, newest first. `ReferenceManyField`, `ReferenceArrayField` and `ReferenceField` read records of their `reference` that the record around them points to or is pointed at by: see [related records](#related-records).
|
|
130
130
|
|
|
131
131
|
A `RecordCard` (its first match), a `ReferenceField`, each card of a `CardRow` and each entry of a `RecordsIterator` hold a **record**. Inside one, `Field`, `Diff`, `Progress`, `Stat field`, `Show`, `Action` and `ModalForm mode="edit"` work on that record, and a `RecordCard`'s header `actions` do too. A field name may follow relations: `company_id.city` is the city of the record's company, fetched like the record page fetches it and cached.
|
|
132
132
|
|
|
@@ -143,7 +143,7 @@ A record's related records repeat under it as a list: a `ReferenceManyField` hol
|
|
|
143
143
|
<ArrayField source="labels">
|
|
144
144
|
<RecordsIterator><Field source="this" label={false} /></RecordsIterator>
|
|
145
145
|
</ArrayField>
|
|
146
|
-
<ReferenceManyField reference="task_claims" target="task_id" sort={
|
|
146
|
+
<ReferenceManyField reference="task_claims" target="task_id" sort={['claimed_at desc']}>
|
|
147
147
|
<RecordsIterator>
|
|
148
148
|
<Card title="Claim {{@index}}">
|
|
149
149
|
<ReferenceField source="worker_id" reference="workers" />
|
|
@@ -156,7 +156,70 @@ A record's related records repeat under it as a list: a `ReferenceManyField` hol
|
|
|
156
156
|
</RecordCard>
|
|
157
157
|
```
|
|
158
158
|
|
|
159
|
-
Each entry is a record of the stack while its children draw, so `Field`, `Show`, `{{path}}` placeholders and nested lists inside it read it, and `@index`, `@first` and `@last` count its place in the list. A text item of an `ArrayField`, such as a label, is read as `this`; an object item by its keys, which no model describes, so the build does not check them, and it warns when an item's key could shadow a field of a record further out. A list ties itself to the record around it by a field of that record, its `source`; a `ReferenceManyField`'s is `id` of the nearest record by default. A `ReferenceManyField`'s and a `ReferenceArrayField`'s `filter` and `sort`
|
|
159
|
+
Each entry is a record of the stack while its children draw, so `Field`, `Show`, `{{path}}` placeholders and nested lists inside it read it, and `@index`, `@first` and `@last` count its place in the list. A text item of an `ArrayField`, such as a label, is read as `this`; an object item by its keys, which no model describes, so the build does not check them, and it warns when an item's key could shadow a field of a record further out. A list ties itself to the record around it by a field of that record, its `source`; a `ReferenceManyField`'s is `id` of the nearest record by default. A `ReferenceManyField`'s and a `ReferenceArrayField`'s `filter` and `sort` are a data block's: AIP-160 text or the builder's arrow, and a list of fields. react-admin's objects are not taken: write `filter={{ status: 'open' }}` as `filter="status = 'open'"` and `sort={{ field: 'claimed_at', order: 'DESC' }}` as `sort={['claimed_at desc']}`. Without `sort`, such a list is in its key's order, descending, as react-admin's is. A `ReferenceManyField`'s `pagination="more"` adds a button that reads the next `perPage` records into the same list. The [blocks reference](blocks.md#related-records) lists every prop.
|
|
160
|
+
|
|
161
|
+
## Typed layouts
|
|
162
|
+
|
|
163
|
+
A layout written as a function of what it reads is typed by the app's resources: `layout()` draws a composed page's tree, and `recordLayout(resource, ...)` a record page's. Each runs its function once, as the config loads, and gives the same tree the JSX would, so the server checks, plans and serves it as any other.
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
/** @jsxImportSource @protobase/layout */
|
|
167
|
+
import { Card, Page, Show, Table, Text, layout, now, page, recordLayout, RecordsIterator, ReferenceManyField } from '@protobase/layout'
|
|
168
|
+
import { l, view } from '@protobase/schema'
|
|
169
|
+
|
|
170
|
+
export const today = page('today', layout(({ resources }) => (
|
|
171
|
+
<Page title="Today">
|
|
172
|
+
<Show when={resources.invoices.count.gt(0)}>
|
|
173
|
+
<Table resource="invoices" filter={(f) => f.status.eq('open').and(f.due_at.lt(now().plus('7d')))} sort={['due_at asc']} columns={['number', 'due_at', 'total']} />
|
|
174
|
+
</Show>
|
|
175
|
+
</Page>
|
|
176
|
+
)))
|
|
177
|
+
|
|
178
|
+
export const tasksView = view<typeof tasks>('tasks').layout(() => [
|
|
179
|
+
l.blocks(recordLayout('tasks', ({ data }) => (
|
|
180
|
+
<ReferenceManyField reference="task_runs" target="task_id">
|
|
181
|
+
<RecordsIterator<'task_runs'>>{(run) => <Card title={`${run.outcome} of ${data.title}`} />}</RecordsIterator>
|
|
182
|
+
</ReferenceManyField>
|
|
183
|
+
))),
|
|
184
|
+
])
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
| | |
|
|
188
|
+
| --- | --- |
|
|
189
|
+
| `data` | The record page's record, in `recordLayout` only: `data.title` is the placeholder `{{title}}`, so `` `Runs of ${data.title}` `` is `Runs of {{title}}`. |
|
|
190
|
+
| `resources` | `resources.invoices.count` is how many `invoices` the user can see, for a [condition](#conditions). |
|
|
191
|
+
| A record block's child | A `RecordCard`, a `CardRow`, a `ReferenceField` or a `RecordsIterator` takes a function of its record as its children, `(run) => ...`. Inside it `run.outcome` is `{{outcome}}`, the page's record is `{{@root.title}}`, and a record further out is `{{../outcome}}`. |
|
|
192
|
+
|
|
193
|
+
With `.protobase/register.d.ts`, which `protobase types`, `dev` and `build` write from `config/index.ts` (see [`types`](cli.md#types)), TypeScript checks the names against the app: `resource` against its resources, `columns`, `fields`, `sort` and the filter's fields against the resource's fields, `data` against the record's fields, and a [`<Trans>`](#texts-in-the-readers-language)'s key against its texts. Without the file, any name type-checks and the server checks them as it starts. Export a typed layout inside `page()` or a view, as above: a tree exported bare, `export const tree = layout(...)`, refers to its own type through the register, and TypeScript gives up on it.
|
|
194
|
+
|
|
195
|
+
### The condition builder
|
|
196
|
+
|
|
197
|
+
A filter's arrow and a typed layout's `when` write AIP-160 with one builder. A field compares with `eq`, `ne`, `lt`, `le`, `gt`, `ge`, `in([...])`, `contains(value)` and `isNull()`, and conditions join with `.and(...)`, `.or(...)` and `not(...)`, bracketed where AND and OR mix:
|
|
198
|
+
|
|
199
|
+
| Builder | AIP-160 |
|
|
200
|
+
| --- | --- |
|
|
201
|
+
| `f.status.eq('open')` | `status = "open"` |
|
|
202
|
+
| `f.total.gt(100).and(f.paid.eq(false))` | `total > 100 AND paid = false` |
|
|
203
|
+
| `f.a.eq(1).and(f.b.eq(2).or(f.c.eq(3)))` | `a = 1 AND (b = 2 OR c = 3)` |
|
|
204
|
+
| `not(f.status.in(['done', 'held']))` | `NOT in(status, "done", "held")` |
|
|
205
|
+
| `f.owner.eq(null)`, `f.owner.isNull()` | `isNull(owner)` |
|
|
206
|
+
| `f.plan.name.ne('Pro')` | `plan.name != "Pro"` |
|
|
207
|
+
| `f.due_at.lt(now().plus('7d'))` | `due_at < now() + 7d` |
|
|
208
|
+
| `f.task_id.eq(data.id)` | `task_id = {{id}}` |
|
|
209
|
+
|
|
210
|
+
`now().plus(...)` and `now().minus(...)` take a duration, a number and one of `s`, `m`, `h`, `d` or `w`. A filter's arrow gives one condition, or the layout fails as it loads; AIP-160 text stays for what the builder does not write, such as `related()`.
|
|
211
|
+
|
|
212
|
+
## Texts in the reader's language
|
|
213
|
+
|
|
214
|
+
A `<Trans i18nKey="..." />` shows one of the app's own texts in the reader's language, as react-i18next's `<Trans>` does, wherever text goes: as a child, or as a `title`, `description`, `label` or `empty`. Its message is ICU, `values` gives what it formats, from a record with `{{path}}` or `data.title`, and `components` the element each of its tags draws:
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
<Card title={<Trans i18nKey="today.open" values={{ count: 2 }} />}>
|
|
218
|
+
<Trans i18nKey="today.owner" values={{ name: '{{owner}}' }} components={{ b: <Text as="strong" /> }} />
|
|
219
|
+
</Card>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
The texts are the app's `translations({ en, nl })`; see [Your own texts](languages.md#your-own-texts).
|
|
160
223
|
|
|
161
224
|
## How a page reads its data
|
|
162
225
|
|
|
@@ -271,7 +334,7 @@ export const tasksView = view<typeof tasks>('tasks').layout((r) => [
|
|
|
271
334
|
])
|
|
272
335
|
```
|
|
273
336
|
|
|
274
|
-
The view's file is then `.tsx` and starts with the JSX import source, as a [layout file](#setup) does, or it imports the tree from a layout file of its own.
|
|
337
|
+
The view's file is then `.tsx` and starts with the JSX import source, as a [layout file](#setup) does, or it imports the tree from a layout file of its own. [`recordLayout('tasks', ({ data }) => ...)`](#typed-layouts) writes the same tree typed by the record, `data.title` for `{{title}}`.
|
|
275
338
|
|
|
276
339
|
| | |
|
|
277
340
|
| --- | --- |
|
|
@@ -319,7 +382,9 @@ A [`Timeline`](blocks.md#timeline) takes `select` too: a bar links to the page w
|
|
|
319
382
|
| `status`, `plan.name` | A field of the records around it, through relations, by the [lookup of paths](#paths-and-scopes). |
|
|
320
383
|
| `invoices.count` | How many `invoices` the user can see (an exact count from the list API). |
|
|
321
384
|
|
|
322
|
-
Comparisons, `AND`, `OR`, `NOT`, parentheses, `isNull(field)
|
|
385
|
+
Comparisons, `AND`, `OR`, `NOT`, parentheses, `isNull(field)`, `in(field, "a", "b")`, `now()` and `now() + 7d` or `now() - 1h` work; a time compares with a timestamp field as the list API compares it. Any other function, such as `regex()` or `related()`, works only in a list's `filter`, which the API reads, and a condition that calls one fails as the config loads. A field that is missing or that the user cannot read makes the comparison false, and a `Show` that names a resource or field the user cannot see is left out of their page.
|
|
386
|
+
|
|
387
|
+
In a [typed layout](#typed-layouts), `when` takes [the builder's](#the-condition-builder) condition too: `when={data.status.eq('done')}` or `when={resources.invoices.count.gt(0)}`.
|
|
323
388
|
|
|
324
389
|
Record pages take the same conditions in the `when` of `l.section`, `l.related` and `l.sidebar`; see [Form and read view](ui-config.md#form-and-read-view).
|
|
325
390
|
|
|
@@ -110,6 +110,7 @@ A workflow's `layout`, a field beside its definition, keeps only where nodes of
|
|
|
110
110
|
| `$trigger` | The trigger. |
|
|
111
111
|
| `Save.record` | In `pins` only: a Break of `record` in what `Save` gives; `Save.#break` one of the whole of it, `$trigger.customer` one of the run's input, and `Save.#status` one of `Save`'s status in data order. |
|
|
112
112
|
| `Save.#make.data` | In `pins` only: a Make of `Save`'s argument `data`. |
|
|
113
|
+
| `Notify.#select.to` | In `pins` only: a Select of `Notify`'s argument `to`. |
|
|
113
114
|
| `Tell.#when` | In `pins` only, in data order: the condition node wired to `Tell`'s Only when pin; `Tell.#when.1` the one at its second side, `Tell.#when.1.0` the one at that node's first. |
|
|
114
115
|
|
|
115
116
|
In a state's name or a field, `%`, `.` and a leading `#` or `$` are written `%25`, `%2E`, `%23` and `%24`, so the state `Step.1` is `Step%2E1`.
|
|
@@ -393,11 +394,12 @@ The bar under the breadcrumb holds what is live, the version shown, *Add step*,
|
|
|
393
394
|
A user who may read a workflow but not change it gets the same page, its fields and graph locked, without Save or Publish. On a mobile screen the bar holds what is live, *Runs* and *Test run*, or *Save* with unsaved changes, and the rest behind "..."; a step's form can be changed, and steps are added on a wider screen.
|
|
394
395
|
|
|
395
396
|
- **The graph lays itself out.** The trigger is on the left, each state is a box, a Map is a box around the states it runs for each item, and each edge is drawn from the field that names it: a state's `Next`, a Choice's rules (labelled with their condition) and its `Default` ("Otherwise"), and a Task's or Map's catchers ("On error", dashed). The graph is laid out in layers, from left to right, each time a state, an edge, a pin or a wire is added, removed or renamed; the document keeps no positions, so the graph a person sees is the one a model or the API wrote, and the one they edit is what a model reads back. The canvas zooms with the wheel, a pinch and its buttons, and pans by dragging the empty canvas.
|
|
396
|
-
- **Moving nodes by hand.** Dragging a node, a step, the trigger, a Break, a Make or a condition node, puts it where it is let go, as do the arrow keys on the chosen node. It stays there, marked with a pin, and the nodes not moved are laid out around it, also as steps and connections change: one the layout would put under it goes below it, and a Map or Block grows around a node moved inside it. *Pins* and *Simple* each keep their own places, so a node moved in one view stays where the layout puts it in the other. The pin's *Unpin* hands the node back to the layout, and *Tidy up*, above the graph, lays the view shown out again, forgetting every node moved in it and leaving the other view's. Where nodes were moved is the workflow's [layout](#layout), shared with everyone who edits it and saved by *Save*; it makes no new version and needs no publish. An older version opens with the layout it was saved with, which cannot be changed. <gap>A step renamed in the editor cannot keep the place it was moved to because carrying its layout key over to its new name is not implemented.</gap>
|
|
397
|
+
- **Moving nodes by hand.** Dragging a node, a step, the trigger, a Break, a Make or a condition node, puts it where it is let go, as do the arrow keys on the chosen node. Shift-click adds a node to the choice or takes it out, and Shift-drag on the empty canvas chooses every node its box covers; the nodes chosen move together, and Delete removes them all. A step's form opens only on a plain click on it, never while a choice is made with Shift or a box. It stays there, marked with a pin, and the nodes not moved are laid out around it, also as steps and connections change: one the layout would put under it goes below it, and a Map or Block grows around a node moved inside it. *Pins* and *Simple* each keep their own places, so a node moved in one view stays where the layout puts it in the other. The pin's *Unpin* hands the node back to the layout, and *Tidy up*, above the graph, lays the view shown out again, forgetting every node moved in it and leaving the other view's. Where nodes were moved is the workflow's [layout](#layout), shared with everyone who edits it and saved by *Save*; it makes no new version and needs no publish. An older version opens with the layout it was saved with, which cannot be changed. <gap>A step renamed in the editor cannot keep the place it was moved to because carrying its layout key over to its new name is not implemented.</gap>
|
|
397
398
|
- **Adding a step.** *Add step* opens a searchable picker in the panel: every step type the app can run, its plugins' included, each with what it does, then Choice, For each item, Wait, Set values, Succeed and Fail. Search finds other words too, such as *email* for Send mail. It says where the step lands, and choosing a step on the graph changes that. Clicking or tapping one of a step's handles, which grows into a plus under the pointer, opens the same picker for a step right there: at the bottom handle after the step, at a Choice's *When* as a new rule and at its *Otherwise* as its `Default`, at *On error* on the path of every error, and at the trigger's as the first step. Where the handle led to a step already, the new one goes in between and goes on to that step, such as between the trigger and the first step; a Succeed or Fail there stays unconnected. A new step is named `Step 1`, `Step 2` and so on, and goes after the chosen step, taking over where it went on to, or after the last step; into the Map chosen; or first, with the trigger chosen. After a Choice or a step that ends the run it stays unconnected, and so does a Succeed or Fail that would cut off the steps after it, such as one added between two steps or first in a workflow that has steps.
|
|
398
|
-
- **Pins and wires.** Execution runs along the square handles in a box's header, and data along round pins below it, coloured by type: each argument of a Task's step type is a pin on the left, with its type on hover, and each value a step returns, or the trigger gives the run, is a pin on the right, such as an HTTP request's *Status*, *Headers* and *Body* and a record trigger's *Record*. A record, an HTTP body with a `body_schema`, headers and any other object with a title are one pin each. Dragging an output pin to an input pin wires them: the input reads that value by name, the step it comes from gets a variable keeping its result when it has none, and taking the wire away empties the input. A wire is refused over a pin that does not take it, saying why, such as *Whole number does not fit Text*, or that the step does not run before. An input no wire reads shows its value on its row, to type there where it is text, a number, true or false or a choice; an expression shows as ƒ and an object as {…}, both edited in the step's form. Inputs a type does not need and that hold nothing fold away behind *N more inputs*.
|
|
399
|
-
- **Break and Make.** Letting go of a wire from an object pin on the empty canvas offers *Break <Type>*, a node with a pin for each field of the object, such as a record's fields; from an object input, *Make <Type>*, which builds it from a pin per field, such as the fields a records step writes. They are the editor's own: they run no step and leave no trace, the inputs that use them read `$fetch.body.ip` and hold `{ "name": "{% $fetch.body.ip %}" }`, and opening a workflow draws a Break for each object a read goes into and a Make for each argument written as an object whose fields read values. One that nothing reads yet goes with a reload.
|
|
400
|
-
- **
|
|
399
|
+
- **Pins and wires.** Execution runs along the square handles in a box's header, and data along round pins below it, coloured by type: each argument of a Task's step type is a pin on the left, with its type on hover, and each value a step returns, or the trigger gives the run, is a pin on the right, such as an HTTP request's *Status*, *Headers* and *Body* and a record trigger's *Record*. A record, an HTTP body with a `body_schema`, headers and any other object with a title are one pin each. Dragging an output pin to an input pin wires them: the input reads that value by name, the step it comes from gets a variable keeping its result when it has none, and taking the wire away empties the input. A wire is refused over a pin that does not take it, saying why, such as *Whole number does not fit Text*, or that the step does not run before. An input no wire reads shows its value on its row, to type there where it is text, a number, true or false or a choice; an expression shows as ƒ and an object as {…}, both edited in the step's form. Inputs a type does not need and that hold nothing fold away behind *N more inputs*. The layout orders the nodes by where their wires meet their pins, so wires cross as little as they can, and in data order puts each node just before what reads it, so a Break, a condition node or a Select stands beside its step.
|
|
400
|
+
- **Break and Make.** Letting go of a wire from an object pin on the empty canvas offers *Break <Type>*, a node with a pin for each field of the object, such as a record's fields; from an object input, *Make <Type>*, which builds it from a pin per field, such as the fields a records step writes. They are the editor's own: they run no step and leave no trace, the inputs that use them read `$fetch.body.ip` and hold `{ "name": "{% $fetch.body.ip %}" }`, and opening a workflow draws a Break for each object a read goes into and a Make for each argument written as an object whose fields read values. One that nothing reads yet goes with a reload. A Break shows only the fields something reads, through a wire or an expression, and *N more fields* opens the rest; one that nothing reads yet shows them all.
|
|
401
|
+
- **Select.** An argument chosen by another value is drawn as a *Select* node between them: its one input is the value it looks at, a row per case gives a value of its own when that value is one of its own, and *Otherwise* gives one for any other, all typed on the node; *Add case* adds one. It is the editor's own: it writes a chain of conditionals, `{% $states.context.Execution.Input.body.topic = 'sales' ? 'sales@example.com' : 'support@example.com' %}`, and one written that way, spaced as the node writes it, opens as the node, as it was saved. Letting go of a wire from an input of a value, empty or holding one of its own, on the empty canvas offers *Select*, whose one case and Otherwise give what the input held. Its position is kept under `Notify.#select.to`. Removing it removes the argument.
|
|
402
|
+
- **Condition nodes.** In data order, a step's Condition is drawn as the nodes it is made of, wired to its Only when pin: *Equals*, *Not equals*, *Greater* and *Less* compare two values, *Matches* tests text against a pattern (`$contains($contact.email, /^[^@\s]+@[^@\s]+$/)`), the pattern written on the node, and *All of*, *Any of* and *Not* join conditions. All of and Any of take any number: each has an empty input after its last, and a wire or a node there adds one more, so `a and b and c` is one All of of three and opens as one; removing one of three or more takes its input away. Each input is wired to a pin or holds a value of its own; one compared with a step's Step status pin is a choice of *Succeeded*, *Failed*, *Timed out*, *Aborted* and *Skipped*, and an All of's, an Any of's or a Not's is true or false. Dropping a step's Step status pin on another step's Only when pin makes that step run once the first succeeded: `{% $states.context.Steps.Save.Status = 'SUCCEEDED' %}`, an Equals of `Save`'s status and *Succeeded*. Letting go of a wire from an empty Only when pin on the empty canvas offers each node, and *Expression*; from an input of an All of, an Any of or a Not that holds a value or none, each node again, there. Any other Condition, such as `{% $count($tickets) > 0 %}`, or one spaced or bracketed otherwise than the nodes write it, is one *Expression* node, its text edited inside it, with a pin for each value it reads. The nodes are the editor's own: they write the Condition as JSONata, and one opened and saved unchanged stays as it was, byte for byte. Removing a node leaves its input what it holds with nothing wired, `''` for a Comparison's or a Matches node's text, `true` for an All of's and `false` for an Any of's or a Not's, or takes the input away from an All of or Any of of three or more; removing the one at Only when removes the Condition.
|
|
401
403
|
- **Execution order.** "Run the steps from the data" or "in sequence" under "..." switches the draft's order. To data, each `Next` becomes what the state it names runs after, by its data or, where it reads none of it, by a Condition on the earlier state's status, so the states run in the same order; refused with a Choice, an error path to another state or a variable two states assign. To sequence, the states form one chain in an order every dependency keeps; refused with a Condition or a catcher without `Next`. In data order the graph has no execution handles: in Pins the wires order the steps, each step has an Only when pin (its Condition) first and a Step status pin last, and in Simple an arrow joins each pair of steps where one reads the other, dashed where it reads only the other's status; a step with a Condition shows an "only when" badge.
|
|
402
404
|
- **Pins or Simple.** *Pins* and *Simple* above the graph switch how it is drawn: Simple shows the steps and the lines between them alone, with every input edited in the step's form, where a wire made in Pins shows as the read it wrote. Both draw the same document, so switching changes nothing saved; the browser remembers the choice, Pins by default.
|
|
403
405
|
- **Connecting steps.** Drag from a step's execution handle to another step; a click or tap without a drag adds a step there instead. The first handle sets `Next`, a Choice's *When* handle adds a rule and its *Otherwise* handle sets `Default`, a Task's or Map's *On error* handle adds a catcher of `States.ALL`, and the trigger's handle sets `StartAt`. A step leads only to steps of its own machine, so an edge into or out of a Map is refused. The chosen step's form sets the same edges with menus: *Goes on to*, each rule's and catcher's *Then goes to*, and *Otherwise goes to*.
|
|
@@ -21,7 +21,7 @@ state, step type and trigger, is in [the workflows reference](references/referen
|
|
|
21
21
|
- `"execution_order": "data"`: no `StartAt`, no `Next`, no `End`, no `Choice`. A state runs once every state it reads
|
|
22
22
|
from has ended, and states that read nothing of each other run at once. Use it when steps are mostly independent,
|
|
23
23
|
or to branch per step with a `Condition`; the editor draws a Condition as nodes (Equals, Not equals, Greater, Less,
|
|
24
|
-
|
|
24
|
+
Matches, All of, Any of, Not), any other expression as one Expression node.
|
|
25
25
|
|
|
26
26
|
Data order's rules, each checked against the save or a run:
|
|
27
27
|
|
|
@@ -70,8 +70,8 @@ A test run does what its steps do: it sends the mail and writes the records.
|
|
|
70
70
|
## Examples
|
|
71
71
|
|
|
72
72
|
A website contact form, in data order: the sender becomes a lead contact with the message as a note, sales or support
|
|
73
|
-
is mailed by the topic, and the sender gets an auto-reply when the address looks valid. The routing Conditions
|
|
74
|
-
Equals and Not equals nodes
|
|
73
|
+
is mailed by the topic, and the sender gets an auto-reply when the stored address looks valid. The routing Conditions
|
|
74
|
+
show as Equals and Not equals nodes, the address check as a Matches node.
|
|
75
75
|
|
|
76
76
|
```json
|
|
77
77
|
{
|
|
@@ -108,8 +108,8 @@ Equals and Not equals nodes; the address check, a regular expression, as an Expr
|
|
|
108
108
|
"AutoReply": {
|
|
109
109
|
"Type": "Task",
|
|
110
110
|
"Resource": "app:mail.send",
|
|
111
|
-
"Condition": "{% $
|
|
112
|
-
"Arguments": { "to": "{% $
|
|
111
|
+
"Condition": "{% $contains($contact.email, /^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$/) %}",
|
|
112
|
+
"Arguments": { "to": "{% $contact.email %}", "subject": "We received your message", "text": "{% 'Hi ' & $contact.name & ',\n\nThanks for getting in touch; we will answer within one working day.' %}" }
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
}
|