Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

feat(ui): Databases SQL editor gutter + highlighting, click opens console (S8.1)

Juan Denis1cbaa6fa2758
diff --git a/docs/REDESIGN_MAP.md b/docs/REDESIGN_MAP.md
index 80c3f1f7..0fa92fe3 100644
--- a/docs/REDESIGN_MAP.md
+++ b/docs/REDESIGN_MAP.md
@@ -255,8 +255,10 @@ Demo is a **flush, full-height, zero-padding 3-pane console** (topbar / tree-rai
toolbar/tree-panel/workspace/statusbar) — this alone makes it "not the demo". Then the deferred items:
- **De-cardify** (STYLE): `_databases.scss` — `.db-explorer` (≈:14) padding/gap→0; `.dbx-toolbar` (≈:90),
`.dbx-tree-panel` (≈:187), `.dbx-workspace` (≈:377), `.dbx-statusbar` (≈:853) → borders-only, radius 0.
-- **SQL editor** (JSX, the big one): bare `<textarea>` (`ConsoleTab.jsx:164`) vs demo's line-number gutter +
- `.kw`/`.num`/`.str` keyword tints + styled `.ro-badge`.
+- ~~**SQL editor**~~ ✅ **done 2026-06-11**: `databases/SqlEditor.jsx` — transparent-textarea-over-highlighted-pre
+ overlay with line-number gutter + SQL keyword/string/number/comment tints (`.dbx-sqled`); also **click-to-open
+ UX fixed** — single-clicking a database node now opens its SQL console (was context-menu-only) and expands its
+ tables; collapse stays on the chevron.
- **Semantic cell tints** (JSX): port demo `cellEl` (`view_databases.jsx:24–31`) into `ResultsGrid.jsx` —
NULL ghost-italic, emails/URLs green, publish/running green, draft/stopped amber.
- Small: tree status-dot glow (`box-shadow: 0 0 6px currentColor`), `+` new-tab pill, ctx-menu "Browse rows"
diff --git a/frontend/src/components/databases/ConsoleTab.jsx b/frontend/src/components/databases/ConsoleTab.jsx
index 0024902c..df397c09 100644
--- a/frontend/src/components/databases/ConsoleTab.jsx
+++ b/frontend/src/components/databases/ConsoleTab.jsx
@@ -3,6 +3,7 @@ import { Play, History, Download, Eraser, Lock, Unlock, Clock } from 'lucide-rea
import { useToast } from '../../contexts/ToastContext';
import { runQuery, connKey } from './dbAdapter';
import ResultsGrid from './ResultsGrid';
+import SqlEditor from './SqlEditor';
const HISTORY_KEY = 'serverkit_query_history';
const MAX_HISTORY = 50;
@@ -162,15 +163,13 @@ export default function ConsoleTab({ conn, tabId, active, isAdmin, initialQuery
<div className="dbx-console-split">
<div className="dbx-editor-wrap">
- <textarea
+ <SqlEditor
ref={editorRef}
- className="dbx-editor"
value={query}
onChange={(e) => setQuery(e.target.value)}
onKeyDown={handleKeyDown}
placeholder={`SELECT * FROM … — querying ${conn.name || conn.path || conn.container}`}
- spellCheck={false}
- aria-label="SQL editor"
+ ariaLabel="SQL editor"
/>
{readonly && (
<span className="dbx-editor-badge">
diff --git a/frontend/src/components/databases/SqlEditor.jsx b/frontend/src/components/databases/SqlEditor.jsx
new file mode 100644
index 00000000..094e63bc
--- /dev/null
+++ b/frontend/src/components/databases/SqlEditor.jsx
@@ -0,0 +1,70 @@
+import { forwardRef, useMemo, useRef } from 'react';
+
+// SQL console editor with a line-number gutter + keyword tinting (the demo's
+// .sql-editor). Classic overlay technique: a transparent <textarea> captures
+// input over a highlighted <pre> kept scroll-synced — both must share the
+// exact same font metrics (see .dbx-sqled in _databases.scss).
+
+const SQL_KEYWORDS = /\b(select|from|where|order\s+by|group\s+by|having|limit|offset|insert\s+into|insert|update|delete|join|left|right|inner|outer|cross|on|as|and|or|not|null|is|in|like|between|exists|union|all|distinct|create|table|database|drop|alter|index|primary|key|foreign|references|values|set|into|desc|asc|show|describe|explain|count|sum|avg|min|max|case|when|then|else|end|begin|commit|rollback|truncate)\b/gi;
+
+function esc(s) {
+ return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
+}
+
+function hlSql(line) {
+ let h = esc(line);
+ if (/^\s*(--|#)/.test(line)) return `<span class="tok-cmt">${h}</span>`;
+ h = h.replace(/("[^"]*"|'[^']*'|`[^`]*`)/g, '<span class="tok-str">$1</span>');
+ h = h.replace(/\b(\d+(?:\.\d+)?)\b/g, '<span class="tok-num">$1</span>');
+ h = h.replace(SQL_KEYWORDS, '<span class="tok-kw">$&</span>');
+ return h;
+}
+
+const SqlEditor = forwardRef(function SqlEditor({ value, onChange, onKeyDown, placeholder, ariaLabel }, ref) {
+ const preRef = useRef(null);
+ const gutterRef = useRef(null);
+
+ const lines = useMemo(() => (value ?? '').split('\n'), [value]);
+ // trailing blank line keeps the pre's scrollHeight in step with the textarea
+ const html = useMemo(() => lines.map(hlSql).join('\n') + '\n', [lines]);
+
+ const syncScroll = (e) => {
+ if (preRef.current) {
+ preRef.current.scrollTop = e.target.scrollTop;
+ preRef.current.scrollLeft = e.target.scrollLeft;
+ }
+ if (gutterRef.current) gutterRef.current.scrollTop = e.target.scrollTop;
+ };
+
+ return (
+ <div className="dbx-sqled">
+ <div className="dbx-sqled__gutter" ref={gutterRef} aria-hidden="true">
+ {lines.map((_, i) => <div key={i}>{i + 1}</div>)}
+ </div>
+ <div className="dbx-sqled__stack">
+ <pre
+ className="dbx-sqled__hl"
+ ref={preRef}
+ aria-hidden="true"
+ dangerouslySetInnerHTML={{ __html: html }}
+ />
+ <textarea
+ ref={ref}
+ className="dbx-sqled__input"
+ value={value}
+ onChange={onChange}
+ onKeyDown={onKeyDown}
+ onScroll={syncScroll}
+ placeholder={placeholder}
+ spellCheck={false}
+ autoCapitalize="off"
+ autoCorrect="off"
+ wrap="off"
+ aria-label={ariaLabel}
+ />
+ </div>
+ </div>
+ );
+});
+
+export default SqlEditor;
diff --git a/frontend/src/pages/Databases.jsx b/frontend/src/pages/Databases.jsx
index 1fb17ed4..df9f4e02 100644
--- a/frontend/src/pages/Databases.jsx
+++ b/frontend/src/pages/Databases.jsx
@@ -250,7 +250,13 @@ export default function Databases() {
function activate(node) {
setSelectedNode(node);
if (node.kind === 'table') openTableTab(node);
- else if (node.expandable) toggle(node);
+ else if (node.kind === 'database') {
+ // single click opens the database's SQL console (it used to be
+ // reachable only via the context menu) and expands its tables;
+ // collapsing stays on the chevron so re-clicks don't fold the tree
+ openConsole(node.conn, node.engine);
+ if (node.expandable && !expanded.has(node.id)) toggle(node);
+ } else if (node.expandable) toggle(node);
}
// ─── tree context menu ────────────────────────────────────
diff --git a/frontend/src/styles/pages/_databases.scss b/frontend/src/styles/pages/_databases.scss
index afd193e3..e5851ac3 100644
--- a/frontend/src/styles/pages/_databases.scss
+++ b/frontend/src/styles/pages/_databases.scss
@@ -569,22 +569,75 @@ $dbx-sqlite: #3d8fd1;
.dbx-editor-wrap { position: relative; flex: 1; min-width: 0; }
- .dbx-editor {
- width: 100%;
+ // SQL editor (demo .sql-editor): line-number gutter + keyword tints. A
+ // transparent textarea sits over a highlighted <pre>; gutter/pre/textarea
+ // MUST share identical font metrics or the overlay drifts.
+ .dbx-sqled {
+ display: flex;
height: 184px;
min-height: 96px;
max-height: 50vh;
resize: vertical;
- padding: $space-3 $space-4;
+ overflow: hidden;
background: $bg-body;
- border: none;
border-bottom: 1px solid $border-default;
- color: $text-primary;
- font-family: $font-mono;
- font-size: $font-size-sm;
- line-height: $line-height-relaxed;
- outline: none;
- &::placeholder { color: $text-tertiary; }
+
+ &__gutter {
+ flex-shrink: 0;
+ min-width: 40px;
+ padding: $space-3 10px $space-3 $space-3;
+ overflow: hidden;
+ text-align: right;
+ font-family: $font-mono;
+ font-size: $font-size-sm;
+ line-height: $line-height-relaxed;
+ color: $text-tertiary;
+ border-right: 1px solid $border-subtle;
+ user-select: none;
+ }
+
+ &__stack {
+ position: relative;
+ flex: 1;
+ min-width: 0;
+ }
+
+ &__hl,
+ &__input {
+ position: absolute;
+ inset: 0;
+ margin: 0;
+ padding: $space-3 $space-4;
+ font-family: $font-mono;
+ font-size: $font-size-sm;
+ line-height: $line-height-relaxed;
+ white-space: pre;
+ tab-size: 4;
+ }
+
+ &__hl {
+ overflow: hidden;
+ pointer-events: none;
+ color: $text-primary;
+
+ .tok-kw { color: var(--accent-bright); font-weight: $font-weight-semibold; }
+ .tok-str { color: $success; }
+ .tok-num { color: $warning; }
+ .tok-cmt { color: var(--text-ghost); font-style: italic; }
+ }
+
+ &__input {
+ background: transparent;
+ border: none;
+ resize: none;
+ outline: none;
+ color: transparent;
+ caret-color: $text-primary;
+ overflow: auto;
+
+ &::placeholder { color: $text-tertiary; }
+ &::selection { background: fade($accent-primary-raw, 28%); }
+ }
}
.dbx-editor-badge {