@xeplr/cli 0.4.0 → 0.6.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/README.md +10 -3
- package/lib/generate/index.js +20 -7
- package/lib/plan.js +1 -0
- package/lib/questions.js +2 -1
- package/package.json +1 -1
- package/templates/README.md +4 -2
- package/templates/api/README.md +2 -1
- package/templates/api/development.env.tpl +1 -0
- package/templates/api/env.required.js +4 -0
- package/templates/api/package.json +3 -1
- package/templates/api/production.env.example +1 -0
- package/templates/api/workflow.js +26 -2
- package/templates/mobile/README.md +5 -3
- package/templates/mobile/package.json +2 -2
- package/templates/mobile/src/app/_layout.jsx +7 -1
- package/templates/mobile/src/app/forms/[form]/index.jsx +2 -2
- package/templates/mobile/src/app/index.jsx +3 -2
- package/templates/mobile/src/lib/app.js +11 -0
- package/templates/ui/package.json +1 -1
- package/templates/ui/pages.json +2 -3
- package/templates-tenancy/mobile/src/app/select.jsx +16 -0
- package/templates-tenancy/ui/src/pages/SelectScope.jsx +38 -113
package/README.md
CHANGED
|
@@ -47,10 +47,12 @@ Already working, with nothing to wire up:
|
|
|
47
47
|
screen, a function that decides, or the end. Walked at `/journey/<key>`, and
|
|
48
48
|
resumable. Run by `@xeplr/workflow-api` **inside the API**, in a database of
|
|
49
49
|
its own (`<name>_workflow`, created on first start) — nothing extra to start.
|
|
50
|
-
|
|
50
|
+
Its clock is `@xeplr/jobs`, started with it in a database of its own
|
|
51
|
+
(`<name>_jobs`): schedules and timed work (a Wait box running out, a
|
|
52
|
+
reminder) run as jobs. It follows the app's tenancy (none, or the levels you chose) and never creates
|
|
51
53
|
companies or workspaces of its own. Approvals (another person's turn) are not
|
|
52
54
|
part of it.
|
|
53
|
-
- **A phone app** — `mobile/` (Expo): the same app drawn natively on Android and iOS — every form added to the menu, its list, add / edit, its buttons and the journeys — with no screen code of its own: it draws what the server holds (`@xeplr/ui-factory/native`, `@xeplr/ui-account/native`). Try it with Expo Go, build an APK with `npm run build:apk`.
|
|
55
|
+
- **A phone app** — `mobile/` (Expo): the same app drawn natively on Android and iOS — every form added to the menu, its list, add / edit, its buttons and the journeys — with no screen code of its own: it draws what the server holds (`@xeplr/ui-factory/native`, `@xeplr/ui-account/native`). Try it with Expo Go, build an APK with `npm run build:apk`. An app whose data is split by company asks for the company first, on the phone as on the web.
|
|
54
56
|
- **Functions** — `api/functions/`: the app's own code, registered with
|
|
55
57
|
`@xeplr/actions` by the event it is for (`beforeSave`, `afterSave`, …,
|
|
56
58
|
`decide`) and picked by name in a screen's events or a flow step. Two to start
|
|
@@ -252,7 +254,12 @@ an app keeps its tables apart, and creates the database on first start), with
|
|
|
252
254
|
`tenantTables: false` so it follows the app's tenancy rather than creating
|
|
253
255
|
`companies` / `workspaces`, and `access: true` so each flows route checks the
|
|
254
256
|
caller's permissions, which its `migrations-auth` grants (loaded through
|
|
255
|
-
`XEPLR_AUTH_MIGRATIONS`).
|
|
257
|
+
`XEPLR_AUTH_MIGRATIONS`). Its clock is `@xeplr/jobs` (`api/workflow.js`): the
|
|
258
|
+
engine runs no timer, so `workflow.js` registers the engine's `jobActions`,
|
|
259
|
+
starts jobs in their own database (`DB_JOBS`, `<name>_jobs`, from jobs'
|
|
260
|
+
`requiredEnv`, `init({ migrate: true })`), passes `keepSchedule` and `startJob`
|
|
261
|
+
to `registerWorkflow`, and starts the jobs scheduler. The app has no jobs
|
|
262
|
+
screens; the jobs only run. The designer is `@xeplr/ui-factory`'s
|
|
256
263
|
`FlowDesignerPage`; the paid canvas designer (X-Flow) is not part of a
|
|
257
264
|
generated app.
|
|
258
265
|
|
package/lib/generate/index.js
CHANGED
|
@@ -32,6 +32,7 @@ function substitutions(answers) {
|
|
|
32
32
|
__DB_API__: answers.databases.api,
|
|
33
33
|
__DB_AUTH__: answers.databases.auth,
|
|
34
34
|
__DB_WORKFLOW__: answers.databases.workflow,
|
|
35
|
+
__DB_JOBS__: answers.databases.jobs,
|
|
35
36
|
__PREFIX__: answers.prefix,
|
|
36
37
|
__UI_PORT__: String(answers.ports.ui),
|
|
37
38
|
__AUTH_PORT__: String(answers.ports.auth),
|
|
@@ -55,7 +56,7 @@ function flowsSubstitutions(answers) {
|
|
|
55
56
|
return {
|
|
56
57
|
__WF_README__: flowsReadme(answers),
|
|
57
58
|
__WF_CLAUDE__: [
|
|
58
|
-
'**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.',
|
|
59
|
+
'**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. Its clock is `@xeplr/jobs`, started in the same place, in a database of its own (`DB_JOBS`): a flow\'s timed work — a Wait box running out, a reminder, a scheduled start — is a job; never add a timer of your own.',
|
|
59
60
|
'',
|
|
60
61
|
'**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 the form designer\'s **Server rules** (nothing selected); 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`.',
|
|
61
62
|
''
|
|
@@ -120,8 +121,22 @@ function tenancySubstitutions(levels) {
|
|
|
120
121
|
|
|
121
122
|
// ui/src/App.jsx
|
|
122
123
|
__MT_APP_UI_IMPORTS__: on ? "import SelectScope, { ScopeGate } from './pages/SelectScope.jsx'" : '',
|
|
123
|
-
// ui/pages.json: the company picker is
|
|
124
|
-
__MT_PAGES_SELECT__: on ? ' { "path": "/select", "menu": "Switch ' + first.label.toLowerCase() + '", "
|
|
124
|
+
// ui/pages.json: the company picker is on the phone too (NativeScopePicker), as a page of its own.
|
|
125
|
+
__MT_PAGES_SELECT__: on ? ',\n { "path": "/select", "menu": "Switch ' + first.label.toLowerCase() + '", "screen": "the ' + levels.map(function (l) { return l.label.toLowerCase(); }).join(' and ') + ' picker — NativeScopePicker on a phone" }' : '',
|
|
126
|
+
// mobile/: the same levels on the phone, the picker first, Switch on the menu.
|
|
127
|
+
__MT_MOBILE_TENANCY__: on ? [
|
|
128
|
+
'',
|
|
129
|
+
'/**',
|
|
130
|
+
' * Who the data belongs to — the same levels as the API and the website. The',
|
|
131
|
+
' * first page after signing in is choosing them (app/select.jsx), and every',
|
|
132
|
+
' * request carries the choice.',
|
|
133
|
+
' */',
|
|
134
|
+
'export const TENANCY = ' + JSON.stringify({ levels: levels, slots: slots }, null, 2)
|
|
135
|
+
].join('\n') : '',
|
|
136
|
+
__MT_MOBILE_IMPORTS__: on ? "import { registerMTs, scopeChosen } from '@xeplr/ui-account/native'\nimport { TENANCY } from '../lib/app.js'" : '',
|
|
137
|
+
__MT_MOBILE_GATE__: on ? " // The company first (once — the choice is remembered).\n if (signedIn && !scopeChosen(TENANCY.levels) && segments[0] !== 'select') return <Redirect href=\"/select\" />" : '',
|
|
138
|
+
__MT_MOBILE_REGISTER__: on ? ' registerMTs(TENANCY.slots)' : '',
|
|
139
|
+
__MT_MOBILE_SWITCH__: on ? " <View style={{ marginBottom: 10 }}><Btn label=\"" + 'Switch ' + first.label.toLowerCase() + "\" onPress={() => router.push('/select')} /></View>" : '',
|
|
125
140
|
__MT_MENU_KEY__: on ? " 'Switch " + first.label.toLowerCase() + "'," : '',
|
|
126
141
|
__MT_DRAWER_ITEM__: on ? " { key: 'Switch " + first.label.toLowerCase() + "', icon: SwitchIcon, clickHandler: () => navigate('/select') }," : '',
|
|
127
142
|
__MT_SWITCH_ICON__: on ? [
|
|
@@ -168,6 +183,7 @@ function flowsReadme(answers) {
|
|
|
168
183
|
? 'this app\'s — flows and runs belong to the ' + tenancy.map(function (l) { return l.label.toLowerCase(); }).join(' and ') + ' chosen after signing in, checked by the same membership gate as everything else.'
|
|
169
184
|
: 'none, like the rest of this app — flows belong to the whole app.') + ' Workflow never creates companies or workspaces of its own. |',
|
|
170
185
|
'| **Permissions** | each route checks the caller\'s (`List flows`, `Start flow run`, `Publish flow`…), granted by `@xeplr/workflow-api`\'s `migrations-auth`, which `XEPLR_AUTH_MIGRATIONS` loads. |',
|
|
186
|
+
'| **Its clock** | `@xeplr/jobs`, started with it, in a database of its own, `DB_JOBS` (`' + answers.databases.jobs + '`), created and migrated on first start. Workflow runs no timer: a flow on a schedule is a job, and everything that falls due with time — a Wait box running out, a reminder or an escalation, a run whose process died — is one system job, every minute. There are no jobs screens in this app; the jobs only run. |',
|
|
171
187
|
'',
|
|
172
188
|
'## Functions — your code, picked by name',
|
|
173
189
|
'',
|
|
@@ -329,10 +345,7 @@ function generate(answers, target) {
|
|
|
329
345
|
|
|
330
346
|
Object.keys(sources).forEach(function (rel) {
|
|
331
347
|
var src = sources[rel];
|
|
332
|
-
|
|
333
|
-
// company on a phone is not built yet, and a phone app that cannot pick one
|
|
334
|
-
// would only be refused by the API. Left out rather than half there.
|
|
335
|
-
if (answers.tenancy && answers.tenancy.length && rel.split(path.sep)[0] === 'mobile') return;
|
|
348
|
+
|
|
336
349
|
var dir = path.dirname(rel);
|
|
337
350
|
var base = path.basename(rel);
|
|
338
351
|
var outName = RENAME[base] || base;
|
package/lib/plan.js
CHANGED
|
@@ -19,6 +19,7 @@ function describe(answers) {
|
|
|
19
19
|
L.push(' ' + answers.databases.auth + ' accounts, roles, permissions');
|
|
20
20
|
L.push(' ' + answers.databases.api + ' your own data');
|
|
21
21
|
L.push(' ' + answers.databases.workflow + ' flows and their runs');
|
|
22
|
+
L.push(' ' + answers.databases.jobs + ' flows\' schedules and timed work');
|
|
22
23
|
L.push('');
|
|
23
24
|
L.push(' You will sign in as ' + answers.admin.email + '.');
|
|
24
25
|
L.push('');
|
package/lib/questions.js
CHANGED
|
@@ -32,7 +32,8 @@ function databaseNames(name) {
|
|
|
32
32
|
var base = name.replace(/-/g, '_');
|
|
33
33
|
// Workflow gets a database of its own: a sub-product embedded in an app is
|
|
34
34
|
// given its own store, never a share of the app's (see the API's workflow.js).
|
|
35
|
-
|
|
35
|
+
// So do the jobs that are its clock: its schedules and its due work.
|
|
36
|
+
return { auth: base + '_auth', api: base + '_api', workflow: base + '_workflow', jobs: base + '_jobs' };
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
// ── tenancy ──────────────────────────────────────────────────────────────
|
package/package.json
CHANGED
package/templates/README.md
CHANGED
|
@@ -24,7 +24,9 @@ cd ui && npm run dev # the app http://localhost:__UI_PORT_
|
|
|
24
24
|
Open http://localhost:__UI_PORT__ and sign in as `__ADMIN_EMAIL__`.
|
|
25
25
|
|
|
26
26
|
Flows (`@xeplr/workflow-api`) run **inside the API**, in a database of their
|
|
27
|
-
own that the API creates on first start — nothing else to start.
|
|
27
|
+
own that the API creates on first start — nothing else to start. Their clock,
|
|
28
|
+
`@xeplr/jobs` (schedules, Wait boxes running out, reminders), starts with them,
|
|
29
|
+
in a database of its own (`DB_JOBS`), also created on first start.
|
|
28
30
|
|
|
29
31
|
## Where each address goes
|
|
30
32
|
|
|
@@ -65,7 +67,7 @@ Every one of these checks the same sign-in token, so one login covers them all.
|
|
|
65
67
|
- **Tasks** — a sample built from screens: a list, and a form it opens on a page of its own, saved into an ordinary `tasks` table. The form is filled in over three steps and uses every control there is — text, a dropdown, radio buttons, a tick box, a date, a date and time, several tags at once, and a file.
|
|
66
68
|
- **Configure UI** — in the settings menu, for Super Admin: every form (make one, design it, publish it, add it to the side rail), every flow (screens one after another — each screen's events, and where it goes next) and the side rail itself (rename, reorder, hide).
|
|
67
69
|
- **Flows** — in the side rail: the journeys people can start, run by `@xeplr/workflow-api` inside the API.
|
|
68
|
-
- **A phone app** — `mobile/` (Expo): every form added to the menu, its list, add / edit, its buttons and the journeys, drawn natively from what the server holds — no screen code, nothing to change when a form is added (see `mobile/README.md`).
|
|
70
|
+
- **A phone app** — `mobile/` (Expo): every form added to the menu, its list, add / edit, its buttons and the journeys, drawn natively from what the server holds — no screen code, nothing to change when a form is added (see `mobile/README.md`).
|
|
69
71
|
- **Functions** — `api/functions/`: your code, registered by event and picked by name in a screen's events or a flow step (see "Functions" below).
|
|
70
72
|
|
|
71
73
|
## Create a new UI
|
package/templates/api/README.md
CHANGED
|
@@ -26,7 +26,7 @@ The API (`@xeplr/base-apis`) and the sign-in service (`@xeplr/auth`), with this
|
|
|
26
26
|
| `routes/access.js` | who may design and publish forms (Super Admin) |
|
|
27
27
|
| `screens/` | the forms this app ships with: per form, its spec, list and edit screens, server functions and model — registered in `screens/index.js` |
|
|
28
28
|
| `functions/` | this app's functions — the code screens' events and flows' `decide` pick by name — registered with `@xeplr/actions` by event, loaded at startup |
|
|
29
|
-
| `workflow.js` | flows: `@xeplr/workflow-api` started inside this API, in its own database (`DB_WORKFLOW`) |
|
|
29
|
+
| `workflow.js` | flows: `@xeplr/workflow-api` started inside this API, in its own database (`DB_WORKFLOW`), with its clock — `@xeplr/jobs`' scheduler, in a database of its own (`DB_JOBS`): a flow's schedules and timed work run as jobs, never on a timer of the app's own |
|
|
30
30
|
| `data/` | `XEPLR_DATA_DIR` in development: every file the app keeps, a folder per company — what people attach through a form's **file** field is in `<company>/screens/`. Never committed, and never served: a file comes back only through the API's own route, which checks the caller the way reading a record does |
|
|
31
31
|
| `migrations/` | hand-written SQL for tables no form owns |
|
|
32
32
|
| `migrations-auth/` | this app's rows in the sign-in database — menus (by key), permissions |
|
|
@@ -40,6 +40,7 @@ The API (`@xeplr/base-apis`) and the sign-in service (`@xeplr/auth`), with this
|
|
|
40
40
|
| `XEPLR_DATA_DIR` | **required, absolute, existing**: where every file the app keeps lives, a folder per company (`<root>/__NAME__/<company>/…`). Generated as `api/data`; on a server, somewhere backed up |
|
|
41
41
|
| `__PREFIX___CONNECTION`, `AUTH_DB_CONNECTION_INFO_ENCRYPTED` | the database, encrypted — `npm run db:encrypt` |
|
|
42
42
|
| `DB_API`, `AUTH_DB_NAME` | the two database names — never guessed |
|
|
43
|
+
| `DB_WORKFLOW`, `DB_JOBS` | flows' database, and the jobs that are their clock — named by `@xeplr/workflow-api` and `@xeplr/jobs`, created and migrated on first start, never guessed |
|
|
43
44
|
| `AUTH_SUPER_ADMIN_EMAIL` / `_PASSWORD` | the first account — created once, when the sign-in database is first set up |
|
|
44
45
|
| `AUTH_TENANT_HEADER` | `none`: one set of roles for everyone. A multi-tenant app names its company header (e.g. `x-company-id`), so a role made inside a company belongs to it |
|
|
45
46
|
| `AUTH_ACTIVATION_URL`, `AUTH_INVITE_URL`, `AUTH_RESET_URL` | the UI pages the emailed links open; the token is appended. The reset address is never taken from the request |
|
|
@@ -36,4 +36,8 @@ module.exports = [
|
|
|
36
36
|
// Flows' own database (DB_WORKFLOW) — workflow is embedded in this API but
|
|
37
37
|
// keeps its tables apart from yours. The library names it.
|
|
38
38
|
...require('@xeplr/workflow-api').embedRequiredEnv,
|
|
39
|
+
|
|
40
|
+
// Flows' clock (DB_JOBS): a flow's schedules and timed work run as jobs of
|
|
41
|
+
// @xeplr/jobs, in a database of their own. The library names it.
|
|
42
|
+
...require('@xeplr/jobs').requiredEnv,
|
|
39
43
|
];
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"multer": "^2.0.2",
|
|
29
29
|
"nodemailer": "^10.0.2",
|
|
30
30
|
"@xeplr/actions": "^2.2.1",
|
|
31
|
-
"@xeplr/workflow-api": "^
|
|
31
|
+
"@xeplr/workflow-api": "^3.0.0",
|
|
32
|
+
"@xeplr/workflow-engine": "^5.0.0",
|
|
33
|
+
"@xeplr/jobs": "^3.1.0"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
34
36
|
"dotenv-cli": "^8.0.0",
|
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
// sub-product embedded in an app gets a store of its own.
|
|
5
5
|
// Created and migrated on first start, with the same
|
|
6
6
|
// server login as the app (__PREFIX___CONNECTION).
|
|
7
|
+
// ITS CLOCK @xeplr/jobs, in a database of its own (DB_JOBS), also
|
|
8
|
+
// created and migrated on first start. Workflow runs no
|
|
9
|
+
// timer: a flow on a schedule is a job, and its timed work
|
|
10
|
+
// — a Wait box running out, a reminder, a run whose
|
|
11
|
+
// process died — is one system job, every minute.
|
|
7
12
|
// THIS APP'S it registers no tenancy of its own: flows and runs are
|
|
8
13
|
// TENANCY filtered by the levels this app registered (or none),
|
|
9
14
|
// behind this app's membership gate.
|
|
@@ -14,9 +19,24 @@
|
|
|
14
19
|
// A flow's "let a function decide" picks one of this app's functions
|
|
15
20
|
// (functions/), the same registry the screens' events use.
|
|
16
21
|
var { registerWorkflow } = require('@xeplr/workflow-api');
|
|
22
|
+
var engine = require('@xeplr/workflow-engine');
|
|
23
|
+
var jobs = require('@xeplr/jobs');
|
|
17
24
|
|
|
18
|
-
/** Creates and migrates workflow's
|
|
25
|
+
/** Creates and migrates workflow's and its jobs' databases, starts the clock, and returns the router — already gated. */
|
|
19
26
|
module.exports = async function startWorkflow(memberGate) {
|
|
27
|
+
// What a job runs to start a scheduled flow, and to do the due work.
|
|
28
|
+
engine.jobActions.forEach(function (a) { jobs.registerAction(a); });
|
|
29
|
+
await jobs.init({
|
|
30
|
+
database: process.env.DB_JOBS,
|
|
31
|
+
connection: process.env.__PREFIX___CONNECTION,
|
|
32
|
+
connectionName: 'jobs',
|
|
33
|
+
migrate: true,
|
|
34
|
+
// Only what workflow needs: no other actions offered to a job.
|
|
35
|
+
defaultActions: false,
|
|
36
|
+
// A finished job resumes the step that started it.
|
|
37
|
+
onFinish: function (report) { return engine.jobFinished(report); }
|
|
38
|
+
});
|
|
39
|
+
|
|
20
40
|
var workflow = await registerWorkflow({
|
|
21
41
|
applicationId: '__NAME__',
|
|
22
42
|
db: {
|
|
@@ -26,7 +46,11 @@ module.exports = async function startWorkflow(memberGate) {
|
|
|
26
46
|
},
|
|
27
47
|
tenantTables: false,
|
|
28
48
|
access: true,
|
|
29
|
-
mtMembershipGate: memberGate
|
|
49
|
+
mtMembershipGate: memberGate,
|
|
50
|
+
startJob: function (jobId, body) { return jobs.trigger(jobId, body, { triggerType: 'workflow' }); },
|
|
51
|
+
keepSchedule: jobs.keepSchedule
|
|
30
52
|
});
|
|
53
|
+
|
|
54
|
+
jobs.startScheduler();
|
|
31
55
|
return workflow.router;
|
|
32
56
|
};
|
|
@@ -52,9 +52,11 @@ Designing (Configure UI) and the admin screens stay on a computer.
|
|
|
52
52
|
| **Dates** | the phone's own date picker |
|
|
53
53
|
| **Journeys** | Start, then each screen with **Next**, as on the website |
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
company
|
|
55
|
+
Every control a form can hold is on the phone — a `table` as a card per row
|
|
56
|
+
with a tick, a `subform` drawn inside its form. When the app's data is split by
|
|
57
|
+
company, the first page after signing in is choosing it (and the workspace),
|
|
58
|
+
as on the website; **Switch company** is on the menu. Designing (Configure UI)
|
|
59
|
+
and the admin screens are for a computer.
|
|
58
60
|
|
|
59
61
|
## Layout
|
|
60
62
|
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@react-native-async-storage/async-storage": "2.2.0",
|
|
15
15
|
"@react-native-community/datetimepicker": "9.2.1",
|
|
16
|
-
"@xeplr/ui-account": "^1.
|
|
17
|
-
"@xeplr/ui-factory": "^1.
|
|
16
|
+
"@xeplr/ui-account": "^1.8.0",
|
|
17
|
+
"@xeplr/ui-factory": "^1.21.0",
|
|
18
18
|
"expo": "~58.0.26",
|
|
19
19
|
"expo-build-properties": "~58.0.12",
|
|
20
20
|
"expo-camera": "~58.0.14",
|
|
@@ -14,6 +14,7 @@ import { CameraView, Camera } from 'expo-camera'
|
|
|
14
14
|
import { hydrateStorage, startSession, useSession } from '@xeplr/ui-account/native'
|
|
15
15
|
import { NativeHostProvider, NativeInsets, NativeTheme, DARK, LIGHT, useNativeTheme } from '@xeplr/ui-factory/native'
|
|
16
16
|
import { APP_NAME, BUILT_IN_SERVER, devServer } from '../lib/app.js'
|
|
17
|
+
__MT_MOBILE_IMPORTS__
|
|
17
18
|
|
|
18
19
|
const PICKERS = { ImagePicker, DocumentPicker, DateTimePicker, DateTimePickerAndroid, CameraView, Camera }
|
|
19
20
|
|
|
@@ -23,6 +24,7 @@ function Frame() {
|
|
|
23
24
|
const { signedIn, server } = useSession()
|
|
24
25
|
const segments = useSegments()
|
|
25
26
|
if (!signedIn && segments[0] !== 'login') return <Redirect href="/login" />
|
|
27
|
+
__MT_MOBILE_GATE__
|
|
26
28
|
return (
|
|
27
29
|
<NativeInsets value={insets}>
|
|
28
30
|
<NativeHostProvider modules={PICKERS} baseUrl={server} appName={APP_NAME}>
|
|
@@ -39,7 +41,11 @@ export default function RootLayout() {
|
|
|
39
41
|
const [failed, setFailed] = useState(null)
|
|
40
42
|
useEffect(() => {
|
|
41
43
|
hydrateStorage({ AsyncStorage, prefix: '__NAME__', web: Platform.OS === 'web' })
|
|
42
|
-
.then(() => {
|
|
44
|
+
.then(() => {
|
|
45
|
+
__MT_MOBILE_REGISTER__
|
|
46
|
+
startSession({ builtInServer: BUILT_IN_SERVER, suggested: devServer() })
|
|
47
|
+
setReady(true)
|
|
48
|
+
}, (e) => setFailed(e.message || 'Could not start'))
|
|
43
49
|
}, [])
|
|
44
50
|
if (failed) return <View style={{ flex: 1, padding: 24, justifyContent: 'center' }}><Text>{failed}</Text></View>
|
|
45
51
|
if (!ready) return null
|
|
@@ -3,13 +3,13 @@ import { useCallback, useState } from 'react'
|
|
|
3
3
|
import { Stack, router, useFocusEffect, useLocalSearchParams } from 'expo-router'
|
|
4
4
|
import { useSession } from '@xeplr/ui-account/native'
|
|
5
5
|
import { NativeFormRecords, phoneMenu } from '@xeplr/ui-factory/native'
|
|
6
|
-
import { factory } from '../../../lib/app.js'
|
|
6
|
+
import { factory, PAGES } from '../../../lib/app.js'
|
|
7
7
|
|
|
8
8
|
export default function FormRecords() {
|
|
9
9
|
const { form } = useLocalSearchParams()
|
|
10
10
|
const { access } = useSession()
|
|
11
11
|
const key = String(form)
|
|
12
|
-
const item = phoneMenu(access).find((m) => m.form === key)
|
|
12
|
+
const item = phoneMenu(access, { pages: PAGES }).find((m) => m.form === key)
|
|
13
13
|
// Coming back from a record reads the list again: what was done there shows here.
|
|
14
14
|
const [tick, setTick] = useState(0)
|
|
15
15
|
useFocusEffect(useCallback(() => { setTick((n) => n + 1) }, []))
|
|
@@ -4,7 +4,7 @@ import { Text, View } from 'react-native'
|
|
|
4
4
|
import { Stack, router } from 'expo-router'
|
|
5
5
|
import { useSession, signOut } from '@xeplr/ui-account/native'
|
|
6
6
|
import { Btn, NativeMenu, phoneMenu, useNativeTheme } from '@xeplr/ui-factory/native'
|
|
7
|
-
import { APP_NAME } from '../lib/app.js'
|
|
7
|
+
import { APP_NAME, PAGES } from '../lib/app.js'
|
|
8
8
|
|
|
9
9
|
export default function Menu() {
|
|
10
10
|
const t = useNativeTheme()
|
|
@@ -13,7 +13,7 @@ export default function Menu() {
|
|
|
13
13
|
return (
|
|
14
14
|
<>
|
|
15
15
|
<Stack.Screen options={{ title: APP_NAME }} />
|
|
16
|
-
<NativeMenu items={phoneMenu(access)} onOpen={open}
|
|
16
|
+
<NativeMenu items={phoneMenu(access, { pages: PAGES })} onOpen={open}
|
|
17
17
|
header={(
|
|
18
18
|
<View style={{ marginBottom: 16 }}>
|
|
19
19
|
<Text style={{ color: t.ink, fontSize: 22, fontWeight: '800' }}>{APP_NAME}</Text>
|
|
@@ -23,6 +23,7 @@ export default function Menu() {
|
|
|
23
23
|
footer={(
|
|
24
24
|
<View style={{ marginTop: 24 }}>
|
|
25
25
|
<Text style={{ color: t.muted, marginBottom: 8, fontSize: 12 }}>{server}</Text>
|
|
26
|
+
__MT_MOBILE_SWITCH__
|
|
26
27
|
<Btn label="Sign out" onPress={() => { signOut(); router.replace('/login') }} />
|
|
27
28
|
</View>
|
|
28
29
|
)} />
|
|
@@ -28,3 +28,14 @@ export function devServer() {
|
|
|
28
28
|
// when they are made, so one of each is enough.
|
|
29
29
|
export const factory = createFactoryApi({ fetch: authFetch, fetchFile: authFetchFile, base: '/api' })
|
|
30
30
|
export const flows = createFlowsApi({ fetch: authFetch, base: '/api/workflow' })
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The app's own pages that are drawn from a form, by their menu key — on the
|
|
34
|
+
* phone as that form's list. Forms added in Configure UI need nothing here;
|
|
35
|
+
* a page added in code with its own menu key is listed like Tasks.
|
|
36
|
+
*/
|
|
37
|
+
export const PAGES = {
|
|
38
|
+
Tasks: { form: 'task' }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
__MT_MOBILE_TENANCY__
|
package/templates/ui/pages.json
CHANGED
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
{ "path": "/tasks/:id", "screen": "task_edit" },
|
|
7
7
|
{ "path": "/forms/:form", "screen": "every form's list" },
|
|
8
8
|
{ "path": "/journey/:flow", "screen": "a flow's screens" },
|
|
9
|
-
{ "path": "/journey/:flow/:run", "screen": "a flow's screens" }
|
|
9
|
+
{ "path": "/journey/:flow/:run", "screen": "a flow's screens" },
|
|
10
|
+
{ "path": "/flows", "menu": "Flows", "screen": "the journeys to start — NativeFlows on a phone" }__MT_PAGES_SELECT__
|
|
10
11
|
],
|
|
11
12
|
"webOnly": [
|
|
12
|
-
__MT_PAGES_SELECT__
|
|
13
13
|
{ "path": "/home", "menu": "Home", "reason": "The starter page that proves sign-in and the API work — replace it with your first page." },
|
|
14
|
-
{ "path": "/flows", "menu": "Flows", "reason": "The flows list and designer are tools for building, used on a computer." },
|
|
15
14
|
{ "path": "/configure/flows/:flow", "reason": "The flow designer is a tool for building, used on a computer." },
|
|
16
15
|
{ "path": "/configure", "menu": "Configure UI", "reason": "The form designer and menu settings are tools for building, used on a computer." },
|
|
17
16
|
{ "path": "/configure/forms/:form/design/:part", "reason": "The form designer is a tool for building, used on a computer." }
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// WHERE ARE YOU WORKING? — the company (and workspace) this app's data belongs
|
|
2
|
+
// to, for apps whose data is split by company: @xeplr/ui-account's own picker,
|
|
3
|
+
// the same picking as the website's. What the person may see depends on the
|
|
4
|
+
// company (its admin there, a viewer elsewhere), so the menu is read again.
|
|
5
|
+
import { Stack, router } from 'expo-router'
|
|
6
|
+
import { NativeScopePicker, refreshAccess } from '@xeplr/ui-account/native'
|
|
7
|
+
import { TENANCY } from '../lib/app.js'
|
|
8
|
+
|
|
9
|
+
export default function Select() {
|
|
10
|
+
return (
|
|
11
|
+
<>
|
|
12
|
+
<Stack.Screen options={{ title: 'Choose', headerBackVisible: router.canGoBack() }} />
|
|
13
|
+
<NativeScopePicker levels={TENANCY.levels} onChosen={() => { refreshAccess().finally(() => router.replace('/')) }} />
|
|
14
|
+
</>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
@@ -4,14 +4,13 @@
|
|
|
4
4
|
// authFetch sends it as a header on every request, the API stamps new rows
|
|
5
5
|
// with it and reads only its rows.
|
|
6
6
|
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
7
|
+
// The picking is @xeplr/ui-account's (useScopeChoice) — the same as the phone
|
|
8
|
+
// app's (NativeScopePicker): each level's list, the last choice already
|
|
9
|
+
// chosen, a list of one chosen for you, adding a new one. This page only
|
|
10
|
+
// draws it. Shown once per browser tab (ScopeGate below); "__MT_SWITCH_NAME__"
|
|
11
|
+
// in the side rail comes back here.
|
|
11
12
|
import { Navigate, useLocation, useNavigate } from 'react-router-dom'
|
|
12
|
-
import {
|
|
13
|
-
authFetch, getActiveScope, setActiveScope, getLastScope, setLastScope, saveReturnTo, consumeReturnTo
|
|
14
|
-
} from '@xeplr/ui-account'
|
|
13
|
+
import { useScopeChoice, scopeChosen, saveReturnTo, consumeReturnTo } from '@xeplr/ui-account'
|
|
15
14
|
import { tenancy } from '../tenancy.js'
|
|
16
15
|
import './SelectScope.css'
|
|
17
16
|
|
|
@@ -23,8 +22,7 @@ const setConfirmed = (yes) => { try { yes ? sessionStorage.setItem(CONFIRMED, '1
|
|
|
23
22
|
/** Lets the app's pages render only once every level is chosen in this tab. */
|
|
24
23
|
export function ScopeGate({ children }) {
|
|
25
24
|
const location = useLocation()
|
|
26
|
-
|
|
27
|
-
if (!complete || !confirmed()) {
|
|
25
|
+
if (!scopeChosen(tenancy.levels) || !confirmed()) {
|
|
28
26
|
saveReturnTo(location)
|
|
29
27
|
return <Navigate to="/select" replace />
|
|
30
28
|
}
|
|
@@ -33,32 +31,10 @@ export function ScopeGate({ children }) {
|
|
|
33
31
|
|
|
34
32
|
export default function SelectScope() {
|
|
35
33
|
const navigate = useNavigate()
|
|
36
|
-
|
|
37
|
-
// Made active straight away — before the lists below load, since a level's
|
|
38
|
-
// list is asked for with the level above it as a header.
|
|
39
|
-
const [chosen, setChosen] = useState(() => {
|
|
40
|
-
const start = Object.fromEntries(tenancy.levels.map((l) => [l.key, getActiveScope(l.key) || getLastScope(l.key) || null]))
|
|
41
|
-
tenancy.levels.forEach((l) => setActiveScope(l.key, start[l.key]))
|
|
42
|
-
return start
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
const choose = useCallback((index, item) => {
|
|
46
|
-
setChosen((c) => {
|
|
47
|
-
const next = { ...c, [tenancy.levels[index].key]: item }
|
|
48
|
-
// A different parent: whatever was chosen below it belonged to the old one.
|
|
49
|
-
tenancy.levels.slice(index + 1).forEach((l) => { next[l.key] = null })
|
|
50
|
-
return next
|
|
51
|
-
})
|
|
52
|
-
// Set as it is chosen, so the level below lists this one's children.
|
|
53
|
-
setActiveScope(tenancy.levels[index].key, item)
|
|
54
|
-
tenancy.levels.slice(index + 1).forEach((l) => setActiveScope(l.key, null))
|
|
55
|
-
setConfirmed(false)
|
|
56
|
-
}, [])
|
|
57
|
-
|
|
58
|
-
const complete = tenancy.levels.every((l) => chosen[l.key])
|
|
34
|
+
const choice = useScopeChoice({ levels: tenancy.levels })
|
|
59
35
|
|
|
60
36
|
const go = () => {
|
|
61
|
-
|
|
37
|
+
if (!choice.finish()) return
|
|
62
38
|
setConfirmed(true)
|
|
63
39
|
navigate(consumeReturnTo() || '/home', { replace: true })
|
|
64
40
|
}
|
|
@@ -68,87 +44,36 @@ export default function SelectScope() {
|
|
|
68
44
|
<h1>Where are you working?</h1>
|
|
69
45
|
<p className="app-page-lead">Everything you see and save next belongs to this choice.</p>
|
|
70
46
|
|
|
71
|
-
{
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
47
|
+
{choice.levels.map((level, i) => (
|
|
48
|
+
<section key={level.key} className={'app-select-level' + (level.enabled ? '' : ' is-disabled')}>
|
|
49
|
+
<h2>{level.label}</h2>
|
|
50
|
+
{!level.enabled && <p className="app-sub">Choose the one above first.</p>}
|
|
51
|
+
{level.enabled && level.items === null && !level.error && <p className="app-sub">Loading…</p>}
|
|
52
|
+
{level.error && <div className="app-error">{level.error}</div>}
|
|
53
|
+
{level.enabled && level.items && (
|
|
54
|
+
<>
|
|
55
|
+
{level.items.length === 0 && <p className="app-sub">No {level.noun} yet — add the first one.</p>}
|
|
56
|
+
<div className="app-select-items">
|
|
57
|
+
{level.items.map((item) => {
|
|
58
|
+
const on = !!level.value && level.value.id === item.id
|
|
59
|
+
return (
|
|
60
|
+
<button key={item.id} type="button" className={'app-select-item' + (on ? ' is-chosen' : '')} aria-pressed={on}
|
|
61
|
+
onClick={() => { setConfirmed(false); choice.choose(i, item) }}>
|
|
62
|
+
{item.name}
|
|
63
|
+
</button>
|
|
64
|
+
)
|
|
65
|
+
})}
|
|
66
|
+
</div>
|
|
67
|
+
<form className="app-select-add" onSubmit={(e) => { e.preventDefault(); setConfirmed(false); choice.add(i) }}>
|
|
68
|
+
<input value={level.adding} onChange={(e) => choice.setAdding(i, e.target.value)} placeholder={'New ' + level.noun + ' name'} aria-label={'New ' + level.noun + ' name'} />
|
|
69
|
+
<button type="submit" className="app-btn app-btn-quiet" disabled={level.busy || !level.adding.trim()}>Add {level.noun}</button>
|
|
70
|
+
</form>
|
|
71
|
+
</>
|
|
72
|
+
)}
|
|
73
|
+
</section>
|
|
74
|
+
))}
|
|
83
75
|
|
|
84
|
-
<button type="button" className="app-btn" disabled={!complete} onClick={go}>Continue</button>
|
|
76
|
+
<button type="button" className="app-btn" disabled={!choice.complete} onClick={go}>Continue</button>
|
|
85
77
|
</div>
|
|
86
78
|
)
|
|
87
79
|
}
|
|
88
|
-
|
|
89
|
-
function LevelChoice({ level, enabled, value, onChoose }) {
|
|
90
|
-
const [items, setItems] = useState(null)
|
|
91
|
-
const [error, setError] = useState(null)
|
|
92
|
-
const [adding, setAdding] = useState('')
|
|
93
|
-
const [busy, setBusy] = useState(false)
|
|
94
|
-
const noun = level.label.toLowerCase()
|
|
95
|
-
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
if (!enabled) return
|
|
98
|
-
authFetch('/api/tenants/' + level.key).then((body) => {
|
|
99
|
-
const rows = body.dataArray || []
|
|
100
|
-
setItems(rows)
|
|
101
|
-
// A remembered choice that is no longer on the list is not a choice.
|
|
102
|
-
if (value && !rows.some((r) => r.id === value.id)) onChoose(null)
|
|
103
|
-
else if (!value && rows.length === 1) onChoose(rows[0])
|
|
104
|
-
}, (e) => setError(e.message))
|
|
105
|
-
}, [enabled, level.key]) // eslint-disable-line react-hooks/exhaustive-deps
|
|
106
|
-
|
|
107
|
-
const add = async (e) => {
|
|
108
|
-
e.preventDefault()
|
|
109
|
-
setBusy(true)
|
|
110
|
-
try {
|
|
111
|
-
const body = await authFetch('/api/tenants/' + level.key, { method: 'POST', body: JSON.stringify({ name: adding }) })
|
|
112
|
-
const created = body.dataArray[0]
|
|
113
|
-
setItems((list) => [...(list || []), created].sort((a, b) => a.name.localeCompare(b.name)))
|
|
114
|
-
setAdding('')
|
|
115
|
-
setError(null)
|
|
116
|
-
onChoose(created)
|
|
117
|
-
} catch (err) {
|
|
118
|
-
setError(err.message)
|
|
119
|
-
} finally {
|
|
120
|
-
setBusy(false)
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<section className={'app-select-level' + (enabled ? '' : ' is-disabled')}>
|
|
126
|
-
<h2>{level.label}</h2>
|
|
127
|
-
{!enabled && <p className="app-sub">Choose the one above first.</p>}
|
|
128
|
-
{enabled && items === null && !error && <p className="app-sub">Loading…</p>}
|
|
129
|
-
{error && <div className="app-error">{error}</div>}
|
|
130
|
-
{enabled && items && (
|
|
131
|
-
<>
|
|
132
|
-
{items.length === 0 && <p className="app-sub">No {noun} yet — add the first one.</p>}
|
|
133
|
-
<div className="app-select-items">
|
|
134
|
-
{items.map((item) => (
|
|
135
|
-
<button
|
|
136
|
-
key={item.id}
|
|
137
|
-
type="button"
|
|
138
|
-
className={'app-select-item' + (value && value.id === item.id ? ' is-chosen' : '')}
|
|
139
|
-
aria-pressed={!!value && value.id === item.id}
|
|
140
|
-
onClick={() => onChoose(item)}
|
|
141
|
-
>
|
|
142
|
-
{item.name}
|
|
143
|
-
</button>
|
|
144
|
-
))}
|
|
145
|
-
</div>
|
|
146
|
-
<form className="app-select-add" onSubmit={add}>
|
|
147
|
-
<input value={adding} onChange={(e) => setAdding(e.target.value)} placeholder={'New ' + noun + ' name'} aria-label={'New ' + noun + ' name'} />
|
|
148
|
-
<button type="submit" className="app-btn app-btn-quiet" disabled={busy || !adding.trim()}>Add {noun}</button>
|
|
149
|
-
</form>
|
|
150
|
-
</>
|
|
151
|
-
)}
|
|
152
|
-
</section>
|
|
153
|
-
)
|
|
154
|
-
}
|