feat(manager): the floor plan editor reworked; Management -> Tables on the page rule; area colours

- Floor editor: one toolbar over the map and the panels (grid on / off, grid resolution Ultra high
  ... Very low, edit the shape, Fit width / Whole plan, undo, save), panels top-aligned and sticky.
- The floor's shape: a '+' on the edge under the pointer, press to add a corner (and drag it);
  resting on a corner shows a bubble to remove it (never below 3).
- Areas: resize handles on the sides and corners, a colour (pastel, see-through; floor_items.color,
  migration 0041), the name repeated in the corner when tables cover it (live maps too).
- Labels can be clicked again after they're placed (transparent fill, not none).
- Management -> Tables: <Page> with the tabs above (?tab=), the list as a container, toolbar
  buttons one height.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 15:17:45 +02:00
co-authored by Claude Opus 5.5
parent 476c55abc0
commit 244e93f827
17 changed files with 389 additions and 111 deletions
@@ -1,7 +1,9 @@
// Management → Tables: the tables and their zones (the list, for typing and bulk changes), and
// the floor plans (plan step 6.8: where the tables stand, drawn on a map).
import { useState } from 'react'
// the floor plans (plan step 6.8: where the tables stand, drawn on a map). On the page rule
// (2026-11-20): the tabs above, the tab in the address (?tab=).
import { useSearchParams } from 'react-router-dom'
import { useTranslation } from '@xenia/i18n'
import { Page, Tabs } from '@xenia/ui'
import FloorPlansTab from '../floor/FloorPlansTab'
import TablesListTab from '../tables/TablesListTab'
@@ -9,21 +11,14 @@ const TABS = ['list', 'floor']
export default function TablesConfigPage() {
const { t } = useTranslation('manager')
const [tab, setTab] = useState('list')
const [params, setParams] = useSearchParams()
const tab = TABS.includes(params.get('tab')) ? params.get('tab') : 'list'
const setTab = v => setParams(p => { const n = new URLSearchParams(p); n.set('tab', v); return n }, { replace: true })
return (
<div className="flex flex-col h-full min-h-0">
<div className="flex flex-wrap gap-1 border-b border-line px-4 md:px-6 pt-3 shrink-0" role="tablist" aria-label={t('floor.pageTabs')}>
{TABS.map(k => (
<button key={k} type="button" role="tab" aria-selected={tab === k} onClick={() => setTab(k)} data-testid={`tables-tab-${k}`}
className={`px-3 py-2 -mb-px border-b-2 text-label font-medium transition-colors duration-fast
${tab === k ? 'border-accent text-accent-ink' : 'border-transparent text-ink-2 hover:text-ink'}`}>
{t(`floor.tabs.${k}`)}
</button>
))}
</div>
<div className="flex-1 min-h-0 overflow-y-auto">
{tab === 'list' ? <TablesListTab /> : <FloorPlansTab />}
</div>
</div>
<Page testId="tables-config"
top={<Tabs size="lg" value={tab} onChange={setTab} aria-label={t('floor.pageTabs')}
tabs={TABS.map(k => ({ id: k, label: t(`floor.tabs.${k}`), testId: `tables-tab-${k}` }))} />}>
{tab === 'list' ? <TablesListTab /> : <FloorPlansTab />}
</Page>
)
}
+164 -53
View File
@@ -1,24 +1,44 @@
// One floor plan's editor (plan step 6.8, D-31). Drag tables and things on the floor; the panel
// on the right edits what's selected (shape, seats, size, rotation, text), adds the tables that
// aren't on the plan and walls / the bar / labels / areas, and holds the plan's settings: name,
// zone, size, the grid (snap on / off and its size), the floor's shape (drag its corners; add or
// remove corners) and a background picture from the media library. Arrow keys move the selected
// thing (a grid cell, or 5; Shift: 1), Delete takes it off, Escape lets go. Nothing is saved
// until "Save"; then every app's map changes at once.
import { useMemo, useRef, useState } from 'react'
// zone, size, a background picture. The toolbar over both: the grid (on / off and its resolution),
// "Edit the floor's shape", fit the width or the whole plan, undo, save.
// The floor's shape (2026-11-20): drag a corner; on an edge a "+" shows where a click adds a
// corner; resting on a corner shows a bubble to remove it (a floor keeps at least 3). An area
// (2026-11-20) is resized by the handles on its sides and corners, and has a colour (pastel, see-
// through); when tables cover its name, the name shows in its corner too.
// Arrow keys move the selected thing (a grid cell, or 5; Shift: 1), Delete takes it off, Escape
// lets go. Nothing is saved until "Save"; then every app's map changes at once.
import { useLayoutEffect, useMemo, useRef, useState } from 'react'
import toast from 'react-hot-toast'
import { RotateCcw, RotateCw, Save, Trash2, Undo2 } from 'lucide-react'
import { errorMessage } from '@xenia/api'
import {
Floor, GRID_SIZES, ITEM_KINDS, Item, SHAPES, TableShape, addCorner, defaultSize, moveCorner, moveTo, outlineOf, removeCorner, toPlan,
AREA_COLOURS, Floor, GRID_LEVELS, ITEM_KINDS, Item, SHAPES, TableShape, addCornerAt, coveredAreas, defaultSize, moveCorner, moveTo,
nearestEdge, outlineOf, removeCorner, resizeBox, toPlan,
} from '@xenia/floorplan'
import { useTranslation } from '@xenia/i18n'
import { Button, Dialog, Field, IconButton, Input, Select, Switch, cx } from '@xenia/ui'
import { Button, Dialog, Dropdown, Field, IconButton, Input, Segmented, Switch, cx } from '@xenia/ui'
import MediaField from '../media/MediaField'
import * as api from './floorApi'
import { addItem, addable, find, fitOutline, layoutBody, layoutOf, nudge, placeTable, planBody, remove, resize, rotate, sameLayout, update } from './editorLogic'
const PAD = 30 // room around the floor for the corner handles
const HANDLES = ['nw', 'n', 'ne', 'e', 'se', 's', 'sw', 'w']
const CURSOR = { n: 'ns-resize', s: 'ns-resize', e: 'ew-resize', w: 'ew-resize', nw: 'nwse-resize', se: 'nwse-resize', ne: 'nesw-resize', sw: 'nesw-resize' }
/** The size of an element, kept up to date. */
function useSize(ref) {
const [size, setSize] = useState({ width: 0, height: 0 })
useLayoutEffect(() => {
const el = ref.current
if (!el) return undefined
const ro = new ResizeObserver(([e]) => setSize({ width: e.contentRect.width, height: e.contentRect.height }))
ro.observe(el)
return () => ro.disconnect()
}, [ref])
return size
}
export default function FloorEditor({ plan: saved, data, groups, onSaved, onDeleted }) {
const { t } = useTranslation('manager')
@@ -30,8 +50,14 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
const [newShape, setNewShape] = useState('square')
const [busy, setBusy] = useState(false)
const [deleting, setDeleting] = useState(false)
const [fit, setFit] = useState('width') // 'width' | 'all'
const [edgeHover, setEdgeHover] = useState(null) // where a click on the edge adds a corner
const [cornerTip, setCornerTip] = useState(null) // the corner showing its "remove" bubble
const tipTimer = useRef(null)
const svg = useRef(null)
const box = useRef(null)
const drag = useRef(null)
const size = useSize(box)
const plan = form // the preview follows the unsaved settings
const dirtySettings = JSON.stringify(planBody(form)) !== JSON.stringify(planBody(saved))
@@ -40,6 +66,13 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
const corners = outlineOf(plan)
const setF = (k, v) => setForm(f => ({ ...f, [k]: v }))
const { own, other } = addable(data, plan, layout)
const covered = coveredAreas(layout.items, layout.tables)
// the scale: the plan (and its margin) fitted to the width, or whole in the box
const vbW = plan.width + 2 * PAD
const vbH = plan.height + 2 * PAD
const scale = size.width ? (fit === 'all' && size.height ? Math.min(size.width / vbW, size.height / vbH) : size.width / vbW) : 1
const r = Math.max(8, 9 / scale) // a handle's size on screen ≈ 18 px
const point = e => toPlan(svg.current, e.clientX, e.clientY)
const start = (e, target) => {
@@ -49,6 +82,8 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
if (target.type === 'corner') {
setSel(target)
drag.current = { target }
} else if (target.handle) {
drag.current = { target }
} else {
const thing = find(layout, target)
setSel(target)
@@ -58,12 +93,22 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
}
const move = e => {
const d = drag.current
if (!d) return
const [px, py] = point(e)
if (!d) {
if (shapeMode) {
const n = nearestEdge(corners, [px, py])
setEdgeHover(n && n.d < 14 / scale ? n : null)
}
return
}
if (d.target.type === 'corner') {
setForm(f => ({ ...f, outline: moveCorner(outlineOf(f), d.target.index, px, py, f) }))
return
}
if (d.target.handle) {
setLayout(l => update(l, d.target, resizeBox(find(l, d.target), d.target.handle, px, py, plan)))
return
}
setLayout(l => {
const thing = find(l, d.target)
if (!thing) return l
@@ -72,6 +117,17 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
})
}
const end = () => { drag.current = null }
const down = e => {
if (shapeMode && edgeHover) {
// a click on an edge adds a corner there and starts dragging it
const index = edgeHover.index + 1
setForm(f => ({ ...f, outline: addCornerAt(outlineOf(f), edgeHover.index, edgeHover.x, edgeHover.y, f) }))
setEdgeHover(null)
start(e, { type: 'corner', index })
return
}
setSel(null)
}
const keys = e => {
if (!sel || sel.type === 'corner') return
const dirs = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }
@@ -79,6 +135,9 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
else if (e.key === 'Delete' || e.key === 'Backspace') { e.preventDefault(); setLayout(l => remove(l, sel)); setSel(null) }
else if (e.key === 'Escape') setSel(null)
}
const showTip = i => { clearTimeout(tipTimer.current); tipTimer.current = setTimeout(() => setCornerTip(i), 600) }
const hideTip = () => { clearTimeout(tipTimer.current); tipTimer.current = setTimeout(() => setCornerTip(null), 500) }
const keepTip = () => clearTimeout(tipTimer.current)
const save = async () => {
setBusy(true)
@@ -90,33 +149,39 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
} catch (err) { toast.error(errorMessage(err, t)) } finally { setBusy(false) }
}
const zoneName = id => groups.find(g => g.id === id)?.name ?? t('floor.noZone')
const gridOptions = [...GRID_LEVELS.map(([k, v]) => ({ value: v, label: t(`floor.gridLevels.${k}`), hint: t('floor.gridCell', { size: v }) })),
...(GRID_LEVELS.some(([, v]) => v === form.grid_size) ? [] : [{ value: form.grid_size, label: t('floor.gridCell', { size: form.grid_size }) }])]
const resizable = selected && sel.type === 'item' && selected.kind === 'area' && !shapeMode && Math.round(selected.rotation || 0) % 180 === 0
return (
<div className="grid gap-4 lg:grid-cols-[1fr_18rem] items-start" data-testid="floor-editor" data-plan={saved.id}>
<div className="grid gap-3 content-start min-w-0">
<div className="flex flex-wrap items-center gap-2">
<h2 className="text-body-lg font-semibold text-ink mr-auto">{form.name || saved.name}</h2>
{dirty && <span className="px-2 py-0.5 rounded-full bg-warning-soft text-warning-ink text-caption font-medium" data-testid="floor-dirty">{t('floor.unsaved')}</span>}
<Button variant="secondary" size="sm" icon={<Undo2 size={16} />} disabled={!dirty || busy}
onClick={() => { setLayout(initial); setForm({ ...saved }); setSel(null) }}>{t('floor.undoAll')}</Button>
<Button size="sm" icon={<Save size={16} />} loading={busy} disabled={!dirty || !form.name.trim()} onClick={save} data-testid="floor-save">{t('floor.save')}</Button>
</div>
<div className="flex flex-wrap items-center gap-3 text-label text-ink-2">
<Switch checked={!!form.grid_on} onChange={v => setF('grid_on', v)} label={t('floor.grid')} data-testid="floor-grid" />
{form.grid_on && (
<Select size="sm" value={String(form.grid_size)} onChange={e => setF('grid_size', Number(e.target.value))} aria-label={t('floor.gridSize')}
options={[...new Set([...GRID_SIZES, form.grid_size])].sort((a, b) => a - b).map(v => ({ value: String(v), label: t('floor.gridCell', { size: v }) }))} />
)}
<Switch checked={shapeMode} onChange={v => { setShapeMode(v); setSel(null) }} label={t('floor.editShape')} data-testid="floor-shape-mode" />
</div>
{shapeMode && <p className="text-caption text-ink-2">{t('floor.shapeHint')}</p>}
<div className="rounded-card border border-line bg-canvas overflow-auto max-h-[70vh]">
<svg ref={svg} viewBox={`${-PAD} ${-PAD} ${plan.width + 2 * PAD} ${plan.height + 2 * PAD}`} tabIndex={0} onKeyDown={keys} role="application" aria-label={t('floor.canvas')}
className="block w-full h-auto touch-none select-none outline-none focus-visible:ring-2 focus-visible:ring-[var(--x-accent)]"
onPointerMove={move} onPointerUp={end} onPointerCancel={end} onPointerDown={() => setSel(null)} data-testid="floor-canvas">
<div className="grid gap-4 lg:grid-cols-[minmax(0,1fr)_19rem] items-start" data-testid="floor-editor" data-plan={saved.id}>
{/* the toolbar, over the map and the panels */}
<div className="lg:col-span-2 flex flex-wrap items-center gap-x-4 gap-y-2 px-card py-card-y rounded-card border border-line bg-surface shadow-raised">
<h2 className="text-body-lg font-semibold text-ink">{form.name || saved.name}</h2>
{dirty && <span className="px-2 py-0.5 rounded-full bg-warning-soft text-warning-ink text-caption font-medium" data-testid="floor-dirty">{t('floor.unsaved')}</span>}
<span className="flex-1" />
<Switch checked={!!form.grid_on} onChange={v => setF('grid_on', v)} label={t('floor.grid')} data-testid="floor-grid" />
{form.grid_on && (
<Dropdown size="sm" className="w-44" value={form.grid_size} onChange={v => setF('grid_size', v)} aria-label={t('floor.gridSize')} data-testid="floor-grid-size" options={gridOptions} />
)}
<Switch checked={shapeMode} onChange={v => { setShapeMode(v); setSel(null); setEdgeHover(null); setCornerTip(null) }} label={t('floor.editShape')} data-testid="floor-shape-mode" />
<Segmented size="sm" value={fit} onChange={setFit} aria-label={t('floor.fit')}
options={[{ value: 'width', label: t('floor.fitWidth'), testId: 'floor-fit-width' }, { value: 'all', label: t('floor.fitAll'), testId: 'floor-fit-all' }]} />
<Button variant="secondary" size="sm" icon={<Undo2 size={16} />} disabled={!dirty || busy}
onClick={() => { setLayout(initial); setForm({ ...saved }); setSel(null) }}>{t('floor.undoAll')}</Button>
<Button size="sm" icon={<Save size={16} />} loading={busy} disabled={!dirty || !form.name.trim()} onClick={save} data-testid="floor-save">{t('floor.save')}</Button>
</div>
<div className="grid gap-2 content-start min-w-0">
<div ref={box} className={cx('rounded-card border border-line bg-canvas overflow-auto', fit === 'all' ? 'h-[calc(100dvh-17rem)] min-h-[22rem]' : 'max-h-[calc(100dvh-17rem)]')}
style={{ scrollbarGutter: 'stable' }}>
<svg ref={svg} viewBox={`${-PAD} ${-PAD} ${vbW} ${vbH}`} tabIndex={0} onKeyDown={keys} role="application" aria-label={t('floor.canvas')}
width={Math.max(1, vbW * scale)} height={Math.max(1, vbH * scale)}
className={cx('block mx-auto touch-none select-none outline-none focus-visible:ring-2 focus-visible:ring-[var(--x-accent)]', shapeMode && edgeHover && 'cursor-copy')}
onPointerMove={move} onPointerUp={end} onPointerCancel={end} onPointerDown={down} onPointerLeave={() => setEdgeHover(null)} data-testid="floor-canvas">
<Floor plan={plan} showGrid={!!plan.grid_on} />
{layout.items.map(i => (
<Item key={i.key} item={i} label={t('floor.kinds.bar')} selected={sel?.type === 'item' && sel.id === i.key}
<Item key={i.key} item={i} label={t('floor.kinds.bar')} selected={sel?.type === 'item' && sel.id === i.key} corner={covered.has(i.key)}
style={{ cursor: shapeMode ? 'default' : 'move' }} pointerEvents={shapeMode ? 'none' : undefined}
onPointerDown={e => start(e, { type: 'item', id: i.key })} data-testid="floor-item" data-kind={i.kind} />
))}
@@ -125,27 +190,55 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
style={{ cursor: shapeMode ? 'default' : 'move' }} pointerEvents={shapeMode ? 'none' : undefined}
onPointerDown={e => start(e, { type: 'table', id: tb.id })} data-testid="floor-table" />
))}
{resizable && HANDLES.map(h => {
const x = selected.x + (h.includes('e') ? 1 : h.includes('w') ? -1 : 0) * selected.width / 2
const y = selected.y + (h.includes('s') ? 1 : h.includes('n') ? -1 : 0) * selected.height / 2
return (
<rect key={h} x={x - r / 2} y={y - r / 2} width={r} height={r} rx={r / 4} fill="var(--x-surface)" stroke="var(--x-accent)" strokeWidth={2 / scale}
style={{ cursor: CURSOR[h] }} data-testid={`floor-handle-${h}`}
onPointerDown={e => start(e, { type: 'item', id: sel.id, handle: h })} />
)
})}
{shapeMode && edgeHover && (
<g transform={`translate(${edgeHover.x} ${edgeHover.y})`} pointerEvents="none" data-testid="floor-edge-add">
<circle r={r} fill="var(--x-accent)" />
<path d={`M ${-r * 0.5} 0 H ${r * 0.5} M 0 ${-r * 0.5} V ${r * 0.5}`} stroke="var(--x-accent-fg)" strokeWidth={2.5 / scale} strokeLinecap="round" />
</g>
)}
{shapeMode && corners.map(([x, y], i) => (
<circle key={i} cx={x} cy={y} r={Math.max(10, plan.width / 90)} data-testid="floor-corner"
fill={sel?.type === 'corner' && sel.index === i ? 'var(--x-accent)' : 'var(--x-surface)'} stroke="var(--x-accent)" strokeWidth="3"
style={{ cursor: 'grab' }} onPointerDown={e => start(e, { type: 'corner', index: i })} />
<circle key={i} cx={x} cy={y} r={r} data-testid="floor-corner"
fill={sel?.type === 'corner' && sel.index === i ? 'var(--x-accent)' : 'var(--x-surface)'} stroke="var(--x-accent)" strokeWidth={3 / scale}
style={{ cursor: 'grab' }} onPointerDown={e => { setCornerTip(null); start(e, { type: 'corner', index: i }) }}
onPointerEnter={() => showTip(i)} onPointerLeave={hideTip} />
))}
{shapeMode && cornerTip != null && corners[cornerTip] && (
// the bubble over a corner: remove it (not below 3 corners)
<g transform={`translate(${corners[cornerTip][0]} ${corners[cornerTip][1] - r * 3.2})`} onPointerEnter={keepTip} onPointerLeave={hideTip} data-testid="floor-corner-tip">
<rect x={-r * 1.6} y={-r * 1.3} width={r * 3.2} height={r * 2.6} rx={r * 0.5} fill="var(--x-surface)" stroke="var(--x-line-strong)" strokeWidth={1.5 / scale} />
<path d={`M ${-r * 0.35} ${r * 1.3} L 0 ${r * 1.9} L ${r * 0.35} ${r * 1.3} Z`} fill="var(--x-surface)" stroke="var(--x-line-strong)" strokeWidth={1.5 / scale} />
<g role="button" aria-label={t('floor.removeCorner')} style={{ cursor: corners.length > 3 ? 'pointer' : 'not-allowed' }} opacity={corners.length > 3 ? 1 : 0.4}
onPointerDown={e => {
e.stopPropagation()
if (corners.length <= 3) return
setForm(f => ({ ...f, outline: removeCorner(outlineOf(f), cornerTip) }))
setCornerTip(null); setSel(null)
}} data-testid="floor-corner-remove">
<rect x={-r * 1.6} y={-r * 1.3} width={r * 3.2} height={r * 2.6} fill="transparent" />
<Trash2 x={-r * 0.8} y={-r * 0.8} width={r * 1.6} height={r * 1.6} color="var(--x-danger-ink)" />
</g>
</g>
)}
</svg>
</div>
<p className="text-caption text-ink-3">{t('floor.keysHint')}</p>
<p className="text-caption text-ink-3">{shapeMode ? t('floor.shapeHint') : t('floor.keysHint')}</p>
</div>
<aside className="grid gap-4 content-start lg:max-h-[calc(100vh-10rem)] lg:overflow-y-auto">
<aside className="grid gap-4 content-start lg:sticky lg:top-0">
{shapeMode ? (
<Panel title={t('floor.shapeTitle')}>
<p className="text-caption text-ink-2">{t('floor.cornerCount', { count: corners.length })}</p>
<div className="flex flex-wrap gap-2">
<Button size="sm" variant="secondary" disabled={sel?.type !== 'corner'} data-testid="floor-corner-add"
onClick={() => setForm(f => ({ ...f, outline: addCorner(outlineOf(f), sel.index) }))}>{t('floor.addCorner')}</Button>
<Button size="sm" variant="secondary" disabled={sel?.type !== 'corner' || corners.length <= 3}
onClick={() => { setForm(f => ({ ...f, outline: removeCorner(outlineOf(f), sel.index) })); setSel(null) }}>{t('floor.removeCorner')}</Button>
<Button size="sm" variant="ghost" disabled={!form.outline} onClick={() => { setF('outline', null); setSel(null) }}>{t('floor.rectangle')}</Button>
</div>
<p className="text-caption text-ink-2">{t('floor.shapeHowTo')}</p>
<Button size="sm" variant="secondary" disabled={!form.outline} className="justify-self-start" onClick={() => { setF('outline', null); setSel(null) }}>{t('floor.rectangle')}</Button>
</Panel>
) : selected ? (
<Selected thing={selected} sel={sel} plan={plan} t={t}
@@ -154,7 +247,7 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
) : (
<Panel title={t('floor.add')}>
<Field label={t('floor.newTableShape')}>
<Select size="sm" value={newShape} onChange={e => setNewShape(e.target.value)} options={SHAPES.map(s => ({ value: s, label: t(`floor.shapes.${s}`) }))} />
<Segmented size="sm" value={newShape} onChange={setNewShape} options={SHAPES.map(s => ({ value: s, label: t(`floor.shapes.${s}`) }))} />
</Field>
{own.length + other.length === 0 ? <p className="text-caption text-ink-3">{t('floor.allPlaced')}</p> : (
<div className="grid gap-2">
@@ -165,11 +258,11 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
</div>
)}
<div className="grid gap-1.5">
<span className="text-label font-semibold text-ink">{t('floor.things')}</span>
<span className="text-overline font-semibold uppercase tracking-wide text-ink-3">{t('floor.things')}</span>
<div className="flex flex-wrap gap-2">
{ITEM_KINDS.map(k => (
<Button key={k} size="sm" variant="secondary" data-testid={`floor-add-${k}`}
onClick={() => { const r = addItem(layout, plan, k, k === 'label' ? t('floor.labelText') : null); setLayout(r.layout); setSel({ type: 'item', id: r.key }) }}>
onClick={() => { const res = addItem(layout, plan, k, k === 'label' ? t('floor.labelText') : null); setLayout(res.layout); setSel({ type: 'item', id: res.key }) }}>
{t(`floor.kinds.${k}`)}
</Button>
))}
@@ -181,7 +274,7 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
<Panel title={t('floor.settings')}>
<Field label={t('floor.name')}><Input size="sm" value={form.name} maxLength={60} onChange={e => setF('name', e.target.value)} data-testid="floor-name" /></Field>
<Field label={t('floor.zone')} hint={t('floor.zoneHint')}>
<Select size="sm" value={form.group_id ?? ''} onChange={e => setF('group_id', e.target.value === '' ? null : Number(e.target.value))}
<Dropdown size="sm" value={form.group_id ?? ''} onChange={v => setF('group_id', v === '' ? null : v)}
options={[{ value: '', label: t('floor.noZone') }, ...groups.map(g => ({ value: g.id, label: g.name }))]} />
</Field>
<div className="grid grid-cols-2 gap-2">
@@ -222,8 +315,8 @@ export default function FloorEditor({ plan: saved, data, groups, onSaved, onDele
function Panel({ title, children }) {
return (
<section className="grid gap-3 p-4 rounded-card border border-line bg-surface shadow-raised">
<h3 className="text-label font-semibold text-ink uppercase tracking-wide">{title}</h3>
<section className="grid gap-3 p-card rounded-card border border-line bg-surface shadow-raised">
<h3 className="text-overline font-semibold text-ink-3 uppercase tracking-wide">{title}</h3>
{children}
</section>
)
@@ -248,6 +341,7 @@ function TableButtons({ tables, title, onAdd, quiet = false }) {
function Selected({ thing, sel, plan, t, onChange, onRemove }) {
const isTable = sel.type === 'table'
const isArea = !isTable && thing.kind === 'area'
const setSize = (w, h) => onChange(resize(thing, plan, w, h))
return (
<Panel title={isTable ? t('floor.table', { name: thing.name }) : t(`floor.kinds.${thing.kind}`)}>
@@ -276,10 +370,27 @@ function Selected({ thing, sel, plan, t, onChange, onRemove }) {
<Input size="sm" value={thing.text ?? ''} maxLength={60} onChange={e => onChange({ text: e.target.value })} data-testid="floor-item-text" />
</Field>
)}
<div className="grid grid-cols-2 gap-2">
<Field label={t('floor.itemWidth')}><Input size="sm" type="number" min={4} value={thing.width} onChange={e => setSize(Number(e.target.value), undefined)} /></Field>
<Field label={t('floor.itemHeight')}><Input size="sm" type="number" min={4} value={thing.height} onChange={e => setSize(undefined, Number(e.target.value))} /></Field>
</div>
{isArea ? (
<>
<Field label={t('floor.colour')}>
<div className="flex flex-wrap gap-2" role="radiogroup" aria-label={t('floor.colour')} data-testid="floor-area-colours">
{AREA_COLOURS.map(c => (
<button key={c} type="button" role="radio" aria-checked={thing.color === c} aria-label={c} onClick={() => onChange({ color: c })}
className={cx('w-8 h-8 rounded-full border-2', thing.color === c ? 'border-accent ring-2 ring-[var(--x-accent)] ring-offset-2 ring-offset-[var(--x-surface)]' : 'border-line')}
style={{ background: c, opacity: 0.85 }} />
))}
<button type="button" role="radio" aria-checked={!thing.color} onClick={() => onChange({ color: null })}
className={cx('px-2 h-8 rounded-full border-2 text-caption text-ink-2', !thing.color ? 'border-accent' : 'border-line')}>{t('floor.noColour')}</button>
</div>
</Field>
<p className="text-caption text-ink-2">{t('floor.areaResizeHint')}</p>
</>
) : (
<div className="grid grid-cols-2 gap-2">
<Field label={t('floor.itemWidth')}><Input size="sm" type="number" min={4} value={thing.width} onChange={e => setSize(Number(e.target.value), undefined)} /></Field>
<Field label={t('floor.itemHeight')}><Input size="sm" type="number" min={4} value={thing.height} onChange={e => setSize(undefined, Number(e.target.value))} /></Field>
</div>
)}
<div className="flex items-center gap-1.5">
<span className="text-label text-ink-2 mr-auto">{t('floor.rotation', { deg: Math.round(thing.rotation || 0) })}</span>
<IconButton size="sm" variant="secondary" label={t('floor.rotateLeft')} onClick={() => onChange({ rotation: rotate(thing.rotation || 0, -15) })}><RotateCcw size={16} /></IconButton>
@@ -29,7 +29,7 @@ export default function FloorPlansTab() {
{ id: null, name: t('floor.noZone'), plans: plans.filter(p => p.group_id == null || !groups.some(g => g.id === p.group_id)) }].filter(z => z.plans.length)
return (
<div className="p-4 md:p-6 grid gap-4" data-testid="floor-plans">
<div className="grid gap-4" data-testid="floor-plans">
<nav className="grid gap-2" aria-label={t('floor.title')}>
<p className="text-label text-ink-2 max-w-4xl">{t('floor.intro')}</p>
<div className="flex flex-wrap items-end gap-x-4 gap-y-2">
@@ -1,7 +1,7 @@
// The floor plan editor's state as plain data (plan step 6.8, D-31), tested in tests/floor.test.mjs.
// A layout = { tables: [...placed tables], items: [...] } for one plan; the editor changes it
// locally and saves it whole (PUT /api/floor-plans/{id}/layout).
import { ITEM_SIZES, clamp, defaultSize, moveTo, snapSize } from '@xenia/floorplan/geometry'
import { AREA_COLOURS, ITEM_SIZES, clamp, defaultSize, moveTo, snapSize } from '@xenia/floorplan/geometry'
/** The layout of a plan from GET /api/floor-plans. Items get local keys (`key`). */
export function layoutOf(data, planId) {
@@ -52,7 +52,8 @@ let counter = 0
export function addItem(layout, plan, kind, text = null) {
const [w, h] = ITEM_SIZES[kind]
const grid = gridOf(plan)
const item = moveTo({ key: `n${++counter}`, kind, width: snapSize(w, grid), height: kind === 'wall' ? h : snapSize(h, grid), rotation: 0, text }, plan.width / 2, plan.height / 2, plan)
const item = moveTo({ key: `n${++counter}`, kind, width: snapSize(w, grid), height: kind === 'wall' ? h : snapSize(h, grid), rotation: 0, text,
color: kind === 'area' ? AREA_COLOURS[layout.items.filter(i => i.kind === 'area').length % AREA_COLOURS.length] : null }, plan.width / 2, plan.height / 2, plan)
return { layout: { ...layout, items: [...layout.items, item] }, key: item.key }
}
@@ -98,7 +99,7 @@ export const rotate = (deg, by) => (((deg + by) % 360) + 360) % 360
export function layoutBody(layout) {
return {
tables: layout.tables.map(t => ({ id: t.id, x: t.x, y: t.y, width: t.width, height: t.height, rotation: t.rotation || 0, shape: t.shape || 'square', seats: t.seats ?? null })),
items: layout.items.map(i => ({ kind: i.kind, x: i.x, y: i.y, width: i.width, height: i.height, rotation: i.rotation || 0, text: i.text || null })),
items: layout.items.map(i => ({ kind: i.kind, x: i.x, y: i.y, width: i.width, height: i.height, rotation: i.rotation || 0, text: i.text || null, color: i.kind === 'area' ? i.color || null : null })),
}
}
@@ -75,8 +75,8 @@ export default function TablesListTab() {
}
return (
<div className="flex flex-col h-full min-h-0" data-testid="tables-list">
<div className="flex flex-wrap items-center gap-2 border-b border-line px-4 md:px-6 py-3 shrink-0">
<div className="rounded-card border border-line bg-surface shadow-raised min-w-0" data-testid="tables-list">
<div className="flex flex-wrap items-center gap-2 border-b border-line px-card py-card-y">
{picking || picked.size ? (<>
<Button size="sm" variant="ghost" icon={<X size={14} />} onClick={stopPicking}>{picked.size ? t('tablesList.picked', { count: picked.size }) : t('tablesList.pick')}</Button>
<Button size="sm" variant="ghost" onClick={pickAll}>{t(allPicked ? 'tablesList.unpickAll' : 'tablesList.pickAll')}</Button>
@@ -92,13 +92,13 @@ export default function TablesListTab() {
</span>
)}
<span className="flex-1" />
<Button size="sm" variant={inactive ? 'primary' : 'secondary'} aria-pressed={inactive} onClick={() => setInactive(v => !v)}>{t('tablesList.showOff')}</Button>
{!picking && <Button size="sm" variant="secondary" onClick={() => setPicking(true)} data-testid="tables-pick">{t('tablesList.pick')}</Button>}
<Button size="sm" variant="secondary" icon={<Plus size={14} />} onClick={() => setDialog({ kind: 'zone', zone: {} })} data-testid="zone-new">{t('tablesList.newZone')}</Button>
<Button size="sm" icon={<Plus size={14} />} onClick={() => setDialog({ kind: 'table', table: null })} data-testid="table-new">{t('tablesList.newTable')}</Button>
<Button variant={inactive ? 'primary' : 'secondary'} aria-pressed={inactive} onClick={() => setInactive(v => !v)}>{t('tablesList.showOff')}</Button>
{!picking && <Button variant="secondary" onClick={() => setPicking(true)} data-testid="tables-pick">{t('tablesList.pick')}</Button>}
<Button variant="secondary" icon={<Plus size={16} />} onClick={() => setDialog({ kind: 'zone', zone: {} })} data-testid="zone-new">{t('tablesList.newZone')}</Button>
<Button icon={<Plus size={16} />} onClick={() => setDialog({ kind: 'table', table: null })} data-testid="table-new">{t('tablesList.newTable')}</Button>
</div>
<div className="flex flex-wrap border-b border-line px-4 shrink-0" role="tablist" aria-label={t('tablesList.zones')}>
<div className="flex flex-wrap border-b border-line px-card" role="tablist" aria-label={t('tablesList.zones')}>
{tabs.map(x => {
const i = x.zone ? zones.indexOf(x.zone) : -1
return (
@@ -119,7 +119,7 @@ export default function TablesListTab() {
</div>
{zone && (
<div className="flex flex-wrap items-center gap-3 px-4 md:px-6 py-2 border-b border-line shrink-0">
<div className="flex flex-wrap items-center gap-3 px-card py-2.5 border-b border-line bg-surface-2">
<span className="font-semibold text-ink text-label">{zone.name}</span>
{zone.prefix && <Pill>{zone.prefix}</Pill>}
<Button size="sm" variant="ghost" icon={<Pencil size={13} />} onClick={() => setDialog({ kind: 'zone', zone })}>{t('tablesList.editZone')}</Button>
@@ -127,7 +127,7 @@ export default function TablesListTab() {
</div>
)}
<div className="flex-1 overflow-y-auto p-4 md:p-6">
<div className="p-card">
{!shown.length ? <EmptyState title={t(inactive ? 'tablesList.none' : 'tablesList.noneActive')} /> : (
<ul className="rounded-card border border-line bg-surface divide-y divide-line overflow-hidden">
{shown.map((x, i) => {