@xeplr/ui-jobs 1.0.1
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/LICENSE +21 -0
- package/README.md +126 -0
- package/package.json +56 -0
- package/src/api/jobs.js +187 -0
- package/src/components/CronScheduleField.css +10 -0
- package/src/components/CronScheduleField.jsx +46 -0
- package/src/index.jsx +104 -0
- package/src/pages/Jobs.css +413 -0
- package/src/pages/Jobs.jsx +1230 -0
- package/src/pages/jobsList.js +196 -0
- package/src/pages/relativeTime.js +26 -0
- package/src/routes.js +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Xeplr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# @xeplr/ui-jobs
|
|
2
|
+
|
|
3
|
+
**The screens for [`@xeplr/jobs`](https://www.npmjs.com/package/@xeplr/jobs).** Create a job, schedule it with cron, run it now, pause and resume it, and watch its occurrences and logs. It ships as React routes your app registers, or as a small standalone app.
|
|
4
|
+
|
|
5
|
+
(The package name on npm is `@xeplr/ui-jobs` — the GitHub repo and folder are named `xeplr-ui-jobs`.)
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
Jobs is a product: a scheduler, an HTTP API **and** the screens for both. Without this package, every app that wanted to schedule something rebuilt those screens itself, and each copy drifted from the backend it talked to.
|
|
10
|
+
|
|
11
|
+
So the UI belongs to the jobs product, and a host supplies only the **infrastructure** it already has: the router, the auth gate, the layout. That is the same split the backend makes — `registerJobs()` mounts into an Express app you already have, or stands up its own.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm i @xeplr/ui-jobs
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Peer dependencies: `react ^18 || ^19`, `react-router-dom ^6 || ^7`, `@xeplr/ui-account` (authenticated requests) and `@xeplr/ui-utils` (confirm dialogs and snackbars).
|
|
20
|
+
|
|
21
|
+
Your bundler must compile JSX and import CSS from the package (Vite does both out of the box).
|
|
22
|
+
|
|
23
|
+
The backend is [`@xeplr/jobs`](https://www.npmjs.com/package/@xeplr/jobs). By default the screens call its routes at your API root: `/jobs`, `/job-occurrences` and `/actions`.
|
|
24
|
+
|
|
25
|
+
## Embed it in your app
|
|
26
|
+
|
|
27
|
+
```jsx
|
|
28
|
+
import { BrowserRouter, Routes, Route } from 'react-router-dom'
|
|
29
|
+
import { AccessProvider } from '@xeplr/ui-account'
|
|
30
|
+
import { registerJobsUI } from '@xeplr/ui-jobs'
|
|
31
|
+
|
|
32
|
+
const jobs = registerJobsUI({ basePath: '/workspace' }) // → /workspace/jobs
|
|
33
|
+
|
|
34
|
+
export function App() {
|
|
35
|
+
return (
|
|
36
|
+
<BrowserRouter>
|
|
37
|
+
<AccessProvider>
|
|
38
|
+
<Routes>
|
|
39
|
+
{/* ...your routes... */}
|
|
40
|
+
{jobs.routes}
|
|
41
|
+
</Routes>
|
|
42
|
+
</AccessProvider>
|
|
43
|
+
</BrowserRouter>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Point your own navigation at the same path instead of retyping it:
|
|
48
|
+
// <Link to={jobs.path}>Jobs</Link>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
There is no embedded/standalone switch. `registerJobsUI()` returns `<Route>` elements; what differs is who wraps them.
|
|
52
|
+
|
|
53
|
+
## `registerJobsUI(config)`
|
|
54
|
+
|
|
55
|
+
| option | type | default | notes |
|
|
56
|
+
|---|---|---|---|
|
|
57
|
+
| `basePath` | string | `''` | prefix for the jobs page path, e.g. `'/workspace'` → `/workspace/jobs` |
|
|
58
|
+
| `apiBase` | string | `''` | prefix for API calls, if you mounted the jobs router somewhere other than the root |
|
|
59
|
+
| `optionSources` | object | — | where a *kind* of thing is listed, for action inputs that declare `optionsFrom` (see below) |
|
|
60
|
+
| `breadcrumb` | component | — | your breadcrumb, rendered above the page |
|
|
61
|
+
| `uploadLink` | element \| string | — | a link to wherever your app loads files, shown in the empty state |
|
|
62
|
+
| `connectLink` | element | — | a link to a workflow canvas, for starting one job when another finishes |
|
|
63
|
+
|
|
64
|
+
Returns `{ routes, path }`.
|
|
65
|
+
|
|
66
|
+
### Option sources
|
|
67
|
+
|
|
68
|
+
An action input can say it wants a choice from a kind of thing — `optionsFrom: 'connections'`. This package never learns what a connection is; your app says once where each kind is listed:
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
registerJobsUI({
|
|
72
|
+
optionSources: {
|
|
73
|
+
connections: { url: '/connectioninfo', label: 'label' },
|
|
74
|
+
databases: { url: '/databases', label: 'name' }
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
A kind with no source gets a plain text input. Standalone, with no catalogue to pick from, a text box is the right answer; an empty dropdown would look broken.
|
|
80
|
+
|
|
81
|
+
## Other exports
|
|
82
|
+
|
|
83
|
+
| export | what |
|
|
84
|
+
|---|---|
|
|
85
|
+
| `CronScheduleField` | the cron input with presets and a plain-English reading — `<CronScheduleField value={cron} onChange={setCron} />` |
|
|
86
|
+
| `CRON_PRESETS` | the presets it offers |
|
|
87
|
+
| `describeCron(expr)` | a cron expression as a sentence — `'*/15 * * * *'` → "Every 15 minutes", `'0 0 1 * *'` → "Monthly on day 1 at 00:00"; `null` for a pattern it has no sentence for |
|
|
88
|
+
| `jobsRoutes` | `{ jobs(base) }` — the page path, for building links |
|
|
89
|
+
|
|
90
|
+
## Run it standalone
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
npm install
|
|
94
|
+
npm run dev # http://localhost:19004 — set API_URL, AUTH_URL, UI_PORT in .env to change
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
`dev/` holds the standalone shell: login screens from `@xeplr/ui-account`, an auth gate, and one call to `registerJobsUI({})`, the same call a host makes. `vite.config.js` proxies the API paths to `API_URL` (default `http://localhost:19003`). None of `dev/` is published.
|
|
98
|
+
|
|
99
|
+
## Theming
|
|
100
|
+
|
|
101
|
+
Styles use the xeplr theme variables — `--accent`, `--surface`, `--ink`, `--muted`, `--hair`, `--plane` and the `--xeplr-*` status, tag and input colours. Each has a light-theme fallback, so the screens look right in an app that defines none of them. Define them to restyle.
|
|
102
|
+
|
|
103
|
+
## Files
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
src/
|
|
107
|
+
index.jsx ─ registerJobsUI and the public exports
|
|
108
|
+
routes.js ─ page paths
|
|
109
|
+
api/jobs.js ─ API calls, option sources
|
|
110
|
+
pages/Jobs.jsx · Jobs.css ─ the jobs screen
|
|
111
|
+
pages/jobsList.js ─ pure: job state, cron descriptions, next run, durations
|
|
112
|
+
pages/relativeTime.js ─ pure: "3 minutes ago"
|
|
113
|
+
components/CronScheduleField.jsx · .css
|
|
114
|
+
dev/ ─ standalone app shell (not published)
|
|
115
|
+
test/ ─ plain Node scripts, no framework
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Tests
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
npm test
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xeplr/ui-jobs",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "The screens for @xeplr/jobs — schedule, run, pause and watch jobs — as routes a host app registers, or a standalone app",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.jsx",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.jsx",
|
|
9
|
+
"./package.json": "./package.json"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"src/"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"dev": "vite",
|
|
16
|
+
"build": "vite build",
|
|
17
|
+
"preview": "vite preview",
|
|
18
|
+
"test": "node test/run.mjs"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"jobs",
|
|
22
|
+
"scheduler",
|
|
23
|
+
"cron",
|
|
24
|
+
"react",
|
|
25
|
+
"routes",
|
|
26
|
+
"xeplr"
|
|
27
|
+
],
|
|
28
|
+
"author": "xeplr",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/Xeplr/xeplr-ui-jobs"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/Xeplr/xeplr-ui-jobs#readme",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/Xeplr/xeplr-ui-jobs/issues"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@xeplr/ui-account": "^1.0.0",
|
|
43
|
+
"@xeplr/ui-utils": "^1.0.0",
|
|
44
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
45
|
+
"react-router-dom": "^6.0.0 || ^7.0.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@vitejs/plugin-react": "^5.2.0",
|
|
49
|
+
"@xeplr/ui-account": "^1.0.2",
|
|
50
|
+
"@xeplr/ui-utils": "^1.0.2",
|
|
51
|
+
"react": "^19.2.4",
|
|
52
|
+
"react-dom": "^19.2.4",
|
|
53
|
+
"react-router-dom": "^7.13.2",
|
|
54
|
+
"vite": "^7.3.1"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/api/jobs.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { authFetch } from '@xeplr/ui-account'
|
|
2
|
+
|
|
3
|
+
// WHERE THE JOBS API LIVES, set once by the host at registration.
|
|
4
|
+
//
|
|
5
|
+
// The router mounts at the API ROOT ('/jobs', '/job-occurrences', '/actions' —
|
|
6
|
+
// see lib/jobRouter.js), so this is empty for every host that mounts it the
|
|
7
|
+
// normal way. It exists for the one that does not: a host free to mount the
|
|
8
|
+
// router under a prefix must be able to say so, and the alternative is this
|
|
9
|
+
// package hardcoding a path it does not control.
|
|
10
|
+
//
|
|
11
|
+
// Module-level rather than passed per call: it is a property of the
|
|
12
|
+
// deployment, fixed before the first request, and threading it through every
|
|
13
|
+
// function would put a parameter on each one that is the same value forever.
|
|
14
|
+
let API_BASE = ''
|
|
15
|
+
|
|
16
|
+
export function configureJobsApi(config) {
|
|
17
|
+
API_BASE = (config && config.base) || ''
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const url = (p) => API_BASE + p
|
|
21
|
+
|
|
22
|
+
// SCHEDULED JOBS — @xeplr/jobs, mounted at the API root (see the bottom of
|
|
23
|
+
// backend/routes/index.js).
|
|
24
|
+
//
|
|
25
|
+
// The trust boundary is the same one the rest of the product keeps: the client
|
|
26
|
+
// sends a job ID and the values a job was configured with. It never sends the
|
|
27
|
+
// action's implementation, a connection, or a credential — `actionName` is a
|
|
28
|
+
// reference into the server's registry, and what that name means is the
|
|
29
|
+
// server's business. A client that could post an executable step could run
|
|
30
|
+
// anything the registry offers, whatever the UI appears to allow.
|
|
31
|
+
|
|
32
|
+
/** Every job, newest change first. */
|
|
33
|
+
export async function listJobs() {
|
|
34
|
+
const res = await authFetch(url('/jobs?limit=0'))
|
|
35
|
+
return res.dataArray || []
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* WHAT IS RUNNING RIGHT NOW — the small request a live screen repeats.
|
|
40
|
+
*
|
|
41
|
+
* Deliberately not listOccurrences() on a timer, which is what this page used
|
|
42
|
+
* to do: that fetches EVERY occurrence ever recorded (`limit=0`) alongside the
|
|
43
|
+
* job list and the action catalogue, three requests and an unbounded one among
|
|
44
|
+
* them, every four seconds. This returns only occurrences still in flight —
|
|
45
|
+
* bounded by the executor's concurrency cap, off an index that already exists
|
|
46
|
+
* for the reaper — and carries each one's live progress.
|
|
47
|
+
*
|
|
48
|
+
* An empty array is the normal answer and the signal to slow down. See the
|
|
49
|
+
* polling rule in Jobs.jsx.
|
|
50
|
+
*/
|
|
51
|
+
export async function listActiveRuns() {
|
|
52
|
+
const res = await authFetch(url('/jobs/active'))
|
|
53
|
+
return res.dataArray || []
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The runs of a job — or of everything, if no id is given. */
|
|
57
|
+
export async function listOccurrences(jobId) {
|
|
58
|
+
const res = await authFetch(url('/job-occurrences?limit=0'))
|
|
59
|
+
const all = res.dataArray || []
|
|
60
|
+
return jobId ? all.filter((o) => o.jobId === jobId) : all
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ── remote option lists ───────────────────────────────────────────────────
|
|
64
|
+
//
|
|
65
|
+
// An input field may name a KIND of thing to choose from — `optionsFrom:
|
|
66
|
+
// 'connections'` — and the host says once where that kind lives. This package
|
|
67
|
+
// never learns what a connection is, nor which URL BI serves them on; it knows
|
|
68
|
+
// only "fetch this list, show labels, store ids".
|
|
69
|
+
//
|
|
70
|
+
// One generic capability instead of a branch per concept. The next picker
|
|
71
|
+
// (a workspace, a folder) is an entry in the host's map, not a change here.
|
|
72
|
+
//
|
|
73
|
+
// Nothing configured for a kind → the field falls back to a plain text input.
|
|
74
|
+
// That is what keeps standalone jobs honest: an empty dropdown looks broken,
|
|
75
|
+
// while a text box is simply what you have when there is no catalogue.
|
|
76
|
+
let _optionSources = {}
|
|
77
|
+
|
|
78
|
+
export function configureOptionSources(sources) {
|
|
79
|
+
_optionSources = sources || {}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function hasOptionSource(kind) {
|
|
83
|
+
return Boolean(_optionSources[kind])
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Fetch one option list.
|
|
88
|
+
*
|
|
89
|
+
* `dependsOn` is passed through as a query parameter so a dependent list can
|
|
90
|
+
* be narrowed — databases on the chosen connection, rather than every database
|
|
91
|
+
* on every connection.
|
|
92
|
+
*/
|
|
93
|
+
export async function fetchOptions(kind, filter) {
|
|
94
|
+
const src = _optionSources[kind]
|
|
95
|
+
if (!src) return []
|
|
96
|
+
const q = filter && filter.value ? `&${encodeURIComponent(filter.name)}=${encodeURIComponent(filter.value)}` : ''
|
|
97
|
+
const res = await authFetch(url(`${src.url}?limit=0${q}`))
|
|
98
|
+
// `dataArray` is what genericRoute returns, so it is the default — but a
|
|
99
|
+
// hand-written endpoint answers with whatever it likes (BI's
|
|
100
|
+
// /warehouse/tables says `tables`). The host names the key rather than this
|
|
101
|
+
// package guessing, because guessing wrong yields an empty dropdown and no
|
|
102
|
+
// error, which reads as "you have none of these".
|
|
103
|
+
const rows = res[src.key || 'dataArray'] || []
|
|
104
|
+
return rows
|
|
105
|
+
.filter((r) => (filter && filter.clientKey ? r[filter.clientKey] === filter.value : true))
|
|
106
|
+
.map((r) => ({ value: r[src.value || 'id'], label: r[src.label] || r[src.value || 'id'] }))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* ONE job's run history, newest first, bounded.
|
|
111
|
+
*
|
|
112
|
+
* Deliberately not listOccurrences(jobId) above, which fetches every
|
|
113
|
+
* occurrence of every job and filters in the browser. That is tolerable for
|
|
114
|
+
* the one-row-per-job summary the table needs; it is not how you open a run
|
|
115
|
+
* history, because the answer grows forever while the question does not.
|
|
116
|
+
*/
|
|
117
|
+
export async function listJobOccurrences(jobId, limit = 50) {
|
|
118
|
+
const res = await authFetch(url(`/jobs/${encodeURIComponent(jobId)}/occurrences?limit=${limit}`))
|
|
119
|
+
return res.dataArray || []
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The actions a job may name.
|
|
124
|
+
*
|
|
125
|
+
* Served from the server's own registry, which is also what the runner
|
|
126
|
+
* validates against — so the dropdown cannot offer something that will not
|
|
127
|
+
* run, and cannot miss something that would. See backend/db/jobsSetup.js for
|
|
128
|
+
* which built-ins this product actually offers, and why it is a whitelist.
|
|
129
|
+
*/
|
|
130
|
+
export async function listJobActions() {
|
|
131
|
+
const res = await authFetch(url('/actions'))
|
|
132
|
+
return res.dataArray || []
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Create or update. The generic route's rules: no id → insert, id → patch,
|
|
137
|
+
* id + deleted → soft delete.
|
|
138
|
+
*/
|
|
139
|
+
export async function saveJob(job) {
|
|
140
|
+
return authFetch(url('/jobs/save'), {
|
|
141
|
+
method: 'POST',
|
|
142
|
+
body: JSON.stringify([job])
|
|
143
|
+
})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function deleteJob(id) {
|
|
147
|
+
return authFetch(url('/jobs/delete'), {
|
|
148
|
+
method: 'POST',
|
|
149
|
+
body: JSON.stringify({ ids: [id] })
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Run it now — one manual occurrence, regardless of the schedule. */
|
|
154
|
+
export async function triggerJob(id) {
|
|
155
|
+
return authFetch(url(`/jobs/${id}/trigger`), { method: 'POST' })
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Pausing sets status to 'pause', which is what the scheduler's picker skips.
|
|
159
|
+
// It does NOT stop a run already going: the job is picked or it isn't, and one
|
|
160
|
+
// that has started is somewhere in an action this has no handle on.
|
|
161
|
+
export async function pauseJob(id) {
|
|
162
|
+
return authFetch(url(`/jobs/${id}/pause`), { method: 'POST' })
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function resumeJob(id) {
|
|
166
|
+
return authFetch(url(`/jobs/${id}/resume`), { method: 'POST' })
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* ONE occurrence's log lines, by the LOGGING KEY.
|
|
171
|
+
*
|
|
172
|
+
* The key is the occurrenceId itself: an action that logs is expected to write
|
|
173
|
+
* under the referenceId it was handed in `system` (see lib/execute.js's
|
|
174
|
+
* buildActionCall), so the lines are already stored under an id this side
|
|
175
|
+
* knows. Nothing here has to learn what the action actually did — a movement,
|
|
176
|
+
* a build, anything — which is the whole point of keying logs by the work
|
|
177
|
+
* rather than by the table that produced them.
|
|
178
|
+
*
|
|
179
|
+
* NOT under API_BASE: /logs is the platform's own generic log route, not part
|
|
180
|
+
* of the jobs router. A host that has no such route answers 404 and the panel
|
|
181
|
+
* says there are no lines — which is the truth for an action that never wrote
|
|
182
|
+
* any, and the same thing this package would show either way.
|
|
183
|
+
*/
|
|
184
|
+
export async function fetchOccurrenceLogs(occurrenceId) {
|
|
185
|
+
const res = await authFetch(`/logs?referenceId=${encodeURIComponent(occurrenceId)}`)
|
|
186
|
+
return res.dataArray || []
|
|
187
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
.csf-field { display: grid; gap: 6px; margin-bottom: 14px; }
|
|
2
|
+
.csf-field label { font-size: 13px; color: var(--muted, #6b6a63); }
|
|
3
|
+
.csf-field select, .csf-field input {
|
|
4
|
+
width: 100%; padding: 9px 11px; font: inherit; font-size: 14px;
|
|
5
|
+
color: var(--xeplr-input-text, #1a1a19); background: var(--xeplr-input-bg, #ffffff);
|
|
6
|
+
border: 1px solid var(--xeplr-input-border, #e2e1d9); border-radius: 8px;
|
|
7
|
+
}
|
|
8
|
+
.csf-field select:focus, .csf-field input:focus { outline: none; border-color: var(--accent, #2563eb); }
|
|
9
|
+
.csf-cron { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
|
|
10
|
+
.csf-help { font-size: 12px; color: var(--muted, #6b6a63); }
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describeCron } from '../pages/jobsList.js'
|
|
2
|
+
import './CronScheduleField.css'
|
|
3
|
+
|
|
4
|
+
// One cron schedule, picked from a few presets or typed by hand. Extracted
|
|
5
|
+
// from Jobs.jsx's own JobEditor (where it was inline, tightly coupled to
|
|
6
|
+
// that form's draft/patch closure) so Move Data's own wizard can offer the
|
|
7
|
+
// exact same picker for "run this on a schedule" — same idea as
|
|
8
|
+
// RunLogPanel's own generalization earlier: two screens wanting identical
|
|
9
|
+
// behavior shouldn't carry two slightly-drifting implementations of it.
|
|
10
|
+
//
|
|
11
|
+
// Deliberately just `{ value, onChange }` — no fetching, no page-specific
|
|
12
|
+
// copy. A caller that needs to explain WHY a schedule is required (or
|
|
13
|
+
// optional, or not applicable) wraps this with its own text; this component
|
|
14
|
+
// only ever describes the schedule itself.
|
|
15
|
+
export const CRON_PRESETS = [
|
|
16
|
+
{ value: '', label: 'Manual only — no schedule' },
|
|
17
|
+
{ value: '*/15 * * * *', label: 'Every 15 minutes' },
|
|
18
|
+
{ value: '0 * * * *', label: 'Hourly, on the hour' },
|
|
19
|
+
{ value: '0 2 * * *', label: 'Daily at 02:00' },
|
|
20
|
+
{ value: '0 6 * * 1', label: 'Weekly, Monday at 06:00' },
|
|
21
|
+
{ value: '0 3 1 * *', label: 'Monthly, the 1st at 03:00' }
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
export default function CronScheduleField({ value, onChange, id = 'csf-sched' }) {
|
|
25
|
+
return (
|
|
26
|
+
<div className="csf-field">
|
|
27
|
+
<label htmlFor={id}>Schedule</label>
|
|
28
|
+
<select id={id}
|
|
29
|
+
value={CRON_PRESETS.some((p) => p.value === value) ? value : 'custom'}
|
|
30
|
+
onChange={(e) => { if (e.target.value !== 'custom') onChange(e.target.value) }}>
|
|
31
|
+
{CRON_PRESETS.map((p) => <option key={p.value || 'none'} value={p.value}>{p.label}</option>)}
|
|
32
|
+
<option value="custom">Custom cron…</option>
|
|
33
|
+
</select>
|
|
34
|
+
<input className="csf-cron" value={value || ''} placeholder="* * * * *"
|
|
35
|
+
onChange={(e) => onChange(e.target.value)} />
|
|
36
|
+
<span className="csf-help">
|
|
37
|
+
{value
|
|
38
|
+
// A wrong plain-English reading of a cron is worse than the cron
|
|
39
|
+
// itself, because you cannot tell it is wrong — so it is only
|
|
40
|
+
// offered for expressions this actually understands.
|
|
41
|
+
? (describeCron(value) || 'Five cron fields: minute, hour, day of month, month, day of week.')
|
|
42
|
+
: 'No schedule set.'}
|
|
43
|
+
</span>
|
|
44
|
+
</div>
|
|
45
|
+
)
|
|
46
|
+
}
|
package/src/index.jsx
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Route } from 'react-router-dom';
|
|
2
|
+
import JobsPage from './pages/Jobs.jsx';
|
|
3
|
+
import { configureJobsApi, configureOptionSources } from './api/jobs.js';
|
|
4
|
+
import { ROUTES } from './routes.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Register @xeplr/jobs' pages into a host app.
|
|
8
|
+
*
|
|
9
|
+
* THE UI BELONGS TO THIS PACKAGE, not to whoever embeds it. Jobs is a product
|
|
10
|
+
* — a scheduler, an HTTP surface AND the screens for both — and a host that
|
|
11
|
+
* wanted to schedule something used to have to rebuild those screens itself.
|
|
12
|
+
* That is how xeplr-bi ended up with its own copy: a second implementation of
|
|
13
|
+
* one product's UI, free to drift from the backend it talks to and from the
|
|
14
|
+
* next host's copy of the same thing.
|
|
15
|
+
*
|
|
16
|
+
* What a host supplies is only the INFRASTRUCTURE it already has — the
|
|
17
|
+
* router, the auth gate, the layout — never the product. Exactly the split the
|
|
18
|
+
* backend already makes: registerJobs() takes an Express app when there is one
|
|
19
|
+
* and stands up its own when there is not.
|
|
20
|
+
*
|
|
21
|
+
* There is no embedded/standalone branch HERE, and there cannot be: React has
|
|
22
|
+
* no imperative "mount onto an app" call, a subtree IS the mount. So this
|
|
23
|
+
* returns <Route> elements and the difference is who wraps them:
|
|
24
|
+
*
|
|
25
|
+
* - EMBEDDED: the host renders them inside its own <BrowserRouter>,
|
|
26
|
+
* <AccessProvider> and shell.
|
|
27
|
+
* - STANDALONE: this package's own dev/main.jsx does that, which is this
|
|
28
|
+
* package consuming its own public API rather than a special case of it.
|
|
29
|
+
*
|
|
30
|
+
* Usage from a host:
|
|
31
|
+
*
|
|
32
|
+
* import { registerJobsUI } from '@xeplr/ui-jobs'
|
|
33
|
+
*
|
|
34
|
+
* <Routes>
|
|
35
|
+
* ...your routes...
|
|
36
|
+
* {registerJobsUI({ basePath: '/workspace' }).routes}
|
|
37
|
+
* </Routes>
|
|
38
|
+
*
|
|
39
|
+
* @param {object} [config]
|
|
40
|
+
* @param {string} [config.basePath=''] - what the host prefixes jobs' paths
|
|
41
|
+
* with. xeplr-bi passes '/workspace' because a job belongs to a workspace
|
|
42
|
+
* there; standalone passes nothing.
|
|
43
|
+
* @param {string} [config.apiBase=''] - prefix for the API calls. The jobs
|
|
44
|
+
* router mounts at the API ROOT ('/jobs', '/job-occurrences', '/actions'),
|
|
45
|
+
* so this is empty unless a host mounts it somewhere else.
|
|
46
|
+
* @param {object} [config.optionSources] - where a KIND of thing is listed,
|
|
47
|
+
* for input fields that declare `optionsFrom`. Shaped
|
|
48
|
+
* { connections: { url: '/connectioninfo', label: 'label' }, ... }.
|
|
49
|
+
*
|
|
50
|
+
* This package never learns what a connection is, nor which URL serves one
|
|
51
|
+
* — it knows only "fetch this list, show labels, store ids". A host that
|
|
52
|
+
* supplies none gets plain text inputs for those fields, which is the
|
|
53
|
+
* correct answer standalone: an empty dropdown looks broken, a text box is
|
|
54
|
+
* simply what you have when there is no catalogue to pick from.
|
|
55
|
+
* @param {Function} [config.breadcrumb] - the host's own breadcrumb component,
|
|
56
|
+
* rendered above the page. Omitted standalone, where there is nothing to
|
|
57
|
+
* navigate back up to.
|
|
58
|
+
* @param {JSX.Element|string} [config.uploadLink] - a link to wherever the host
|
|
59
|
+
* loads files, named in the empty state.
|
|
60
|
+
* @param {JSX.Element} [config.connectLink] - a link to the workflow canvas,
|
|
61
|
+
* for connecting jobs so one starts when another finishes. Supplied by the
|
|
62
|
+
* host because this package must not import @xeplr/workflow — workflow
|
|
63
|
+
* already calls jobs over HTTP at run time, and importing its UI here would
|
|
64
|
+
* close that into a circular dependency between two packages that are
|
|
65
|
+
* deliberately installable on their own.
|
|
66
|
+
* @returns {{ routes: JSX.Element[], path: string }}
|
|
67
|
+
*/
|
|
68
|
+
export function registerJobsUI(config) {
|
|
69
|
+
config = config || {};
|
|
70
|
+
if (config.apiBase !== undefined) configureJobsApi({ base: config.apiBase });
|
|
71
|
+
configureOptionSources(config.optionSources);
|
|
72
|
+
|
|
73
|
+
var path = ROUTES.jobs(config.basePath);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
routes: [
|
|
77
|
+
// EVERY PAGE-LEVEL PROP FORWARDED, not a hand-picked subset.
|
|
78
|
+
//
|
|
79
|
+
// This passed `breadcrumb` alone, so `uploadLink` — which xeplr-bi has
|
|
80
|
+
// been supplying all along — was accepted by this function, dropped
|
|
81
|
+
// here, and silently never rendered. Nothing reported it: the page's
|
|
82
|
+
// empty state falls back to the words "the upload screen" when no link
|
|
83
|
+
// is given, so the failure looked exactly like a host that had not
|
|
84
|
+
// configured one.
|
|
85
|
+
//
|
|
86
|
+
// Naming each prop is what caused that, and would cause it again for the
|
|
87
|
+
// next one added to the page. The page's own signature is the list of
|
|
88
|
+
// what it accepts; anything not destructured there is ignored, which is
|
|
89
|
+
// the same outcome as filtering, without the gap.
|
|
90
|
+
<Route key="jobs-list" path={path} element={<JobsPage {...config} />} />
|
|
91
|
+
],
|
|
92
|
+
// Handed back so a host can point its own nav at the same string instead
|
|
93
|
+
// of writing '/workspace/jobs' a second time and having the two drift.
|
|
94
|
+
path: path
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { ROUTES as jobsRoutes } from './routes.js';
|
|
99
|
+
|
|
100
|
+
// The cron field, and the sentence it reads a schedule back as. Public because
|
|
101
|
+
// a host schedules other things too — xeplr-bi's movements use the same field —
|
|
102
|
+
// and a copy of it in the host is a second implementation free to drift.
|
|
103
|
+
export { default as CronScheduleField, CRON_PRESETS } from './components/CronScheduleField.jsx';
|
|
104
|
+
export { describeCron } from './pages/jobsList.js';
|