@xeplr/ui-jobs 1.3.0 → 1.4.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 +3 -2
- package/package.json +1 -1
- package/src/api/jobs.js +16 -0
- package/src/components/JobChainSection.jsx +1 -11
- package/src/components/ParametersField.jsx +28 -6
- package/src/lib/parametersModel.js +11 -12
- package/src/pages/Jobs.jsx +4 -29
package/README.md
CHANGED
|
@@ -107,6 +107,7 @@ Every call goes through `authFetch`, which prefixes the base URL `@xeplr/ui-acco
|
|
|
107
107
|
| pause / resume | `POST /jobs/:id/pause`, `POST /jobs/:id/resume` |
|
|
108
108
|
| a run's log lines | `GET /logs?referenceId=<occurrenceId>` — **not** under `apiBase` |
|
|
109
109
|
| an option list | `GET <source.url>?limit=0` — under `apiBase` |
|
|
110
|
+
| name suggestions | `GET <source.url>?limit=0&<param>=<value>…` for each of the field's `suggestWith` — under `apiBase` |
|
|
110
111
|
| a job's "After this job" rules | `GET` / `PUT <chainsApiBase>/job-chains/:jobId` with `{ rules, jobName }` — **not** under `apiBase` |
|
|
111
112
|
|
|
112
113
|
`/logs` is the platform's generic log route, not part of `@xeplr/jobs`. A host without it answers 404 and the panel shows an error in place of the log. Log lines are keyed by occurrence id because an action writes under the `referenceId` it is handed.
|
|
@@ -134,9 +135,9 @@ Three steps (four with `chainsApiBase`), all reachable at any time, with **Save
|
|
|
134
135
|
|
|
135
136
|
The period this job ran for passes to the next job by itself. Text that is not JSON, a missing job, or an "otherwise" that is not last is refused before anything is saved; the server checks the meaning and names the rule. An existing job's rules are saved before the job, and a new job's right after it (it needs its id).
|
|
136
137
|
|
|
137
|
-
An input the action marks `control: 'parameters'` (a procedure's parameters) is shown as rows, not JSON (`ParametersField`, `lib/parametersModel.js`): a parameter's name, and where its value comes from: **Start of the window**, **End of the window** (saved as `{window.from}` / `{window.to}`, which `@xeplr/jobs` fills in with the run's dates) or a **Fixed value**. The choices are the jobs package's run contract (`GET /jobs/run-contract`, `useRunContract`), grouped: **This run** (start / end of the window) and **The job before** (the range it was given and the range it actually used, start / end). A job with no parameters
|
|
138
|
+
An input the action marks `control: 'parameters'` (a procedure's parameters) is shown as rows, not JSON (`ParametersField`, `lib/parametersModel.js`): a parameter's name, and where its value comes from: **Start of the window**, **End of the window** (saved as `{window.from}` / `{window.to}`, which `@xeplr/jobs` fills in with the run's dates) or a **Fixed value**. The choices are the jobs package's run contract (`GET /jobs/run-contract`, `useRunContract`), grouped: **This run** (start / end of the window) and **The job before** (the range it was given and the range it actually used, start / end). A job with no parameters starts with none (**+ Add parameter**). When the action names a `suggestFrom` source (`db-procedure`: `procedureParams`, asked with the connection, database and procedure), clicking a name box offers the procedure's own parameter names, minus those already used. A row with neither name nor value is not saved. An input marked `hidden` (the procedure's old **Window**) is shown only when a job already holds one.
|
|
138
139
|
|
|
139
|
-
|
|
140
|
+
A job's saved `acceptsInputs` (what the job before may fill) is kept as it is but no longer edited here: a job takes what it needs from the job before through its parameters. The **After this job** rules offer a condition, the job to run and values to **carry** for later jobs.
|
|
140
141
|
|
|
141
142
|
A new job with a schedule defaults to **Paused**, so it can be written now and started later. A job with no schedule is saved as `ready` and runs only when triggered.
|
|
142
143
|
|
package/package.json
CHANGED
package/src/api/jobs.js
CHANGED
|
@@ -90,6 +90,22 @@ export function hasOptionSource(kind) {
|
|
|
90
90
|
* be narrowed — databases on the chosen connection, rather than every database
|
|
91
91
|
* on every connection.
|
|
92
92
|
*/
|
|
93
|
+
/**
|
|
94
|
+
* Fetch suggestions from an option source, asked with several values at once
|
|
95
|
+
* — `query` is { param: value }. Answers the list of values (strings), empty
|
|
96
|
+
* when the source is not configured or something it needs is not chosen yet.
|
|
97
|
+
*/
|
|
98
|
+
export async function fetchSuggestions(kind, query) {
|
|
99
|
+
const src = _optionSources[kind]
|
|
100
|
+
if (!src) return []
|
|
101
|
+
const pairs = Object.entries(query || {})
|
|
102
|
+
if (pairs.some(([, v]) => v === undefined || v === null || v === '')) return []
|
|
103
|
+
const q = pairs.map(([k, v]) => `&${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('')
|
|
104
|
+
const res = await authFetch(url(`${src.url}?limit=0${q}`))
|
|
105
|
+
const list = (res && res[src.key || 'dataArray']) || []
|
|
106
|
+
return list.map((o) => String(o[src.value || 'value'])).filter(Boolean)
|
|
107
|
+
}
|
|
108
|
+
|
|
93
109
|
export async function fetchOptions(kind, filter) {
|
|
94
110
|
const src = _optionSources[kind]
|
|
95
111
|
if (!src) return []
|
|
@@ -65,18 +65,8 @@ export default function JobChainSection({ chain, jobs, jobId }) {
|
|
|
65
65
|
</select>
|
|
66
66
|
</div>
|
|
67
67
|
|
|
68
|
-
<details className="jb-advanced" open={Boolean(row.
|
|
68
|
+
<details className="jb-advanced" open={Boolean(row.carry)}>
|
|
69
69
|
<summary>Pass values on <span className="jb-dim">— optional</span></summary>
|
|
70
|
-
<div className="jb-field">
|
|
71
|
-
<label htmlFor={`jb-chain-inputs-${i}`}>Inputs of the next job <span className="jb-type">· JSON</span></label>
|
|
72
|
-
<textarea id={`jb-chain-inputs-${i}`} className="jb-chain-json" rows={3}
|
|
73
|
-
placeholder={'{ "region": "{output.region}" }'} value={row.inputs}
|
|
74
|
-
onChange={(e) => chain.updateRow(i, { inputs: e.target.value })} />
|
|
75
|
-
<span className="jb-help">
|
|
76
|
-
Only inputs the next job accepts (its Inputs step lists them). Leave out
|
|
77
|
-
<code className="jb-code">window</code> to pass this job's period on unchanged.
|
|
78
|
-
</span>
|
|
79
|
-
</div>
|
|
80
70
|
<div className="jb-field">
|
|
81
71
|
<label htmlFor={`jb-chain-carry-${i}`}>Carry for later jobs <span className="jb-type">· JSON</span></label>
|
|
82
72
|
<textarea id={`jb-chain-carry-${i}`} className="jb-chain-json" rows={3}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
import {
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { fetchSuggestions } from '../api/jobs.js'
|
|
3
|
+
import { FIXED, groupedChoices, rowsFromText, rowsToText, sourceOf, unusedNames, valueForSource } from '../lib/parametersModel.js'
|
|
3
4
|
import './ParametersField.css'
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -14,11 +15,27 @@ import './ParametersField.css'
|
|
|
14
15
|
* @param {string} props.value saved JSON text
|
|
15
16
|
* @param {Function} props.onChange
|
|
16
17
|
* @param {object[]} props.contract what every run receives (useRunContract)
|
|
18
|
+
* @param {object} props.inputs the job's other inputs — what the name
|
|
19
|
+
* suggestions are asked with (field.suggestWith)
|
|
17
20
|
*/
|
|
18
|
-
export default function ParametersField({ field, value, onChange, contract }) {
|
|
21
|
+
export default function ParametersField({ field, value, onChange, contract, inputs }) {
|
|
19
22
|
const [rows, setRows] = useState(() => rowsFromText(value, contract))
|
|
20
23
|
const id = `jb-in-${field.name}`
|
|
21
24
|
|
|
25
|
+
// THE PROCEDURE'S OWN PARAMETER NAMES, offered when a name box is clicked —
|
|
26
|
+
// asked again whenever the connection, database or procedure changes.
|
|
27
|
+
const query = Object.fromEntries(Object.entries(field.suggestWith || {}).map(([k, from]) => [k, inputs?.[from]]))
|
|
28
|
+
const queryKey = JSON.stringify(query)
|
|
29
|
+
const [names, setNames] = useState([])
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!field.suggestFrom) return undefined
|
|
32
|
+
let live = true
|
|
33
|
+
fetchSuggestions(field.suggestFrom, JSON.parse(queryKey))
|
|
34
|
+
.then((n) => { if (live) setNames(n) })
|
|
35
|
+
.catch(() => { if (live) setNames([]) })
|
|
36
|
+
return () => { live = false }
|
|
37
|
+
}, [field.suggestFrom, queryKey])
|
|
38
|
+
|
|
22
39
|
// Saved text that is not a list (typed by hand before this control
|
|
23
40
|
// existed) is shown as it is rather than guessed at.
|
|
24
41
|
if (rows === null) {
|
|
@@ -53,8 +70,11 @@ export default function ParametersField({ field, value, onChange, contract }) {
|
|
|
53
70
|
return (
|
|
54
71
|
<div key={i} className="jb-param">
|
|
55
72
|
<input aria-label={`Parameter ${i + 1} name`} className="jb-param-name" value={r.name}
|
|
56
|
-
|
|
73
|
+
list={`${id}-names-${i}`} placeholder="name"
|
|
57
74
|
onChange={(e) => patchRow(i, { name: e.target.value })} />
|
|
75
|
+
<datalist id={`${id}-names-${i}`}>
|
|
76
|
+
{unusedNames(names, rows, i).map((n) => <option key={n} value={n} />)}
|
|
77
|
+
</datalist>
|
|
58
78
|
<span className="jb-param-arrow" aria-hidden="true">←</span>
|
|
59
79
|
<select aria-label={`Parameter ${i + 1} value`} value={source}
|
|
60
80
|
onChange={(e) => patchRow(i, { value: valueForSource(e.target.value, r.value, contract) })}>
|
|
@@ -77,8 +97,10 @@ export default function ParametersField({ field, value, onChange, contract }) {
|
|
|
77
97
|
</div>
|
|
78
98
|
<button type="button" className="jb-param-add" onClick={() => update([...rows, { name: '', value: '' }])}>+ Add parameter</button>
|
|
79
99
|
<span className="jb-help">
|
|
80
|
-
|
|
81
|
-
|
|
100
|
+
{names.length
|
|
101
|
+
? `Click a name box to pick one of the procedure's parameters (${names.join(', ')}), or type your own.`
|
|
102
|
+
: 'The name is the procedure\'s own parameter name.'}
|
|
103
|
+
{' '}On MySQL, parameters go by position, so keep them in the order the procedure declares them.
|
|
82
104
|
</span>
|
|
83
105
|
</div>
|
|
84
106
|
)
|
|
@@ -35,36 +35,35 @@ export function groupedChoices(contract) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* Saved text → rows. A job with no parameters yet
|
|
39
|
-
*
|
|
40
|
-
* period is what nearly every scheduled procedure takes. The job before's
|
|
41
|
-
* ranges are in every row's dropdown, but not rows of their own.
|
|
38
|
+
* Saved text → rows. A job with no parameters yet has none: the person adds
|
|
39
|
+
* them, picking each name from the procedure's own (see ParametersField).
|
|
42
40
|
*/
|
|
43
41
|
export function rowsFromText(text, contract) {
|
|
44
42
|
let list = []
|
|
45
43
|
try { list = text ? JSON.parse(text) : [] } catch (e) { list = null }
|
|
46
44
|
if (!Array.isArray(list)) return null
|
|
47
|
-
if (!list.length) {
|
|
48
|
-
return (contract || []).filter((c) => /^window\./.test(c.key))
|
|
49
|
-
.map((c) => ({ name: '', value: bindingFor(c.key), starter: true }))
|
|
50
|
-
}
|
|
51
45
|
return list.map((p) => (p && typeof p === 'object' && !Array.isArray(p)
|
|
52
46
|
? { name: p.name == null ? '' : String(p.name), value: p.value == null ? '' : p.value }
|
|
53
47
|
: { name: '', value: p == null ? '' : p, bare: true }))
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
/**
|
|
57
|
-
* Rows → the text the form saves. A
|
|
58
|
-
*
|
|
59
|
-
* as a bare (positional) value.
|
|
51
|
+
* Rows → the text the form saves. A row with no name is kept as a bare
|
|
52
|
+
* (positional) value; a row with neither name nor value is left out.
|
|
60
53
|
*/
|
|
61
54
|
export function rowsToText(rows) {
|
|
62
55
|
const list = (rows || [])
|
|
63
|
-
.filter((r) =>
|
|
56
|
+
.filter((r) => String(r.name || '').trim() || (r.value !== '' && r.value != null))
|
|
64
57
|
.map((r) => (String(r.name || '').trim() ? { name: String(r.name).trim(), value: r.value } : r.value))
|
|
65
58
|
return list.length ? JSON.stringify(list, null, 2) : ''
|
|
66
59
|
}
|
|
67
60
|
|
|
61
|
+
/** Suggested names not already used by another row. */
|
|
62
|
+
export function unusedNames(names, rows, index) {
|
|
63
|
+
const taken = new Set((rows || []).filter((_, i) => i !== index).map((r) => String(r.name || '').trim()).filter(Boolean))
|
|
64
|
+
return (names || []).filter((n) => !taken.has(n))
|
|
65
|
+
}
|
|
66
|
+
|
|
68
67
|
/** A row's value when its source changes: a binding, or empty fixed text. */
|
|
69
68
|
export function valueForSource(source, current, contract) {
|
|
70
69
|
if (source === FIXED) return sourceOf(current, contract) === FIXED ? current : ''
|
package/src/pages/Jobs.jsx
CHANGED
|
@@ -15,7 +15,7 @@ import JobChainSection from '../components/JobChainSection.jsx'
|
|
|
15
15
|
import ParametersField from '../components/ParametersField.jsx'
|
|
16
16
|
import { useRunContract } from '../useRunContract.js'
|
|
17
17
|
import { useJobChainController } from '../useJobChainController.js'
|
|
18
|
-
import { acceptableFields
|
|
18
|
+
import { acceptableFields } from '../lib/jobChainModel.js'
|
|
19
19
|
import './Jobs.css'
|
|
20
20
|
|
|
21
21
|
// SCHEDULED JOBS — @xeplr/jobs, in this product's chrome.
|
|
@@ -448,7 +448,7 @@ function ActionInput({ field, value, onChange, inputs, contract }) {
|
|
|
448
448
|
|
|
449
449
|
// Rows rather than JSON, for an input the action marks as parameters.
|
|
450
450
|
if (field.control === 'parameters') {
|
|
451
|
-
return <ParametersField field={field} value={value} onChange={onChange} contract={contract || []} />
|
|
451
|
+
return <ParametersField field={field} value={value} onChange={onChange} contract={contract || []} inputs={inputs} />
|
|
452
452
|
}
|
|
453
453
|
const common = { id, value, onChange: (e) => onChange(e.target.value) }
|
|
454
454
|
|
|
@@ -536,7 +536,8 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved }) {
|
|
|
536
536
|
Object.entries(job?.inputs || {}).map(([k, v]) => [k, toFieldValue(v)])
|
|
537
537
|
),
|
|
538
538
|
// Inputs the job BEFORE this one in a chain may fill (@xeplr/jobs'
|
|
539
|
-
// acceptsInputs).
|
|
539
|
+
// acceptsInputs). No longer edited here — a job takes what it needs from
|
|
540
|
+
// the job before through its parameters — but kept as saved.
|
|
540
541
|
acceptsInputs: Array.isArray(job?.acceptsInputs) ? job.acceptsInputs : []
|
|
541
542
|
}))
|
|
542
543
|
const [saving, setSaving] = useState(false)
|
|
@@ -697,35 +698,9 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved }) {
|
|
|
697
698
|
onChange={(v) => patch({ inputs: { ...draft.inputs, [f.name]: v } })}
|
|
698
699
|
/>
|
|
699
700
|
)
|
|
700
|
-
const acceptable = acceptableFields(fields)
|
|
701
701
|
return (
|
|
702
702
|
<>
|
|
703
703
|
<div className="jb-grid">{primary.map(render)}</div>
|
|
704
|
-
{chain.enabled && acceptable.length > 0 && (
|
|
705
|
-
/* WHAT THE JOB BEFORE THIS ONE MAY FILL. Off for every
|
|
706
|
-
field until ticked: a chain may otherwise only pass the
|
|
707
|
-
period (window), never this job's SQL or connection. */
|
|
708
|
-
<details className="jb-advanced" open={draft.acceptsInputs.length > 0}>
|
|
709
|
-
<summary>
|
|
710
|
-
From the job before
|
|
711
|
-
<span className="jb-dim">
|
|
712
|
-
{' — '}
|
|
713
|
-
{draft.acceptsInputs.length ? draft.acceptsInputs.map((n) => fieldLabel(acceptable.find((f) => f.name === n) || { name: n })).join(' · ') : 'only the period'}
|
|
714
|
-
</span>
|
|
715
|
-
</summary>
|
|
716
|
-
<p className="jb-help">
|
|
717
|
-
When another job runs this one, it always passes the period it ran for. Tick the inputs
|
|
718
|
-
it may also fill; everything else stays as saved here.
|
|
719
|
-
</p>
|
|
720
|
-
{acceptable.map((f) => (
|
|
721
|
-
<label key={f.name} className="jb-chain-toggle">
|
|
722
|
-
<input type="checkbox" checked={draft.acceptsInputs.includes(f.name)}
|
|
723
|
-
onChange={(e) => patch({ acceptsInputs: toggleAccepted(draft.acceptsInputs, f.name, e.target.checked) })} />
|
|
724
|
-
{fieldLabel(f)}
|
|
725
|
-
</label>
|
|
726
|
-
))}
|
|
727
|
-
</details>
|
|
728
|
-
)}
|
|
729
704
|
{advanced.length > 0 && (
|
|
730
705
|
/* COLLAPSED, NOT HIDDEN. The summary names every field in
|
|
731
706
|
here and its current value, so closing it never conceals
|