Round dashboards: one face at a time, a face per widget type, paged by swipe, dots and keys; slider reading; face row in the editor

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Melvin Strobl
2026-10-14 15:24:25 +02:00
co-authored by Claude Opus 5.5
parent 8b8cb5cda9
commit 84071ee106
20 changed files with 1238 additions and 604 deletions
@@ -1,12 +1,11 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import { useNavigate } from "@tanstack/react-router"
import { Check, ExternalLink, Pencil, Plus, Settings2 } from "lucide-react"
import { motion } from "motion/react"
import { motion, Reorder } from "motion/react"
import { type CSSProperties, useEffect, useRef, useState } from "react"
import {
GridLayout,
type Layout,
noCompactor,
type Position,
setTransform,
} from "react-grid-layout"
@@ -44,15 +43,14 @@ import { DashboardPalette } from "./DashboardPalette"
import {
areaOf,
CanvasSurface,
canvasOf,
columnsOf,
type Dashboard,
DashboardView,
GRID_GAP,
isPlaced,
isRound,
offFace,
placement,
ringOf,
rowHeightOf,
rowsOf,
widgetsOf,
@@ -67,7 +65,7 @@ import {
usePublishDashboard,
useSaveDashboard,
} from "./queries"
import { RoundFace } from "./RingWidget"
import { ROUND_TYPES, RoundView } from "./RoundFace"
import { PaletteProvider } from "./settings"
import { useUi } from "./ui"
import { showTitle } from "./ui/core/config"
@@ -116,6 +114,91 @@ function Pickable({
)
}
/**
* A round dashboard's faces, in the order a panel pages through them.
*
* Its arrangement, since a round dashboard has no grid: press a face to show
* it and open its settings, and drag it along the row — or Alt+←/→ on it — to
* move it. A type drawn as a rectangle in the middle of the face says it is a
* poor fit. Floating chrome over the canvas, as the dock is.
*/
function FaceRow({
widgets,
shown,
reorder,
onPick,
onOrder,
}: {
widgets: WidgetDef[]
shown?: string
/** Dragging is a desktop affordance (DESIGN-GUIDELINES.md → Responsive). */
reorder: boolean
onPick: (id: string) => void
onOrder: (ids: string[]) => void
}) {
const ids = widgets.map((widget) => widget.id)
const move = (from: number, to: number) => {
if (to < 0 || to >= ids.length) return
const next = [...ids]
next.splice(to, 0, ...next.splice(from, 1))
onOrder(next)
}
return (
<Reorder.Group
as="div"
axis="x"
values={ids}
onReorder={onOrder}
layoutScroll
aria-label="Faces"
data-testid="face-row"
className="absolute bottom-full left-1/2 mb-3 flex max-w-[calc(100vw-2rem)] -translate-x-1/2 gap-1 overflow-x-auto rounded-full border border-border bg-card/80 p-1 shadow-e2 backdrop-blur-md [scrollbar-width:none]"
>
{widgets.map((widget, at) => (
<Reorder.Item
key={widget.id}
value={widget.id}
as="div"
dragListener={reorder}
className="shrink-0"
>
<button
type="button"
data-testid={`face-${widget.id}`}
aria-current={widget.id === shown ? "true" : undefined}
className={cn(
"flex h-11 items-center gap-1.5 rounded-full px-3 text-sm md:h-8",
widget.id === shown
? "bg-accent text-accent-foreground"
: "text-muted-foreground hover:bg-accent/50",
)}
onClick={() => onPick(widget.id)}
onKeyDown={(event) => {
const by =
event.key === "ArrowRight"
? 1
: event.key === "ArrowLeft"
? -1
: 0
if (!event.altKey || !by) return
event.preventDefault()
move(at, at + by)
}}
>
<span className="tabular-nums opacity-60">{at + 1}</span>
<span className="max-w-32 truncate">
{widget.title || WIDGET_LABELS[widget.type]}
</span>
{ROUND_TYPES.has(widget.type) ? null : (
<span className="text-xs text-muted-foreground">Poor fit</span>
)}
</button>
</Reorder.Item>
))}
</Reorder.Group>
)
}
/** How long to sit on edits before saving, so typing is not a save per key. */
const AUTOSAVE_MS = 800
@@ -140,7 +223,8 @@ const INTERACTIVE =
* still working on it. The grid item covers both; the frame is what a stacked
* dashboard has instead.
*/
const ON_WIDGET = "[data-testid=widget-frame], .react-grid-item"
const ON_WIDGET =
"[data-testid=widget-frame], .react-grid-item, [data-testid=round-face]"
function nextId(dashboard: DashboardDef_Output, type: string): string {
const taken = new Set(widgetsOf(dashboard).map((widget) => widget.id))
@@ -236,13 +320,17 @@ export function DashboardEditor({
}) {
const [draft, setDraft] = useState<Dashboard>(dashboard)
const [selected, setSelected] = useState<string | null>(null)
// The face a round dashboard shows: the widget picked, or the one last
// picked or paged to once its settings are put away.
const [face, setFace] = useState<string | null>(null)
const [settingsOpen, setSettingsOpen] = useState(false)
const [paletteOpen, setPaletteOpen] = useState(false)
// A phone reads the dashboard rather than arranges it, so the grid library
// never mounts there. See DESIGN-GUIDELINES.md → Responsive. A round one is
// the exception: a knob's face is about a phone's width as it is.
// never mounts there. See DESIGN-GUIDELINES.md → Responsive. A round one has
// no grid to arrange, and a knob's face is about a phone's width as it is.
const round = isRound(draft)
const stacked = useIsMobile() && !round
const mobile = useIsMobile()
const stacked = mobile && !round
// The dashboard's own appearance, on the surface only: the shell around the
// canvas stays whatever the person editing chose for the app. Non-stacked,
// `CanvasSurface` states it on the canvas box itself.
@@ -266,6 +354,10 @@ export function DashboardEditor({
version.current = dashboard.version
}, [dashboard.version])
useEffect(() => {
if (selected) setFace(selected)
}, [selected])
const store = (next: Dashboard) => {
const request = save
.mutateAsync({ ...next, version: version.current })
@@ -317,11 +409,6 @@ export function DashboardEditor({
const hasDraft = Boolean(dashboard.has_draft)
const columns = columnsOf(draft)
const widgets = widgetsOf(draft)
// The ring is drawn along a round face's edge and takes no cell.
const ring = ringOf(draft)
const placedWidgets = ring
? widgets.filter((widget) => widget !== ring)
: widgets
const updateWidgets = (next: WidgetDef[]) => {
commit({ ...draft, widgets: next })
@@ -386,35 +473,39 @@ export function DashboardEditor({
(panel.dashboards ?? []).length > 1 &&
(panel.dashboards ?? []).includes(draft.name),
)?.dashboards ?? null
const hasRail = Boolean(railDashboards) && !stacked
const rail = railDashboards ? (
<PanelRail
dashboards={railDashboards}
current={draft.name}
horizontal={stacked}
dots={round}
// Editing one dashboard of a panel and editing its neighbour are the
// same job, so the rail keeps whichever mode this one is in.
linkFor={(name) => ({
to: "/dashboards/$name",
params: { name },
search: edit ? { edit: true } : {},
})}
/>
) : null
// A round face has no room for one: a panel swipes between those instead.
const hasRail = Boolean(railDashboards) && !stacked && !round
const rail =
railDashboards && !round ? (
<PanelRail
dashboards={railDashboards}
current={draft.name}
horizontal={stacked}
// Editing one dashboard of a panel and editing its neighbour are the
// same job, so the rail keeps whichever mode this one is in.
linkFor={(name) => ({
to: "/dashboards/$name",
params: { name },
search: edit ? { edit: true } : {},
})}
/>
) : null
// What the arrangement is laid out in: the canvas less its margin, and less
// the rail's column when the panel carries one.
const area = areaOf(draft, hasRail)
const layout = layoutOf(placedWidgets, columns)
const layout = layoutOf(widgets, columns)
const rows = rowsOf(draft, hasRail)
// maxRows below only constrains a *drag*. A stored placement is corrected
// against `cols` and nothing else, so a canvas that shrank leaves whatever
// now falls past its bottom edge drawn under the clip.
const clipped = layout.filter((item) => item.y + item.h > rows)
// A round face cuts the corners off the grid it is laid out in.
const cornered = offFace(draft, layout)
// now falls past its bottom edge drawn under the clip. A round face has no
// grid to fall off.
const clipped = round ? [] : layout.filter((item) => item.y + item.h > rows)
const shown = Math.max(
0,
widgets.findIndex((widget) => widget.id === (selected ?? face)),
)
/** Store what the grid ended up doing, unless it did nothing. */
const applyLayout = (next: Layout) => {
@@ -443,7 +534,7 @@ export function DashboardEditor({
* room above it — it has to move sideways. */
const reflow = () => {
const at = new Map(layout.map((item) => [item.i, item]))
const ordered = [...placedWidgets].sort((a, b) => {
const ordered = [...widgets].sort((a, b) => {
const left = at.get(a.id)
const right = at.get(b.id)
return (
@@ -519,35 +610,32 @@ export function DashboardEditor({
) : null}
</div>
) : (
<CanvasSurface
dashboard={draft}
dots={edit}
rail={rail}
face={
<RoundFace
dashboard={draft}
editing={edit}
selected={Boolean(ring) && ring?.id === selected}
onPick={(id) => {
setSettingsOpen(false)
setSelected(id)
}}
/>
}
>
<CanvasSurface dashboard={draft} dots={edit} rail={rail}>
{(scale) =>
!edit ? (
<DashboardView dashboard={draft} rail={hasRail} />
) : round ? (
// One face at a time, the one picked in the row of faces below.
<RoundView
dashboard={draft}
size={canvasOf(draft).width}
face={shown}
editing
onFace={(index) => {
setFace(widgets[index].id)
if (selected) setSelected(widgets[index].id)
}}
onPick={(id) => {
setSettingsOpen(false)
setSelected(id)
}}
/>
) : (
<GridLayout
width={area.width}
layout={layout}
onLayoutChange={applyLayout}
positionStrategy={scaledStrategy(scale)}
// A circle is narrowest at the top, which is where packing
// upwards would put everything: a round face keeps each tile
// where it was placed.
compactor={round ? noCompactor : undefined}
gridConfig={{
cols: columns,
rowHeight: rowHeightOf(draft, hasRail),
@@ -569,7 +657,7 @@ export function DashboardEditor({
}}
resizeConfig={{ handles: ["e", "s", "se"] }}
>
{placedWidgets.map((widget) => (
{widgets.map((widget) => (
<div key={widget.id}>{pickable(widget, true)}</div>
))}
</GridLayout>
@@ -591,6 +679,8 @@ export function DashboardEditor({
className={cn(
"absolute inset-0 overflow-hidden px-4 pb-24 pt-20 transition-[padding] duration-200",
panelOpen && "md:pr-[27rem]",
// Clear of the row of faces above the dock.
edit && round && "pb-40",
)}
data-testid="dashboard-canvas"
onClick={(event) => {
@@ -660,26 +750,23 @@ export function DashboardEditor({
Reflow
</Button>
</motion.div>
) : cornered.length > 0 && !stacked ? (
// Not a fault and nothing to re-pack: the tile still shows,
// less what the circle cuts off it.
<motion.div
variants={slideUp}
initial="hidden"
animate="visible"
exit="exit"
transition={transitions.emphasized}
role="status"
aria-live="polite"
data-testid="canvas-cornered"
className="absolute bottom-full left-1/2 mb-3 flex max-w-[calc(100vw-2rem)] -translate-x-1/2 items-center rounded-full border border-border bg-card/80 px-4 py-1.5 shadow-e2 backdrop-blur-md"
>
<span className="truncate text-sm">
{cornered.length === 1
? "1 widget reaches past the round face — its corners will be cut off."
: `${cornered.length} widgets reach past the round face — their corners will be cut off.`}
</span>
</motion.div>
) : round && widgets.length > 0 ? (
<FaceRow
widgets={widgets}
shown={widgets[shown]?.id}
reorder={!mobile}
onPick={(id) => {
setSettingsOpen(false)
setSelected(id)
}}
onOrder={(ids) =>
updateWidgets(
ids.flatMap((id) =>
widgets.filter((widget) => widget.id === id),
),
)
}
/>
) : null}
<Tooltip>
@@ -793,21 +880,10 @@ export function DashboardEditor({
<WidgetPanel
widget={active}
round={round}
onRing={Boolean(active) && draft.ring === active?.id}
// One ring per face, so putting a widget on it takes it off any
// other.
onRingChange={(on) =>
active && commit({ ...draft, ring: on ? active.id : "" })
}
onChange={(changes) => active && patch(active.id, changes)}
onDelete={() => {
if (!active) return
// A ring naming a widget that is gone is refused on save.
commit({
...draft,
widgets: widgets.filter((other) => other.id !== active.id),
ring: draft.ring === active.id ? "" : draft.ring,
})
updateWidgets(widgets.filter((other) => other.id !== active.id))
setSelected(null)
}}
onClose={() => setSelected(null)}