feat(backend): KDS settings as device config, zone enforced for kitchen screens, KDS-only API (platform-v2 3.2a)
- KDS manifest: 23 typed settings (prep zone, board, waiting-time minutes and colours,
behaviour) replacing the KDS page's localStorage settings.
- ConfigField: colour type, "after" ordering (warning < late < flash), groups for the
manager's dialogs, ".none" text for an empty ref choice.
- routers/kds.py: a KDS device gets only its zone's orders, prints to its zone by default
and signs waiter messages with its zone/name. New GET /api/kds/context and
POST /api/kds/orders/{id}/retry-print so the screen never leaves its kds.* scope.
Unused v1 /items and /items/{id}/status endpoints removed (D-21).
- PATCH /api/devices/me/config: a screen changes its own settings when the signed-in
person holds core.devices.manage.
- Manager Devices dialogs: settings in sections, colour pickers, "All zones".
- Tests: test_kds_device.py, colour/ordered fields; terminal.mjs scope + zone checks;
manager.mjs settings sections; stack.mjs detaches the non-LAN network before the
restart check (one flaky 403).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
// Per-device settings of an app, rendered from its manifest (plan step 3.1a): the
|
||||
// Per-device settings of an app, rendered from its manifest (plan steps 3.1a, 3.2a): the
|
||||
// fields come from GET /api/platform/modules → device_app.config, the texts from
|
||||
// modules:<app>.config.<key>.{label,hint,choices.<value>}. The backend validates them
|
||||
// (validation.device_config). Used by the pair and edit dialogs of DevicesPage.
|
||||
// modules:<app>.config.<key>.{label,hint,choices.<value>,none} and section headings from
|
||||
// modules:<app>.config_groups.<group>. The backend validates them (validation.device_config).
|
||||
// Used by the pair and edit dialogs of DevicesPage.
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Field, Input, Select, Switch } from '@xenia/ui'
|
||||
import client from '../../api/client'
|
||||
import { configValue, refOptions } from './devicesLogic'
|
||||
import { configGroups, configValue, refOptions } from './devicesLogic'
|
||||
|
||||
export default function DeviceConfigFields({ appKey, fields = [], value, onChange, devices = [], selfId = null }) {
|
||||
const { t } = useTranslation('manager')
|
||||
@@ -24,38 +25,59 @@ export default function DeviceConfigFields({ appKey, fields = [], value, onChang
|
||||
const base = key => `modules:${appKey}.config.${key}`
|
||||
const set = (f, raw) => onChange({ ...value, [f.key]: configValue(f, raw) })
|
||||
|
||||
const control = f => {
|
||||
const label = t(`${base(f.key)}.label`, { defaultValue: f.key })
|
||||
const hint = t(`${base(f.key)}.hint`, { defaultValue: '' }) || undefined
|
||||
const v = value?.[f.key]
|
||||
if (f.type === 'bool') {
|
||||
return <Switch key={f.key} checked={!!v} onChange={on => set(f, on)} label={label} description={hint} data-config={f.key} />
|
||||
}
|
||||
if (f.choices?.length) {
|
||||
return (
|
||||
<Field key={f.key} label={label} hint={hint}>
|
||||
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
|
||||
options={f.choices.map(c => ({ value: String(c), label: t(`${base(f.key)}.choices.${c}`, { defaultValue: String(c) }) }))} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
if (f.type === 'ref') {
|
||||
return (
|
||||
<Field key={f.key} label={label} hint={hint}>
|
||||
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
|
||||
options={[{ value: '', label: t(`${base(f.key)}.none`, { defaultValue: t('devices.form.none') }) },
|
||||
...refOptions(f, { zones, devices, selfId })]} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
if (f.type === 'color') {
|
||||
return (
|
||||
<Field key={f.key} label={label} hint={hint}>
|
||||
<input type="color" value={v || '#000000'} onChange={e => set(f, e.target.value)} data-config={f.key}
|
||||
className="h-10 w-16 rounded-control border border-line bg-surface cursor-pointer" />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Field key={f.key} label={label} hint={hint}>
|
||||
<Input type={f.type === 'int' ? 'number' : 'text'} value={v ?? ''} min={f.min ?? undefined} max={f.max ?? undefined}
|
||||
onChange={e => set(f, e.target.value)} data-config={f.key} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
|
||||
const groups = configGroups(fields)
|
||||
return (
|
||||
<div className="grid gap-4" data-testid="device-config">
|
||||
{fields.map(f => {
|
||||
const label = t(`${base(f.key)}.label`, { defaultValue: f.key })
|
||||
const hint = t(`${base(f.key)}.hint`, { defaultValue: '' }) || undefined
|
||||
const v = value?.[f.key]
|
||||
if (f.type === 'bool') {
|
||||
return <Switch key={f.key} checked={!!v} onChange={on => set(f, on)} label={label} description={hint} data-config={f.key} />
|
||||
}
|
||||
if (f.choices?.length) {
|
||||
return (
|
||||
<Field key={f.key} label={label} hint={hint}>
|
||||
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
|
||||
options={f.choices.map(c => ({ value: String(c), label: t(`${base(f.key)}.choices.${c}`, { defaultValue: String(c) }) }))} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
if (f.type === 'ref') {
|
||||
return (
|
||||
<Field key={f.key} label={label} hint={hint}>
|
||||
<Select value={v == null ? '' : String(v)} onChange={e => set(f, e.target.value)} data-config={f.key}
|
||||
options={[{ value: '', label: t('devices.form.none') }, ...refOptions(f, { zones, devices, selfId })]} />
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<Field key={f.key} label={label} hint={hint}>
|
||||
<Input type={f.type === 'int' ? 'number' : 'text'} value={v ?? ''} min={f.min ?? undefined} max={f.max ?? undefined}
|
||||
onChange={e => set(f, e.target.value)} data-config={f.key} />
|
||||
</Field>
|
||||
)
|
||||
})}
|
||||
<div className="grid gap-5" data-testid="device-config">
|
||||
{groups.map(g => (
|
||||
<section key={g.group ?? '_'} className="grid gap-4" data-config-group={g.group ?? ''}>
|
||||
{g.group && groups.length > 1 && g.fields.length > 1 && (
|
||||
<h3 className="text-label font-semibold text-ink-2 uppercase tracking-wide">
|
||||
{t(`modules:${appKey}.config_groups.${g.group}`, { defaultValue: g.group })}
|
||||
</h3>
|
||||
)}
|
||||
{g.fields.map(control)}
|
||||
</section>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user