@xeplr/ui-jobs 1.6.12 → 1.7.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/README.md CHANGED
@@ -123,6 +123,8 @@ Every call goes through `authFetch`, which prefixes the base URL `@xeplr/ui-acco
123
123
 
124
124
  **On a phone** (below 640px) the search, sort and **New job** wrap onto their own lines instead of running off the edge, the table keeps scrolling sideways inside its own box, row buttons and the run-history expander become thumb-sized (40px / 32px), and the search and sort are 16px so iOS does not zoom the page. A job's description and raw cron are still in the row's tooltip, which a phone cannot show — open the job to read them.
125
125
 
126
+ A **system job** (`system: true` from `@xeplr/jobs` — today the workflows' due work, `workflow-due`) is listed to every company with a **System** mark, **Always on** instead of the switch, and **Run now** only — no Edit, no Delete. Under the table it says why, in plain words: it does the workflows' due work for every company, so it cannot be changed, paused or deleted (the server refuses those for every caller, Super Admin included). A link to its editor (`?edit=<id>`) shows the same sentence instead of a form. A workflow "On a schedule" appears here as an ordinary job named "Workflow: <name>": pausing it pauses the workflow; its schedule is changed in the workflow.
127
+
126
128
  State shows **Running** over **Paused**: a pause takes effect at the next pick, and "paused" over a live run invites starting a second one. A job with no schedule has its switch off and disabled — there is nothing for the scheduler to pick.
127
129
 
128
130
  ### The editor
@@ -131,7 +133,7 @@ Three steps (four with `chainsApiBase`), all reachable at any time, with **Save
131
133
 
132
134
  1. **Job** — name, description, action.
133
135
  2. **Inputs** — a control per field of the action's `inputSchema`: a select for `options`, true/false for `boolean`, a number input, a JSON textarea for `object` / `array` (invalid JSON blocks the save), text otherwise. Fields marked `system: true` are never shown — the server fills them, and rendering them would ask for a credential. Optional fields with a `default` are under **Advanced**, whose summary lists their values. Values are converted to the declared types on save, since `@xeplr/schema-handler` rejects `"1000"` for a number.
134
- 3. **Schedule** — cron (`CronScheduleField`), status, **Start from** (`startAt`), **Retry on failure** (0–3, default 0), **Give up after** (`timeoutMinutes`, blank = server default of 30).
136
+ 3. **Schedule** — cron (`CronScheduleField`), **Time zone** (an IANA name such as `Asia/Kolkata`; empty = the server's; a name the browser cannot read is shown in red and Save waits), status, **Start from** (`startAt`), **Retry on failure** (0–3, default 0), **Give up after** (`timeoutMinutes`, blank = server default of 30).
135
137
  **Each run takes** (only for an action with a `window` input) — which rows each run takes, the job's decision (`incrementalMode`): *Everything, each run* (none), *Since the last successful run* (`period`), or *Continue from what is already loaded* (`watermark`, offered only when the action's `window` field says `watermark: true`, since the action has to read its own target). With `watermark`, **Also re-read the last … days** (`reloadDays`). A range given when the job is started always wins. Logic in `src/lib/incrementalModel.js`.
136
138
  4. **After this job** (`JobChainSection`, `useJobChainController`, `lib/jobChainModel.js`) — "Run another job when this one finishes", then rules checked top to bottom, first match wins. Each rule has:
137
139
  - **If**: a JSON condition, e.g. `{ "field": "status", "op": "=", "value": "success" }`, or `{ "all": [ … ] }` / `{ "any": [ … ] }`. Empty means "otherwise" and must come last.
@@ -218,7 +220,7 @@ Styles read `--accent`, `--surface`, `--ink`, `--muted`, `--hair`, `--plane` and
218
220
  npm test
219
221
  ```
220
222
 
