@xeplr/ui-jobs 1.2.0 → 1.3.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
CHANGED
|
@@ -134,7 +134,7 @@ Three steps (four with `chainsApiBase`), all reachable at any time, with **Save
|
|
|
134
134
|
|
|
135
135
|
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
136
|
|
|
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`). A job with no parameters yet starts with the two window rows, and one whose name is left empty is not saved. An input marked `hidden` (the procedure's old **Window**) is shown only when a job already holds one.
|
|
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 yet starts with the two window rows, and one whose name is left empty is not saved. An input marked `hidden` (the procedure's old **Window**) is shown only when a job already holds one.
|
|
138
138
|
|
|
139
139
|
With `chainsApiBase`, **Inputs** also has **From the job before**: tickboxes for the inputs another job may fill when it runs this one (the job's `acceptsInputs`). No field is ticked by default, and a field naming a connection is never offered.
|
|
140
140
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from 'react'
|
|
2
|
-
import { FIXED, rowsFromText, rowsToText, sourceOf, valueForSource } from '../lib/parametersModel.js'
|
|
2
|
+
import { FIXED, groupedChoices, rowsFromText, rowsToText, sourceOf, valueForSource } from '../lib/parametersModel.js'
|
|
3
3
|
import './ParametersField.css'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -42,8 +42,9 @@ export default function ParametersField({ field, value, onChange, contract }) {
|
|
|
42
42
|
<label>{field.label || field.name}</label>
|
|
43
43
|
{contract.length > 0 && (
|
|
44
44
|
<span className="jb-help">
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
Pick each value from what every run receives: this run's window (from its schedule or the job
|
|
46
|
+
before it), and, when another job started it, the range that job was given and the range it
|
|
47
|
+
actually used. Anything else is a fixed value.
|
|
47
48
|
</span>
|
|
48
49
|
)}
|
|
49
50
|
<div className="jb-params">
|
|
@@ -57,7 +58,11 @@ export default function ParametersField({ field, value, onChange, contract }) {
|
|
|
57
58
|
<span className="jb-param-arrow" aria-hidden="true">←</span>
|
|
58
59
|
<select aria-label={`Parameter ${i + 1} value`} value={source}
|
|
59
60
|
onChange={(e) => patchRow(i, { value: valueForSource(e.target.value, r.value, contract) })}>
|
|
60
|
-
{contract.map((
|
|
61
|
+
{groupedChoices(contract).map((g) => (
|
|
62
|
+
<optgroup key={g.group} label={g.group}>
|
|
63
|
+
{g.options.map((c) => <option key={c.key} value={c.key} title={c.description}>{c.label}</option>)}
|
|
64
|
+
</optgroup>
|
|
65
|
+
))}
|
|
61
66
|
<option value={FIXED}>Fixed value</option>
|
|
62
67
|
</select>
|
|
63
68
|
{source === FIXED ? (
|
|
@@ -20,16 +20,33 @@ export function sourceOf(value, contract) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
|
|
23
|
+
* The contract grouped for a dropdown, in its own order:
|
|
24
|
+
* [{ group, options: [{ key, label }] }].
|
|
25
|
+
*/
|
|
26
|
+
export function groupedChoices(contract) {
|
|
27
|
+
const groups = []
|
|
28
|
+
;(contract || []).forEach((c) => {
|
|
29
|
+
const name = c.group || ''
|
|
30
|
+
let g = groups.find((x) => x.group === name)
|
|
31
|
+
if (!g) { g = { group: name, options: [] }; groups.push(g) }
|
|
32
|
+
g.options.push(c)
|
|
33
|
+
})
|
|
34
|
+
return groups
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Saved text → rows. A job with no parameters yet starts with one row for
|
|
39
|
+
* this run's window start and one for its end, named by the person — the
|
|
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.
|
|
26
42
|
*/
|
|
27
43
|
export function rowsFromText(text, contract) {
|
|
28
44
|
let list = []
|
|
29
45
|
try { list = text ? JSON.parse(text) : [] } catch (e) { list = null }
|
|
30
46
|
if (!Array.isArray(list)) return null
|
|
31
47
|
if (!list.length) {
|
|
32
|
-
return (contract || []).
|
|
48
|
+
return (contract || []).filter((c) => /^window\./.test(c.key))
|
|
49
|
+
.map((c) => ({ name: '', value: bindingFor(c.key), starter: true }))
|
|
33
50
|
}
|
|
34
51
|
return list.map((p) => (p && typeof p === 'object' && !Array.isArray(p)
|
|
35
52
|
? { name: p.name == null ? '' : String(p.name), value: p.value == null ? '' : p.value }
|