dsh-data-window 0.0.0-stage → 0.1.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/AGENTS.md +111 -0
- package/CHANGELOG.md +239 -0
- package/LICENSE +21 -0
- package/README.md +146 -2
- package/client.js +7779 -0
- package/cordis.patch.yml +4 -0
- package/docs/BRIDGE.md +100 -0
- package/docs/DESIGN.md +417 -0
- package/docs/DETAIL.md +220 -0
- package/docs/screenshots/ddl.png +0 -0
- package/docs/screenshots/workbench.png +0 -0
- package/icon.svg +30 -0
- package/index.js +180 -0
- package/locale/en.json +286 -0
- package/locale/zh.json +286 -0
- package/package.json +68 -4
- package/src/client/00-css.js +993 -0
- package/src/client/05-icons.js +137 -0
- package/src/client/05-theme.js +107 -0
- package/src/client/06-shortcuts.js +89 -0
- package/src/client/07-bridge.js +193 -0
- package/src/client/10-core.js +1352 -0
- package/src/client/20-tree.js +281 -0
- package/src/client/25-sql.js +631 -0
- package/src/client/30-editor.js +537 -0
- package/src/client/40-results.js +556 -0
- package/src/client/45-export.js +219 -0
- package/src/client/50-panel.js +761 -0
- package/src/client/60-settings.js +180 -0
- package/src/client/63-schema.js +186 -0
- package/src/client/64-manual.js +350 -0
- package/src/client/65-ai.js +320 -0
- package/src/client/66-optimize.js +98 -0
- package/src/client/90-apply.js +183 -0
- package/src/host/ai.js +721 -0
- package/src/host/cache.js +157 -0
- package/src/host/catalog.js +161 -0
- package/src/host/consoles.js +116 -0
- package/src/host/discovery.js +603 -0
- package/src/host/manual.js +276 -0
- package/src/host/mysql.js +650 -0
- package/src/host/remembered.js +225 -0
- package/src/host/rpc.js +487 -0
- package/src/host/shared.js +172 -0
- package/src/host/yaml.js +335 -0
|
@@ -0,0 +1,761 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Panel and workspace binding.
|
|
3
|
+
*
|
|
4
|
+
* Requirement 1 is "opening a workspace loads its own configuration". A global main
|
|
5
|
+
* panel is not a conversation, so the panel cannot read the Session on screen at
|
|
6
|
+
* paint time; a headless tracker in the frame's overlay layer remembers the Session
|
|
7
|
+
* — and therefore the Workspace — while the Conversation still holds the column,
|
|
8
|
+
* and the store follows whatever that tracker last saw.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Bounds for the editor/document split, in pixels. */
|
|
12
|
+
const DW_EDITOR_MIN = 88
|
|
13
|
+
const DW_EDITOR_MAX = 620
|
|
14
|
+
|
|
15
|
+
/** Bounds for the explorer column, in pixels. */
|
|
16
|
+
const DW_SIDE_MIN = 200
|
|
17
|
+
const DW_SIDE_MAX = 720
|
|
18
|
+
const DW_SIDE_DEFAULT = 268
|
|
19
|
+
const DW_SIDE_KEY = 'dsh-data-window:side-width'
|
|
20
|
+
|
|
21
|
+
/** Wide layouts collapse the navigation column; below this the toggle is a drawer. */
|
|
22
|
+
const DW_WIDE_LAYOUT = 1024
|
|
23
|
+
|
|
24
|
+
/** Last path segment, used when a Workspace has no title. */
|
|
25
|
+
function dwBasename(path) {
|
|
26
|
+
const parts = String(path ?? '').split('/').filter((part) => part !== '')
|
|
27
|
+
return parts.length === 0 ? String(path ?? '') : parts[parts.length - 1]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** `~/Documents/x` instead of an absolute home path. */
|
|
31
|
+
function dwShortPath(path) {
|
|
32
|
+
return String(path ?? '').replace(/^\/(?:Users|home)\/[^/]+\//, '~/')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Stored explorer width, clamped so a bad value cannot hide the tree. */
|
|
36
|
+
function dwReadSideWidth() {
|
|
37
|
+
const raw = Number(globalThis.localStorage?.getItem(DW_SIDE_KEY))
|
|
38
|
+
if (!Number.isFinite(raw) || raw <= 0) return DW_SIDE_DEFAULT
|
|
39
|
+
return Math.min(DW_SIDE_MAX, Math.max(DW_SIDE_MIN, raw))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Whether the shell's navigation column is collapsed.
|
|
44
|
+
*
|
|
45
|
+
* `layout.toggleSidebar()` is a bare toggle with no readable state, so the frame's
|
|
46
|
+
* own marker is the only way to avoid flipping a column the user had already
|
|
47
|
+
* folded.
|
|
48
|
+
*/
|
|
49
|
+
function dwSidebarCollapsed() {
|
|
50
|
+
try {
|
|
51
|
+
const layer = document.querySelector('[data-shell-overlay]')
|
|
52
|
+
const frame = layer === null ? null : layer.parentElement
|
|
53
|
+
return frame === null ? false : frame.hasAttribute('data-sidebar-collapsed')
|
|
54
|
+
} catch (error) {
|
|
55
|
+
void error
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Fold the navigation column; false when it was already folded or unavailable. */
|
|
61
|
+
function dwHideSidebar(store) {
|
|
62
|
+
const layout = store.layout?.()
|
|
63
|
+
if (layout === undefined || typeof layout.toggleSidebar !== 'function') return false
|
|
64
|
+
if ((Number(globalThis.innerWidth) || 0) < DW_WIDE_LAYOUT) return false
|
|
65
|
+
if (dwSidebarCollapsed()) return false
|
|
66
|
+
layout.toggleSidebar()
|
|
67
|
+
return true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Unfold the navigation column, but only when it is still folded. */
|
|
71
|
+
function dwShowSidebar(store) {
|
|
72
|
+
const layout = store.layout?.()
|
|
73
|
+
if (layout === undefined || typeof layout.toggleSidebar !== 'function') return
|
|
74
|
+
if (!dwSidebarCollapsed()) return
|
|
75
|
+
layout.toggleSidebar()
|
|
76
|
+
try {
|
|
77
|
+
globalThis.dispatchEvent(new Event('resize'))
|
|
78
|
+
} catch (error) {
|
|
79
|
+
void error
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The workspace a Session belongs to, tolerating both snapshot spellings. */
|
|
84
|
+
function dwResolveRoot(sessionsState, workspacesState) {
|
|
85
|
+
const byId = sessionsState?.byId ?? {}
|
|
86
|
+
const ids = Array.isArray(sessionsState?.ids) ? sessionsState.ids : []
|
|
87
|
+
const workspaceItems = Array.isArray(workspacesState?.items) ? workspacesState.items : []
|
|
88
|
+
|
|
89
|
+
const candidates = []
|
|
90
|
+
for (const id of ids) {
|
|
91
|
+
const row = byId[id]
|
|
92
|
+
if (row === undefined) continue
|
|
93
|
+
const retained = Number(row.retainedBy?.mainView ?? 0)
|
|
94
|
+
const cwd = typeof row.cwd === 'string' ? row.cwd : ''
|
|
95
|
+
candidates.push({ id, retained: Number.isFinite(retained) ? retained : 0, cwd })
|
|
96
|
+
}
|
|
97
|
+
candidates.sort((left, right) => right.retained - left.retained)
|
|
98
|
+
|
|
99
|
+
for (const candidate of candidates) {
|
|
100
|
+
const workspace = workspaceItems.find((item) => {
|
|
101
|
+
const sessionIds = Array.isArray(item?.sessionIds) ? item.sessionIds : []
|
|
102
|
+
return sessionIds.includes(candidate.id)
|
|
103
|
+
})
|
|
104
|
+
const fromWorkspace = typeof workspace?.path === 'string' ? workspace.path : ''
|
|
105
|
+
if (fromWorkspace !== '') return fromWorkspace
|
|
106
|
+
if (candidate.cwd !== '') return candidate.cwd
|
|
107
|
+
}
|
|
108
|
+
// No Session yet (a fresh window): the first Workspace is the best answer.
|
|
109
|
+
const first = workspaceItems.find((item) => typeof item?.path === 'string' && item.path !== '')
|
|
110
|
+
return typeof first?.path === 'string' ? first.path : ''
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Headless entry that keeps the resolved workspace in the store. */
|
|
114
|
+
function DwTracker({ store, useSessions, useWorkspaces }) {
|
|
115
|
+
const selectSessions = typeof useSessions === 'function' ? useSessions : () => undefined
|
|
116
|
+
const selectWorkspaces = typeof useWorkspaces === 'function' ? useWorkspaces : () => undefined
|
|
117
|
+
const sessions = selectSessions((snapshot) => snapshot)
|
|
118
|
+
const workspaces = selectWorkspaces((snapshot) => snapshot)
|
|
119
|
+
const root = dwResolveRoot(sessions, workspaces)
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
if (root === '') return
|
|
122
|
+
store.setDetectedRoot(root)
|
|
123
|
+
}, [root, store])
|
|
124
|
+
return null
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The workspace chip and its menu: switching here re-roots the window in place. */
|
|
128
|
+
function DwProjectMenu({ state, projects, tr, onSelect, onFollow }) {
|
|
129
|
+
const [open, setOpen] = useState(false)
|
|
130
|
+
const root = state.root === '' ? '' : state.root.replace(/\/+$/, '')
|
|
131
|
+
const current = projects.find((item) => item.path === root)
|
|
132
|
+
const label = current === undefined
|
|
133
|
+
? (state.root === '' ? tr('noWorkspace') : dwBasename(state.root))
|
|
134
|
+
: current.title
|
|
135
|
+
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (!open) return undefined
|
|
138
|
+
const onDown = (event) => {
|
|
139
|
+
const element = event.target
|
|
140
|
+
if (element instanceof Element && element.closest('.dw-project') !== null) return
|
|
141
|
+
setOpen(false)
|
|
142
|
+
}
|
|
143
|
+
globalThis.addEventListener('pointerdown', onDown, true)
|
|
144
|
+
return () => globalThis.removeEventListener('pointerdown', onDown, true)
|
|
145
|
+
}, [open])
|
|
146
|
+
|
|
147
|
+
return h('div', { className: 'dw-project' }, [
|
|
148
|
+
h('button', {
|
|
149
|
+
key: 'btn',
|
|
150
|
+
type: 'button',
|
|
151
|
+
className: 'dw-project-btn',
|
|
152
|
+
title: tr('projectSwitch'),
|
|
153
|
+
'aria-label': tr('projectSwitch'),
|
|
154
|
+
onClick: () => setOpen(!open),
|
|
155
|
+
}, [
|
|
156
|
+
h('span', { key: 'nm', className: 'dw-project-name' }, label),
|
|
157
|
+
h('span', { key: 'c', className: 'dw-project-caret' }, '\u25be'),
|
|
158
|
+
]),
|
|
159
|
+
open
|
|
160
|
+
? h('div', { key: 'menu', className: 'dw-project-menu', role: 'menu' }, [
|
|
161
|
+
h('button', {
|
|
162
|
+
key: '__follow',
|
|
163
|
+
type: 'button',
|
|
164
|
+
role: 'menuitem',
|
|
165
|
+
className: state.manual === true ? 'dw-project-row' : 'dw-project-row active',
|
|
166
|
+
onClick: () => {
|
|
167
|
+
setOpen(false)
|
|
168
|
+
if (state.manual === true) onFollow()
|
|
169
|
+
},
|
|
170
|
+
}, tr('followWorkspace')),
|
|
171
|
+
h('div', { key: '__sep', className: 'dw-project-sep' }),
|
|
172
|
+
...projects.map((item) => h('button', {
|
|
173
|
+
key: item.path,
|
|
174
|
+
type: 'button',
|
|
175
|
+
role: 'menuitem',
|
|
176
|
+
className: item.path === root ? 'dw-project-row active' : 'dw-project-row',
|
|
177
|
+
title: item.path,
|
|
178
|
+
onClick: () => {
|
|
179
|
+
setOpen(false)
|
|
180
|
+
if (item.path !== root) onSelect(item.path)
|
|
181
|
+
},
|
|
182
|
+
}, [
|
|
183
|
+
h('span', { key: 't', className: 'dw-project-row-title' }, item.title),
|
|
184
|
+
h('span', { key: 'p', className: 'dw-project-row-path' }, dwShortPath(item.path)),
|
|
185
|
+
])),
|
|
186
|
+
])
|
|
187
|
+
: null,
|
|
188
|
+
])
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function DwPanel({ store, translate, useSessions, useWorkspaces, pickDirectory }) {
|
|
192
|
+
const tr = typeof translate === 'function' ? translate : (key) => key
|
|
193
|
+
const state = useSyncExternalStore(store.subscribe, store.getState, store.getState)
|
|
194
|
+
const [menu, setMenu] = useState(null)
|
|
195
|
+
const [editorHeight, setEditorHeight] = useState(168)
|
|
196
|
+
const [sideWidth, setSideWidth] = useState(() => dwReadSideWidth())
|
|
197
|
+
const [sidebarHidden, setSidebarHidden] = useState(false)
|
|
198
|
+
const [aiOpen, setAiOpen] = useState(false)
|
|
199
|
+
const [manualOpen, setManualOpen] = useState(false)
|
|
200
|
+
const [schemaTarget, setSchemaTarget] = useState(null)
|
|
201
|
+
const [renameTarget, setRenameTarget] = useState(null)
|
|
202
|
+
const [removeEnvTarget, setRemoveEnvTarget] = useState(null)
|
|
203
|
+
const aiPrompted = useRef(false)
|
|
204
|
+
const panelRef = useRef(null)
|
|
205
|
+
const logRef = useRef(null)
|
|
206
|
+
const sideWidthRef = useRef(sideWidth)
|
|
207
|
+
const sidebarHiddenRef = useRef(false)
|
|
208
|
+
|
|
209
|
+
// The tracker in the overlay reports first; these hooks read the same data, so
|
|
210
|
+
// whichever mounted first decides, and a Workspace switch updates both.
|
|
211
|
+
const selectSessions = typeof useSessions === 'function' ? useSessions : () => undefined
|
|
212
|
+
const selectWorkspaces = typeof useWorkspaces === 'function' ? useWorkspaces : () => undefined
|
|
213
|
+
const sessions = selectSessions((snapshot) => snapshot)
|
|
214
|
+
const workspaces = selectWorkspaces((snapshot) => snapshot)
|
|
215
|
+
const detected = dwResolveRoot(sessions, workspaces)
|
|
216
|
+
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
if (detected !== '') store.setDetectedRoot(detected)
|
|
219
|
+
}, [detected, store])
|
|
220
|
+
|
|
221
|
+
// First open of a workspace the rule-based scan cannot read: offer the model
|
|
222
|
+
// picker instead of leaving the user with an empty tree and no next step. It
|
|
223
|
+
// asks once per mount and only while no model has been chosen yet.
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
if (aiPrompted.current) return
|
|
226
|
+
if (state.root === '' || state.phase !== 'empty') return
|
|
227
|
+
if (dwAiModel() !== null) return
|
|
228
|
+
aiPrompted.current = true
|
|
229
|
+
setAiOpen(true)
|
|
230
|
+
}, [state.phase, state.root])
|
|
231
|
+
|
|
232
|
+
// Requirement: entering the window folds the shell's navigation column, so the
|
|
233
|
+
// explorer and the workbench get the whole frame. Leaving unfolds it again, but
|
|
234
|
+
// only if it is still folded.
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
// The settings page can keep the shell's navigation column where it is; the
|
|
237
|
+
// toolbar button still folds it on demand.
|
|
238
|
+
if (dwReadPrefs().autoHideSidebar === false) return undefined
|
|
239
|
+
if (dwHideSidebar(store)) {
|
|
240
|
+
sidebarHiddenRef.current = true
|
|
241
|
+
setSidebarHidden(true)
|
|
242
|
+
}
|
|
243
|
+
return () => {
|
|
244
|
+
if (!sidebarHiddenRef.current) return
|
|
245
|
+
sidebarHiddenRef.current = false
|
|
246
|
+
dwShowSidebar(store)
|
|
247
|
+
}
|
|
248
|
+
}, [store])
|
|
249
|
+
|
|
250
|
+
const toggleSidebar = () => {
|
|
251
|
+
if (sidebarHiddenRef.current || dwSidebarCollapsed()) {
|
|
252
|
+
sidebarHiddenRef.current = false
|
|
253
|
+
setSidebarHidden(false)
|
|
254
|
+
dwShowSidebar(store)
|
|
255
|
+
return
|
|
256
|
+
}
|
|
257
|
+
if (dwHideSidebar(store)) {
|
|
258
|
+
sidebarHiddenRef.current = true
|
|
259
|
+
setSidebarHidden(true)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Drag the divider between the explorer and the workbench; the width is stored
|
|
264
|
+
// per browser because it is a reading preference, not a per-project fact.
|
|
265
|
+
const startSideResize = (event) => {
|
|
266
|
+
if (event.button !== 0) return
|
|
267
|
+
event.preventDefault()
|
|
268
|
+
const startX = event.clientX
|
|
269
|
+
const startWidth = sideWidthRef.current
|
|
270
|
+
const panelWidth = panelRef.current?.getBoundingClientRect?.().width ?? globalThis.innerWidth
|
|
271
|
+
const max = Math.max(DW_SIDE_MIN + 40, Math.min(DW_SIDE_MAX, panelWidth - 360))
|
|
272
|
+
const previousSelect = document.body.style.userSelect
|
|
273
|
+
document.body.style.userSelect = 'none'
|
|
274
|
+
const move = (moveEvent) => {
|
|
275
|
+
const width = Math.min(max, Math.max(DW_SIDE_MIN, startWidth + moveEvent.clientX - startX))
|
|
276
|
+
sideWidthRef.current = width
|
|
277
|
+
setSideWidth(width)
|
|
278
|
+
}
|
|
279
|
+
const stop = () => {
|
|
280
|
+
globalThis.removeEventListener('pointermove', move)
|
|
281
|
+
globalThis.removeEventListener('pointerup', stop)
|
|
282
|
+
document.body.style.userSelect = previousSelect
|
|
283
|
+
globalThis.localStorage?.setItem(DW_SIDE_KEY, String(sideWidthRef.current))
|
|
284
|
+
}
|
|
285
|
+
globalThis.addEventListener('pointermove', move)
|
|
286
|
+
globalThis.addEventListener('pointerup', stop)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const resetSideWidth = () => {
|
|
290
|
+
sideWidthRef.current = DW_SIDE_DEFAULT
|
|
291
|
+
setSideWidth(DW_SIDE_DEFAULT)
|
|
292
|
+
globalThis.localStorage?.setItem(DW_SIDE_KEY, String(DW_SIDE_DEFAULT))
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// Requirement 3: one keystroke from the selected table to its create statement.
|
|
296
|
+
useEffect(() => {
|
|
297
|
+
const onKey = (event) => {
|
|
298
|
+
const modifier = event.metaKey || event.ctrlKey
|
|
299
|
+
const isDdl = event.key === 'F4' || (modifier && event.shiftKey && (event.key === 'd' || event.key === 'D'))
|
|
300
|
+
if (!isDdl) return
|
|
301
|
+
const selected = store.getState().selectedNode
|
|
302
|
+
if (selected === null || selected === undefined) return
|
|
303
|
+
if (selected.kind !== 'table' && selected.kind !== 'view') return
|
|
304
|
+
event.preventDefault()
|
|
305
|
+
event.stopPropagation()
|
|
306
|
+
void store.openDdl(selected)
|
|
307
|
+
}
|
|
308
|
+
globalThis.addEventListener('keydown', onKey, true)
|
|
309
|
+
return () => globalThis.removeEventListener('keydown', onKey, true)
|
|
310
|
+
}, [store])
|
|
311
|
+
|
|
312
|
+
// Escape closes the context menu, the same way the shipped menus behave.
|
|
313
|
+
useEffect(() => {
|
|
314
|
+
if (menu === null) return
|
|
315
|
+
const onKey = (event) => {
|
|
316
|
+
if (event.key === 'Escape') setMenu(null)
|
|
317
|
+
}
|
|
318
|
+
globalThis.addEventListener('keydown', onKey)
|
|
319
|
+
return () => globalThis.removeEventListener('keydown', onKey)
|
|
320
|
+
}, [menu])
|
|
321
|
+
|
|
322
|
+
// The log follows the newest line while it is open; a user who scrolled up is
|
|
323
|
+
// left where they are, because the next line would otherwise yank them away.
|
|
324
|
+
useEffect(() => {
|
|
325
|
+
const node = logRef.current
|
|
326
|
+
if (node === null || state.logOpen !== true) return
|
|
327
|
+
node.scrollTop = node.scrollHeight
|
|
328
|
+
}, [state.log, state.logOpen])
|
|
329
|
+
|
|
330
|
+
const activeTab = (state.tabs ?? []).find((tab) => tab.id === state.activeTab)
|
|
331
|
+
const environments = state.environments ?? []
|
|
332
|
+
// The palette is owned by the code workspace; watch it so switching there
|
|
333
|
+
// recolours this panel without a reload.
|
|
334
|
+
const themeId = useSyncExternalStore(dwSubscribeTheme, dwSharedTheme, dwSharedTheme)
|
|
335
|
+
useEffect(() => { dwWatchTheme() }, [])
|
|
336
|
+
|
|
337
|
+
// Every Workspace the shell knows, plus the current root when it is not a
|
|
338
|
+
// registered Workspace yet (a directory picked by hand).
|
|
339
|
+
const projectItems = []
|
|
340
|
+
const seenProjectPaths = new Set()
|
|
341
|
+
for (const item of Array.isArray(workspaces?.items) ? workspaces.items : []) {
|
|
342
|
+
const path = typeof item?.path === 'string' ? item.path.replace(/\/+$/, '') : ''
|
|
343
|
+
if (path === '' || seenProjectPaths.has(path)) continue
|
|
344
|
+
seenProjectPaths.add(path)
|
|
345
|
+
const title = typeof item?.title === 'string' && item.title.trim() !== '' ? item.title.trim() : dwBasename(path)
|
|
346
|
+
projectItems.push({ path, title })
|
|
347
|
+
}
|
|
348
|
+
const currentRoot = state.root === '' ? '' : state.root.replace(/\/+$/, '')
|
|
349
|
+
if (currentRoot !== '' && !seenProjectPaths.has(currentRoot)) {
|
|
350
|
+
projectItems.unshift({ path: currentRoot, title: dwBasename(currentRoot) })
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const pickWorkspace = async () => {
|
|
354
|
+
if (typeof pickDirectory !== 'function') return
|
|
355
|
+
try {
|
|
356
|
+
const picked = await pickDirectory()
|
|
357
|
+
if (typeof picked !== 'string' || picked === '') return
|
|
358
|
+
store.setManualRoot(picked)
|
|
359
|
+
} catch (error) {
|
|
360
|
+
store.pushLog('error', tr('log.pickFailed', { message: error?.message ?? error }))
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const toolbar = h('div', { key: 'toolbar', className: 'dw-toolbar' }, [
|
|
365
|
+
h('span', { key: 'ic', className: 'dw-node-icon' }, h(DwIcon, { name: 'database-play', size: 15 })),
|
|
366
|
+
h('div', { key: 'title', className: 'dw-toolbar-title' }, [
|
|
367
|
+
h(DwProjectMenu, {
|
|
368
|
+
key: 'ws',
|
|
369
|
+
state,
|
|
370
|
+
projects: projectItems,
|
|
371
|
+
tr,
|
|
372
|
+
onSelect: (path) => store.setManualRoot(path),
|
|
373
|
+
onFollow: () => store.followDetected(),
|
|
374
|
+
}),
|
|
375
|
+
h('span', { key: 'path', className: 'dw-toolbar-path', title: state.root }, state.root),
|
|
376
|
+
]),
|
|
377
|
+
environments.length > 0 ? h('span', { key: 'envs', className: 'dw-badge', style: { marginLeft: 0 } }, `${environments.length} ${tr('environments')}`) : null,
|
|
378
|
+
state.manual === true
|
|
379
|
+
? h('span', { key: 'manual', className: 'dw-badge', style: { marginLeft: 0 }, title: state.detected }, tr('manualWorkspace'))
|
|
380
|
+
: null,
|
|
381
|
+
h('span', { key: 'sp', className: 'dw-spacer' }),
|
|
382
|
+
h('button', {
|
|
383
|
+
key: 'sidebar',
|
|
384
|
+
type: 'button',
|
|
385
|
+
className: 'dw-btn dw-btn-icon',
|
|
386
|
+
onClick: toggleSidebar,
|
|
387
|
+
title: sidebarHidden ? tr('showSidebar') : tr('hideSidebar'),
|
|
388
|
+
'aria-label': sidebarHidden ? tr('showSidebar') : tr('hideSidebar'),
|
|
389
|
+
}, h(DwIcon, { name: 'panel', size: 13 })),
|
|
390
|
+
h('button', {
|
|
391
|
+
key: 'refresh',
|
|
392
|
+
type: 'button',
|
|
393
|
+
className: 'dw-btn',
|
|
394
|
+
disabled: state.root === '' || state.refreshing === true || state.phase === 'loading',
|
|
395
|
+
onClick: () => void store.loadDiscovery({ refresh: true }),
|
|
396
|
+
title: tr('refreshHint'),
|
|
397
|
+
}, [
|
|
398
|
+
h(DwIcon, { key: 'i', name: state.refreshing === true || state.phase === 'loading' ? 'spinner' : 'refresh', size: 12 }),
|
|
399
|
+
h('span', { key: 't' }, tr('refresh')),
|
|
400
|
+
]),
|
|
401
|
+
])
|
|
402
|
+
|
|
403
|
+
const selectedTable = state.selectedNode !== null
|
|
404
|
+
&& state.selectedNode !== undefined
|
|
405
|
+
&& (state.selectedNode.kind === 'table' || state.selectedNode.kind === 'view')
|
|
406
|
+
|
|
407
|
+
const side = h('aside', { key: 'side', className: 'dw-side', style: { width: sideWidth } }, [
|
|
408
|
+
h('div', { key: 'head', className: 'dw-side-head' }, [
|
|
409
|
+
h('span', { key: 't' }, tr('treeTitle')),
|
|
410
|
+
h('span', { key: 'sp', className: 'dw-spacer' }),
|
|
411
|
+
selectedTable === true ? h('span', { key: 'n' }, tr('ddlShortcutHint')) : null,
|
|
412
|
+
// These two belong to the tree, so they live in the tree's own header.
|
|
413
|
+
h('button', {
|
|
414
|
+
key: 'ai',
|
|
415
|
+
type: 'button',
|
|
416
|
+
className: 'dw-btn dw-btn-icon',
|
|
417
|
+
disabled: state.root === '' || state.aiRunning === true,
|
|
418
|
+
onClick: () => setAiOpen(true),
|
|
419
|
+
title: tr('aiOpenHint'),
|
|
420
|
+
'aria-label': tr('aiOpen'),
|
|
421
|
+
}, h(DwIcon, { key: 'i', name: state.aiRunning === true ? 'spinner' : 'ai', size: 12 })),
|
|
422
|
+
h('button', {
|
|
423
|
+
// A distinct key: the manual-workspace badge in the toolbar already owns
|
|
424
|
+
// 'manual', and duplicate keys make React reuse one node for both.
|
|
425
|
+
key: 'add-manual',
|
|
426
|
+
type: 'button',
|
|
427
|
+
className: 'dw-btn dw-btn-icon',
|
|
428
|
+
disabled: state.root === '',
|
|
429
|
+
onClick: () => setManualOpen(true),
|
|
430
|
+
title: tr('manualOpenHint'),
|
|
431
|
+
'aria-label': tr('manualOpen'),
|
|
432
|
+
}, h(DwIcon, { key: 'i', name: 'plus', size: 12 })),
|
|
433
|
+
]),
|
|
434
|
+
h('div', { key: 'filter', style: { padding: '5px 8px', borderBottom: '1px solid var(--dsw-alias-border-l1)' } }, [
|
|
435
|
+
h('input', {
|
|
436
|
+
key: 'i',
|
|
437
|
+
type: 'search',
|
|
438
|
+
value: state.filter ?? '',
|
|
439
|
+
placeholder: tr('filterPlaceholder'),
|
|
440
|
+
onChange: (event) => store.patch({ filter: event.target.value }),
|
|
441
|
+
style: {
|
|
442
|
+
width: '100%',
|
|
443
|
+
height: 24,
|
|
444
|
+
padding: '0 8px',
|
|
445
|
+
borderRadius: 6,
|
|
446
|
+
border: '1px solid var(--dsw-alias-border-l1, #31353d)',
|
|
447
|
+
background: 'var(--dsw-alias-bg-layer-2, #262930)',
|
|
448
|
+
color: 'inherit',
|
|
449
|
+
font: 'inherit',
|
|
450
|
+
fontSize: 12,
|
|
451
|
+
outline: 'none',
|
|
452
|
+
},
|
|
453
|
+
}),
|
|
454
|
+
]),
|
|
455
|
+
h(DwTree, {
|
|
456
|
+
key: 'tree',
|
|
457
|
+
store,
|
|
458
|
+
state,
|
|
459
|
+
tr,
|
|
460
|
+
onContextMenu: (event, node) => setMenu({ x: event.clientX, y: event.clientY, node }),
|
|
461
|
+
onChooseDatabases: (node) => setSchemaTarget(node),
|
|
462
|
+
}),
|
|
463
|
+
])
|
|
464
|
+
|
|
465
|
+
let main
|
|
466
|
+
if (state.root === '') {
|
|
467
|
+
main = h('div', { key: 'main', className: 'dw-main' }, h(DwEmpty, {
|
|
468
|
+
tr,
|
|
469
|
+
state,
|
|
470
|
+
onPick: pickWorkspace,
|
|
471
|
+
onOpenAi: () => setAiOpen(true),
|
|
472
|
+
onOpenManual: () => setManualOpen(true),
|
|
473
|
+
}))
|
|
474
|
+
} else if (state.phase === 'loading' && environments.length === 0) {
|
|
475
|
+
main = h('div', { key: 'main', className: 'dw-main' }, h('div', { className: 'dw-empty' }, [
|
|
476
|
+
h(DwIcon, { key: 'i', name: 'spinner', size: 20 }),
|
|
477
|
+
h('div', { key: 't', className: 'dw-empty-title' }, tr('discovering')),
|
|
478
|
+
h('div', { key: 'h', className: 'dw-empty-hint' }, tr('discoveringHint')),
|
|
479
|
+
]))
|
|
480
|
+
} else {
|
|
481
|
+
main = h('div', { key: 'main', className: 'dw-main' }, [
|
|
482
|
+
h(DwTabs, { key: 'tabs', store, state, tr }),
|
|
483
|
+
activeTab === undefined
|
|
484
|
+
? h(DwEmpty, { key: 'empty', tr, state, onPick: pickWorkspace, onOpenAi: () => setAiOpen(true), onOpenManual: () => setManualOpen(true) })
|
|
485
|
+
: activeTab.kind === 'ddl'
|
|
486
|
+
? h(DwDdlView, { key: activeTab.id, tab: activeTab, tr, store })
|
|
487
|
+
: h(React.Fragment, { key: activeTab.id }, [
|
|
488
|
+
h(DwEditor, {
|
|
489
|
+
key: 'editor',
|
|
490
|
+
store,
|
|
491
|
+
tab: activeTab,
|
|
492
|
+
tr,
|
|
493
|
+
height: editorHeight,
|
|
494
|
+
schema: state.schemas?.get(activeTab.dbId),
|
|
495
|
+
onRun: (statement) => void store.runActiveTab(statement),
|
|
496
|
+
}),
|
|
497
|
+
h(DwDragHandle, {
|
|
498
|
+
key: 'drag',
|
|
499
|
+
value: editorHeight,
|
|
500
|
+
min: DW_EDITOR_MIN,
|
|
501
|
+
max: DW_EDITOR_MAX,
|
|
502
|
+
onChange: setEditorHeight,
|
|
503
|
+
}),
|
|
504
|
+
h(DwResults, { key: 'results', store, state, tab: activeTab, tr }),
|
|
505
|
+
]),
|
|
506
|
+
])
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
const log = h('div', { key: 'log', className: `dw-log${state.logOpen === true ? '' : ' dw-log-collapsed'}` }, [
|
|
510
|
+
h('div', { key: 'bar', className: 'dw-log-bar' }, [
|
|
511
|
+
h('button', {
|
|
512
|
+
key: 'toggle',
|
|
513
|
+
type: 'button',
|
|
514
|
+
className: 'dw-log-toggle',
|
|
515
|
+
title: tr('logTitle'),
|
|
516
|
+
onClick: () => store.setLogOpen(state.logOpen !== true),
|
|
517
|
+
}, [
|
|
518
|
+
h(DwIcon, { key: 'i', name: 'chevron', size: 10, className: state.logOpen === true ? 'dw-rot-down' : '' }),
|
|
519
|
+
h('span', { key: 't' }, tr('logTitle')),
|
|
520
|
+
h('span', { key: 'c' }, `${state.log.length}`),
|
|
521
|
+
]),
|
|
522
|
+
state.log.some((entry) => entry.level === 'error')
|
|
523
|
+
? h('span', { key: 'err', className: 'dw-log-error' }, tr('logHasError'))
|
|
524
|
+
: null,
|
|
525
|
+
h('span', { key: 'sp', className: 'dw-spacer' }),
|
|
526
|
+
h('button', {
|
|
527
|
+
key: 'clear',
|
|
528
|
+
type: 'button',
|
|
529
|
+
className: 'dw-btn',
|
|
530
|
+
style: { height: 20, fontSize: 11 },
|
|
531
|
+
onClick: () => store.patch({ log: [] }),
|
|
532
|
+
}, tr('clear')),
|
|
533
|
+
]),
|
|
534
|
+
h('div', { key: 'body', className: 'dw-log-body', ref: logRef }, state.log.map((entry) => h('div', {
|
|
535
|
+
key: entry.id,
|
|
536
|
+
className: `dw-log-line ${entry.level === 'error' ? 'dw-log-error' : entry.level === 'warn' ? 'dw-log-warn' : entry.level === 'ok' ? 'dw-log-ok' : entry.level === 'sql' ? 'dw-log-sql' : ''}`,
|
|
537
|
+
}, [
|
|
538
|
+
h('b', { key: 't' }, `[${dwClock(entry.at)}] `),
|
|
539
|
+
entry.level === 'sql' ? h('span', { key: 'tag', className: 'dw-log-tag' }, 'SQL') : null,
|
|
540
|
+
entry.text,
|
|
541
|
+
]))),
|
|
542
|
+
])
|
|
543
|
+
|
|
544
|
+
// The menu is fixed-positioned inside a clipped panel, so it is clamped to the
|
|
545
|
+
// panel's own rectangle instead of the viewport: otherwise a menu opened near the
|
|
546
|
+
// bottom edge would be cut in half.
|
|
547
|
+
let menuLayer = null
|
|
548
|
+
if (menu !== null) {
|
|
549
|
+
const rect = panelRef.current?.getBoundingClientRect?.()
|
|
550
|
+
const width = 210
|
|
551
|
+
const height = 230
|
|
552
|
+
const left = rect === undefined ? menu.x : Math.min(menu.x, rect.right - width)
|
|
553
|
+
const top = rect === undefined ? menu.y : Math.min(menu.y, rect.bottom - height)
|
|
554
|
+
menuLayer = h(React.Fragment, null, [
|
|
555
|
+
h('div', { key: 'backdrop', className: 'dw-backdrop', onClick: () => setMenu(null), onContextMenu: (event) => { event.preventDefault(); setMenu(null) } }),
|
|
556
|
+
h('div', {
|
|
557
|
+
key: 'menu',
|
|
558
|
+
className: 'dw-menu',
|
|
559
|
+
style: {
|
|
560
|
+
left: Math.max(rect === undefined ? 0 : rect.left, left),
|
|
561
|
+
top: Math.max(rect === undefined ? 0 : rect.top, top),
|
|
562
|
+
},
|
|
563
|
+
}, dwMenuItems(menu.node, store, tr, () => setMenu(null), (node) => setSchemaTarget(node), (node) => setRenameTarget(node), (node) => setRemoveEnvTarget(node))),
|
|
564
|
+
])
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
return h('div', { className: 'dw-root', ref: panelRef, 'data-dsh-theme': themeId === '' ? undefined : themeId }, [
|
|
568
|
+
h(DwStyles, { key: 'style' }),
|
|
569
|
+
toolbar,
|
|
570
|
+
h('div', { key: 'body', className: 'dw-body' }, [
|
|
571
|
+
side,
|
|
572
|
+
h('div', {
|
|
573
|
+
key: 'resizer',
|
|
574
|
+
className: 'dw-resizer',
|
|
575
|
+
role: 'separator',
|
|
576
|
+
'aria-orientation': 'vertical',
|
|
577
|
+
title: tr('resizeTree'),
|
|
578
|
+
onPointerDown: startSideResize,
|
|
579
|
+
onDoubleClick: resetSideWidth,
|
|
580
|
+
}),
|
|
581
|
+
main,
|
|
582
|
+
]),
|
|
583
|
+
log,
|
|
584
|
+
menuLayer,
|
|
585
|
+
aiOpen ? h(DwAiDialog, {
|
|
586
|
+
key: 'ai-dialog',
|
|
587
|
+
store,
|
|
588
|
+
tr,
|
|
589
|
+
onClose: () => setAiOpen(false),
|
|
590
|
+
onManual: () => {
|
|
591
|
+
setAiOpen(false)
|
|
592
|
+
setManualOpen(true)
|
|
593
|
+
},
|
|
594
|
+
}) : null,
|
|
595
|
+
manualOpen ? h(DwManualDialog, {
|
|
596
|
+
key: 'manual-dialog',
|
|
597
|
+
store,
|
|
598
|
+
tr,
|
|
599
|
+
onClose: () => setManualOpen(false),
|
|
600
|
+
onSaved: () => void store.loadDiscovery({ quiet: true }),
|
|
601
|
+
}) : null,
|
|
602
|
+
removeEnvTarget === null ? null : h(DwConfirmDialog, {
|
|
603
|
+
key: 'remove-env-dialog',
|
|
604
|
+
tr,
|
|
605
|
+
title: tr('removeEnvironmentTitle'),
|
|
606
|
+
message: tr('removeEnvironmentHint', { name: removeEnvTarget.label }),
|
|
607
|
+
confirmLabel: tr('removeEnvironmentConfirm'),
|
|
608
|
+
onClose: () => setRemoveEnvTarget(null),
|
|
609
|
+
onConfirm: async () => {
|
|
610
|
+
await store.removeManualEnvironment(removeEnvTarget.label)
|
|
611
|
+
setRemoveEnvTarget(null)
|
|
612
|
+
},
|
|
613
|
+
}),
|
|
614
|
+
renameTarget === null ? null : h(DwRenameEnvDialog, {
|
|
615
|
+
key: 'rename-dialog',
|
|
616
|
+
store,
|
|
617
|
+
tr,
|
|
618
|
+
label: renameTarget.label,
|
|
619
|
+
onClose: () => setRenameTarget(null),
|
|
620
|
+
onRenamed: () => void store.loadDiscovery({ quiet: true }),
|
|
621
|
+
}),
|
|
622
|
+
schemaTarget === null ? null : h(DwSchemaDialog, {
|
|
623
|
+
key: 'schema-dialog',
|
|
624
|
+
store,
|
|
625
|
+
tr,
|
|
626
|
+
instance: schemaTarget,
|
|
627
|
+
onClose: () => setSchemaTarget(null),
|
|
628
|
+
}),
|
|
629
|
+
])
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/** Local wall-clock time for one log line. */
|
|
633
|
+
function dwClock(date) {
|
|
634
|
+
const value = date instanceof Date ? date : new Date()
|
|
635
|
+
const pad = (number) => String(number).padStart(2, '0')
|
|
636
|
+
return `${pad(value.getHours())}:${pad(value.getMinutes())}:${pad(value.getSeconds())}`
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
/** The context menu of one node. */
|
|
640
|
+
function dwMenuItems(node, store, tr, close, openSchemaDialog, openRenameEnv, openRemoveEnv) {
|
|
641
|
+
const items = []
|
|
642
|
+
const add = (key, label, shortcut, run, tone) => items.push(h('button', {
|
|
643
|
+
key,
|
|
644
|
+
type: 'button',
|
|
645
|
+
className: tone === undefined ? 'dw-menu-item' : `dw-menu-item ${tone}`,
|
|
646
|
+
onClick: () => {
|
|
647
|
+
close()
|
|
648
|
+
run()
|
|
649
|
+
},
|
|
650
|
+
}, [h('span', { key: 'l' }, label), shortcut === '' ? null : h('span', { key: 's', className: 'dw-menu-shortcut' }, shortcut)]))
|
|
651
|
+
|
|
652
|
+
if (node.kind === 'table' || node.kind === 'view') {
|
|
653
|
+
add('ddl', tr('menuDdl'), 'F4', () => void store.openDdl(node))
|
|
654
|
+
add('data', tr('menuOpenData'), '', () => {
|
|
655
|
+
const statement = `SELECT *\nFROM \`${node.database}\`.\`${node.table}\`\nLIMIT 100`
|
|
656
|
+
store.seedStatement(node, statement)
|
|
657
|
+
void store.runActiveTab(statement)
|
|
658
|
+
})
|
|
659
|
+
add('refresh', tr('refreshStructure'), '', () => void store.refreshNode(node))
|
|
660
|
+
add('name', tr('menuCopyName'), '', () => {
|
|
661
|
+
const write = globalThis.navigator?.clipboard?.writeText?.(node.table)
|
|
662
|
+
if (write !== undefined) write.then(() => store.pushLog('info', tr('log.copiedName', { name: node.table }))).catch(() => undefined)
|
|
663
|
+
})
|
|
664
|
+
} else if (node.kind === 'database') {
|
|
665
|
+
add('open', tr('menuOpenConsole'), '', () => store.openDatabase(node))
|
|
666
|
+
add('refresh', tr('refreshStructure'), '', () => void store.refreshNode(node))
|
|
667
|
+
if (node.remembered === true) {
|
|
668
|
+
add('forget-database', tr('forgetDatabase'), '', () => void store.forgetDatabase(node), 'dw-menu-danger')
|
|
669
|
+
}
|
|
670
|
+
} else if (node.kind === 'instance') {
|
|
671
|
+
add('pick', tr('chooseDatabases'), '', () => openSchemaDialog(node))
|
|
672
|
+
add('refresh', tr('refreshStructure'), '', () => void store.refreshNode(node))
|
|
673
|
+
if (node.manual === true && typeof node.entryId === 'string') {
|
|
674
|
+
add('remove-manual', tr('removeConnection'), '', () => void store.removeManual(node.entryId), 'dw-menu-danger')
|
|
675
|
+
}
|
|
676
|
+
} else if (node.kind === 'env') {
|
|
677
|
+
add('expand', tr('menuExpand'), '', () => void store.toggleNode(node))
|
|
678
|
+
if (node.manual === true) {
|
|
679
|
+
add('rename', tr('renameEnvironment'), '', () => openRenameEnv(node))
|
|
680
|
+
add('remove-env', tr('removeEnvironment'), '', () => openRemoveEnv(node), 'dw-menu-danger')
|
|
681
|
+
}
|
|
682
|
+
} else if (node.kind === 'column') {
|
|
683
|
+
add('name', tr('menuCopyName'), '', () => {
|
|
684
|
+
const write = globalThis.navigator?.clipboard?.writeText?.(node.label)
|
|
685
|
+
if (write !== undefined) write.then(() => store.pushLog('info', tr('log.copiedName', { name: node.label }))).catch(() => undefined)
|
|
686
|
+
})
|
|
687
|
+
}
|
|
688
|
+
if (items.length === 0) items.push(h('div', { key: 'none', className: 'dw-menu-item', style: { opacity: .5 } }, tr('menuEmpty')))
|
|
689
|
+
return items
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* The panel's empty state.
|
|
694
|
+
*
|
|
695
|
+
* Three different situations used to share one misleading sentence: no workspace,
|
|
696
|
+
* a workspace whose configuration resolved no database, and a workspace whose
|
|
697
|
+
* configuration failed. Each one now says what happened and what to do next.
|
|
698
|
+
*/
|
|
699
|
+
function DwEmpty({ tr, state, onPick, onOpenAi, onOpenManual }) {
|
|
700
|
+
const warnings = state.warnings ?? []
|
|
701
|
+
const canUseAi = state.root !== '' && (state.environments ?? []).length === 0
|
|
702
|
+
const states = []
|
|
703
|
+
if (state.root === '') {
|
|
704
|
+
states.push({ title: tr('emptyTitle'), hint: tr('emptyHint') })
|
|
705
|
+
} else if (state.phase === 'error') {
|
|
706
|
+
states.push({ title: tr('stateError'), hint: state.discoveryError })
|
|
707
|
+
} else if ((state.environments ?? []).length === 0) {
|
|
708
|
+
states.push({ title: tr('emptyNoEnvTitle'), hint: tr('emptyNoEnvHint') })
|
|
709
|
+
} else {
|
|
710
|
+
states.push({ title: tr('emptyReadyTitle'), hint: tr('emptyReadyHint') })
|
|
711
|
+
}
|
|
712
|
+
const current = states[0]
|
|
713
|
+
|
|
714
|
+
return h('div', { className: 'dw-empty' }, [
|
|
715
|
+
h('div', { key: 't', className: 'dw-empty-title' }, current.title),
|
|
716
|
+
h('div', { key: 'h', className: 'dw-empty-hint' }, current.hint),
|
|
717
|
+
h('div', { key: 'k', className: 'dw-empty-hint', style: { fontSize: 11.5, opacity: .8 } }, tr('shortcutSummary')),
|
|
718
|
+
h('button', { key: 'b', type: 'button', className: 'dw-btn', onClick: onPick }, tr('pickWorkspace')),
|
|
719
|
+
canUseAi === true
|
|
720
|
+
? h('button', {
|
|
721
|
+
key: 'ai',
|
|
722
|
+
type: 'button',
|
|
723
|
+
className: 'dw-btn dw-btn-accent',
|
|
724
|
+
disabled: state.aiRunning === true,
|
|
725
|
+
onClick: onOpenAi,
|
|
726
|
+
}, [
|
|
727
|
+
h(DwIcon, { key: 'i', name: 'ai', size: 12 }),
|
|
728
|
+
h('span', { key: 't' }, state.aiRunning === true ? tr('aiRunningShort') : tr('aiOpen')),
|
|
729
|
+
])
|
|
730
|
+
: null,
|
|
731
|
+
canUseAi === true
|
|
732
|
+
? h('button', {
|
|
733
|
+
key: 'manual',
|
|
734
|
+
type: 'button',
|
|
735
|
+
className: 'dw-btn',
|
|
736
|
+
onClick: onOpenManual,
|
|
737
|
+
}, [
|
|
738
|
+
h(DwIcon, { key: 'i', name: 'plus', size: 12 }),
|
|
739
|
+
h('span', { key: 't' }, tr('manualOpen')),
|
|
740
|
+
])
|
|
741
|
+
: null,
|
|
742
|
+
canUseAi === true
|
|
743
|
+
? h('div', { key: 'aihint', className: 'dw-empty-hint', style: { fontSize: 11.5, opacity: .8 } }, tr('aiEmptyHint'))
|
|
744
|
+
: null,
|
|
745
|
+
warnings.length > 0
|
|
746
|
+
? h('div', { key: 'w', className: 'dw-code-block' }, warnings.map((warning) => dwWarningText(warning, tr)).join('\n'))
|
|
747
|
+
: null,
|
|
748
|
+
])
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/** Turn one discovery warning code into a sentence. */
|
|
752
|
+
function dwWarningText(code, tr) {
|
|
753
|
+
// A code may carry a detail after a colon (`unparsed-jdbc-url:spring.datasource`);
|
|
754
|
+
// the dictionary is keyed by the code alone.
|
|
755
|
+
const base = String(code).split(':')[0]
|
|
756
|
+
const key = `warning.${base}`
|
|
757
|
+
const text = tr(key)
|
|
758
|
+
return text === key ? `· ${code}` : `· ${text}`
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
export { DwPanel, DwTracker, dwResolveRoot, DwEmpty, dwWarningText }
|