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.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
feat(databases): make "Not installed" a door instead of a sign
Juan Denisbccc951d5b3b
diff --git a/frontend/src/components/databases/EngineCatalogDrawer.jsx b/frontend/src/components/databases/EngineCatalogDrawer.jsxindex 3c1c311d..8b902340 100644--- a/frontend/src/components/databases/EngineCatalogDrawer.jsx+++ b/frontend/src/components/databases/EngineCatalogDrawer.jsx@@ -1,4 +1,4 @@-import { useMemo, useState } from 'react';+import { useEffect, useMemo, useState } from 'react';import { Link } from 'react-router-dom';import {Layers, Check, Download, Loader2, PackageX, ShieldAlert, RefreshCw, ChevronRight,@@ -119,6 +119,10 @@ export default function EngineCatalogDrawer({families: providedFamilies = null,loading = false,unavailable = false,+ // Seeds the search box each time the drawer opens, so a caller that already+ // knows which engine you asked for (an "Install" on a tree row) doesn't make+ // you find it again. Empty is the normal case: browse everything.+ presetQuery = '',onPick,onSynced,}) {@@ -127,6 +131,15 @@ export default function EngineCatalogDrawer({const [family, setFamily] = useState(null);const [syncing, setSyncing] = useState(false);+ // Only on open/preset change — typing while open must not be overwritten. A+ // scoped open also drops a family filter left over from a previous visit,+ // which would otherwise hide the very engine the caller asked for.+ useEffect(() => {+ if (!open) return;+ setQuery(presetQuery);+ if (presetQuery) setFamily(null);+ }, [open, presetQuery]);+const families = useMemo(() => (providedFamilies?.length ? providedFamilies : familiesOf(catalog)),[providedFamilies, catalog],diff --git a/frontend/src/components/databases/SourceTree.jsx b/frontend/src/components/databases/SourceTree.jsxindex 335a1e05..abf961b7 100644--- a/frontend/src/components/databases/SourceTree.jsx+++ b/frontend/src/components/databases/SourceTree.jsx@@ -1,4 +1,4 @@-import { ChevronRight, ChevronDown, Table2, Loader2, MoreHorizontal, Plus } from 'lucide-react';+import { ChevronRight, ChevronDown, Table2, Loader2, MoreHorizontal, Plus, Download } from 'lucide-react';import { EngineIcon } from '../icons/DatabaseBrands';import EngineGlyph from './EngineGlyph';@@ -28,6 +28,24 @@ function matches(node, filter) {return !filter || node.label.toLowerCase().includes(filter.toLowerCase());}+// What a node counts, so the number beside it is never ambiguous. Children are+// apps under the Docker root, databases under any other engine, tables under a+// database.+function countNoun(node) {+ if (node.kind === 'database') return 'tables';+ if (node.kind === 'engine' && node.engine === 'docker') return 'apps';+ return 'databases';+}++// "Nothing here" is a normal fact and must never read like a failure. Each kind+// gets its own words rather than a shared "Empty".+function emptyLabel(node) {+ if (node.kind === 'database') return 'No tables yet';+ if (node.kind === 'app') return 'No databases';+ if (node.kind === 'engine' && node.engine === 'docker') return 'No Docker apps';+ return 'No databases yet';+}+function TreeRow({ node, depth, expanded, childrenCache, loading, activeKey, selectedId, filter, handlers }) {const isOpen = expanded.has(node.id);const isLoading = loading.has(node.id);@@ -40,6 +58,11 @@ function TreeRow({ node, depth, expanded, childrenCache, loading, activeKey, selconst hadError = errorMsg != null;const childNodes = Array.isArray(kids) ? kids : [];const visibleChildren = childNodes.filter((c) => c.expandable || matches(c, filter));+ // Counted off children we actually hold. A node nobody has opened has no+ // count — which is honest — and an empty one says so in words below instead+ // of wearing a "0".+ const childCount = Array.isArray(kids) && kids.length > 0 ? kids.length : null;+ const canInstall = Boolean(node.installers?.length && handlers.onInstall);return (<li className="dbx-tree-node" role="none">@@ -77,7 +100,9 @@ function TreeRow({ node, depth, expanded, childrenCache, loading, activeKey, sel)}<span className="dbx-tree-icon"><NodeIcon node={node} /></span>- <span className="dbx-tree-label">{node.label}</span>+ {/* Rows carry status, counts and actions, so the name is the+ first thing to lose width — keep it recoverable on hover. */}+ <span className="dbx-tree-label" title={node.label}>{node.label}</span>{node.kind === 'database' && node.source === 'docker' && (<span className="dbx-tree-source" title={node.appName ? `Docker container · ${node.appName}` : 'Docker container'}>@@ -87,19 +112,47 @@ function TreeRow({ node, depth, expanded, childrenCache, loading, activeKey, sel)}{node.kind === 'engine' && node.status && node.status !== 'available' && (- <span className={`dbx-tree-status is-${node.status}`}>+ <span className={`dbx-tree-status is-${node.status}`} title={STATUS_LABEL[node.status]}>{node.status === 'installing'? <Loader2 size={11} className="dbx-spin" aria-hidden="true" />: <span className="dbx-status-dot" aria-hidden="true" />}- {STATUS_LABEL[node.status]}+ {/* A running engine's version says more than the word+ "Running" the green dot already carries. */}+ {node.status === 'active' && node.version+ ? `v${node.version}`+ : STATUS_LABEL[node.status]}</span>)}++ {/* A not-installed engine is a dead end only if we make it one.+ Unlike the row's other buttons this one keeps its place in the+ tab order: it is the only way out of the state it announces. */}+ {canInstall && (+ <button+ type="button"+ className="dbx-tree-install-btn"+ onClick={(e) => { e.stopPropagation(); handlers.onInstall(node); }}+ aria-label={`${node.label} is not installed — install it`}+ title={`Install ${node.label}`}+ >+ <Download size={11} aria-hidden="true" /> Install+ </button>+ )}+ {!canInstall && node.installHint && (+ <span className="dbx-tree-hint">{node.installHint}</span>+ )}+{node.kind === 'table' && node.rows != null && (<span className="dbx-tree-badge">{node.rows.toLocaleString()}</span>)}{node.kind === 'database' && node.sizeText && (<span className="dbx-tree-badge">{node.sizeText}</span>)}+ {node.kind !== 'table' && childCount != null && (+ <span className="dbx-tree-count" title={`${childCount} ${countNoun(node)}`}>+ {childCount}+ </span>+ )}{node.canCreate && handlers.onCreateChild && (<button@@ -137,7 +190,15 @@ function TreeRow({ node, depth, expanded, childrenCache, loading, activeKey, sel)}{!isLoading && !hadError && childNodes.length === 0 && (<li className="dbx-tree-leaf-msg" style={{ paddingLeft: `${(depth + 1) * 14 + 22}px` }}>- {node.kind === 'database' ? 'No tables yet' : 'Empty'}+ {canInstall ? (+ <button+ type="button"+ className="dbx-tree-leaf-link"+ onClick={() => handlers.onInstall(node)}+ >+ Not installed — install {node.label}+ </button>+ ) : emptyLabel(node)}</li>)}{visibleChildren.map((child) => (diff --git a/frontend/src/pages/Databases.jsx b/frontend/src/pages/Databases.jsxindex 2201b181..bc22b25a 100644--- a/frontend/src/pages/Databases.jsx+++ b/frontend/src/pages/Databases.jsx@@ -4,7 +4,7 @@ import {PanelLeftClose, PanelLeftOpen, Search, X, RefreshCw, Plus, Terminal,Archive, Database, Table2, Server, ChevronDown,Trash2, DatabaseBackup, Copy, FileCode2, Lock, BookMarked, Activity,- SlidersHorizontal, Layers, ExternalLink,+ SlidersHorizontal, Layers, ExternalLink, Download,} from 'lucide-react';import api from '../services/api';import Modal from '@/components/Modal';@@ -103,6 +103,9 @@ export default function Databases() {const [engineData, setEngineData] = useState({ catalog: [], installed: [], unavailable: false });const [enginesLoading, setEnginesLoading] = useState(true);const [catalogOpen, setCatalogOpen] = useState(false);+ // Seeds the catalog's search box, so "Install" on a specific tree row opens+ // the catalog already narrowed to the engines that could fill that row.+ const [catalogQuery, setCatalogQuery] = useState('');const [installEntry, setInstallEntry] = useState(null);// What the workspace shows when there is no tab to show: an engine that is// still installing, an engine that is up but empty, an empty database.@@ -162,27 +165,88 @@ export default function Databases() {return () => clearInterval(timer);}, [installingCount, loadEngines]);- const roots = useMemo(() => ([+ const openCatalog = useCallback((query = '') => {+ setCatalogQuery(query);+ setCatalogOpen(true);+ }, []);++ // The install flow for one specific tree row. A single candidate goes+ // straight to its configure drawer; several (MySQL and MariaDB both speak+ // `mysql`) go to the catalog narrowed to exactly those.+ const startInstall = useCallback((node) => {+ const offers = node?.installers || [];+ if (offers.length === 1) {+ setInstallEntry(offers[0]);+ return;+ }+ openCatalog(offers.length ? node.engine || '' : '');+ }, [openCatalog]);++ // Which catalog templates could stand in for a host engine that isn't+ // installed, keyed by the engine's own wire protocol. Nothing is named here:+ // a new MySQL-compatible template joins the `mysql` list by declaring+ // `engine.protocol: mysql`, exactly like MariaDB does.+ const installersByProtocol = useMemo(() => {+ const map = new Map();+ engineData.catalog.forEach((entry) => {+ const key = entry.engine?.protocol || entry.id;+ if (!key) return;+ map.set(key, [...(map.get(key) || []), entry]);+ });+ return map;+ }, [engineData.catalog]);++ const roots = useMemo(() => {// mysql/postgresql stay expandable even when the host engine is absent —- // they can still contain databases that live in Docker containers.- { id: 'eng:mysql', kind: 'engine', engine: 'mysql', label: ENGINE_META.mysql.label, status: engineState('mysql', status), expandable: true, canCreate: engineState('mysql', status) === 'active' },- { id: 'eng:postgresql', kind: 'engine', engine: 'postgresql', label: ENGINE_META.postgresql.label, status: engineState('postgresql', status), expandable: true, canCreate: engineState('postgresql', status) === 'active' },- { id: 'eng:sqlite', kind: 'engine', engine: 'sqlite', label: ENGINE_META.sqlite.label, status: 'available', expandable: true },- { id: 'eng:docker', kind: 'engine', engine: 'docker', label: ENGINE_META.docker.label, status: 'available', expandable: true },- // Engines installed from the template catalog join the built-in roots- // rather than replacing them. They are leaves: each runs as its own- // service, and selecting one shows its state in the workspace.- ...engineData.installed.map((inst) => ({- id: `dbe:${engineInstanceKey(inst)}`,- kind: 'engine',- engine: engineBrandKey(inst) || 'database',- iconEntry: inst,- label: inst.name || inst.instance_name || inst.template_id,- status: engineTreeStatus(inst),- expandable: false,- instance: inst,- })),- ]), [status, engineData.installed]);+ // they can still contain databases that live in Docker containers. And+ // "not installed" is a to-do, not a verdict: the row carries whatever+ // the catalog can do about it.+ const hostRoot = (engine) => {+ const state = engineState(engine, status);+ const node = {+ id: `eng:${engine}`,+ kind: 'engine',+ engine,+ label: ENGINE_META[engine].label,+ status: state,+ expandable: true,+ canCreate: state === 'active',+ };+ if (state !== 'missing') return node;+ const offers = installersByProtocol.get(engine) || [];+ if (offers.length) node.installers = offers;+ else if (!enginesLoading) {+ // No offer is still an answer — say which kind of nothing it is.+ node.installHint = engineData.unavailable+ ? 'catalog unavailable'+ : 'no engine template';+ }+ return node;+ };++ return [+ hostRoot('mysql'),+ hostRoot('postgresql'),+ { id: 'eng:sqlite', kind: 'engine', engine: 'sqlite', label: ENGINE_META.sqlite.label, status: 'available', expandable: true },+ { id: 'eng:docker', kind: 'engine', engine: 'docker', label: ENGINE_META.docker.label, status: 'available', expandable: true },+ // Engines installed from the template catalog join the built-in roots+ // rather than replacing them. They are leaves: each runs as its own+ // service, and selecting one shows its state in the workspace.+ ...engineData.installed.map((inst) => ({+ id: `dbe:${engineInstanceKey(inst)}`,+ kind: 'engine',+ engine: engineBrandKey(inst) || 'database',+ iconEntry: inst,+ label: inst.name || inst.instance_name || inst.template_id,+ status: engineTreeStatus(inst),+ // The template's version is the engine's version — the only+ // version any endpoint here reports. Host engines have none.+ version: inst.template_version || null,+ expandable: false,+ instance: inst,+ })),+ ];+ }, [status, engineData.installed, engineData.unavailable, enginesLoading, installersByProtocol]);// ─── lazy child loading ───────────────────────────────────const loadChildren = useCallback(async (node) => {@@ -217,7 +281,17 @@ export default function Databases() {}}if (node.kind === 'app') {- const d = await api.getAppDatabases(node.appId);+ // An app with nothing to introspect answers 400 ("not a Docker app",+ // no compose to read). That is a fact about the app, not a failure to+ // read it — the row must say "No databases", not turn red. Anything+ // else (auth, network, a broken route) really is a failure.+ let d;+ try {+ d = await api.getAppDatabases(node.appId);+ } catch (err) {+ if (err.status === 400) return [];+ throw err;+ }return (d.databases || []).map((db, i) => ({// engine = the brand (mysql/postgresql) so the row shows the right// brand icon/tint; the connection is still routed over docker exec.@@ -465,6 +539,12 @@ export default function Databases() {{ label: 'Refresh', icon: RefreshCw, onClick: () => refresh(node) },];}+ if (node.installers?.length) {+ return [+ { label: `Install ${node.label}…`, icon: Download, onClick: () => startInstall(node) },+ { label: 'Refresh', icon: RefreshCw, onClick: () => refresh(node) },+ ];+ }return [{ label: 'Refresh', icon: RefreshCw, onClick: () => refresh(node) }];case 'database': {const actions = [@@ -542,8 +622,9 @@ export default function Databases() {onToggle: toggle,onActivate: activate,onContext: openContext,+ onInstall: startInstall,onCreateChild: (node) => setModal({ type: node.engine === 'mysql' ? 'mysql-db' : 'pg-db' }),- }), [toggle]); // eslint-disable-line react-hooks/exhaustive-deps+ }), [toggle, startInstall]); // eslint-disable-line react-hooks/exhaustive-depsreturn (<div className="page-container page-container--full-bleed db-explorer">@@ -599,7 +680,7 @@ export default function Databases() {<Server size={14} aria-hidden="true" /> PostgreSQL user</button><div className="dbx-menu-sep" />- <button type="button" role="menuitem" onClick={() => { setCatalogOpen(true); setShowNewMenu(false); }}>+ <button type="button" role="menuitem" onClick={() => { openCatalog(); setShowNewMenu(false); }}><Layers size={14} aria-hidden="true" /> Install a database engine…</button></div>@@ -653,9 +734,17 @@ export default function Databases() {<buttontype="button"className="dbx-tree-install"- onClick={() => setCatalogOpen(true)}+ onClick={() => openCatalog()}><Layers size={14} aria-hidden="true" /> Install a database engine+ {engineData.catalog.length > 0 && (+ <span+ className="dbx-tree-install-count"+ title={`${engineData.catalog.length} engines in the catalog`}+ >+ {engineData.catalog.length}+ </span>+ )}</button>)}</>@@ -833,7 +922,7 @@ export default function Databases() {status={status}onClose={() => setModal(null)}onCreated={onModalCreated}- onInstallEngine={() => setCatalogOpen(true)}+ onInstallEngine={() => openCatalog()}/>)}{modal?.type === 'mysql-user' && <CreateMySQLUserModal databases={modal.databases} onClose={() => setModal(null)} onCreated={onModalCreated} />}@@ -846,6 +935,7 @@ export default function Databases() {catalog={engineData.catalog}installed={engineData.installed}families={engineData.families}+ presetQuery={catalogQuery}loading={enginesLoading}unavailable={engineData.unavailable}onSynced={loadEngines}diff --git a/frontend/src/styles/pages/_databases.scss b/frontend/src/styles/pages/_databases.scssindex 37141cb9..90e2525c 100644--- a/frontend/src/styles/pages/_databases.scss+++ b/frontend/src/styles/pages/_databases.scss@@ -258,6 +258,10 @@ $dbx-sqlite: #3d8fd1;padding: 0;}+ // The row owns its own padding and truncation; the node is only the+ // grouping element that carries a row plus its children.+ .dbx-tree-node { min-width: 0; }+.dbx-tree-row {display: flex;align-items: center;@@ -340,6 +344,25 @@ $dbx-sqlite: #3d8fd1;line-height: 16px;}+ // How many children a node actually holds. Deliberately not a pill: it is a+ // fact read off the loaded tree, so it sits quieter than the size badge.+ .dbx-tree-count {+ flex-shrink: 0;+ font-family: $font-mono;+ font-size: 10px;+ line-height: 16px;+ color: $text-tertiary;+ font-variant-numeric: tabular-nums;+ }++ // Why a not-installed engine offers no install button.+ .dbx-tree-hint {+ flex-shrink: 0;+ font-size: 10px;+ font-style: italic;+ color: $text-tertiary;+ }+.dbx-tree-status {display: inline-flex;align-items: center;@@ -379,6 +402,23 @@ $dbx-sqlite: #3d8fd1;&.is-error { color: $danger; }}+ // The same message, but the missing thing is one click away. Reads as a+ // link rather than italic prose, because it does something.+ .dbx-tree-leaf-link {+ padding: 0;+ background: none;+ border: none;+ color: $accent-primary;+ font-family: inherit;+ font-size: inherit;+ font-style: normal;+ text-align: left;+ cursor: pointer;++ &:hover { text-decoration: underline; }+ &:focus-visible { outline: 2px solid $accent-primary; outline-offset: 2px; }+ }+// ─── Workspace ────────────────────────────────────────.dbx-workspace {display: flex;@@ -984,6 +1024,29 @@ $dbx-sqlite: #3d8fd1;.dbx-tree-row:hover .dbx-tree-add,.dbx-tree-row:focus-within .dbx-tree-add { opacity: 1; }+ // Unlike the "+", this one is always visible: an engine you cannot install+ // is the whole problem, so the way out must not be hidden behind a hover.+ .dbx-tree-install-btn {+ display: inline-flex;+ align-items: center;+ gap: 4px;+ flex-shrink: 0;+ padding: 1px 7px;+ background: $accent-glow;+ border: 1px solid transparent;+ border-radius: $radius-full;+ color: $accent-primary;+ font-family: inherit;+ font-size: 10px;+ font-weight: $font-weight-medium;+ line-height: 1.6;+ cursor: pointer;+ transition: background $transition-fast, color $transition-fast, border-color $transition-fast;++ &:hover { background: $accent-primary; color: $bg-card; border-color: $accent-primary; }+ svg { flex-shrink: 0; }+ }+.dbx-tree-status.is-installing { color: $warning; }.dbx-tree-status.is-failed { color: $danger; }.dbx-tree-row.is-installing .dbx-tree-label { color: $warning; }@@ -1014,6 +1077,16 @@ $dbx-sqlite: #3d8fd1;svg { flex-shrink: 0; }}+ // How many engines the catalog behind that row actually holds.+ .dbx-tree-install-count {+ margin-left: auto;+ flex-shrink: 0;+ font-family: $font-mono;+ font-size: 10px;+ color: $text-tertiary;+ font-variant-numeric: tabular-nums;+ }+// ─── Main-pane blank states ───────────────────────────// Reachable three ways: an engine mid-install, an engine that is up but// empty, a database with nothing in it.