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): one colour dot per series, not the whole palette every time

Juan Denisfc7bb3a0a14f
diff --git a/frontend/src/components/dashboard/grid/WidgetEditor.jsx b/frontend/src/components/dashboard/grid/WidgetEditor.jsx
index fbc1527e..5d5b2e45 100644
--- a/frontend/src/components/dashboard/grid/WidgetEditor.jsx
+++ b/frontend/src/components/dashboard/grid/WidgetEditor.jsx
@@ -1,9 +1,10 @@
-import { useMemo } from 'react';
+import { useMemo, useState } from 'react';
import {
Copy, LayoutGrid, Minus, Plus, Trash2,
} from 'lucide-react';
import { Drawer, SegControl } from '@/components/ds';
import { Switch } from '@/components/ui/switch';
+import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover';
import {
AGGREGATIONS, LINE_STYLES, SERIES_COLORS, getMetric,
metricsForResource, metricsForSource,
@@ -167,6 +168,44 @@ function Stepper({ label, value, onStep, suffix }) {
* any `[role=dialog][data-state=open]` is mounted. The old inspector was a bare
* <aside>, which is exactly why the bubble sat on top of its footer.
*/
+/**
+ * One dot showing a series' current colour; the palette lives behind it.
+ *
+ * The first pass rendered all seven swatches inline on every series row, which
+ * for a four-series chart meant twenty-eight coloured squares competing with
+ * the controls that actually matter. A colour picker only needs to show the
+ * colour — the alternatives are a click away.
+ */
+function SeriesColor({ value, fallback, index, onChange }) {
+ const [open, setOpen] = useState(false);
+ return (
+ <Popover open={open} onOpenChange={setOpen}>
+ <PopoverTrigger asChild>
+ <button
+ type="button"
+ className="skwe-edit__color"
+ aria-label={`Series ${index + 1} colour`}
+ title="Series colour"
+ style={{ background: value || fallback }}
+ />
+ </PopoverTrigger>
+ <PopoverContent align="start" sideOffset={6} className="skwe-palette">
+ {SERIES_COLORS.map(([option, name]) => (
+ <button
+ key={option || 'default'}
+ type="button"
+ aria-label={name}
+ title={name}
+ className={`skwe-palette__dot${(value || '') === option ? ' is-on' : ''}`}
+ style={{ background: option || fallback }}
+ onClick={() => { onChange(option); setOpen(false); }}
+ />
+ ))}
+ </PopoverContent>
+ </Popover>
+ );
+}
+
export function WidgetEditor({
widget,
type,
@@ -373,6 +412,12 @@ export function WidgetEditor({
key={index}
className={`skwe-edit__ser${multiResource ? '' : ' skwe-edit__ser--solo'}`}
>
+ <SeriesColor
+ value={series.color}
+ fallback={getMetric(series.metric)?.color}
+ index={index}
+ onChange={(value) => setSeries(index, 'color', value)}
+ />
{multiResource && (
<Select
label={`Series ${index + 1} resource`}
@@ -387,29 +432,6 @@ 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"
diff --git a/frontend/src/styles/components/_widget-editor.scss b/frontend/src/styles/components/_widget-editor.scss
index 74d79137..0c01c684 100644
--- a/frontend/src/styles/components/_widget-editor.scss
+++ b/frontend/src/styles/components/_widget-editor.scss
@@ -271,13 +271,13 @@ $skwe-pane-w: 340px;
&__ser {
display: grid;
- grid-template-columns: 1fr 1fr 26px;
+ grid-template-columns: 18px 1fr 1fr 26px;
align-items: center;
gap: 6px;
// Single-machine install: the resource picker is gone, so the metric
- // select takes the whole row.
- &--solo { grid-template-columns: 1fr 26px; }
+ // select takes the rest of the row.
+ &--solo { grid-template-columns: 18px 1fr 26px; }
.skwe-edit__select {
padding: 6px 22px 6px 8px;
@@ -384,18 +384,10 @@ $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 {
+ // Per-series colour: one dot showing the current choice. The palette is a
+ // popover, not an inline row — seven swatches repeated on every series made
+ // a four-series chart into twenty-eight competing squares.
+ &__color {
width: 16px;
height: 16px;
padding: 0;
@@ -404,13 +396,11 @@ $skwe-pane-w: 340px;
cursor: pointer;
transition: 0.12s;
- &:hover { transform: scale(1.12); }
+ &:hover { border-color: var(--text-faint); }
- // 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);
+ &:focus-visible {
+ outline: none;
+ box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--accent);
}
}
}
@@ -486,3 +476,33 @@ $skwe-pane-w: 340px;
}
}
}
+
+// Colour palette popover. Portalled to the body by Radix, so it is a top-level
+// block rather than nested inside .skwe-edit.
+.skwe-palette {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ width: auto;
+ padding: 8px;
+
+ &__dot {
+ width: 18px;
+ height: 18px;
+ 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: the swatch keeps its exact size, so
+ // selecting one cannot shift the row.
+ &.is-on {
+ border-color: var(--text);
+ box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--text-faint);
+ }
+ }
+}
+