@xeplr/ui-utils 1.1.5 → 1.1.6
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 -1
- package/package.json +1 -1
- package/src/optionSources/optionSources.js +8 -2
package/README.md
CHANGED
|
@@ -522,7 +522,7 @@ await sources.fetchSuggestions('procedureParams', { connectionId, procedure })
|
|
|
522
522
|
|
|
523
523
|
- **A kind nobody configured** is `has() === false`: show a text box. An empty dropdown looks broken.
|
|
524
524
|
- **`where`** keeps only rows with those values, e.g. `{ connectionType: 'api' }`: sent to the server as query values and checked again in the browser.
|
|
525
|
-
- **`key`** names the list in a hand-written endpoint's answer (default `dataArray`). Guessing
|
|
525
|
+
- **`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.
|
|
526
526
|
- **Pure, no React, no login of its own:** the host passes its own fetch.
|
|
527
527
|
|
|
528
528
|
## `fieldLabel`
|
package/package.json
CHANGED
|
@@ -26,6 +26,12 @@
|
|
|
26
26
|
function whereQuery(src) {
|
|
27
27
|
return Object.entries(src.where || {}).map(([k, v]) => `&${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('')
|
|
28
28
|
}
|
|
29
|
+
// The list in an answer: under `key` (default dataArray), or the answer
|
|
30
|
+
// itself when it IS a list — the auth service's /admin/roles answers so.
|
|
31
|
+
function listOf(res, src) {
|
|
32
|
+
if (Array.isArray(res)) return res
|
|
33
|
+
return (res && res[src.key || 'dataArray']) || []
|
|
34
|
+
}
|
|
29
35
|
function matchesWhere(src, row) {
|
|
30
36
|
return Object.entries(src.where || {}).every(([k, v]) => row[k] === v)
|
|
31
37
|
}
|
|
@@ -50,7 +56,7 @@ export function createOptionSources(sources, fetchJson) {
|
|
|
50
56
|
// `dataArray` is what a generic route answers; a hand-written endpoint
|
|
51
57
|
// answers with its own key, which the host names. Guessing wrong would
|
|
52
58
|
// give an empty list and no error, which reads as "you have none".
|
|
53
|
-
const rows = (res
|
|
59
|
+
const rows = listOf(res, src)
|
|
54
60
|
return rows
|
|
55
61
|
.filter((r) => matchesWhere(src, r))
|
|
56
62
|
.filter((r) => (filter && filter.clientKey ? r[filter.clientKey] === filter.value : true))
|
|
@@ -69,7 +75,7 @@ export function createOptionSources(sources, fetchJson) {
|
|
|
69
75
|
if (pairs.some(([, v]) => v === undefined || v === null || v === '')) return []
|
|
70
76
|
const q = pairs.map(([k, v]) => `&${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('')
|
|
71
77
|
const res = await fetchJson(`${src.url}?limit=0${q}`)
|
|
72
|
-
const list = (res
|
|
78
|
+
const list = listOf(res, src)
|
|
73
79
|
return list.map((o) => String(o[src.value || 'value'])).filter(Boolean)
|
|
74
80
|
}
|
|
75
81
|
|