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.

redesign(dashboard): server-switcher dropdown on title

Juan Denis1feb6ef336b7
diff --git a/frontend/src/pages/Dashboard.jsx b/frontend/src/pages/Dashboard.jsx
index 1cc66cc8..ed304735 100644
--- a/frontend/src/pages/Dashboard.jsx
+++ b/frontend/src/pages/Dashboard.jsx
@@ -3,13 +3,15 @@ import { useNavigate, Link } from 'react-router-dom';
import {
HardDrive, Activity,
RefreshCw, Zap,
- Database, Container, Globe, Code, Layers, Server, Terminal
+ Database, Container, Globe, Code, Layers, Server, Terminal,
+ ChevronDown, Check
} from 'lucide-react';
import api from '../services/api';
import { useMetrics } from '../hooks/useMetrics';
import MetricsGraph from '../components/MetricsGraph';
import useDashboardLayout from '../hooks/useDashboardLayout';
import { Button } from '@/components/ui/button';
+import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover';
import { MetricCard, Pill } from '@/components/ds';
// Refresh interval options in seconds
@@ -21,15 +23,6 @@ const REFRESH_OPTIONS = [
{ label: '1m', value: 60 },
];
-const ServerSelectorIcon = () => (
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
- <rect x="2" y="2" width="20" height="8" rx="2" ry="2"/>
- <rect x="2" y="14" width="20" height="8" rx="2" ry="2"/>
- <line x1="6" y1="6" x2="6.01" y2="6"/>
- <line x1="6" y1="18" x2="6.01" y2="18"/>
- </svg>
-);
-
const Dashboard = () => {
const navigate = useNavigate();
const { metrics: localMetrics, loading: metricsLoading, connected, refresh: refreshMetrics } = useMetrics(true);
@@ -49,6 +42,7 @@ const Dashboard = () => {
// Server selector state
const [servers, setServers] = useState([]);
const [selectedServer, setSelectedServer] = useState({ id: 'local', name: 'Local (this server)' });
+ const [serverMenuOpen, setServerMenuOpen] = useState(false);
const isRemote = selectedServer.id !== 'local';
// Remote metrics (when a non-local server is selected)
@@ -157,8 +151,7 @@ const Dashboard = () => {
localStorage.setItem('dashboard_refresh_interval', value.toString());
}, []);
- function handleServerChange(e) {
- const serverId = e.target.value;
+ function handleServerChange(serverId) {
const server = servers.find(s => s.id === serverId) || { id: 'local', name: 'Local (this server)' };
setSelectedServer(server);
// Reset ticking counters when switching servers
@@ -236,7 +229,55 @@ const Dashboard = () => {
{/* Top Bar */}
<div className="top-bar">
<div className="server-identity">
- <h1>{hostname}</h1>
+ <Popover open={serverMenuOpen} onOpenChange={setServerMenuOpen}>
+ <PopoverTrigger asChild>
+ <button
+ type="button"
+ className={`srv-switch${serverMenuOpen ? ' srv-switch--open' : ''}`}
+ aria-label="Switch server"
+ >
+ <span className="srv-switch__name">{hostname}</span>
+ <ChevronDown size={18} className="srv-switch__chev" aria-hidden="true" />
+ </button>
+ </PopoverTrigger>
+ <PopoverContent
+ align="start"
+ sideOffset={7}
+ className="env-menu"
+ >
+ <div className="env-menu__head">Connected servers · {servers.length}</div>
+ {servers.map(server => {
+ const online = server.status === 'online';
+ const active = server.id === selectedServer.id;
+ return (
+ <button
+ type="button"
+ key={server.id}
+ className="env-opt"
+ onClick={() => { handleServerChange(server.id); setServerMenuOpen(false); }}
+ >
+ <span
+ className={`env-opt__dot env-opt__dot--${online ? 'online' : 'offline'}`}
+ aria-hidden="true"
+ ></span>
+ <span className="env-opt__body">
+ <span className="env-opt__name">{server.name}</span>
+ <span className="env-opt__meta">
+ {server.group_name || (server.is_local ? 'local' : server.id)}
+ {' · '}
+ {online ? 'online' : 'offline'}
+ </span>
+ </span>
+ {active && (
+ <span className="env-opt__check" aria-hidden="true">
+ <Check size={15} />
+ </span>
+ )}
+ </button>
+ );
+ })}
+ </PopoverContent>
+ </Popover>
<div className="server-details">
<span
className={`conn-status conn-status--${isConnected ? 'live' : 'down'}`}
@@ -254,18 +295,6 @@ const Dashboard = () => {
</div>
</div>
<div className="top-bar-right">
- {servers.length > 1 && (
- <div className="server-selector">
- <ServerSelectorIcon />
- <select value={selectedServer.id} onChange={handleServerChange}>
- {servers.map(server => (
- <option key={server.id} value={server.id} disabled={server.status === 'offline'}>
- {server.name} {server.status === 'offline' ? '(Offline)' : ''}
- </option>
- ))}
- </select>
- </div>
- )}
<div className="clock-widget">
<span className="clock-time">{displayTime}</span>
<span className="clock-zone">{serverTime?.timezone_id || 'UTC'}</span>
diff --git a/frontend/src/styles/pages/_dashboard.scss b/frontend/src/styles/pages/_dashboard.scss
index e694525c..f94cd6fa 100644
--- a/frontend/src/styles/pages/_dashboard.scss
+++ b/frontend/src/styles/pages/_dashboard.scss
@@ -36,6 +36,126 @@
}
}
+// --- Server switcher (title becomes a clickable name + chevron) ---
+// Visual parity with the design's `.srv-switch` + `.env-menu` popover.
+.srv-switch {
+ display: inline-flex;
+ align-items: center;
+ gap: 10px;
+ padding: 2px 4px;
+ border: none;
+ background: transparent;
+ border-radius: $radius-sm;
+ cursor: pointer;
+ color: $text-primary;
+ @include focus-ring();
+
+ &__name {
+ font-size: 1.5rem;
+ font-weight: $font-weight-bold;
+ letter-spacing: -0.02em;
+ font-family: $font-mono;
+ color: $text-primary;
+ }
+
+ &__chev {
+ color: var(--text-faint);
+ transition: transform 0.15s ease;
+ flex-shrink: 0;
+ }
+
+ &--open &__chev {
+ transform: rotate(180deg);
+ }
+}
+
+// Popover menu listing connected servers (PopoverContent className="env-menu").
+// Plain SCSS class overrides the primitive's baked-in utilities — same pattern
+// as `.ui-popover-content`.
+.env-menu {
+ min-width: 280px;
+ padding: 7px;
+ background: var(--surface-2);
+ border: 1px solid var(--border-strong);
+ border-radius: var(--radius-lg);
+ box-shadow: var(--shadow-lg);
+ color: var(--text);
+
+ &__head {
+ font-family: var(--mono);
+ font-size: 10px;
+ letter-spacing: 0.12em;
+ text-transform: uppercase;
+ color: var(--text-ghost);
+ padding: 7px 10px 5px;
+ }
+}
+
+.env-opt {
+ display: flex;
+ align-items: center;
+ gap: 11px;
+ width: 100%;
+ padding: 9px 10px;
+ border: none;
+ background: transparent;
+ border-radius: 9px;
+ text-align: left;
+ cursor: pointer;
+ transition: background 0.1s ease;
+ @include focus-ring();
+
+ &:hover {
+ background: var(--surface-3);
+ }
+
+ &__dot {
+ width: 9px;
+ height: 9px;
+ border-radius: 50%;
+ flex-shrink: 0;
+
+ &--online {
+ background: var(--green);
+ box-shadow: 0 0 6px var(--green);
+ }
+
+ &--offline {
+ background: var(--red);
+ }
+ }
+
+ &__body {
+ flex: 1;
+ min-width: 0;
+ display: flex;
+ flex-direction: column;
+ }
+
+ &__name {
+ font-weight: $font-weight-semibold;
+ font-size: 13px;
+ color: var(--text);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ }
+
+ &__meta {
+ font-family: var(--mono);
+ font-size: 10.5px;
+ color: var(--text-faint);
+ margin-top: 1px;
+ }
+
+ &__check {
+ margin-left: auto;
+ color: var(--accent-bright);
+ flex-shrink: 0;
+ display: inline-flex;
+ }
+}
+
// Connection status: dot + text label (never color alone), announced to
// screen readers via role="status". The label stays a readable neutral
// (contrast-safe in both themes); the dot carries the status color.