@xeplr/cli 0.3.9 → 0.3.10
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/README.md +22 -0
- package/lib/generate/index.js +15 -1
- package/package.json +1 -1
- package/templates/BUILDING.md +274 -0
- package/templates/CLAUDE.md +9 -2
- package/templates/README.md +6 -0
- package/templates/api/functions/index.js +28 -8
package/README.md
CHANGED
|
@@ -60,6 +60,7 @@ Already working, with nothing to wire up:
|
|
|
60
60
|
and choosing one is the first screen after signing in.
|
|
61
61
|
- **A welcome screen** that checks it can reach everything and tells you which
|
|
62
62
|
files to change first.
|
|
63
|
+
- **`BUILDING.md`** — every step of building the app, click or code (see below).
|
|
63
64
|
- **READMEs** at the project root and in `api/` and `ui/`: how to start it,
|
|
64
65
|
every command, where things live, and the rules the app follows.
|
|
65
66
|
- **A `CLAUDE.md`** that tells Claude how to create a new UI in this app — the
|
|
@@ -146,6 +147,27 @@ a package name).
|
|
|
146
147
|
way (Postgres not running, say), the installer says which step and the command
|
|
147
148
|
to run again.
|
|
148
149
|
|
|
150
|
+
## Building the app — what is a click, what is code
|
|
151
|
+
|
|
152
|
+
Every generated project has a **`BUILDING.md`** at its root: every step of
|
|
153
|
+
growing it into a full application, each marked as a **click** in Configure UI
|
|
154
|
+
or **code**.
|
|
155
|
+
|
|
156
|
+
- **Clicks** — masters, forms and their lists (publishing creates the tables),
|
|
157
|
+
the side rail, users and roles, flows.
|
|
158
|
+
- **Code, then a click** — everything a screen *does*: buttons, lists worked out
|
|
159
|
+
from several tables (with chips, KPI cards and a date range), a record's
|
|
160
|
+
details and comments, suggestions as you type, rules on save, emails after.
|
|
161
|
+
Each is a function in `api/functions/`, registered with `@xeplr/actions`
|
|
162
|
+
under the event it is for; the designer then offers it in a dropdown in the
|
|
163
|
+
right place (a button's **Runs**, a list's **Rows from**, …). The guide lists
|
|
164
|
+
all thirteen events, where each is picked, what it gets and returns, with a
|
|
165
|
+
recipe for the common ones.
|
|
166
|
+
- **Still a page written by hand** — a screen that is not a form and its list
|
|
167
|
+
(a record's own view, a Home with tiles), a record on its own page, fields
|
|
168
|
+
that show or hide as another changes, charts, approvals, addresses of your
|
|
169
|
+
own. Each is named, with what to write.
|
|
170
|
+
|
|
149
171
|
## Creating a new UI
|
|
150
172
|
|
|
151
173
|
Two ways, both in the running app's project:
|
package/lib/generate/index.js
CHANGED
|
@@ -52,7 +52,7 @@ function flowsSubstitutions(answers) {
|
|
|
52
52
|
__WF_CLAUDE__: [
|
|
53
53
|
'**Flows** — forms one after another, run by `@xeplr/workflow-api` INSIDE this API (bin/www starts it, workflow.js) in a database of its own (`DB_WORKFLOW`). Design them in Configure UI → Flows, never in code: a flow is data, reached through `/api/workflow/flows`, and walked at `/journey/<key>`. After a step, a flow goes to a screen, lets one of the app\'s `decide` functions choose, or finishes. Workflow follows this app\'s tenancy — it never creates companies or workspaces of its own.',
|
|
54
54
|
'',
|
|
55
|
-
'**Functions** — the code around a form\'s records lives in `api/functions/`, registered with `@xeplr/actions` under the event it is for (`beforeLoad`, `beforeSave`, `afterSave`, `beforeDelete`, `onError
|
|
55
|
+
'**Functions** — the code around a form\'s records lives in `api/functions/`, registered with `@xeplr/actions` under the event it is for, and is picked BY NAME: the screen\'s own events (`beforeLoad`, `beforeSave`, `afterSave`, `beforeDelete`, `onError`) in its `events` or Configure UI → Flows → Events; a flow step\'s `decide`; and its controls\' — `button` (a button\'s `action`), `buttonOptions` (a popup checklist\'s `optionsFrom`), `listRows` (a list\'s `rowsFrom`), `rowDetails` (a column\'s `details`), `recordDetails` (`detailsFrom`), `feedEntries` (`entriesFrom`), `suggest` (`suggestFrom`). There are no SERVER hook files — the browser\'s front-end hooks are the page\'s (`Edit<Form>.jsx`). A screen naming a function nobody registered is refused at publish. The full table, with what each gets and returns and where the designer picks it, is in `BUILDING.md`.',
|
|
56
56
|
''
|
|
57
57
|
].join('\n')
|
|
58
58
|
};
|
|
@@ -172,6 +172,20 @@ function flowsReadme(answers) {
|
|
|
172
172
|
'| `onError` | when load / save / delete failed | (ignored) |',
|
|
173
173
|
'| `decide` | a flow step is done | the next step\'s key |',
|
|
174
174
|
'',
|
|
175
|
+
'A screen\'s **controls** name functions too, each picked from a dropdown in the designer:',
|
|
176
|
+
'',
|
|
177
|
+
'| event | named by | return |',
|
|
178
|
+
'|---|---|---|',
|
|
179
|
+
'| `button` | a button\'s **Runs** (Actions → Buttons) | `{ message }` |',
|
|
180
|
+
'| `buttonOptions` | a checklist in a button\'s popup | the entries to tick |',
|
|
181
|
+
'| `listRows` | a list\'s **Rows from** | `{ rows, counts, kpis }` |',
|
|
182
|
+
'| `rowDetails` | a list column\'s **Hover box from** | the hover box\'s lines |',
|
|
183
|
+
'| `recordDetails` | a Details control\'s **Details from** | `{ sections }` |',
|
|
184
|
+
'| `feedEntries` | a Comments & history control\'s **Entries from** | the comments and events |',
|
|
185
|
+
'| `suggest` | an Autocomplete field\'s **Suggestions from** | the suggestions |',
|
|
186
|
+
'',
|
|
187
|
+
'Every step of building the app — which are clicks, which need a function, and a recipe for each — is in **`BUILDING.md`**.',
|
|
188
|
+
'',
|
|
175
189
|
'`api/functions/index.js` registers two to start from: `tidyTaskTitle` (Tasks\' `beforeSave`) and `byPriority` (a `decide`). A screen that names a function nobody registered is refused when it is published, by name.',
|
|
176
190
|
''
|
|
177
191
|
].join('\n');
|
package/package.json
CHANGED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# Building __NAME__, step by step
|
|
2
|
+
|
|
3
|
+
Everything it takes to grow this app into a full application — and, for each
|
|
4
|
+
step, whether it is a **click** (Configure UI, as Super Admin, no code) or
|
|
5
|
+
**code** (a function you write in `api/`, which the designer then lets you
|
|
6
|
+
pick from a dropdown).
|
|
7
|
+
|
|
8
|
+
The split is deliberate. **A screen holds no code**: what it looks like, its
|
|
9
|
+
fields and its rules are a document you design. What it **does** — a button
|
|
10
|
+
that changes a status, a list worked out from three tables, an email after a
|
|
11
|
+
save — is a function on the server, written once and **picked by name** in the
|
|
12
|
+
designer. So:
|
|
13
|
+
|
|
14
|
+
1. you write the function in `api/functions/` and restart the API;
|
|
15
|
+
2. it appears in the designer's dropdown for what it was written for;
|
|
16
|
+
3. you pick it, give it its values, and publish.
|
|
17
|
+
|
|
18
|
+
Publishing refuses a function nobody registered, one written for something
|
|
19
|
+
else, or a value it does not take — by name — so a mistake is found then, not
|
|
20
|
+
when somebody presses the button.
|
|
21
|
+
|
|
22
|
+
| | Step | How |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| 1 | [Lists other forms choose from](#1-masters--click) — departments, statuses | **Click** |
|
|
25
|
+
| 2 | [A form and its list](#2-a-form-and-its-list--click) — the records, in a real table | **Click** |
|
|
26
|
+
| 3 | [The side rail](#3-the-side-rail--click) | **Click** |
|
|
27
|
+
| 4 | [Who may do what](#4-who-may-do-what--click) | **Click** |
|
|
28
|
+
| 5 | [Forms one after another](#5-flows--click) | **Click** (plus a function to choose the next step) |
|
|
29
|
+
| 6 | [What the app does](#6-what-the-app-does--code-then-click) — buttons, worked-out lists, rules, emails | **Code**, then **click** |
|
|
30
|
+
| 7 | [What a screen cannot say yet](#7-what-a-screen-cannot-say-yet--code) — a page written by hand | **Code** |
|
|
31
|
+
|
|
32
|
+
Everything below is in **Configure UI**: the settings menu, top right, for
|
|
33
|
+
Super Admin only.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 1. Masters — click
|
|
38
|
+
|
|
39
|
+
**Configure UI → Masters.** The small lists the rest of the app points at:
|
|
40
|
+
departments, statuses, categories. A master is an ordinary form with a flag,
|
|
41
|
+
so it has a table, a list and an edit form like any other. Make them first —
|
|
42
|
+
a dropdown on another table needs that table to exist.
|
|
43
|
+
|
|
44
|
+
## 2. A form and its list — click
|
|
45
|
+
|
|
46
|
+
**Configure UI → Forms → New form.**
|
|
47
|
+
|
|
48
|
+
1. Give it a **label** (what people read, renamed any time) and a **key**
|
|
49
|
+
(`farming_department` — it names the table and never changes once
|
|
50
|
+
published).
|
|
51
|
+
2. **Design → Form**: drag controls onto the sheet, or click one to add it.
|
|
52
|
+
Select a control to set its label, field name, required, default, rules
|
|
53
|
+
and look.
|
|
54
|
+
3. **Design → List**: which columns the list shows, its title, its look.
|
|
55
|
+
4. **Publish.** This creates the table — one column per field — or changes it
|
|
56
|
+
to match. Removing a field asks first, because its column and data go.
|
|
57
|
+
5. **Add to menu.** It is now in the side rail, at `/forms/<key>`: the list,
|
|
58
|
+
with New and Edit opening the form in a popup.
|
|
59
|
+
|
|
60
|
+
What a form can hold, all by clicking:
|
|
61
|
+
|
|
62
|
+
| | |
|
|
63
|
+
|---|---|
|
|
64
|
+
| **Inputs** | text, long text, number, date, date and time, tick box, dropdown, radio buttons, several from a list, file (gallery, camera, several), text with suggestions* |
|
|
65
|
+
| **Ready-made fields** | email, phone, website, LinkedIn, age, date of birth, gender, country, amount, percentage, yes / no, postal code — keyboard, format check and options included |
|
|
66
|
+
| **Rules** | required, min / max, length, pattern, file types and size — checked in the browser **and** on the server |
|
|
67
|
+
| **Dropdowns** | a fixed list of options, or the rows of another table (a master) |
|
|
68
|
+
| **Layout** | steps across the top (or tabs), headings and text, colours, fonts, sizes. On a phone the form stacks itself |
|
|
69
|
+
| **Rows that belong to it** | a **Form** control (Data → Form): another form drawn inside this one, saving into its own table — an order's lines |
|
|
70
|
+
| **Buttons, details, comments, worked-out lists*** | Actions → Buttons; Data → Details, Comments & history, List — see step 6 |
|
|
71
|
+
|
|
72
|
+
\* These run a function — step 6.
|
|
73
|
+
|
|
74
|
+
Change a published form at any time the same way: design, then **Publish**.
|
|
75
|
+
Never rename a field that is already a column (its data would be left
|
|
76
|
+
behind) — add a new field instead.
|
|
77
|
+
|
|
78
|
+
## 3. The side rail — click
|
|
79
|
+
|
|
80
|
+
**Configure UI → Menu**: rename, reorder and hide the side rail's items. The
|
|
81
|
+
label is what people read; the key underneath never changes, so renaming
|
|
82
|
+
breaks nothing.
|
|
83
|
+
|
|
84
|
+
## 4. Who may do what — click
|
|
85
|
+
|
|
86
|
+
**Admin** (settings menu): users, roles, and the permissions each role has.
|
|
87
|
+
Activate new accounts there. Designing and publishing forms stays Super Admin
|
|
88
|
+
only (`api/routes/access.js`).
|
|
89
|
+
|
|
90
|
+
A button only some people may press — Reopen, for managers — checks the
|
|
91
|
+
caller's roles inside its function (step 6, `system.access.roles`).
|
|
92
|
+
|
|
93
|
+
## 5. Flows — click
|
|
94
|
+
|
|
95
|
+
**Configure UI → Flows**: forms one after another — a sign-up, then its
|
|
96
|
+
documents, then a review. For each step: which form, what runs around its
|
|
97
|
+
records (its **events**, step 6), and where it goes once saved: another form,
|
|
98
|
+
the end, or **a function that decides** (`decide`, step 6). People start a
|
|
99
|
+
flow from **Flows** in the side rail; a half-done one can be left and resumed.
|
|
100
|
+
|
|
101
|
+
Not here: approvals (another person's turn, with an assignee and a timeout).
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## 6. What the app does — code, then click
|
|
106
|
+
|
|
107
|
+
### The pattern, every time
|
|
108
|
+
|
|
109
|
+
1. **Write the function** in a file under `api/functions/`, for example
|
|
110
|
+
`api/functions/orders.js`, and add `require('./orders')` to
|
|
111
|
+
`api/functions/index.js`.
|
|
112
|
+
2. **Register it** with `@xeplr/actions` — a `name`, the **`event`** it is
|
|
113
|
+
for (the table below), a `description` people read in the designer, and
|
|
114
|
+
`execute`.
|
|
115
|
+
3. **Restart the API** (`npm run start-api`) — functions are loaded at start.
|
|
116
|
+
4. **Pick it** in the designer, where the table says. The dropdown offers only
|
|
117
|
+
the functions written for that purpose; if there are none it says which
|
|
118
|
+
event to register.
|
|
119
|
+
5. **Publish** the form.
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
// api/functions/orders.js
|
|
123
|
+
var { register } = require('@xeplr/actions');
|
|
124
|
+
|
|
125
|
+
register({
|
|
126
|
+
name: 'setOrderStatus',
|
|
127
|
+
event: 'button',
|
|
128
|
+
description: 'Sets the order status',
|
|
129
|
+
execute: async function ({ input, system }) { /* … */ }
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Every function runs **on the server**, sees only the signed-in person's
|
|
134
|
+
company, and can refuse with `ctx.reject('message', { field })` — the message
|
|
135
|
+
shows on that field.
|
|
136
|
+
|
|
137
|
+
### Which event, and where you pick it
|
|
138
|
+
|
|
139
|
+
| I want… | `event` | Pick it in the designer | Gets | Returns |
|
|
140
|
+
|---|---|---|---|---|
|
|
141
|
+
| **A button** — set a status, confirm, approve, merge | `button` | select a **Buttons** control (Actions → Buttons) → a button → **Runs** | `{ input, system }` — `input`: the button's values; `system`: `record`, `id`, `user`, `access`, `db`, `knex`, `reject` | `{ message }` — shown to the person |
|
|
142
|
+
| **A checklist or choice inside a button's popup** — the products still out | `buttonOptions` | the button → Ask first → Asks for → a checklist → **Entries from** | `ctx.record`, `ctx.id`, `ctx.field` | `[{ id, label, sub?, image? }]` |
|
|
143
|
+
| **A list worked out by you** — from several tables, with search, filter chips, KPI cards and a date range | `listRows` | select the **List** → **Rows from** (then Filter chips, KPI cards, Date range in the same panel) | `ctx.query` — `{ q, filter, kpi, from, to }`; on a record's screen `ctx.record` | `{ rows, counts: { chip: n }, kpis: { card: n } }` |
|
|
144
|
+
| **A hover box on a list cell** — the last activity | `rowDetails` | the List → a column drawn as activity → **Hover box from** | `ctx.id`, `ctx.column` | `[{ text, sub?, at? }]` |
|
|
145
|
+
| **What is known about a record** — its products, contact, delivery | `recordDetails` | a **Details** control (Data → Details) → **Details from** | `ctx.record`, `ctx.id`, `ctx.query.more` | `{ sections: [{ title, rows: [{ label, text }] }] }` |
|
|
146
|
+
| **Comments and history** on a record | `feedEntries` | a **Comments & history** control → **Entries from** | `ctx.record`, `ctx.id` | `[{ id, kind: 'comment' \| 'event', text, author?, at? }]` |
|
|
147
|
+
| **Suggestions as someone types** — a product from the shop | `suggest` | an **Autocomplete** field → **Suggestions from** | `ctx.query.q` | `[{ value, label?, sub?, fill? }]` |
|
|
148
|
+
| **A rule on save** — must / only if / check against, or work a value out | `beforeSave` | Configure UI → Flows → a flow with the form → its step → **Events & navigation** — saved to the form itself, so it runs everywhere | `ctx.values`, `ctx.isNew`, `ctx.previous` | the values to save; or `ctx.reject(…)` |
|
|
149
|
+
| **Something after a save** — an email, another record | `afterSave` | the same place | `ctx.result` (the saved row), `ctx.isNew` | — |
|
|
150
|
+
| **Only some rows** — a person sees their own | `beforeLoad` | the same place | `ctx.query` (narrow it) | — |
|
|
151
|
+
| **A check before delete** | `beforeDelete` | the same place | `ctx.previous` | — (or `ctx.reject`) |
|
|
152
|
+
| **When load / save / delete failed** | `onError` | the same place | `ctx.error` | — |
|
|
153
|
+
| **Where a flow goes next** | `decide` | Configure UI → Flows → a step → **Let a function decide** | `ctx.values`, `ctx.targets` | one of `ctx.targets` |
|
|
154
|
+
|
|
155
|
+
Every `ctx` also has `user`, `access` (`{ roles }`), `tenant`, `knex` (the
|
|
156
|
+
database) and `db(table)` (a table, this company's active rows only).
|
|
157
|
+
|
|
158
|
+
### Recipes
|
|
159
|
+
|
|
160
|
+
**A row of status buttons — one function, not one per status.** Register it
|
|
161
|
+
with an `inputSchema` saying what it takes; `options` are the values allowed,
|
|
162
|
+
and the designer shows them as a dropdown per button:
|
|
163
|
+
|
|
164
|
+
```js
|
|
165
|
+
register({
|
|
166
|
+
name: 'setOrderStatus', event: 'button',
|
|
167
|
+
description: 'Sets the order status',
|
|
168
|
+
inputSchema: [
|
|
169
|
+
{ name: 'status', type: 'string', required: true,
|
|
170
|
+
options: [{ value: 'packed', label: 'Packed' }, { value: 'shipped', label: 'Shipped' }] },
|
|
171
|
+
{ name: 'note', type: 'string' }
|
|
172
|
+
],
|
|
173
|
+
execute: async function ({ input, system }) {
|
|
174
|
+
await system.db('orders').where('id', system.id).update({ status: input.status });
|
|
175
|
+
return { message: 'Now ' + input.status };
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Then, on the order's form: **Actions → Buttons**, add *Packed* and *Shipped*,
|
|
181
|
+
both **Runs** `setOrderStatus`, with status `packed` / `shipped`. Still by
|
|
182
|
+
clicking, per button:
|
|
183
|
+
|
|
184
|
+
- **Ask first** — a confirmation, a note box (the function takes `note`),
|
|
185
|
+
values to type (**Asks for** — a parcel's weight), photos (`files`).
|
|
186
|
+
- **Shows when / Greyed out when / Shown as the current choice when** — rules
|
|
187
|
+
on the record (`status` equals `packed`). The server checks them again on
|
|
188
|
+
the press, so a hidden button cannot be pressed by hand.
|
|
189
|
+
- **Opens** a form instead of running a function — an Edit button.
|
|
190
|
+
|
|
191
|
+
A button acts on the record the form has open — a saved one.
|
|
192
|
+
|
|
193
|
+
**A board — a list with chips and KPI cards:**
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
register({
|
|
197
|
+
name: 'orderBoard', event: 'listRows',
|
|
198
|
+
description: 'Open orders, newest first',
|
|
199
|
+
execute: async function (ctx) {
|
|
200
|
+
var q = ctx.db('orders');
|
|
201
|
+
if (ctx.query.filter === 'packed') q = q.where('status', 'packed');
|
|
202
|
+
if (ctx.query.from) q = q.where('placedOn', '>=', ctx.query.from);
|
|
203
|
+
var rows = await q.orderBy('placedOn', 'desc');
|
|
204
|
+
return { rows: rows, counts: { all: rows.length, packed: rows.filter(function (r) { return r.status === 'packed'; }).length } };
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Then the form's **List** → **Rows from** `orderBoard`, add the chips (*All*,
|
|
210
|
+
*Packed*) and, if you want them, KPI cards and a date range. The text in each
|
|
211
|
+
cell is what the function wrote — format dates and money there.
|
|
212
|
+
|
|
213
|
+
**A rule that must hold:**
|
|
214
|
+
|
|
215
|
+
```js
|
|
216
|
+
register({
|
|
217
|
+
name: 'checkCreditLimit', event: 'beforeSave',
|
|
218
|
+
description: 'Refuses an order over the customer\'s credit limit',
|
|
219
|
+
execute: async function (ctx) {
|
|
220
|
+
var customer = await ctx.knex('customers').where('id', ctx.values.customerId).first();
|
|
221
|
+
if (ctx.values.amount > customer.creditLimit) ctx.reject('Over the credit limit', { field: 'amount' });
|
|
222
|
+
return ctx.values;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Rules that must hold always go here, on the server — never only in the
|
|
228
|
+
browser, where a person can skip them.
|
|
229
|
+
|
|
230
|
+
**Storing a value differently from how it is shown** (an array kept as text,
|
|
231
|
+
a code in capitals): the form's server **model**, `api/screens/<form>/<form>.model.js`
|
|
232
|
+
— see "Create a new UI" in `CLAUDE.md`.
|
|
233
|
+
|
|
234
|
+
The full reference for each — every option of a button's popup, a list's
|
|
235
|
+
columns, cards instead of a table — is `ui/node_modules/@xeplr/ui-factory/AUTHORING.md`
|
|
236
|
+
and that package's README ("Buttons", "A list whose rows a function works
|
|
237
|
+
out", "What is known about a record", "Comments and history"). For the server
|
|
238
|
+
side: `api/node_modules/@xeplr/factory/README.md`, "Events" and "Buttons and
|
|
239
|
+
worked-out lists".
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## 7. What a screen cannot say yet — code
|
|
244
|
+
|
|
245
|
+
These are not in Configure UI today. Each needs files in the project:
|
|
246
|
+
|
|
247
|
+
| I want… | What to write |
|
|
248
|
+
|---|---|
|
|
249
|
+
| **A screen that is not a form and its list** — a record's own view (its details, comments and buttons, with Edit opening the form), a board of its own, a Home page with tiles | the screen as a document in `api/screens/<name>/`, registered in `api/screens/index.js`; a page that loads it (copy `ui/src/pages/FormRecords.jsx`); its route in `ui/src/App.jsx`; a side-rail item and its menu row — the steps in "Create a new UI", `CLAUDE.md`. Once it is published, its look is designed in the designer like any other |
|
|
250
|
+
| **A record on a page of its own**, rather than in a popup | the list page and form page pattern of Tasks — `ui/src/pages/Tasks.jsx` and `EditTask.jsx` |
|
|
251
|
+
| **A field that shows, hides or fills itself as another changes** | the form's front-end hooks, in its page (`EditTask.jsx` shows where). Browser only — anything that must hold goes in `beforeSave` as well |
|
|
252
|
+
| **Charts and dashboards** | a page written by hand — there is no chart control yet |
|
|
253
|
+
| **Approvals** — another person's turn, with an assignee and a timeout | not in this app's flows |
|
|
254
|
+
| **An address of your own** in the API — a webhook, an export | `api/routes/index.js`, plus its `apis` row and role mappings in a migration under `api/migrations-auth/` |
|
|
255
|
+
|
|
256
|
+
A page written by hand is **web only**: list it in `ui/pages.json` under
|
|
257
|
+
`webOnly`, with the reason, so nobody is surprised that it is missing from a
|
|
258
|
+
phone app. The pre-commit hook warns about every one.
|
|
259
|
+
|
|
260
|
+
If a screen *nearly* says what you need, ask for the control to be added to
|
|
261
|
+
`@xeplr/ui-factory` instead of writing a page around it.
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## With Claude
|
|
266
|
+
|
|
267
|
+
Every step above can also be asked for. Open Claude in this folder:
|
|
268
|
+
|
|
269
|
+
> Create a new UI for **farming departments** … Follow "Create a new UI" in CLAUDE.md.
|
|
270
|
+
|
|
271
|
+
and, for what a form does, say it in the same message — *"a Mark active button
|
|
272
|
+
on each row"*, *"refuse an Area over 10,000"*, *"email the manager after a
|
|
273
|
+
save"*. Claude writes the function, registers it under the right event and
|
|
274
|
+
names it in the screen, exactly as step 6 does by hand.
|
package/templates/CLAUDE.md
CHANGED
|
@@ -7,6 +7,8 @@ Read `api/node_modules/@xeplr/ui-factory/AUTHORING.md` for what screens, functio
|
|
|
7
7
|
|
|
8
8
|
**Before changing any screen or button, read the "Screens and buttons — the rules" section of `ui/node_modules/@xeplr/ui-factory/README.md` and follow it.** In short: a screen is a document; a button is a registered function and its parameters; a page written by hand is web only, listed in `ui/pages.json` with the reason — and before writing one, say so and ask whether to add the missing control to the factory instead.
|
|
9
9
|
|
|
10
|
+
**`BUILDING.md` is the whole map for people:** every step of building this app, which ones are clicks in Configure UI and which need a function in `api/`, every function event and where the designer picks it. Keep it true when you change what the app can do.
|
|
11
|
+
|
|
10
12
|
## Create a new UI
|
|
11
13
|
|
|
12
14
|
A new UI is a **form**: a list, and an add / edit form it opens — on a page of its own (like Tasks) or in a popup — saved in its own table. Use the singular for `<form>` (`farming_department`), the plural for the page (`FarmingDepartments`).
|
|
@@ -35,7 +37,12 @@ Then change only what the request asks for:
|
|
|
35
37
|
|---|---|
|
|
36
38
|
| a field, label, rule, dropdown, layout, colour | the screen JSON → validate → publish in Configure UI → Forms (or, never published yet, restart the API) |
|
|
37
39
|
| a button that does something to a record — set a status, confirm, approve | a **Buttons** control in the screen JSON naming a server function (`event: 'button'`, with an `inputSchema` — `options` for the values allowed) and its `params`; the function in `<form>.functions.js`. Several buttons that differ only by a value are ONE function |
|
|
38
|
-
| a list whose rows are worked out, a search box, filter chips with counts | a list with `rowsFrom` naming a server function (`event: 'listRows'`) that returns `{ rows, counts }` — it writes the text the list shows |
|
|
40
|
+
| a list whose rows are worked out, a search box, filter chips with counts, KPI cards, a date range | a list with `rowsFrom` naming a server function (`event: 'listRows'`) that returns `{ rows, counts, kpis }` — it writes the text the list shows |
|
|
41
|
+
| a hover box on a list cell | the column's `details` naming a `rowDetails` function |
|
|
42
|
+
| what is known about a record (its products, contact, delivery) | a `details` control whose `detailsFrom` names a `recordDetails` function |
|
|
43
|
+
| comments and history on a record | a `feed` control whose `entriesFrom` names a `feedEntries` function |
|
|
44
|
+
| suggestions as someone types | an `autocomplete` field whose `suggestFrom` names a `suggest` function |
|
|
45
|
+
| a checklist inside a button's popup | an `ask.fields` entry of `type: "checklist"` whose `optionsFrom` names a `buttonOptions` function |
|
|
39
46
|
| hide / filter rows on screen, fill in a value before saving, check something before Next moves on | front-end hooks — `ui/src/pages/Edit<Form>.jsx` (`get`, `save`, `delete`, `step`). Browser only: say so if it matters on a phone |
|
|
40
47
|
| must / only if / check against / email when / only managers see | a server function — registered in `api/screens/<form>/<form>.functions.js` with its `event`, then named in `<form>-edit.screen.json`'s `events` (or picked in Configure UI → Flows → Events). Register before naming: a screen naming an unregistered function is refused at publish |
|
|
41
48
|
| store as / convert / comma-separated ↔ array / work out X from Y | server model — `api/screens/<form>/<form>.model.js` |
|
|
@@ -45,7 +52,7 @@ Then change only what the request asks for:
|
|
|
45
52
|
|
|
46
53
|
### The controls a field can be
|
|
47
54
|
|
|
48
|
-
`text` (default), `textarea`, `number`, `date`, `datetime`, `checkbox`, `dropdown`, `radio`, `multiselect`, `file`, plus `stepper` and `label`. The sample uses every
|
|
55
|
+
`text` (default), `textarea`, `number`, `date`, `datetime`, `checkbox`, `dropdown`, `radio`, `multiselect`, `file`, plus `stepper` and `label`. A screen can also hold controls that are not fields — `autocomplete`, `list`, `buttons`, `details`, `feed`, `table`, `subform`, `tiles` — see "Controls" in the ui-factory README. The sample uses every field type — read `api/screens/task/task.entity.json` for how each is written. Three are worth knowing about:
|
|
49
56
|
|
|
50
57
|
- **`multiselect`** — several ids in ONE text column, comma separated, and an array in your code. An option's id may not contain a comma.
|
|
51
58
|
- **`file`** — the column holds the **path**, never the file. Say which extensions (`"accept": ".pdf,.docx"`) and how large (`"maxSize": 10`, in MB); the API enforces both, by extension, and keeps the file in the company's own folder under `XEPLR_DATA_DIR` (`screens/<table>/`). Uploading needs `multer` in `api/` (already in package.json).
|
package/templates/README.md
CHANGED
|
@@ -6,6 +6,7 @@ An xeplr application, created by [`@xeplr/cli`](https://www.npmjs.com/package/@x
|
|
|
6
6
|
__NAME__/
|
|
7
7
|
├─ api/ the API and the sign-in service → api/README.md
|
|
8
8
|
├─ ui/ the React app → ui/README.md
|
|
9
|
+
├─ BUILDING.md every step of building the app: what is a click, what needs a function
|
|
9
10
|
└─ CLAUDE.md how to change this app — for Claude, and a good read for people
|
|
10
11
|
```
|
|
11
12
|
|
|
@@ -67,6 +68,11 @@ Every one of these checks the same sign-in token, so one login covers them all.
|
|
|
67
68
|
|
|
68
69
|
## Create a new UI
|
|
69
70
|
|
|
71
|
+
**[`BUILDING.md`](BUILDING.md) is the step-by-step guide** — masters, forms,
|
|
72
|
+
the menu, roles and flows by clicking; buttons, worked-out lists, rules and
|
|
73
|
+
emails as a function you write in `api/functions/` and then pick from a
|
|
74
|
+
dropdown in the designer; and what still needs a page written by hand.
|
|
75
|
+
|
|
70
76
|
- **Without code** — Configure UI → Forms → New form → design → Publish → Add to menu.
|
|
71
77
|
- **With Claude** — open Claude in this folder and give it (change the name and the fields):
|
|
72
78
|
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
// THIS APP'S FUNCTIONS —
|
|
2
|
-
//
|
|
1
|
+
// THIS APP'S FUNCTIONS — everything a screen DOES: its buttons, the lists it
|
|
2
|
+
// works out, its rules on save, a flow's "let a function decide". Loaded once
|
|
3
|
+
// at startup (bin/www), before the screens — restart the API after adding one.
|
|
3
4
|
//
|
|
4
5
|
// A function is registered under the EVENT it is written for, and picked BY
|
|
5
|
-
// NAME in the designer
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
6
|
+
// NAME from a dropdown in the designer, which offers each place only the
|
|
7
|
+
// functions written for it. The designer only ever sees the name, the
|
|
8
|
+
// description and what the event hands it — the code stays here, and runs on
|
|
9
|
+
// the server. BUILDING.md, at the project's root, has a recipe for each.
|
|
10
|
+
//
|
|
11
|
+
// The screen's own events — picked in Configure UI → Flows → a step → Events
|
|
12
|
+
// & navigation (or a screen's `events` in its .screen.json):
|
|
9
13
|
//
|
|
10
14
|
// event runs ctx adds return
|
|
11
15
|
// beforeLoad before records are read query (narrow it) nothing, or a new query
|
|
@@ -16,8 +20,24 @@
|
|
|
16
20
|
// onError when load / save / delete failed error (ignored)
|
|
17
21
|
// decide a flow step is done: where next? values, targets a step key
|
|
18
22
|
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
23
|
+
// A screen's controls — picked on the control, in Configure UI → Forms → Design:
|
|
24
|
+
//
|
|
25
|
+
// event picked at ctx adds return
|
|
26
|
+
// button Buttons → a button → Runs ({ input, system }): { message }
|
|
27
|
+
// input = its values,
|
|
28
|
+
// system.record / id
|
|
29
|
+
// buttonOptions a button's popup → a checklist record, id, field [{ id, label }]
|
|
30
|
+
// → Entries from
|
|
31
|
+
// listRows List → Rows from query { q, filter, { rows, counts, kpis }
|
|
32
|
+
// kpi, from, to }
|
|
33
|
+
// rowDetails List → a column → Hover box from id, column [{ text, sub, at }]
|
|
34
|
+
// recordDetails Details → Details from record, id { sections }
|
|
35
|
+
// feedEntries Comments & history → Entries from record, id [{ id, kind, text }]
|
|
36
|
+
// suggest Autocomplete → Suggestions from query { q } [{ value, label }]
|
|
37
|
+
//
|
|
38
|
+
// Every ctx has user, access ({ roles }), tenant, knex, db() (a table, this
|
|
39
|
+
// company's active rows) and reject(message, { field }) — which refuses with
|
|
40
|
+
// the message on that field.
|
|
21
41
|
//
|
|
22
42
|
// A screen that names a function nobody registered is refused when it is
|
|
23
43
|
// published, by name — so renaming one here means renaming it there too.
|