@xeplr/ui-utils 1.1.14 → 1.2.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 +1 -0
- package/package.json +1 -1
- package/src/optionSources/optionSources.js +13 -3
package/README.md
CHANGED
|
@@ -530,6 +530,7 @@ await sources.fetchSuggestions('procedureParams', { connectionId, procedure })
|
|
|
530
530
|
- **A kind nobody configured** is `has() === false`: show a text box. An empty dropdown looks broken.
|
|
531
531
|
- **`where`** keeps only rows with those values, e.g. `{ connectionType: 'api' }`: sent to the server as query values and checked again in the browser.
|
|
532
532
|
- **`key`** names the list in a hand-written endpoint's answer (default `dataArray`); an answer that is itself a list is read as one. Guessing the key wrong would show an empty list and no error.
|
|
533
|
+
- **`locked` / `why`** name a row's fields that say it is offered but cannot be picked, and why: `{ url: '/automl-forecasts/choices', value: 'id', label: 'name', locked: 'locked', why: 'why' }`. Such a row comes back `{ value, label, locked: true, why }`, and the screen shows it greyed with its reason (a model shared with someone who has no seat for it). "You may not" and "there is none" are different facts, so it is never left out.
|
|
533
534
|
- **Pure, no React, no login of its own:** the host passes its own fetch.
|
|
534
535
|
|
|
535
536
|
## `fieldLabel`
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
// (@xeplr/ui-account's authFetch), so this package never learns about logins.
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* @param {object} sources { kind: { url, value?='id', label?, key?='dataArray', where? } }
|
|
20
|
+
* @param {object} sources { kind: { url, value?='id', label?, key?='dataArray', where?, locked?, why? } }
|
|
21
21
|
* @param {Function} fetchJson (path) → Promise of the parsed answer
|
|
22
22
|
*/
|
|
23
23
|
// `where`: only rows with these values, e.g. { connectionType: 'api' } so a
|
|
@@ -32,6 +32,15 @@ function listOf(res, src) {
|
|
|
32
32
|
if (Array.isArray(res)) return res
|
|
33
33
|
return (res && res[src.key || 'dataArray']) || []
|
|
34
34
|
}
|
|
35
|
+
// `locked`: the name of a row's field saying it is offered but cannot be
|
|
36
|
+
// picked (a model shared with someone who has no seat for it), and `why`: the
|
|
37
|
+
// field saying why. Such an option comes back { value, label, locked: true,
|
|
38
|
+
// why } — shown greyed with its reason, never silently left out: "you may not"
|
|
39
|
+
// and "there is none" are different facts.
|
|
40
|
+
function lockOf(src, row) {
|
|
41
|
+
if (!src.locked || !row[src.locked]) return null
|
|
42
|
+
return { locked: true, why: (src.why && row[src.why]) || '' }
|
|
43
|
+
}
|
|
35
44
|
function matchesWhere(src, row) {
|
|
36
45
|
return Object.entries(src.where || {}).every(([k, v]) => row[k] === v)
|
|
37
46
|
}
|
|
@@ -44,7 +53,8 @@ export function createOptionSources(sources, fetchJson) {
|
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
/**
|
|
47
|
-
* One list, as [{ value, label }]
|
|
56
|
+
* One list, as [{ value, label }] — plus { locked: true, why } on a row
|
|
57
|
+
* the host's `locked` field marks. `filter` narrows a dependent list — the
|
|
48
58
|
* databases on the chosen connection — as a query parameter, and, with
|
|
49
59
|
* `clientKey`, again in the browser for an endpoint that ignores it.
|
|
50
60
|
*/
|
|
@@ -60,7 +70,7 @@ export function createOptionSources(sources, fetchJson) {
|
|
|
60
70
|
return rows
|
|
61
71
|
.filter((r) => matchesWhere(src, r))
|
|
62
72
|
.filter((r) => (filter && filter.clientKey ? r[filter.clientKey] === filter.value : true))
|
|
63
|
-
.map((r) => ({ value: r[src.value || 'id'], label: r[src.label] || r[src.value || 'id'] }))
|
|
73
|
+
.map((r) => Object.assign({ value: r[src.value || 'id'], label: r[src.label] || r[src.value || 'id'] }, lockOf(src, r)))
|
|
64
74
|
}
|
|
65
75
|
|
|
66
76
|
/**
|