@slack/radar-mcp 1.17.1 → 1.18.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 +24 -7
- package/dist/mcp/flags-tools.d.ts +14 -9
- package/dist/mcp/flags-tools.js +70 -20
- package/dist/mcp/index.js +15 -4
- package/dist/mcp/platform-detect.d.ts +2 -0
- package/dist/mcp/platform-detect.js +2 -0
- package/dist/mcp/tools.js +4 -3
- package/dist/shared/android-dashboard-screen.d.ts +15 -0
- package/dist/shared/android-dashboard-screen.js +48 -0
- package/dist/shared/android.d.ts +1 -0
- package/dist/shared/android.js +2 -0
- package/dist/shared/dashboard-screen.d.ts +35 -0
- package/dist/shared/dashboard-screen.js +12 -0
- package/dist/shared/ios-dashboard-screen.d.ts +32 -0
- package/dist/shared/ios-dashboard-screen.js +266 -0
- package/dist/shared/ios.d.ts +72 -0
- package/dist/shared/ios.js +313 -0
- package/dist/shared/platform.d.ts +3 -0
- package/dist/shared/platform.js +16 -0
- package/dist/shared/screen-artifacts.d.ts +10 -0
- package/dist/shared/screen-artifacts.js +57 -0
- package/dist/shared/screen.d.ts +20 -5
- package/dist/shared/screen.js +35 -39
- package/dist/shared/transport.d.ts +38 -0
- package/dist/shared/webapp.d.ts +1 -0
- package/dist/shared/webapp.js +2 -0
- package/dist/web/public/index.html +51 -11
- package/dist/web/public/next/db.js +292 -39
- package/dist/web/public/next/flags.js +306 -48
- package/dist/web/public/next/screen.js +76 -11
- package/dist/web/public/next/store.js +1 -1
- package/dist/web/server.d.ts +2 -3
- package/dist/web/server.js +169 -74
- package/package.json +3 -2
|
@@ -11,6 +11,108 @@
|
|
|
11
11
|
import { html } from "./html.js";
|
|
12
12
|
import { useState, useEffect, useCallback, useRef } from "preact/hooks";
|
|
13
13
|
import { useLatestRef, useGlobalKeydown } from "./hooks.js";
|
|
14
|
+
// --- query history ---
|
|
15
|
+
// The queries you ran by hand in this tab, newest-first, per database AND per profile (the same
|
|
16
|
+
// filename means a different store on a different user). Persisted in localStorage so it
|
|
17
|
+
// survives a reload; when storage is unusable (privacy mode raises on every access) we fall back
|
|
18
|
+
// to this module-level map so history still works for the session.
|
|
19
|
+
const HISTORY_KEY = "radar-db-history";
|
|
20
|
+
const HISTORY_CAP = 25;
|
|
21
|
+
let memHistory = {};
|
|
22
|
+
// Latched on the FIRST storage failure, read or write. Without this, a write-only failure (quota
|
|
23
|
+
// exceeded; reads keep working) went stale on the very next read: readHistoryMap only consulted
|
|
24
|
+
// memHistory when the read itself threw, so it happily returned the untouched, pre-failure
|
|
25
|
+
// localStorage value and the just-recorded entry vanished. Once storage has failed once, treat it
|
|
26
|
+
// as unusable for the rest of the session rather than racing a fallback against it.
|
|
27
|
+
let historyStorageBroken = false;
|
|
28
|
+
function historySlot(user, db) {
|
|
29
|
+
return (user ?? "") + "|" + db;
|
|
30
|
+
}
|
|
31
|
+
// Test-only: both fields above are module-level singletons that outlive any one test's
|
|
32
|
+
// localStorage stub, so a leftover write or a latched failure from an earlier test would
|
|
33
|
+
// otherwise leak into the next. Centralized so a future third field cannot be forgotten.
|
|
34
|
+
export function _resetHistoryStateForTest() {
|
|
35
|
+
memHistory = {};
|
|
36
|
+
historyStorageBroken = false;
|
|
37
|
+
}
|
|
38
|
+
// Read the whole map. Once storage is known broken, or a fresh access fails, this returns the
|
|
39
|
+
// in-memory map; a corrupt or non-object stored value reads as empty (and the next write
|
|
40
|
+
// overwrites it), so a bad value cannot wedge the tab.
|
|
41
|
+
function readHistoryMap() {
|
|
42
|
+
if (historyStorageBroken)
|
|
43
|
+
return memHistory;
|
|
44
|
+
let raw;
|
|
45
|
+
try {
|
|
46
|
+
raw = localStorage.getItem(HISTORY_KEY);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
historyStorageBroken = true;
|
|
50
|
+
return memHistory;
|
|
51
|
+
}
|
|
52
|
+
if (!raw)
|
|
53
|
+
return {};
|
|
54
|
+
try {
|
|
55
|
+
const parsed = JSON.parse(raw);
|
|
56
|
+
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return {};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function writeHistoryMap(map) {
|
|
63
|
+
// Kept current on every write, not just a failed one: if a LATER write fails, the fallback
|
|
64
|
+
// must already hold this write's data, not whatever was last written successfully.
|
|
65
|
+
memHistory = map;
|
|
66
|
+
if (historyStorageBroken)
|
|
67
|
+
return;
|
|
68
|
+
try {
|
|
69
|
+
localStorage.setItem(HISTORY_KEY, JSON.stringify(map));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
historyStorageBroken = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function readHistory(user, db) {
|
|
76
|
+
const list = readHistoryMap()[historySlot(user, db)];
|
|
77
|
+
return Array.isArray(list) ? list.filter((q) => typeof q === "string") : [];
|
|
78
|
+
}
|
|
79
|
+
// Push `sql` onto the front of this database's history and persist, returning the new list. A
|
|
80
|
+
// query already in the list moves to the top rather than adding a duplicate.
|
|
81
|
+
function pushHistory(user, db, sql) {
|
|
82
|
+
const map = readHistoryMap();
|
|
83
|
+
const slot = historySlot(user, db);
|
|
84
|
+
const prev = Array.isArray(map[slot]) ? map[slot] : [];
|
|
85
|
+
const next = [sql, ...prev.filter((q) => q !== sql)].slice(0, HISTORY_CAP);
|
|
86
|
+
writeHistoryMap({ ...map, [slot]: next });
|
|
87
|
+
return next;
|
|
88
|
+
}
|
|
89
|
+
function clearHistory(user, db) {
|
|
90
|
+
const map = readHistoryMap();
|
|
91
|
+
delete map[historySlot(user, db)];
|
|
92
|
+
writeHistoryMap(map);
|
|
93
|
+
}
|
|
94
|
+
// Whether the right dock was left open on the history tab. Only the history tab is remembered:
|
|
95
|
+
// the row tab needs a selected row, which no reload can restore.
|
|
96
|
+
const DOCK_KEY = "radar-db-dock";
|
|
97
|
+
function readDockPref() {
|
|
98
|
+
try {
|
|
99
|
+
return localStorage.getItem(DOCK_KEY) === "history";
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function writeDockPref(open) {
|
|
106
|
+
try {
|
|
107
|
+
if (open)
|
|
108
|
+
localStorage.setItem(DOCK_KEY, "history");
|
|
109
|
+
else
|
|
110
|
+
localStorage.removeItem(DOCK_KEY);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
/* privacy mode: the dock still works, it just will not be remembered */
|
|
114
|
+
}
|
|
115
|
+
}
|
|
14
116
|
function profileLabel(u) {
|
|
15
117
|
return u === "" || u == null ? "device" : u === "0" ? "personal (user 0)" : "secondary (user " + u + ")";
|
|
16
118
|
}
|
|
@@ -50,16 +152,22 @@ export function DbBrowser({ spec }) {
|
|
|
50
152
|
const [sql, setSql] = useState("");
|
|
51
153
|
const [out, setOut] = useState({ msg: "pick a database, then a table" });
|
|
52
154
|
const [meta, setMeta] = useState("");
|
|
53
|
-
// The result row whose full detail is open in the
|
|
54
|
-
//
|
|
155
|
+
// The result row whose full detail is open in the dock. Cleared whenever a new query runs,
|
|
156
|
+
// since a stale row index would point into the old result set.
|
|
55
157
|
const [selectedRow, setSelectedRow] = useState(null);
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
|
|
59
|
-
//
|
|
158
|
+
// What the right-hand dock is showing, if anything. Row detail and query history share one
|
|
159
|
+
// dock (tabbed) so the results grid never has to give up width to two panels at once.
|
|
160
|
+
const [dock, setDock] = useState(() => (readDockPref() ? "history" : null));
|
|
161
|
+
// The current database's query history, newest-first (see the history helpers above).
|
|
162
|
+
const [history, setHistory] = useState([]);
|
|
163
|
+
// keyboard nav: which pane has focus (the "db", "tbl", or "hist" list) + the highlighted index
|
|
164
|
+
// in each. j/k and Up/Down move the highlight within a pane, Enter drills in (or re-runs, in
|
|
165
|
+
// the history pane), Esc backs out to the db list, Tab cycles panes. Arrow keys are consumed
|
|
166
|
+
// here (preventDefault) so list navigation does not also scroll the page.
|
|
60
167
|
const [pane, setPane] = useState("db");
|
|
61
168
|
const [dbIdx, setDbIdx] = useState(0);
|
|
62
169
|
const [tblIdx, setTblIdx] = useState(0);
|
|
170
|
+
const [histIdx, setHistIdx] = useState(0);
|
|
63
171
|
const userQS = useCallback((u) => (u != null ? "&user=" + encodeURIComponent(u) : ""), []);
|
|
64
172
|
const loadList = useCallback(async (u) => {
|
|
65
173
|
setDbs(null);
|
|
@@ -84,12 +192,17 @@ export function DbBrowser({ spec }) {
|
|
|
84
192
|
useEffect(() => {
|
|
85
193
|
setTblIdx((i) => Math.max(0, Math.min(((tables && tables.tables) || []).length - 1, i)));
|
|
86
194
|
}, [tables]);
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
setHistIdx((i) => Math.max(0, Math.min(history.length - 1, i)));
|
|
197
|
+
}, [history]);
|
|
87
198
|
const pickDb = useCallback(async (name, refresh) => {
|
|
88
199
|
setDb(name);
|
|
89
200
|
setSql("");
|
|
90
201
|
setSelectedRow(null); // resetting the output invalidates any open row panel
|
|
91
202
|
setOut({ msg: "pick a table or write a query" });
|
|
92
203
|
setTables(null);
|
|
204
|
+
setDock((d) => (d === "row" ? (readDockPref() ? "history" : null) : d));
|
|
205
|
+
setHistory(readHistory(user, name)); // history is per database, so it swaps with the db
|
|
93
206
|
try {
|
|
94
207
|
const r = await (
|
|
95
208
|
// Authored: /dbtables pulls a plaintext copy of the device database to local disk, so
|
|
@@ -103,21 +216,46 @@ export function DbBrowser({ spec }) {
|
|
|
103
216
|
setTables({ error: "network error loading tables" });
|
|
104
217
|
}
|
|
105
218
|
}, [user, userQS]);
|
|
219
|
+
// Open the first database as soon as a list arrives and nothing is picked yet. The tab is
|
|
220
|
+
// useless until something is open (no tables, no query bar controls, no results), and the first
|
|
221
|
+
// row already carries the keyboard highlight, so leaving it unopened reads as a broken tab.
|
|
222
|
+
// Guarded on `db` so this fires once per list: after it picks, db is set and the effect is a
|
|
223
|
+
// no-op until the list itself changes (a profile switch, which clears db, or a device remount).
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
if (db)
|
|
226
|
+
return;
|
|
227
|
+
const names = (dbs && !dbs.error && dbs.names) || [];
|
|
228
|
+
if (names.length)
|
|
229
|
+
void pickDb(names[0]);
|
|
230
|
+
}, [dbs, db, pickDb]);
|
|
106
231
|
const RENDER_LIMIT = 10000;
|
|
107
|
-
|
|
232
|
+
// `record` decides whether a successful query lands in the history. It defaults to "yes" for
|
|
233
|
+
// the no-argument call, which is the only path a human types into (Run / Enter in the SQL box);
|
|
234
|
+
// pickTable passes its generated SELECT explicitly so browsing the table list does not bury
|
|
235
|
+
// hand-written history under one entry per table.
|
|
236
|
+
const run = useCallback(async (q, record = q === undefined) => {
|
|
108
237
|
const theSql = q ?? sql;
|
|
109
238
|
if (!db || !theSql)
|
|
110
239
|
return;
|
|
111
|
-
|
|
240
|
+
// A new result set invalidates the open row, so the dock falls back to history (if that is
|
|
241
|
+
// where you left it) rather than staying on a row that no longer exists.
|
|
242
|
+
setSelectedRow(null);
|
|
243
|
+
setDock((d) => (d === "row" ? (readDockPref() ? "history" : null) : d));
|
|
112
244
|
setOut({ msg: "running…" });
|
|
113
245
|
try {
|
|
114
246
|
const r = await (
|
|
115
247
|
// Authored for the same reason as /dbtables: queryDatabase pulls the device database to
|
|
116
248
|
// local disk when no copy exists yet.
|
|
117
249
|
await fetch("/dbquery?db=" + encodeURIComponent(db) + "&sql=" + encodeURIComponent(theSql) + userQS(user), { headers: { "X-Radar-Dashboard": "1" } })).json();
|
|
118
|
-
if (r.error)
|
|
250
|
+
if (r.error) {
|
|
119
251
|
setOut({ error: r.error });
|
|
120
|
-
|
|
252
|
+
return; // a rejected query is not worth remembering
|
|
253
|
+
}
|
|
254
|
+
// Recorded on any answer the server accepted, 0 rows included -- an empty result is a
|
|
255
|
+
// legitimate query you may well want to run again.
|
|
256
|
+
if (record)
|
|
257
|
+
setHistory(pushHistory(user, db, theSql));
|
|
258
|
+
if (!r.rows || !r.rows.length) {
|
|
121
259
|
setOut({ rows: [] });
|
|
122
260
|
setMeta(db + " — 0 rows");
|
|
123
261
|
}
|
|
@@ -136,23 +274,63 @@ export function DbBrowser({ spec }) {
|
|
|
136
274
|
const pickTable = useCallback((t) => {
|
|
137
275
|
const q = 'SELECT * FROM "' + t + '" LIMIT 100';
|
|
138
276
|
setSql(q);
|
|
139
|
-
run(q);
|
|
277
|
+
run(q, false); // generated, not typed: keep it out of the history
|
|
278
|
+
}, [run]);
|
|
279
|
+
// Recall a history entry: put it back in the SQL box and run it. Recorded again so the query
|
|
280
|
+
// you just reached for moves back to the top of the list.
|
|
281
|
+
const recall = useCallback((q) => {
|
|
282
|
+
setSql(q);
|
|
283
|
+
run(q, true);
|
|
140
284
|
}, [run]);
|
|
285
|
+
const wipeHistory = useCallback(() => {
|
|
286
|
+
if (!db)
|
|
287
|
+
return;
|
|
288
|
+
clearHistory(user, db);
|
|
289
|
+
setHistory([]);
|
|
290
|
+
}, [db, user]);
|
|
291
|
+
// Drop keyboard focus out of the history pane. Called whenever the dock stops showing history,
|
|
292
|
+
// so j/k/Enter cannot keep acting on a list that is no longer on screen -- Enter in particular
|
|
293
|
+
// would otherwise re-run whatever was highlighted with nothing visible to show it came from.
|
|
294
|
+
const releaseHistFocus = useCallback(() => {
|
|
295
|
+
setPane((p) => (p === "hist" ? "db" : p));
|
|
296
|
+
}, []);
|
|
297
|
+
// The query-bar button: open the dock on history, or close it if that is already what it shows.
|
|
298
|
+
const toggleHistoryDock = useCallback(() => {
|
|
299
|
+
setDock((d) => {
|
|
300
|
+
const next = d === "history" ? null : "history";
|
|
301
|
+
writeDockPref(next === "history");
|
|
302
|
+
if (!next)
|
|
303
|
+
releaseHistFocus();
|
|
304
|
+
return next;
|
|
305
|
+
});
|
|
306
|
+
}, [releaseHistFocus]);
|
|
307
|
+
const closeDock = useCallback(() => {
|
|
308
|
+
setDock((d) => {
|
|
309
|
+
if (d === "history")
|
|
310
|
+
writeDockPref(false);
|
|
311
|
+
return null;
|
|
312
|
+
});
|
|
313
|
+
setSelectedRow(null);
|
|
314
|
+
releaseHistFocus();
|
|
315
|
+
}, [releaseHistFocus]);
|
|
141
316
|
// Scroll the keyboard-highlighted item into view as the focus index moves, so paging a long
|
|
142
317
|
// list with j/k keeps the green-outlined row on screen. block:nearest avoids a jump when it
|
|
143
|
-
// is already visible.
|
|
144
|
-
|
|
318
|
+
// is already visible. Scoped to the whole tab (viewRef wraps db/table rail AND the dock), not
|
|
319
|
+
// just the rail -- history rows render in the dock, a separate subtree, and a rail-only scope
|
|
320
|
+
// silently found nothing for them. The bare ".kbd" selector (rather than ".dbitem.kbd") is what
|
|
321
|
+
// matches a history row too; pane is exclusive, so exactly one row carries it at a time.
|
|
322
|
+
const viewRef = useRef(null);
|
|
145
323
|
useEffect(() => {
|
|
146
|
-
const el =
|
|
324
|
+
const el = viewRef.current && viewRef.current.querySelector(".kbd");
|
|
147
325
|
if (el && el.scrollIntoView)
|
|
148
326
|
el.scrollIntoView({ block: "nearest" });
|
|
149
|
-
}, [pane, dbIdx, tblIdx]);
|
|
327
|
+
}, [pane, dbIdx, tblIdx, histIdx]);
|
|
150
328
|
// Keyboard navigation. The latest lists/indices/handlers live in a ref so the single window
|
|
151
329
|
// listener (attached once by useGlobalKeydown) never goes stale. Mirrors the PoC's
|
|
152
330
|
// stale-closure-ref pattern, now via the shared Foundation hooks.
|
|
153
331
|
const dbNames = (dbs && dbs.names) || [];
|
|
154
332
|
const tblNames = (tables && tables.tables) || [];
|
|
155
|
-
const st = useLatestRef({ dbNames, tblNames, pane, dbIdx, tblIdx, pickDb, pickTable });
|
|
333
|
+
const st = useLatestRef({ dbNames, tblNames, history, dock, pane, dbIdx, tblIdx, histIdx, pickDb, pickTable, recall });
|
|
156
334
|
useGlobalKeydown((e) => {
|
|
157
335
|
// never hijack the SQL box or the profile dropdown
|
|
158
336
|
const t = e.target;
|
|
@@ -161,7 +339,7 @@ export function DbBrowser({ spec }) {
|
|
|
161
339
|
if (e.metaKey || e.ctrlKey || e.altKey)
|
|
162
340
|
return;
|
|
163
341
|
const s = st.current;
|
|
164
|
-
const list = s.pane === "tbl" ? s.tblNames : s.dbNames;
|
|
342
|
+
const list = s.pane === "tbl" ? s.tblNames : s.pane === "hist" ? s.history : s.dbNames;
|
|
165
343
|
switch (e.key) {
|
|
166
344
|
case "ArrowDown":
|
|
167
345
|
case "j":
|
|
@@ -169,6 +347,8 @@ export function DbBrowser({ spec }) {
|
|
|
169
347
|
return;
|
|
170
348
|
if (s.pane === "tbl")
|
|
171
349
|
setTblIdx((i) => Math.min(s.tblNames.length - 1, i + 1));
|
|
350
|
+
else if (s.pane === "hist")
|
|
351
|
+
setHistIdx((i) => Math.min(s.history.length - 1, i + 1));
|
|
172
352
|
else
|
|
173
353
|
setDbIdx((i) => Math.min(s.dbNames.length - 1, i + 1));
|
|
174
354
|
break;
|
|
@@ -178,15 +358,23 @@ export function DbBrowser({ spec }) {
|
|
|
178
358
|
return;
|
|
179
359
|
if (s.pane === "tbl")
|
|
180
360
|
setTblIdx((i) => Math.max(0, i - 1));
|
|
361
|
+
else if (s.pane === "hist")
|
|
362
|
+
setHistIdx((i) => Math.max(0, i - 1));
|
|
181
363
|
else
|
|
182
364
|
setDbIdx((i) => Math.max(0, i - 1));
|
|
183
365
|
break;
|
|
184
|
-
case "Tab":
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
366
|
+
case "Tab": {
|
|
367
|
+
// cycle db -> tables -> history -> db, skipping the tables list when empty and the
|
|
368
|
+
// history list unless the dock is actually showing it
|
|
369
|
+
const order = ["db"];
|
|
370
|
+
if (s.tblNames.length)
|
|
371
|
+
order.push("tbl");
|
|
372
|
+
if (s.dock === "history" && s.history.length)
|
|
373
|
+
order.push("hist");
|
|
374
|
+
const at = order.indexOf(s.pane);
|
|
375
|
+
setPane(order[(at + 1) % order.length]);
|
|
189
376
|
break;
|
|
377
|
+
}
|
|
190
378
|
case "Enter":
|
|
191
379
|
if (s.pane === "db") {
|
|
192
380
|
const name = s.dbNames[s.dbIdx];
|
|
@@ -196,6 +384,16 @@ export function DbBrowser({ spec }) {
|
|
|
196
384
|
setTblIdx(0);
|
|
197
385
|
}
|
|
198
386
|
}
|
|
387
|
+
else if (s.pane === "hist") {
|
|
388
|
+
// Belt-and-suspenders: pane is reset out of "hist" whenever the dock stops showing
|
|
389
|
+
// history, but this guard is what stops Enter acting on a list that is not on screen
|
|
390
|
+
// if that ever drifts again.
|
|
391
|
+
if (s.dock !== "history")
|
|
392
|
+
return;
|
|
393
|
+
const q = s.history[s.histIdx];
|
|
394
|
+
if (q)
|
|
395
|
+
s.recall(q);
|
|
396
|
+
}
|
|
199
397
|
else {
|
|
200
398
|
const tbl = s.tblNames[s.tblIdx];
|
|
201
399
|
if (tbl)
|
|
@@ -203,11 +401,10 @@ export function DbBrowser({ spec }) {
|
|
|
203
401
|
}
|
|
204
402
|
break;
|
|
205
403
|
case "Escape":
|
|
206
|
-
// back out of the tables pane to the db list; from the db pane Escape is a no-op
|
|
207
|
-
if (s.pane === "
|
|
208
|
-
setPane("db");
|
|
209
|
-
else
|
|
404
|
+
// back out of the tables or history pane to the db list; from the db pane Escape is a no-op
|
|
405
|
+
if (s.pane === "db")
|
|
210
406
|
return;
|
|
407
|
+
setPane("db");
|
|
211
408
|
break;
|
|
212
409
|
default:
|
|
213
410
|
return;
|
|
@@ -215,8 +412,8 @@ export function DbBrowser({ spec }) {
|
|
|
215
412
|
e.preventDefault();
|
|
216
413
|
});
|
|
217
414
|
return html `
|
|
218
|
-
<div class="dbview">
|
|
219
|
-
<div class="dbside"
|
|
415
|
+
<div class="dbview" ref=${viewRef}>
|
|
416
|
+
<div class="dbside">
|
|
220
417
|
<div class="dbsec">databases</div>
|
|
221
418
|
${dbs == null
|
|
222
419
|
? html `<div class="msg">loading…</div>`
|
|
@@ -234,6 +431,7 @@ export function DbBrowser({ spec }) {
|
|
|
234
431
|
setUser(v);
|
|
235
432
|
setDb(null);
|
|
236
433
|
setTables(null);
|
|
434
|
+
setHistory([]); // history is per profile too, so it goes with the db
|
|
237
435
|
setOut({ msg: "pick a database" });
|
|
238
436
|
loadList(v);
|
|
239
437
|
}}
|
|
@@ -275,8 +473,9 @@ export function DbBrowser({ spec }) {
|
|
|
275
473
|
<div class="dbprivacy">
|
|
276
474
|
Privacy: opening a database copies the on-device Slack store (message text,
|
|
277
475
|
request/response bodies, user, channel, and team IDs) in plaintext to a temp file on
|
|
278
|
-
this machine. The copy is read-only and auto-deleted when this dashboard stops.
|
|
279
|
-
|
|
476
|
+
this machine. The copy is read-only and auto-deleted when this dashboard stops. Query
|
|
477
|
+
history, unlike that copy, persists in this browser's localStorage indefinitely and can
|
|
478
|
+
carry sensitive literals from what you typed. Review before sharing anything from here.
|
|
280
479
|
</div>
|
|
281
480
|
<div class="dbqbar">
|
|
282
481
|
<input
|
|
@@ -291,9 +490,14 @@ export function DbBrowser({ spec }) {
|
|
|
291
490
|
/>
|
|
292
491
|
<button onClick=${() => run()}>Run</button>
|
|
293
492
|
${db ? html `<button class="dbrefresh" onClick=${() => pickDb(db, true)}>↻ refresh</button>` : null}
|
|
493
|
+
${db
|
|
494
|
+
? html `<button class=${"dbhistbtn" + (dock === "history" ? " on" : "")} title="Queries you have run against this database" onClick=${toggleHistoryDock}>
|
|
495
|
+
history${history.length ? html ` <span class="dbhistn">${history.length}</span>` : null}
|
|
496
|
+
</button>`
|
|
497
|
+
: null}
|
|
294
498
|
</div>
|
|
295
499
|
<div class="dbmeta">${meta}</div>
|
|
296
|
-
<div class=${"dbsplit" + (
|
|
500
|
+
<div class=${"dbsplit" + (dock ? " open" : "")}>
|
|
297
501
|
<div class="dbout">
|
|
298
502
|
${out.msg
|
|
299
503
|
? html `<div class="msg">${out.msg}</div>`
|
|
@@ -303,11 +507,46 @@ export function DbBrowser({ spec }) {
|
|
|
303
507
|
? html `<div class="msg">0 rows</div>`
|
|
304
508
|
: html `<${Grid}
|
|
305
509
|
rows=${out.rows}
|
|
306
|
-
selectedIndex=${selectedRow ? selectedRow.index : -1}
|
|
307
|
-
onSelect=${(row, index) =>
|
|
510
|
+
selectedIndex=${dock === "row" && selectedRow ? selectedRow.index : -1}
|
|
511
|
+
onSelect=${(row, index) => {
|
|
512
|
+
// Clicking the open row again closes it; the dock then falls back to
|
|
513
|
+
// history if that is where you had it.
|
|
514
|
+
const same = dock === "row" && selectedRow && selectedRow.index === index;
|
|
515
|
+
setSelectedRow(same ? null : { row, index });
|
|
516
|
+
setDock(same ? (readDockPref() ? "history" : null) : "row");
|
|
517
|
+
}}
|
|
308
518
|
/>`}
|
|
309
519
|
</div>
|
|
310
|
-
${
|
|
520
|
+
${dock
|
|
521
|
+
? html `<div class="dbdock">
|
|
522
|
+
<div class="dbdocktabs">
|
|
523
|
+
${selectedRow
|
|
524
|
+
? html `<span class=${"dbtab" + (dock === "row" ? " on" : "")} onClick=${() => setDock("row")}>row</span>`
|
|
525
|
+
: null}
|
|
526
|
+
<span
|
|
527
|
+
class=${"dbtab" + (dock === "history" ? " on" : "")}
|
|
528
|
+
onClick=${() => {
|
|
529
|
+
setDock("history");
|
|
530
|
+
writeDockPref(true);
|
|
531
|
+
}}
|
|
532
|
+
>history</span
|
|
533
|
+
>
|
|
534
|
+
<span class="x" title="close" onClick=${closeDock}>✕</span>
|
|
535
|
+
</div>
|
|
536
|
+
${dock === "row" && selectedRow
|
|
537
|
+
? html `<${RowInspector} row=${selectedRow.row} />`
|
|
538
|
+
: html `<${HistoryPanel}
|
|
539
|
+
entries=${history}
|
|
540
|
+
focusIdx=${pane === "hist" ? histIdx : -1}
|
|
541
|
+
onPick=${(q, i) => {
|
|
542
|
+
setPane("hist");
|
|
543
|
+
setHistIdx(i);
|
|
544
|
+
recall(q);
|
|
545
|
+
}}
|
|
546
|
+
onClear=${wipeHistory}
|
|
547
|
+
/>`}
|
|
548
|
+
</div>`
|
|
549
|
+
: null}
|
|
311
550
|
</div>
|
|
312
551
|
</div>
|
|
313
552
|
</div>
|
|
@@ -394,17 +633,31 @@ function JsonNode({ k, value, depth }) {
|
|
|
394
633
|
function JsonTree({ value }) {
|
|
395
634
|
return html `<div class="jtree"><${JsonNode} value=${value} depth=${0} /></div>`;
|
|
396
635
|
}
|
|
397
|
-
// The
|
|
398
|
-
//
|
|
399
|
-
|
|
400
|
-
|
|
636
|
+
// The `history` tab of the dock: the queries you ran against this database, newest first. Each
|
|
637
|
+
// line is one clipped query (full text in the tooltip) that re-runs on click.
|
|
638
|
+
function HistoryPanel({ entries, focusIdx, onPick, onClear, }) {
|
|
639
|
+
if (!entries.length)
|
|
640
|
+
return html `<div class="dbhistempty">queries you run appear here — the last ${HISTORY_CAP} per database, newest first</div>`;
|
|
641
|
+
return html `
|
|
642
|
+
<div class="dbhistbar">
|
|
643
|
+
<span class="dbhistclear" title="Clear this database's query history" onClick=${onClear}>clear</span>
|
|
644
|
+
</div>
|
|
645
|
+
<div class="dbhistlist">
|
|
646
|
+
${entries.map((q, i) => html `<div class=${"dbhist" + (i === focusIdx ? " kbd" : "")} title=${q} onClick=${() => onPick(q, i)}>${q}</div>`)}
|
|
647
|
+
</div>
|
|
648
|
+
`;
|
|
649
|
+
}
|
|
650
|
+
// The `row` tab of the dock: every column's FULL value (not the grid's clipped one line). A
|
|
651
|
+
// JSON-valued column renders as a collapsible tree; anything else renders as wrapped text. Each
|
|
652
|
+
// field, and the row as a whole, can be copied to the clipboard. Closing is the dock's job, so
|
|
653
|
+
// this panel has no control of its own.
|
|
654
|
+
function RowInspector({ row }) {
|
|
401
655
|
const cols = Object.keys(row);
|
|
402
656
|
const title = String(row.id ?? row[cols[0]] ?? "row");
|
|
403
657
|
return html `
|
|
404
658
|
<div class="rowinspector">
|
|
405
659
|
<div class="inspector-hd">
|
|
406
660
|
<span class="ttl">${title}</span>
|
|
407
|
-
<span class="x" onClick=${onClose} title="close">✕</span>
|
|
408
661
|
</div>
|
|
409
662
|
<div class="copybar">
|
|
410
663
|
<button class="copybtn" onClick=${(e) => copyText(JSON.stringify(row, null, 2), e)}>Copy row (JSON)</button>
|