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.

fix(dashboard): line up the control row, and let series pick a colour

Juan Denis5180ad4360b5
diff --git a/frontend/src/components/dashboard/grid/WidgetEditor.jsx b/frontend/src/components/dashboard/grid/WidgetEditor.jsx
index aa671e58..fbc1527e 100644
--- a/frontend/src/components/dashboard/grid/WidgetEditor.jsx
+++ b/frontend/src/components/dashboard/grid/WidgetEditor.jsx
@@ -5,7 +5,8 @@ import {
import { Drawer, SegControl } from '@/components/ds';
import { Switch } from '@/components/ui/switch';
import {
- AGGREGATIONS, getMetric, metricsForResource, metricsForSource,
+ AGGREGATIONS, LINE_STYLES, SERIES_COLORS, getMetric,
+ metricsForResource, metricsForSource,
} from '../widgets/metrics';
// Single source of truth for shortcut targets: what a user can pick here is
// exactly what the renderer can draw. WidgetBody is what the board itself
@@ -386,6 +387,29 @@ export function WidgetEditor({
onChange={(value) => setSeries(index, 'metric', value)}
options={metricOptionsFor(series.resource, series.metric)}
/>
+ <div
+ className="skwe-edit__swatches"
+ role="radiogroup"
+ aria-label={`Series ${index + 1} colour`}
+ >
+ {SERIES_COLORS.map(([value, name]) => {
+ const active = (series.color || '') === value;
+ const metric = getMetric(series.metric);
+ return (
+ <button
+ key={value || 'default'}
+ type="button"
+ role="radio"
+ aria-checked={active}
+ aria-label={name}
+ title={name}
+ className={`skwe-edit__swatch${active ? ' is-on' : ''}`}
+ style={{ background: value || metric?.color }}
+ onClick={() => setSeries(index, 'color', value)}
+ />
+ );
+ })}
+ </div>
<button
type="button"
className="skwe-edit__del"
@@ -419,6 +443,14 @@ export function WidgetEditor({
onCheckedChange={(checked) => set('legend', checked)}
/>
</Field>
+ <Field label="Line style">
+ <SegControl
+ options={LINE_STYLES.map(([value, label]) => ({ value, label }))}
+ value={cfg.lineStyle || 'smooth'}
+ onChange={(value) => set('lineStyle', value)}
+ aria-label="Line style"
+ />
+ </Field>
<Field label="Area fill" inline>
<Switch
checked={cfg.fill !== false}
diff --git a/frontend/src/components/dashboard/widgets/metrics.js b/frontend/src/components/dashboard/widgets/metrics.js
index 7f90dc24..43ca9be1 100644
--- a/frontend/src/components/dashboard/widgets/metrics.js
+++ b/frontend/src/components/dashboard/widgets/metrics.js
@@ -97,7 +97,11 @@ export const METRICS = [
id: 'load',
label: 'Load average',
unit: '',
- color: 'var(--accent-bright)',
+ // NOT --accent-bright: cpu already owns it, so a chart of CPU +
+ // load drew two identical lines. The six metrics map 1:1 onto the
+ // six themeable semantic tokens; load takes red because load
+ // spiking is the classic "this box is struggling" signal.
+ color: 'var(--red)',
max: null,
// MetricsHistory column load_1m is serialised as load['1m'].
// ServerMetrics has no load column, so this is local-host only.
@@ -300,3 +304,27 @@ export function chartDomain(metricIds) {
const allPercent = metrics.every((m) => m && m.unit === '%' && m.max === 100);
return allPercent ? [0, 100] : null;
}
+
+
+/**
+ * Colours a series may be set to in the widget editor.
+ *
+ * Tokens, never hex: a theme repaints these, so a chart follows whatever skin
+ * the operator is running. `''` means "use the metric's own colour", which is
+ * the default and where most series should stay.
+ */
+export const SERIES_COLORS = [
+ ['', 'Metric default'],
+ ['var(--accent-bright)', 'Accent'],
+ ['var(--green)', 'Green'],
+ ['var(--amber)', 'Amber'],
+ ['var(--cyan)', 'Cyan'],
+ ['var(--violet)', 'Violet'],
+ ['var(--red)', 'Red'],
+];
+
+/** Line shapes a chart can draw. `step` is the squared-off look. */
+export const LINE_STYLES = [
+ ['smooth', 'Line'],
+ ['step', 'Stepped'],
+];
diff --git a/frontend/src/components/dashboard/widgets/renderers.jsx b/frontend/src/components/dashboard/widgets/renderers.jsx
index 4d1bd8b3..4871d46d 100644
--- a/frontend/src/components/dashboard/widgets/renderers.jsx
+++ b/frontend/src/components/dashboard/widgets/renderers.jsx
@@ -105,7 +105,7 @@ function pillKind(state) {
* Gradient ids are per-instance (useId) so two charts on one board cannot
* capture each other's fills.
*/
-function WidgetChart({ series, colors, fill = true, grid = true, height = '100%', domain = null }) {
+function WidgetChart({ series, colors, fill = true, grid = true, height = '100%', domain = null, lineStyle = 'smooth' }) {
const uid = useId().replace(/:/g, '');
const data = (series || []).filter((s) => Array.isArray(s) && s.length > 0);
const all = data.flat();
@@ -123,7 +123,21 @@ function WidgetChart({ series, colors, fill = true, grid = true, height = '100%'
const span = max - min || 1;
const toX = (i, len) => (i / (len - 1 || 1)) * w;
const toY = (v) => h - ((Math.max(min, Math.min(max, v)) - min) / span) * h;
- const line = (s) => s.map((v, i) => `${i ? 'L' : 'M'}${toX(i, s.length).toFixed(2)} ${toY(v).toFixed(2)}`).join(' ');
+ const line = (s) => {
+ if (lineStyle !== 'step') {
+ return s.map((v, i) => `${i ? 'L' : 'M'}${toX(i, s.length).toFixed(2)} ${toY(v).toFixed(2)}`).join(' ');
+ }
+ // Hold each reading until the next one, then jump — the squared-off
+ // look. A sampled metric genuinely is a series of discrete readings,
+ // and this draws that instead of inventing a slope between them.
+ return s.map((v, i) => {
+ const x = toX(i, s.length).toFixed(2);
+ const y = toY(v).toFixed(2);
+ if (!i) return `M${x} ${y}`;
+ const prevY = toY(s[i - 1]).toFixed(2);
+ return `L${x} ${prevY} L${x} ${y}`;
+ }).join(' ');
+ };
return (
<svg
@@ -223,6 +237,7 @@ function WStat({ cfg, ctx }) {
grid={false}
height="100%"
domain={chartDomain([metric.id])}
+ lineStyle={cfg.lineStyle || 'smooth'}
/>
</div>
)}
@@ -274,6 +289,7 @@ function WTimeseries({ cfg, ctx }) {
colors={colors}
fill={cfg.fill !== false}
domain={chartDomain(withData.map((r) => r.metric.id))}
+ lineStyle={cfg.lineStyle || 'smooth'}
/>
</div>
{cfg.legend !== false && (
diff --git a/frontend/src/pages/Dashboard.jsx b/frontend/src/pages/Dashboard.jsx
index bd5db654..1c80c179 100644
--- a/frontend/src/pages/Dashboard.jsx
+++ b/frontend/src/pages/Dashboard.jsx
@@ -456,17 +456,18 @@ const Dashboard = () => {
onChange={setRange}
aria-label="Time range"
/>
- <select
- value={refreshInterval}
- onChange={(e) => handleRefreshIntervalChange(parseInt(e.target.value, 10))}
- className="refresh-select"
- title="Auto-refresh interval"
- aria-label="Auto-refresh interval"
- >
- {REFRESH_OPTIONS.map((opt) => (
- <option key={opt.value} value={opt.value}>↻ {opt.label}</option>
- ))}
- </select>
+ <div className="skw-refresh">
+ <select
+ value={refreshInterval}
+ onChange={(e) => handleRefreshIntervalChange(parseInt(e.target.value, 10))}
+ title="Auto-refresh interval"
+ aria-label="Auto-refresh interval"
+ >
+ {REFRESH_OPTIONS.map((opt) => (
+ <option key={opt.value} value={opt.value}>↻ {opt.label}</option>
+ ))}
+ </select>
+ </div>
<button
type="button"
className="skw-iconbtn"
@@ -487,25 +488,25 @@ const Dashboard = () => {
</button>
{edit ? (
<>
- <button type="button" className="btn btn-outline btn-sm" onClick={() => setLibraryOpen(true)}>
+ <button type="button" className="skw-barbtn" onClick={() => setLibraryOpen(true)}>
<Plus size={14} /> Add widget
</button>
<button
type="button"
- className="btn btn-sm"
+ className="skw-iconbtn"
onClick={handleReset}
title="Restore the shipped layout"
aria-label="Restore the shipped layout"
>
<History size={14} />
</button>
- <button type="button" className="btn btn-sm" onClick={discardEdit}>Discard</button>
- <button type="button" className="btn btn-primary btn-sm" onClick={finishEdit}>
+ <button type="button" className="skw-barbtn" onClick={discardEdit}>Discard</button>
+ <button type="button" className="skw-barbtn skw-barbtn--primary" onClick={finishEdit}>
<Check size={14} /> Done
</button>
</>
) : (
- <button type="button" className="btn btn-outline btn-sm" onClick={startEdit}>
+ <button type="button" className="skw-barbtn" onClick={startEdit}>
<SlidersHorizontal size={14} /> Edit
</button>
)}
diff --git a/frontend/src/styles/components/_dashboard-widgets.scss b/frontend/src/styles/components/_dashboard-widgets.scss
index 742cf99d..1988f800 100644
--- a/frontend/src/styles/components/_dashboard-widgets.scss
+++ b/frontend/src/styles/components/_dashboard-widgets.scss
@@ -55,6 +55,75 @@ $skw-z-tv: 200;
gap: 8px;
margin-left: auto;
flex-wrap: wrap;
+
+ // Every control in this row is exactly 32px tall and vertically
+ // centred. Without this they came from four different places — a
+ // segmented control, a native select, icon buttons and .btn — each with
+ // its own padding, and the row read as a ragged line of mismatched
+ // pills. Height is asserted here rather than trusted from each source.
+ > *,
+ .sk-seg,
+ .skw-varpick,
+ .skw-iconbtn,
+ .skw-barbtn {
+ height: 32px;
+ flex-shrink: 0;
+ }
+
+ .sk-seg {
+ display: flex;
+ align-items: center;
+ box-sizing: border-box;
+ }
+
+ // The segmented control's own buttons must fill it, or the fill sits
+ // proud of the track.
+ .sk-seg__btn {
+ display: flex;
+ align-items: center;
+ }
+ }
+}
+
+// Text button in the board bar. Matches .skw-iconbtn's shell so Edit, Discard
+// and Done sit on the same line as the pickers instead of floating as bare
+// labels — the old `.btn.btn-sm` carried different padding and a different
+// height, which is what made the row look unaligned.
+.skw-barbtn {
+ display: inline-flex;
+ align-items: center;
+ gap: 7px;
+ padding: 0 12px;
+ border: 1px solid var(--border);
+ border-radius: 8px;
+ background: var(--surface-2);
+ color: var(--text-dim);
+ font-family: inherit;
+ font-size: 12.5px;
+ font-weight: 500;
+ white-space: nowrap;
+ cursor: pointer;
+ transition: 0.13s;
+
+ svg { flex-shrink: 0; }
+
+ &:hover {
+ color: var(--text);
+ border-color: var(--border-strong);
+ background: var(--surface-3);
+ }
+
+ // The one committing action in the row.
+ &--primary {
+ border-color: var(--accent);
+ background: var(--accent);
+ color: #fff;
+
+ &:hover {
+ border-color: var(--accent-bright);
+ background: var(--accent-bright);
+ color: #fff;
+ }
}
}
@@ -177,11 +246,57 @@ $skw-z-tv: 200;
// Refresh-interval select. Sizing only — the select chrome comes from the
// shared form styles.
.skw-refresh {
+ position: relative;
+ display: inline-flex;
+ align-items: center;
+
select {
+ // `appearance: none` matters: without it the browser paints its own
+ // control, which on a dark panel arrives as a light box with a
+ // system chevron and ignores every rule below.
+ appearance: none;
height: 32px;
padding: 0 26px 0 10px;
+ border: 1px solid var(--border);
+ border-radius: 8px;
+ background: var(--surface-2);
+ color: var(--text-dim);
font-family: var(--mono);
font-size: 11.5px;
+ cursor: pointer;
+ outline: none;
+ transition: 0.13s;
+
+ &:hover {
+ color: var(--text);
+ border-color: var(--border-strong);
+ background: var(--surface-3);
+ }
+
+ &:focus-visible {
+ border-color: var(--accent);
+ box-shadow: 0 0 0 3px var(--accent-bg);
+ }
+
+ // Native popups are drawn by the OS; name the colours or a dark theme
+ // gets white-on-white options.
+ option {
+ background: var(--surface-2);
+ color: var(--text);
+ }
+ }
+
+ // Our own chevron, since the native one is gone.
+ &::after {
+ content: '';
+ position: absolute;
+ right: 10px;
+ width: 6px;
+ height: 6px;
+ border-right: 1.5px solid var(--text-faint);
+ border-bottom: 1.5px solid var(--text-faint);
+ transform: translateY(-2px) rotate(45deg);
+ pointer-events: none;
}
}
@@ -227,6 +342,13 @@ $skw-z-tv: 200;
background: var(--accent-bg);
color: var(--accent-bright);
font-size: 11.5px;
+
+ // Same shape, but for a board that failed to save or load.
+ &--error {
+ border-color: var(--red);
+ background: var(--red-bg);
+ color: var(--red);
+ }
}
// ------------------------------------------------------------
@@ -1408,6 +1530,28 @@ $skw-z-tv: 200;
padding: 18px 20px;
@include custom-scrollbar;
}
+
+ // Wall-display bar: board name, live dot, what the board is scoped to, and
+ // the time. Larger than the normal chrome because this is read at distance.
+ &__name {
+ font-family: var(--mono);
+ font-size: 14px;
+ font-weight: 600;
+ color: var(--text);
+ }
+
+ &__meta {
+ color: var(--text-faint);
+ font-size: 12px;
+ }
+
+ &__clock {
+ margin-left: auto;
+ font-size: 16px;
+ font-weight: 600;
+ color: var(--text);
+ font-variant-numeric: tabular-nums;
+ }
}
// ============================================================
@@ -1423,6 +1567,14 @@ $skw-z-tv: 200;
&__title { margin: 0 0 6px; color: var(--text); font-size: 15px; font-weight: 600; }
&__desc { margin: 0 auto 24px; max-width: 460px; color: var(--text-dim); font-size: 13px; }
+
+ &__acts {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 9px;
+ margin-top: 18px;
+ }
}
.skw-tpl {
diff --git a/frontend/src/styles/components/_widget-editor.scss b/frontend/src/styles/components/_widget-editor.scss
index b7c2bef1..74d79137 100644
--- a/frontend/src/styles/components/_widget-editor.scss
+++ b/frontend/src/styles/components/_widget-editor.scss
@@ -383,6 +383,36 @@ $skwe-pane-w: 340px;
// Pushes the close affordance to the far edge, away from Remove.
&__spacer { flex: 1; }
+
+ // Per-series colour. Swatches rather than a select: the choice IS the
+ // colour, so showing the name instead of the thing would be a worse
+ // control. Values are theme tokens, so these repaint with the skin.
+ &__swatches {
+ grid-column: 1 / -1;
+ display: flex;
+ align-items: center;
+ gap: 5px;
+ padding-top: 2px;
+ }
+
+ &__swatch {
+ width: 16px;
+ height: 16px;
+ padding: 0;
+ border: 1px solid var(--border-strong);
+ border-radius: 5px;
+ cursor: pointer;
+ transition: 0.12s;
+
+ &:hover { transform: scale(1.12); }
+
+ // Ring rather than a border swap, so the swatch's own colour stays
+ // exactly the size it was and the row cannot shift on selection.
+ &.is-on {
+ border-color: var(--text);
+ box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--text-faint);
+ }
+ }
}
// ------------------------------------------------------------