@xeplr/ui-jobs 1.5.0 → 1.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 +2 -0
- package/package.json +1 -1
- package/src/pages/Jobs.css +1 -0
- package/src/pages/Jobs.jsx +35 -12
- package/src/useJobsUrl.js +43 -0
package/README.md
CHANGED
|
@@ -114,6 +114,8 @@ Every call goes through `authFetch`, which prefixes the base URL `@xeplr/ui-acco
|
|
|
114
114
|
|
|
115
115
|
## The screen
|
|
116
116
|
|
|
117
|
+
**Where you are is in the URL** (`useJobsUrl`), so a refresh or a shared link lands on the same screen: `?edit=<jobId>` or `?edit=new` opens the editor, `&step=inputs|schedule|after` its step, `?runs=<jobId>` a job's run history, `&log=<occurrenceId>` one run's log, `?q=` and `?sort=` the search and sort. Opening and closing add a history entry (Back closes them); steps and typing replace it. An `edit` id that is not there says so.
|
|
118
|
+
|
|
117
119
|
- **Jobs table** — name, state (Running, Paused, Manual only, Scheduled), schedule in words (`describeCron`, else "Custom"), next run ("in 3 hours", "due now"), last run, an **on / paused switch**, and **Run now**, **Edit**, **Delete** (confirmed; run history is kept). Search matches name, description and action; sort by name, next run or action.
|
|
118
120
|
- **Run history** — the last-run cell opens that job's newest 50 runs, each with its log.
|
|
119
121
|
- **Recent runs** — the 12 latest runs across all jobs, with duration, trigger and error message.
|
package/package.json
CHANGED
package/src/pages/Jobs.css
CHANGED
|
@@ -411,3 +411,4 @@
|
|
|
411
411
|
mark — a rotated '>' glyph never sat straight, whatever the box did. */
|
|
412
412
|
.jb-caret { padding: 0; }
|
|
413
413
|
.jb-caret .jb-icon { transition: none; }
|
|
414
|
+
.jb-linkish { padding: 0; font: inherit; color: var(--accent, #2563eb); background: none; border: 0; cursor: pointer; text-decoration: underline; }
|
package/src/pages/Jobs.jsx
CHANGED
|
@@ -14,6 +14,7 @@ import CronScheduleField from '../components/CronScheduleField.jsx'
|
|
|
14
14
|
import JobChainSection from '../components/JobChainSection.jsx'
|
|
15
15
|
import ParametersField from '../components/ParametersField.jsx'
|
|
16
16
|
import { useRunContract } from '../useRunContract.js'
|
|
17
|
+
import { useJobsUrl } from '../useJobsUrl.js'
|
|
17
18
|
import { useJobChainController } from '../useJobChainController.js'
|
|
18
19
|
import { acceptableFields } from '../lib/jobChainModel.js'
|
|
19
20
|
import './Jobs.css'
|
|
@@ -147,12 +148,12 @@ function OccurrenceLogs({ occurrenceId }) {
|
|
|
147
148
|
* Re-fetched on `refreshKey` so that pressing Run now updates the open history
|
|
148
149
|
* instead of leaving it showing the state from before the click.
|
|
149
150
|
*/
|
|
150
|
-
function JobRuns({ jobId, refreshKey }) {
|
|
151
|
+
function JobRuns({ jobId, refreshKey, openLogId, onOpenLog }) {
|
|
151
152
|
const [runs, setRuns] = useState(null)
|
|
152
153
|
const [error, setError] = useState(null)
|
|
153
|
-
// Which occurrence has its log open
|
|
154
|
-
//
|
|
155
|
-
|
|
154
|
+
// Which occurrence has its log open — in the URL (?log=), so a refresh keeps
|
|
155
|
+
// it open. One at a time: two open logs is two scrolling regions competing
|
|
156
|
+
// inside a row that is already an expansion.
|
|
156
157
|
|
|
157
158
|
useEffect(() => {
|
|
158
159
|
let alive = true
|
|
@@ -227,7 +228,7 @@ function JobRuns({ jobId, refreshKey }) {
|
|
|
227
228
|
aria-expanded={openLogId === run.id}
|
|
228
229
|
title={openLogId === run.id ? 'Hide this run’s log' : 'Show this run’s log'}
|
|
229
230
|
aria-label={openLogId === run.id ? 'Hide this run’s log' : 'Show this run’s log'}
|
|
230
|
-
onClick={() =>
|
|
231
|
+
onClick={() => onOpenLog(openLogId === run.id ? null : run.id)}>
|
|
231
232
|
<Icon path={ICON_CHEVRON} size={14} />
|
|
232
233
|
</button>
|
|
233
234
|
</td>
|
|
@@ -508,7 +509,7 @@ function ActionInput({ field, value, onChange, inputs, contract }) {
|
|
|
508
509
|
|
|
509
510
|
// The editor. A panel rather than a route: a job is a handful of fields, and a
|
|
510
511
|
// page you navigate to and back from for those is three navigations too many.
|
|
511
|
-
function JobEditor({ job, jobs, actions, onCancel, onSaved }) {
|
|
512
|
+
function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
|
|
512
513
|
const [draft, setDraft] = useState(() => ({
|
|
513
514
|
name: job?.name || '',
|
|
514
515
|
description: job?.description || '',
|
|
@@ -541,10 +542,12 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved }) {
|
|
|
541
542
|
acceptsInputs: Array.isArray(job?.acceptsInputs) ? job.acceptsInputs : []
|
|
542
543
|
}))
|
|
543
544
|
const [saving, setSaving] = useState(false)
|
|
544
|
-
const [step, setStep] = useState(0)
|
|
545
545
|
const chain = useJobChainController(job?.id || null)
|
|
546
546
|
const contract = useRunContract()
|
|
547
547
|
const STEPS = chain.enabled ? [...BASE_STEPS, AFTER_STEP] : BASE_STEPS
|
|
548
|
+
// THE STEP IS IN THE URL (?step=), so a refresh reopens the same one.
|
|
549
|
+
const step = Math.max(0, STEPS.findIndex((s) => s.key === stepKey))
|
|
550
|
+
const setStep = (i) => onStep(STEPS[Math.max(0, Math.min(STEPS.length - 1, i))].key)
|
|
548
551
|
|
|
549
552
|
const action = actions.find((a) => a.name === draft.actionName) || null
|
|
550
553
|
const patch = (p) => setDraft((d) => ({ ...d, ...p }))
|
|
@@ -877,11 +880,21 @@ export default function Jobs({ breadcrumb: Breadcrumb, uploadLink } = {}) {
|
|
|
877
880
|
const [runs, setRuns] = useState([])
|
|
878
881
|
const [actions, setActions] = useState([])
|
|
879
882
|
const [error, setError] = useState(null)
|
|
880
|
-
|
|
881
|
-
const
|
|
882
|
-
const
|
|
883
|
+
// EVERYTHING THAT SAYS WHERE YOU ARE comes from the URL — see useJobsUrl.
|
|
884
|
+
const url = useJobsUrl()
|
|
885
|
+
const query = url.q
|
|
886
|
+
const sort = url.sort
|
|
887
|
+
const setQuery = (q) => url.set({ q: q }, { replace: true })
|
|
888
|
+
const setSort = (v) => url.set({ sort: v === 'name' ? null : v }, { replace: true })
|
|
889
|
+
const openRuns = url.runs
|
|
890
|
+
const setOpenRuns = (id) => url.set({ runs: id, log: null })
|
|
891
|
+
// ?edit=new is a new job; ?edit=<id> is that job once the list has loaded.
|
|
892
|
+
const editing = url.edit === 'new' ? {}
|
|
893
|
+
: url.edit && jobs ? (jobs.find((j) => j.id === url.edit) || null)
|
|
894
|
+
: null
|
|
895
|
+
const editMissing = Boolean(url.edit && url.edit !== 'new' && jobs && !editing)
|
|
896
|
+
const setEditing = (job) => url.set({ edit: job ? (job.id || 'new') : null, step: null })
|
|
883
897
|
const [busyId, setBusyId] = useState(null)
|
|
884
|
-
const [openRuns, setOpenRuns] = useState(null) // jobId whose history is expanded
|
|
885
898
|
// Bumped by anything that creates an occurrence, so an OPEN history refetches
|
|
886
899
|
// rather than sitting there showing the state from before Run now was pressed.
|
|
887
900
|
const [runsVersion, setRunsVersion] = useState(0)
|
|
@@ -1050,11 +1063,21 @@ export default function Jobs({ breadcrumb: Breadcrumb, uploadLink } = {}) {
|
|
|
1050
1063
|
{error && <p className="report-builder-error">{error}</p>}
|
|
1051
1064
|
{jobs === null && !error && <p className="muted">Loading…</p>}
|
|
1052
1065
|
|
|
1066
|
+
{editMissing && (
|
|
1067
|
+
<p className="report-builder-error">
|
|
1068
|
+
There is no job {url.edit} here — it may have been deleted.{' '}
|
|
1069
|
+
<button type="button" className="jb-linkish" onClick={() => setEditing(null)}>Back to the list</button>
|
|
1070
|
+
</p>
|
|
1071
|
+
)}
|
|
1072
|
+
|
|
1053
1073
|
{editing && (
|
|
1054
1074
|
<JobEditor
|
|
1075
|
+
key={url.edit}
|
|
1055
1076
|
job={editing.id ? editing : null}
|
|
1056
1077
|
jobs={jobs || []}
|
|
1057
1078
|
actions={actions}
|
|
1079
|
+
stepKey={url.step}
|
|
1080
|
+
onStep={(key) => url.set({ step: key === 'job' ? null : key }, { replace: true })}
|
|
1058
1081
|
onCancel={() => setEditing(null)}
|
|
1059
1082
|
onSaved={() => { setEditing(null); load() }}
|
|
1060
1083
|
/>
|
|
@@ -1229,7 +1252,7 @@ export default function Jobs({ breadcrumb: Breadcrumb, uploadLink } = {}) {
|
|
|
1229
1252
|
{open && (
|
|
1230
1253
|
<tr className="jb-runs-row">
|
|
1231
1254
|
<td colSpan={7}>
|
|
1232
|
-
<JobRuns jobId={job.id} refreshKey={runsVersion} />
|
|
1255
|
+
<JobRuns jobId={job.id} refreshKey={runsVersion} openLogId={url.log} onOpenLog={(id) => url.set({ log: id })} />
|
|
1233
1256
|
</td>
|
|
1234
1257
|
</tr>
|
|
1235
1258
|
)}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useCallback } from 'react'
|
|
2
|
+
import { useSearchParams } from 'react-router-dom'
|
|
3
|
+
|
|
4
|
+
// WHERE YOU ARE ON THE JOBS SCREEN LIVES IN THE URL, so a refresh or a shared
|
|
5
|
+
// link lands on exactly this screen:
|
|
6
|
+
//
|
|
7
|
+
// ?edit=<jobId> | ?edit=new the editor, open on that job (or a new one)
|
|
8
|
+
// &step=job|inputs|schedule|after its step
|
|
9
|
+
// ?runs=<jobId> that job's run history, expanded
|
|
10
|
+
// &log=<occurrenceId> one run's log, open
|
|
11
|
+
// ?q=…&sort=… the search and the sort
|
|
12
|
+
//
|
|
13
|
+
// Opening and closing things adds a history entry, so Back closes them;
|
|
14
|
+
// typing and switching steps replaces it, so Back is not a keystroke undo.
|
|
15
|
+
const KEYS = ['edit', 'step', 'runs', 'log', 'q', 'sort']
|
|
16
|
+
|
|
17
|
+
export function useJobsUrl() {
|
|
18
|
+
const [params, setParams] = useSearchParams()
|
|
19
|
+
const read = (k) => params.get(k) || null
|
|
20
|
+
|
|
21
|
+
const set = useCallback((patch, opts) => {
|
|
22
|
+
setParams((prev) => {
|
|
23
|
+
const next = new URLSearchParams(prev)
|
|
24
|
+
Object.keys(patch).forEach((k) => {
|
|
25
|
+
const v = patch[k]
|
|
26
|
+
if (v === null || v === undefined || v === '') next.delete(k)
|
|
27
|
+
else next.set(k, String(v))
|
|
28
|
+
})
|
|
29
|
+
return next
|
|
30
|
+
}, { replace: Boolean(opts && opts.replace) })
|
|
31
|
+
}, [setParams])
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
edit: read('edit'),
|
|
35
|
+
step: read('step'),
|
|
36
|
+
runs: read('runs'),
|
|
37
|
+
log: read('log'),
|
|
38
|
+
q: read('q') || '',
|
|
39
|
+
sort: read('sort') || 'name',
|
|
40
|
+
set: set,
|
|
41
|
+
KEYS: KEYS
|
|
42
|
+
}
|
|
43
|
+
}
|