@xeplr/ui-utils 1.1.4 → 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 +5 -1
- package/package.json +1 -1
- package/src/fields/fieldLabel.js +31 -0
- package/src/index.js +4 -0
- package/src/optionSources/optionSources.js +8 -2
package/README.md
CHANGED
|
@@ -522,9 +522,13 @@ 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
|
+
## `fieldLabel`
|
|
529
|
+
|
|
530
|
+
A schema field's name as words, when it has no `label` of its own: `connectionInfoId` → **Connection**, `dbInfoId` → **Database**, `streaming_mode` → **Streaming mode**, `timeoutMs` → **Timeout (ms)**. `Id` / `Info` are dropped: you pick a connection, not its id. Used by `@xeplr/ui-jobs` and X-Flow's step editor.
|
|
531
|
+
|
|
528
532
|
## raiseSnackbar, raiseConfirm, raiseChoice
|
|
529
533
|
|
|
530
534
|
```js
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// WHAT A SCHEMA FIELD IS CALLED ON SCREEN.
|
|
2
|
+
//
|
|
3
|
+
// A field's name is written for the action's code. Showing it raw put
|
|
4
|
+
// "connectionInfoId", "dbInfoId", "streaming_mode" and "batchSize" in front of
|
|
5
|
+
// people as though those were English. A field may carry its own `label`;
|
|
6
|
+
// this is the fallback, good enough that most fields never need one.
|
|
7
|
+
// `Id` / `Info` are suffixes of the storage, not of the thing: you pick a
|
|
8
|
+
// Connection, not a connectionInfoId.
|
|
9
|
+
//
|
|
10
|
+
// One copy, used by @xeplr/ui-jobs' job editor and X-Flow's step editor.
|
|
11
|
+
// Pure: no React.
|
|
12
|
+
|
|
13
|
+
const LABEL_WORDS = { db: 'Database', sql: 'SQL', url: 'URL', id: 'ID', api: 'API', http: 'HTTP', ms: '(ms)' }
|
|
14
|
+
|
|
15
|
+
export function fieldLabel(field) {
|
|
16
|
+
if (!field) return ''
|
|
17
|
+
if (field.label) return field.label
|
|
18
|
+
return String(field.name || '')
|
|
19
|
+
.replace(/Id$/, '')
|
|
20
|
+
.replace(/Info$/, '')
|
|
21
|
+
.replace(/[_-]+/g, ' ')
|
|
22
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
|
|
23
|
+
.trim()
|
|
24
|
+
.split(' ')
|
|
25
|
+
.map((w, i) => {
|
|
26
|
+
const known = LABEL_WORDS[w.toLowerCase()]
|
|
27
|
+
if (known) return known
|
|
28
|
+
return i === 0 ? w.charAt(0).toUpperCase() + w.slice(1) : w.toLowerCase()
|
|
29
|
+
})
|
|
30
|
+
.join(' ')
|
|
31
|
+
}
|
package/src/index.js
CHANGED
|
@@ -241,3 +241,7 @@ export { ExpandersPage, SettingsTreePage } from './panel/pages.jsx';
|
|
|
241
241
|
// Option sources — where a KIND of thing an input names (`optionsFrom`) is
|
|
242
242
|
// listed. Shared by @xeplr/ui-jobs and X-Flow's step editor.
|
|
243
243
|
export { createOptionSources } from './optionSources/optionSources.js';
|
|
244
|
+
|
|
245
|
+
// Field labels — a schema field's name as words ("connectionInfoId" →
|
|
246
|
+
// "Connection"). Shared by @xeplr/ui-jobs and X-Flow's step editor.
|
|
247
|
+
export { fieldLabel } from './fields/fieldLabel.js';
|
|
@@ -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
|
|