@xeplr/ui-jobs 1.4.0 → 1.5.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
@@ -135,7 +135,7 @@ Three steps (four with `chainsApiBase`), all reachable at any time, with **Save
135
135
 
136
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).
137
137
 
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
+ 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 opens a list of the procedure's own parameter names (`NameBox`), minus those already used and narrowed by what is typed; when it cannot have them yet it says which of connection, database and procedure is still to be chosen. 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.
139
139
 
140
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.
141
141
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-jobs",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "The screens for @xeplr/jobs — schedule, run, pause and watch jobs — as routes a host app registers, or a standalone app",
5
5
  "type": "module",
6
6
  "main": "src/index.jsx",
@@ -18,3 +18,18 @@
18
18
  .jb-param { grid-template-columns: 1fr auto; }
19
19
  .jb-param-arrow { display: none; }
20
20
  }
21
+ /* The name box and its list, which opens on click. */
22
+ .jb-namebox { position: relative; min-width: 0; }
23
+ .jb-namebox-list {
24
+ position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px;
25
+ list-style: none; max-height: 220px; overflow: auto;
26
+ background: var(--surface, #ffffff); border: 1px solid var(--hair, #e2e1d9); border-radius: 8px;
27
+ box-shadow: 0 6px 18px rgba(0, 0, 0, .12);
28
+ }
29
+ .jb-namebox-list li {
30
+ padding: 6px 8px; border-radius: 6px; cursor: pointer;
31
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; color: var(--ink, #1a1a19);
32
+ }
33
+ .jb-namebox-list li:hover, .jb-namebox-list li[aria-selected="true"] { background: var(--xeplr-hover, #f0efe9); }
34
+ .jb-namebox-list .jb-namebox-note { cursor: default; font-family: inherit; font-size: 12px; color: var(--muted, #6b6a63); }
35
+ .jb-namebox-list .jb-namebox-note:hover { background: none; }
@@ -18,6 +18,40 @@ import './ParametersField.css'
18
18
  * @param {object} props.inputs the job's other inputs — what the name
19
19
  * suggestions are asked with (field.suggestWith)
20
20
  */
21
+ // What each input the suggestions depend on is called, for "choose the … above".
22
+ const WHAT = { connectionInfoId: 'connection', dbInfoId: 'database', procedure: 'procedure' }
23
+
24
+ /**
25
+ * A name box whose list OPENS ON CLICK — the procedure's parameter names,
26
+ * narrowed by what is typed — and says why when it has none. A plain
27
+ * <datalist> shows nothing until something is typed in several browsers.
28
+ */
29
+ function NameBox({ label, value, names, emptyNote, onChange }) {
30
+ const [open, setOpen] = useState(false)
31
+ const typed = String(value || '').trim().toLowerCase()
32
+ const shown = names.filter((n) => !typed || n.toLowerCase().includes(typed))
33
+ return (
34
+ <div className="jb-namebox">
35
+ <input aria-label={label} className="jb-param-name" value={value} placeholder="name" autoComplete="off"
36
+ role="combobox" aria-expanded={open}
37
+ onFocus={() => setOpen(true)} onClick={() => setOpen(true)}
38
+ onBlur={() => setOpen(false)}
39
+ onKeyDown={(e) => { if (e.key === 'Escape') setOpen(false) }}
40
+ onChange={(e) => { onChange(e.target.value); setOpen(true) }} />
41
+ {open && (
42
+ <ul className="jb-namebox-list" role="listbox">
43
+ {shown.length ? shown.map((n) => (
44
+ <li key={n} role="option" aria-selected={n === value}
45
+ onMouseDown={(e) => { e.preventDefault(); onChange(n); setOpen(false) }}>{n}</li>
46
+ )) : (
47
+ <li className="jb-namebox-note">{names.length ? 'No parameter matches what is typed.' : (emptyNote || 'Type the name.')}</li>
48
+ )}
49
+ </ul>
50
+ )}
51
+ </div>
52
+ )
53
+ }
54
+
21
55
  export default function ParametersField({ field, value, onChange, contract, inputs }) {
22
56
  const [rows, setRows] = useState(() => rowsFromText(value, contract))
23
57
  const id = `jb-in-${field.name}`
@@ -26,15 +60,27 @@ export default function ParametersField({ field, value, onChange, contract, inpu
26
60
  // asked again whenever the connection, database or procedure changes.
27
61
  const query = Object.fromEntries(Object.entries(field.suggestWith || {}).map(([k, from]) => [k, inputs?.[from]]))
28
62
  const queryKey = JSON.stringify(query)
63
+ // What the name list says when it has nothing: which choice above is still
64
+ // missing, that it is looking, or that the procedure has none.
65
+ const missing = Object.entries(field.suggestWith || {}).filter(([k]) => !query[k]).map(([, from]) => WHAT[from] || from)
29
66
  const [names, setNames] = useState([])
67
+ const [state, setState] = useState('idle')
30
68
  useEffect(() => {
31
69
  if (!field.suggestFrom) return undefined
70
+ const q = JSON.parse(queryKey)
71
+ if (Object.values(q).some((v) => v === undefined || v === null || v === '')) { setNames([]); setState('idle'); return undefined }
32
72
  let live = true
33
- fetchSuggestions(field.suggestFrom, JSON.parse(queryKey))
34
- .then((n) => { if (live) setNames(n) })
35
- .catch(() => { if (live) setNames([]) })
73
+ setState('loading')
74
+ fetchSuggestions(field.suggestFrom, q)
75
+ .then((n) => { if (live) { setNames(n); setState('ready') } })
76
+ .catch(() => { if (live) { setNames([]); setState('failed') } })
36
77
  return () => { live = false }
37
78
  }, [field.suggestFrom, queryKey])
79
+ const emptyNote = !field.suggestFrom ? null
80
+ : missing.length ? `Choose the ${missing.join(', ')} above to see this procedure's parameters.`
81
+ : state === 'loading' ? 'Reading the procedure\'s parameters…'
82
+ : state === 'failed' ? 'Could not read the procedure\'s parameters. Type the name.'
83
+ : 'This procedure has no parameters to fill, or it was not found. Type the name.'
38
84
 
39
85
  // Saved text that is not a list (typed by hand before this control
40
86
  // existed) is shown as it is rather than guessed at.
@@ -69,12 +115,9 @@ export default function ParametersField({ field, value, onChange, contract, inpu
69
115
  const source = sourceOf(r.value, contract)
70
116
  return (
71
117
  <div key={i} className="jb-param">
72
- <input aria-label={`Parameter ${i + 1} name`} className="jb-param-name" value={r.name}
73
- list={`${id}-names-${i}`} placeholder="name"
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>
118
+ <NameBox label={`Parameter ${i + 1} name`} value={r.name}
119
+ names={unusedNames(names, rows, i)} emptyNote={emptyNote}
120
+ onChange={(name) => patchRow(i, { name })} />
78
121
  <span className="jb-param-arrow" aria-hidden="true">←</span>
79
122
  <select aria-label={`Parameter ${i + 1} value`} value={source}
80
123
  onChange={(e) => patchRow(i, { value: valueForSource(e.target.value, r.value, contract) })}>
@@ -97,9 +140,7 @@ export default function ParametersField({ field, value, onChange, contract, inpu
97
140
  </div>
98
141
  <button type="button" className="jb-param-add" onClick={() => update([...rows, { name: '', value: '' }])}>+ Add parameter</button>
99
142
  <span className="jb-help">
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.'}
143
+ Click a name box to pick one of the procedure's parameters, or type your own.
103
144
  {' '}On MySQL, parameters go by position, so keep them in the order the procedure declares them.
104
145
  </span>
105
146
  </div>