221
- Plain Node scripts, no framework (`test/run.mjs` runs each `*.test.*` file): job state, `describeCron`, next-run and duration labels, latest run per job, search and sort; and the "After this job" form's rules: text to rules and back, what is refused, what the job before may fill, and rules ⇄ the workflow they are (its trigger, `when` arrows, `job-run` steps, reused and deleted steps, a draft, and every reshape that counts as edited elsewhere) (`jobChainModel.test.mjs`).
223
+ Plain Node scripts, no framework (`test/run.mjs` runs each `*.test.*` file): job state, `describeCron`, next-run and duration labels, latest run per job, search and sort, a system job and a time zone the browser can read; and the "After this job" form's rules: text to rules and back, what is refused, what the job before may fill, and rules ⇄ the workflow they are (its trigger, `when` arrows, `job-run` steps, reused and deleted steps, a draft, and every reshape that counts as edited elsewhere) (`jobChainModel.test.mjs`).
222
224
 
223
225
  ## License
224
226
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-jobs",
3
- "version": "1.6.12",
3
+ "version": "1.7.1",
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",
@@ -446,3 +446,9 @@
446
446
  .jb-pick span { overflow-wrap: anywhere; }
447
447
  .jb-pick input[type="checkbox"] { width: 16px; height: 16px; padding: 0; margin: 0; flex: none; accent-color: var(--accent, var(--xeplr-accent, #2563eb)); }
448
448
  .jb-pick { font-weight: 400; }
449
+
450
+ /* A system job (@xeplr/jobs migrations/0012): marked, and the reason said
451
+ under the table in plain words. */
452
+ .jb-pill--system { background: var(--xeplr-tag-bg, #f0efe9); color: var(--xeplr-text-secondary, #6b6a63); margin-left: 6px; }
453
+ .jb-system-note { margin: 8px 0 0; font-size: 13px; color: var(--muted, var(--xeplr-text-secondary, #6b6a63)); }
454
+ .jb-help--error { color: var(--xeplr-danger, #b42318); }
@@ -9,6 +9,7 @@ import {
9
9
  } from '../api/jobs.js'
10
10
  import {
11
11
  jobState, STATE_LABELS, describeCron, nextRunLabel, durationLabel,
12
+ isSystemJob, SYSTEM_JOB_TEXT, timezoneProblem,
12
13
  latestByJob, prepareJobs, progressLabel, progressStale, lastSeenLabel
13
14
  } from './jobsList.js'
14
15
  import CronScheduleField from '../components/CronScheduleField.jsx'
@@ -524,6 +525,9 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
524
525
  description: job?.description || '',
525
526
  actionName: job?.actionName || '',
526
527
  schedule: job?.schedule || '',
528
+ // The zone the schedule is read in (@xeplr/jobs migrations/0011). Empty:
529
+ // the server's.
530
+ timezone: job?.timezone || '',
527
531
  // 'ready' | 'pause' — see xeplr-jobs migrations/0001_jobs.js. Editable
528
532
  // HERE and not only from the list, because "write it now, start it later"
529
533
  // is a normal thing to want: a job saved from this panel used to go
@@ -606,6 +610,7 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
606
610
  // as manual-only, and an empty string is a cron expression the picker
607
611
  // would try to parse.
608
612
  schedule: draft.schedule.trim() || null,
613
+ timezone: draft.schedule.trim() && draft.timezone.trim() ? draft.timezone.trim() : null,
609
614
  // A job with no schedule is manual-only, so 'ready' vs 'pause' says
610
615
  // nothing about it — the picker never looks at it either way. Sent as
611
616
  // 'ready' so it does not sit in the list wearing a Paused badge that
@@ -748,6 +753,19 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
748
753
  <>
749
754
  <CronScheduleField id="jb-sched" value={draft.schedule} onChange={(schedule) => patch({ schedule })} />
750
755
 
756
+ {/* WHERE "9:00" IS. A schedule is read in this zone; empty is the
757
+ server's, which is what every job did before there was a choice. */}
758
+ {draft.schedule.trim() && (
759
+ <div className="jb-field">
760
+ <label htmlFor="jb-tz">Time zone</label>
761
+ <input id="jb-tz" value={draft.timezone} placeholder="Asia/Kolkata"
762
+ onChange={(e) => patch({ timezone: e.target.value })} />
763
+ <span className={timezoneProblem(draft.timezone) ? 'jb-help jb-help--error' : 'jb-help'}>
764
+ {timezoneProblem(draft.timezone) || 'The schedule runs at these times in this zone. Empty: the server\'s own time.'}
765
+ </span>
766
+ </div>
767
+ )}
768
+
751
769
  {/* ACTIVE OR PAUSED, decided while writing the job rather than after it
752
770
  is already live — "save it, but do not start it yet" is a normal
753
771
  thing to want, and without this the only way to author a scheduled
@@ -893,7 +911,7 @@ function JobEditor({ job, jobs, actions, onCancel, onSaved, stepKey, onStep }) {
893
911
  </span>
894
912
  {/* AVAILABLE ON EVERY STEP. Changing one job's cron should not mean
895
913
  walking past its name and its inputs to reach a button. */}
896
- <button type="submit" className="jb-primary" disabled={saving || !draft.actionName}>
914
+ <button type="submit" className="jb-primary" disabled={saving || !draft.actionName || Boolean(timezoneProblem(draft.timezone))}>
897
915
  {saving ? 'Saving…' : 'Save job'}
898
916
  </button>
899
917
  </div>
@@ -1127,7 +1145,13 @@ export default function Jobs({ breadcrumb: Breadcrumb, uploadLink } = {}) {
1127
1145
  </p>
1128
1146
  )}
1129
1147
 
1130
- {editing && (
1148
+ {/* A link straight to a system job's editor (?edit=<id>) gets the
1149
+ reason instead of a form whose Save would be refused. */}
1150
+ {editing && isSystemJob(editing) && (
1151
+ <p className="jb-system-note"><span className="jb-pill jb-pill--system">System</span> {SYSTEM_JOB_TEXT}</p>
1152
+ )}
1153
+
1154
+ {editing && !isSystemJob(editing) && (
1131
1155
  <JobEditor
1132
1156
  // A new job filled in from a link is checked against the actions,
1133
1157
  // so it starts again once they have loaded.
@@ -1191,6 +1215,7 @@ export default function Jobs({ breadcrumb: Breadcrumb, uploadLink } = {}) {
1191
1215
  <td className="jb-cell-job" title={job.description || job.name}>
1192
1216
  <span className="jb-name">{job.name}</span>
1193
1217
  <StatePill state={state} />
1218
+ {isSystemJob(job) && <span className="jb-pill jb-pill--system" title={SYSTEM_JOB_TEXT}>System</span>}
1194
1219
  {/* WHAT IT HAS DONE SO FAR, next to the pill that says it
1195
1220
  is running. Absent until the first throttled write
1196
1221
  lands, and absent forever for an action that reports
@@ -1269,6 +1294,9 @@ export default function Jobs({ breadcrumb: Breadcrumb, uploadLink } = {}) {
1269
1294
  and disabled rather than absent, which would leave a
1270
1295
  hole in the column. */}
1271
1296
  <td className="jb-row-toggle">
1297
+ {isSystemJob(job) ? (
1298
+ <span className="jb-dim" title={SYSTEM_JOB_TEXT}>Always on</span>
1299
+ ) : (
1272
1300
  <label className="jb-switch"
1273
1301
  title={!job.schedule
1274
1302
  ? 'No schedule — there is nothing for the scheduler to pick up'
@@ -1288,6 +1316,7 @@ export default function Jobs({ breadcrumb: Breadcrumb, uploadLink } = {}) {
1288
1316
  {!job.schedule ? 'No schedule' : job.status === 'pause' ? 'Paused' : 'On'}
1289
1317
  </span>
1290
1318
  </label>
1319
+ )}
1291
1320
  </td>
1292
1321
  {/* ICONS, with the words moved into title/aria-label.
1293
1322
  Three labelled buttons per row is a paragraph of text
@@ -1300,14 +1329,19 @@ export default function Jobs({ breadcrumb: Breadcrumb, uploadLink } = {}) {
1300
1329
  onClick={() => act(job.id, triggerJob, 'Could not trigger the job')}>
1301
1330
  <Icon path={ICON_RUN} size={14} />
1302
1331
  </button>
1303
- <button type="button" disabled={busy} title="Edit" aria-label="Edit"
1304
- onClick={() => setEditing(job)}>
1305
- <Icon path={ICON_EDIT} />
1306
- </button>
1307
- <button type="button" className="jb-danger" disabled={busy}
1308
- title="Delete" aria-label="Delete" onClick={() => remove(job)}>
1309
- <Icon path={ICON_DELETE} />
1310
- </button>
1332
+ {/* A system job is run, never changed: no Edit, no Delete. */}
1333
+ {!isSystemJob(job) && (
1334
+ <>
1335
+ <button type="button" disabled={busy} title="Edit" aria-label="Edit"
1336
+ onClick={() => setEditing(job)}>
1337
+ <Icon path={ICON_EDIT} />
1338
+ </button>
1339
+ <button type="button" className="jb-danger" disabled={busy}
1340
+ title="Delete" aria-label="Delete" onClick={() => remove(job)}>
1341
+ <Icon path={ICON_DELETE} />
1342
+ </button>
1343
+ </>
1344
+ )}
1311
1345
  </td>
1312
1346
  </tr>
1313
1347
  {open && (
@@ -1322,6 +1356,11 @@ export default function Jobs({ breadcrumb: Breadcrumb, uploadLink } = {}) {
1322
1356
  })}
1323
1357
  </tbody>
1324
1358
  </table>
1359
+ {/* SAID, not only hovered: why the System row has no switch, Edit
1360
+ or Delete. */}
1361
+ {rows.some(isSystemJob) && (
1362
+ <p className="jb-system-note"><span className="jb-pill jb-pill--system">System</span> {SYSTEM_JOB_TEXT}</p>
1363
+ )}
1325
1364
  {rows.length === 0 && (
1326
1365
  <div className="jb-empty jb-empty--inline">
1327
1366
  <p className="muted">Nothing matches “{query}”.</p>
@@ -17,6 +17,29 @@ export function jobState(job) {
17
17
  return 'scheduled'
18
18
  }
19
19
 
20
+ /**
21
+ * A JOB OF THE INSTALL ITSELF (@xeplr/jobs migrations/0012): listed to every
22
+ * company, changed by no one — the server refuses to save, pause or delete it
23
+ * for every caller. The screen says so rather than offering buttons that fail.
24
+ */
25
+ export function isSystemJob(job) {
26
+ return Boolean(job && job.system)
27
+ }
28
+
29
+ /** Why a system job cannot be changed, in the words the screen shows. */
30
+ export const SYSTEM_JOB_TEXT = 'This is a system job. It does the workflows\' due work for every company — ' +
31
+ 'Wait boxes that run out of time, reminders and escalations, and runs that stopped halfway — ' +
32
+ 'so it cannot be changed, paused or deleted. You can still run it now.'
33
+
34
+ /** A time zone the browser can read (an IANA name such as Asia/Kolkata); blank is fine — the server's. */
35
+ export function timezoneProblem(zone) {
36
+ const z = (zone || '').trim()
37
+ if (!z) return null
38
+ try { new Intl.DateTimeFormat('en-GB', { timeZone: z }); return null } catch (e) {
39
+ return `"${z}" is not a time zone. Use a name such as Asia/Kolkata or Europe/London, or leave it empty for the server's.`
40
+ }
41
+ }
42
+
20
43
  export const STATE_LABELS = {
21
44
  running: 'Running',
22
45
  paused: 'Paused',