feat(terminal): kitchen display on paired screens, live without polling (platform-v2 3.2b)

Port of the manager's KdsPage.jsx into terminal/src/apps/kds, split into pure logic
(layout packing, age, buckets, rounds, totals, status cycle, settings; unit-tested) and
components (card, item, action bars, dialogs, item totals, rails, settings panel).
- Settings are the device's config; the settings panel saves them (managers only),
  zoom changes the size for the session.
- Orders reload on live events and every reconnect; polling only while the live
  connection is down (DeviceProvider exposes liveUp; useLiveEvents helper).
- "Tap to start" unlocks sound; venue clock via useFormat; English-first texts.
- Undo of an item recomputes the order status at once; undo/redo clear the selection.
- Tests: terminal unit +15, terminal.mjs +12 KDS checks (no polling, live order + chime,
  item/undo/prepare/decline, settings permission, change made elsewhere), backend
  regression for an item back to pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 19:27:11 +02:00
co-authored by Claude Opus 5.5
parent d5c4400fde
commit 5f6d4ab428
24 changed files with 2550 additions and 12 deletions
+131
View File
@@ -0,0 +1,131 @@
// The board's side rail (status filters with counts, undo/redo, call, sound, settings) and
// top bar (here / takeaway / delivery tabs, item totals button, venue clock, zoom).
// Plan step 3.2b, from KdsPage.jsx.
import { BellRing, CheckCheck, Clock, CookingPot, Flame, Redo2, Settings, Timer, Undo2, Volume2, VolumeX, ZoomIn, ZoomOut } from 'lucide-react'
import { useFormat, useTranslation } from '@xenia/i18n'
import { KDS } from '../theme'
const STATUSES = [
{ key: 'future', Icon: Clock, colour: KDS.green },
{ key: 'pending', Icon: Timer, colour: KDS.amber },
{ key: 'preparing', Icon: Flame, colour: KDS.accent },
{ key: 'done', Icon: CheckCheck, colour: '#cdd6e0' },
]
function RailButton({ active, colour, onClick, disabled, fs, children, testId }) {
return (
<button type="button" data-testid={testId} data-active={active ? 'true' : 'false'} onClick={onClick} disabled={disabled} style={{
position: 'relative', width: '100%', display: 'flex', flexDirection: 'column', alignItems: 'center',
gap: Math.round(4 * fs), padding: `${Math.round(9 * fs)}px ${Math.round(4 * fs)}px`, borderRadius: Math.round(10 * fs),
color: active ? colour : '#8b95a1', background: active ? 'rgba(255,255,255,0.06)' : 'none',
border: active ? '1px solid rgba(255,255,255,0.08)' : '1px solid transparent',
cursor: disabled ? 'default' : 'pointer', fontFamily: 'inherit', opacity: disabled ? 0.32 : 1, transition: 'background .12s, color .12s, opacity .15s',
}}>
{children}
</button>
)
}
export function SideRail({ filters, counts, onToggleFilter, soundOn, onToggleSound, canUndo, canRedo, onUndo, onRedo, onSettings, onCall, fontScale = 1 }) {
const { t } = useTranslation('terminal')
const fs = fontScale
const lg = { width: Math.round(24 * fs), height: Math.round(24 * fs) }
const sm = { width: Math.round(20 * fs), height: Math.round(20 * fs) }
const label = text => <span style={{ fontSize: Math.round(10 * fs), fontWeight: 600, letterSpacing: '.06em', textTransform: 'uppercase' }}>{text}</span>
const badgeH = Math.round(22 * fs)
const group = { display: 'flex', flexDirection: 'column', gap: 2, padding: `2px ${Math.round(8 * fs)}px` }
return (
<nav data-testid="kds-rail" style={{ width: Math.round(KDS.railW * fs), flexShrink: 0, background: KDS.rail, borderRight: `1px solid ${KDS.railLine}`,
display: 'flex', flexDirection: 'column', alignItems: 'stretch', padding: `${Math.round(10 * fs)}px 0`, gap: 2, overflowY: 'auto' }}>
<div style={group}>
{STATUSES.map(({ key, Icon, colour }) => {
const active = filters.has(key)
return (
<RailButton key={key} testId={`filter-${key}`} active={active} colour={colour} onClick={() => onToggleFilter(key)} fs={fs}>
<Icon style={lg} />
{label(t(`kds.rail.${key}`))}
<span data-testid={`count-${key}`} style={{ minWidth: badgeH, height: badgeH, padding: `0 ${Math.round(6 * fs)}px`, display: 'inline-flex',
alignItems: 'center', justifyContent: 'center', borderRadius: Math.round(11 * fs), fontSize: Math.round(12 * fs), fontWeight: 700,
background: active ? colour : '#2b333d', color: active ? '#0e1217' : '#cfd6df' }}>
{counts[key] || 0}
</span>
</RailButton>
)
})}
<div style={{ height: 1, background: KDS.railLine, margin: `${Math.round(6 * fs)}px` }} />
<RailButton testId="kds-undo" active={false} colour="#fff" onClick={onUndo} disabled={!canUndo} fs={fs}><Undo2 style={sm} />{label(t('kds.rail.undo'))}</RailButton>
<RailButton testId="kds-redo" active={false} colour="#fff" onClick={onRedo} disabled={!canRedo} fs={fs}><Redo2 style={sm} />{label(t('kds.rail.redo'))}</RailButton>
</div>
<div style={{ flex: '1 1 auto' }} />
<div style={group}>
<RailButton testId="kds-call" active={false} colour="#fff" onClick={onCall} fs={fs}><BellRing style={sm} />{label(t('kds.rail.call'))}</RailButton>
<RailButton testId="kds-sound" active={false} colour="#fff" onClick={onToggleSound} fs={fs}>
{soundOn ? <Volume2 style={sm} /> : <VolumeX style={sm} />}{label(soundOn ? t('kds.rail.sound') : t('kds.rail.muted'))}
</RailButton>
<RailButton testId="kds-settings" active={false} colour="#fff" onClick={onSettings} fs={fs}><Settings style={sm} />{label(t('kds.rail.settings'))}</RailButton>
</div>
</nav>
)
}
const TABS = ['all', 'here', 'takeaway', 'delivery']
export function TopBar({ tab, counts, onTab, now, fontScale = 1, zoomPercent, onZoom, showSummaryButton, summaryOpen, onToggleSummary }) {
const { t } = useTranslation('terminal')
const { formatDate, formatTime } = useFormat()
const fs = fontScale
const tabH = Math.round(36 * fs)
const tabR = Math.round(9 * fs)
const clockFont = { fontSize: Math.round(14 * fs), fontFamily: 'Arial, "Helvetica Neue", sans-serif' }
const zoomButton = { width: tabH, height: tabH, display: 'flex', alignItems: 'center', justifyContent: 'center', background: 'none', border: 'none',
cursor: 'pointer', color: KDS.tabInk, borderRadius: Math.round(7 * fs) }
const zi = { width: Math.round(15 * fs), height: Math.round(15 * fs) }
return (
<div data-testid="kds-topbar" style={{ height: Math.round(KDS.topbarH * fs), flexShrink: 0, background: KDS.topbar, borderBottom: `1px solid ${KDS.railLine}`,
display: 'flex', alignItems: 'center', gap: 8, padding: '0 12px' }}>
<div style={{ display: 'flex', alignItems: 'center', gap: 6, flexShrink: 0, overflowX: 'auto' }}>
{TABS.map(key => {
const active = tab === key
return (
<button key={key} type="button" data-testid={`tab-${key}`} onClick={() => onTab(key)} style={{
flexShrink: 0, display: 'flex', alignItems: 'center', gap: Math.round(7 * fs), height: tabH, padding: `0 ${Math.round(14 * fs)}px`,
borderRadius: tabR, background: active ? KDS.tabActiveBg : KDS.tab, color: active ? KDS.tabActiveInk : KDS.tabInk,
fontSize: Math.round(13 * fs), fontWeight: 600, whiteSpace: 'nowrap', border: 'none', cursor: 'pointer', fontFamily: 'inherit',
}}>
{key === 'all' ? t('kds.tabs.all') : t(`kds.channel.${key}`)}
<span style={{ minWidth: Math.round(20 * fs), height: Math.round(20 * fs), padding: `0 ${Math.round(5 * fs)}px`, display: 'inline-flex',
alignItems: 'center', justifyContent: 'center', borderRadius: Math.round(6 * fs), fontSize: Math.round(11 * fs), fontWeight: 700,
background: active ? 'rgba(0,0,0,.10)' : 'rgba(255,255,255,.08)', color: active ? '#41474f' : KDS.tabInk }}>
{counts[key] ?? 0}
</span>
</button>
)
})}
</div>
<div style={{ flex: '1 1 0' }} />
{showSummaryButton && (
<button type="button" data-testid="summary-button" onClick={onToggleSummary} style={{
flexShrink: 0, display: 'flex', alignItems: 'center', gap: Math.round(6 * fs), height: tabH, padding: `0 ${Math.round(14 * fs)}px`,
borderRadius: tabR, background: summaryOpen ? KDS.tabActiveBg : KDS.tab, color: summaryOpen ? KDS.tabActiveInk : KDS.tabInk,
fontSize: Math.round(13 * fs), fontWeight: 600, border: 'none', cursor: 'pointer', fontFamily: 'inherit',
}}>
<CookingPot style={zi} />
{t('kds.summary.button')}
</button>
)}
<div style={{ flex: '1 1 0' }} />
<div data-testid="kds-clock" style={{ display: 'flex', alignItems: 'center', gap: Math.round(6 * fs), flexShrink: 0, whiteSpace: 'nowrap' }}>
<span style={{ ...clockFont, fontWeight: 600, color: '#c8d0db' }}>{formatDate(now, 'dateLong')}</span>
<span style={{ ...clockFont, fontWeight: 700, color: '#f1f4f8' }}>{formatTime(now)}</span>
</div>
<div style={{ width: 1, height: Math.round(24 * fs), background: KDS.railLine, flexShrink: 0 }} />
<div style={{ display: 'flex', alignItems: 'center', gap: 2, background: KDS.tab, borderRadius: tabR, padding: `0 ${Math.round(4 * fs)}px`, flexShrink: 0, height: tabH }}>
<button type="button" data-testid="zoom-out" aria-label={t('kds.zoom.smaller')} title={t('kds.zoom.smaller')} onClick={() => onZoom(-1)} style={zoomButton}><ZoomOut style={zi} /></button>
<span data-testid="zoom-level" style={{ fontSize: Math.round(11 * fs), fontWeight: 700, color: KDS.tabInk, minWidth: Math.round(34 * fs), textAlign: 'center', fontFamily: 'ui-monospace, monospace' }}>
{zoomPercent}%
</span>
<button type="button" data-testid="zoom-in" aria-label={t('kds.zoom.larger')} title={t('kds.zoom.larger')} onClick={() => onZoom(1)} style={zoomButton}><ZoomIn style={zi} /></button>
</div>
</div>
)
}