@xeplr/ui-jobs 1.6.10 → 1.6.11

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
@@ -187,6 +187,7 @@ registerJobsUI({
187
187
 
188
188
  - **A kind with no source gets a plain text input.** An empty dropdown looks broken; a text box is what you have without a catalogue.
189
189
  - A field with `dependsOn: 'connectionInfoId'` stays disabled until that field has a value, then requests `?connectionInfoId=<value>` and keeps only rows whose `connectionId` equals it.
190
+ - A field of `type: 'array'` with `optionsFrom` is **ticks**: several chosen at once, saved as a list (`["taskie", "taskie_jobs"]`), in the options' order. A saved value the source no longer offers stays ticked, marked "not offered now", so a save never drops it silently.
190
191
  - A failed fetch says "Could not load the list" rather than showing an empty one.
191
192
 
192
193
  ## Other exports
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-jobs",
3
- "version": "1.6.10",
3
+ "version": "1.6.11",
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",
@@ -437,3 +437,12 @@
437
437
  .jb-caret { width: 32px; height: 32px; }
438
438
  .jb-editor { padding: 16px; }
439
439
  }
440
+
441
+ /* A list chosen from the host's options (an 'array' input with optionsFrom): ticks. */
442
+ .jb-picks { border: 0; padding: 0; min-width: 0; }
443
+ .jb-picks legend { padding: 0; margin-bottom: 5px; }
444
+ .jb-picks-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 16px; max-height: 240px; overflow: auto; }
445
+ .jb-pick { display: flex; align-items: center; gap: 8px; min-width: 0; cursor: pointer; }
446
+ .jb-pick span { overflow-wrap: anywhere; }
447
+ .jb-pick input[type="checkbox"] { width: 16px; height: 16px; padding: 0; margin: 0; flex: none; accent-color: var(--accent, #2563eb); }
448
+ .jb-pick { font-weight: 400; }
@@ -1,3 +1,4 @@
1
+ import { pickedOf, toggled } from './multiPick.js'
1
2
  import { Fragment, useCallback, useEffect, useMemo, useState } from 'react'
2
3
  import { fieldLabel, raiseConfirm, raiseSnackbar } from '@xeplr/ui-utils'
3
4
  import { relativeTime } from './relativeTime.js'
@@ -399,6 +400,36 @@ function RemoteSelect({ field, value, onChange, dependsOnValue }) {
399
400
  return () => { alive = false }
400
401
  }, [field.optionsFrom, field.dependsOn, dependsOnValue])
401
402
 
403
+ // A LIST from the host's options (type 'array'): ticks, several at once.
404
+ if (field.type === 'array') {
405
+ const picked = pickedOf(value)
406
+ const waiting = field.dependsOn && !dependsOnValue
407
+ const shown = (options || []).concat(picked.filter((v) => !(options || []).some((o) => String(o.value) === v)).map((v) => ({ value: v, label: v + ' (not offered now)' })))
408
+ return (
409
+ <fieldset className="jb-field jb-field--wide jb-picks" id={id}>
410
+ <legend>{fieldLabel(field)}{field.required && <span className="jb-req"> *</span>}
411
+ {picked.length ? <span className="jb-type"> · {picked.length} chosen</span> : null}</legend>
412
+ {waiting ? <span className="jb-help">{`Choose ${field.dependsOn} first…`}</span>
413
+ : options === null ? <span className="jb-help">Loading…</span>
414
+ : !shown.length ? <span className="jb-help">Nothing to choose from</span>
415
+ : (
416
+ <div className="jb-picks-list">
417
+ {shown.map((o) => (
418
+ <label key={o.value} className="jb-pick">
419
+ <input type="checkbox" checked={picked.includes(String(o.value))}
420
+ onChange={() => onChange(toggled(picked, String(o.value), options))} />
421
+ <span>{o.label}</span>
422
+ </label>
423
+ ))}
424
+ </div>
425
+ )}
426
+ {failed
427
+ ? <span className="jb-help jb-warn">Could not load the list.</span>
428
+ : field.description && <span className="jb-help">{field.description}</span>}
429
+ </fieldset>
430
+ )
431
+ }
432
+
402
433
  return (
403
434
  <div className="jb-field">
404
435
  <label htmlFor={id}>
@@ -0,0 +1,22 @@
1
+ // A LIST INPUT CHOSEN FROM A HOST'S OPTIONS — an action's field of type
2
+ // 'array' with `optionsFrom` (several databases for one backup job) is a set
3
+ // of ticks, not JSON to type. Pure: what is ticked, and ticking one.
4
+
5
+ /** What is ticked: the saved list, the form's JSON text of it, or nothing. */
6
+ export function pickedOf(value) {
7
+ if (Array.isArray(value)) return value.map(String)
8
+ if (typeof value !== 'string' || !value.trim()) return []
9
+ try {
10
+ const v = JSON.parse(value)
11
+ return Array.isArray(v) ? v.map(String) : []
12
+ } catch (e) {
13
+ return []
14
+ }
15
+ }
16
+
17
+ /** Tick or untick one, keeping the options' order. */
18
+ export function toggled(picked, value, options) {
19
+ const on = picked.includes(value) ? picked.filter((v) => v !== value) : picked.concat([value])
20
+ const order = (options || []).map((o) => String(o.value))
21
+ return on.slice().sort((a, b) => (order.indexOf(a) + 1 || Infinity) - (order.indexOf(b) + 1 || Infinity))
22
+ }