Files
xenia-pos-local/manager_dashboard/src/pages/platform/DeviceConfigFields.jsx
T
bonaminandClaude Opus 5.5 aa3fe85053 feat(signage): venue badges, widgets' own look, widgets placed inside stacks, Save and leave, shared controls (owner review 5)
- Badges: the venue's list (setting signage.badges: names el/en, colours, an icon from a food and
  drink set) edited under Signage -> "Message & settings"; sent with the venue to screens and
  previews; several badges per product (MenuList.badges lists, a single one still read) in the
  shared multiple Dropdown; a board's badge colour / text colour override them (None = each own).
- Widgets: colour, background plate, font, bold / italic / underline, text size, QR colours;
  widgets in a stack's part get every setting, vertical alignment, and a custom box inside their
  place, picked (stack, then widget) and dragged on the preview (selection by path "2.1.0").
- Menu slides: vertical alignment of the list (board_valign); "Where the list sits" is now
  "Horizontal alignment".
- Message of the day: one component in the settings tab, on the Overview and from its widget.
- Leaving a slide with changes: "Save and leave" (ConfirmDialog altLabel).
- @xenia/ui: ColourField (with colour.js helpers), FieldRow (framed only while wrapped), Slider,
  IconPicker, Segmented multiple; native selects on the Overview and signage replaced by Dropdown,
  the device settings' colour input by ColourField.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-21 14:17:27 +02:00

94 lines
4.5 KiB
React

// 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>,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 { ColourField, Field, Input, Select, Switch } from '@xenia/ui'
import client from '../../api/client'
import { configGroups, configValue, refOptions } from './devicesLogic'
// Where a `ref` field's choices come from (the device list is passed in)
const REF_URLS = { prep_zones: '/api/prep-zones', categories: '/api/products/categories', printers: '/api/system/printers', display_looks: '/api/display/looks', signage_playlists: '/api/signage/playlists', signage_slides: '/api/signage/library', signage_schedules: '/api/signage/schedules', tables: '/api/tables/' }
export default function DeviceConfigFields({ appKey, fields = [], value, onChange, devices = [], selfId = null }) {
const { t } = useTranslation('manager')
const sources = [...new Set(fields.map(f => f.choices_from).filter(s => s && REF_URLS[s]))].join(',')
const [lists, setLists] = useState({})
useEffect(() => {
if (!sources) return undefined
let alive = true
for (const s of sources.split(',')) {
client.get(REF_URLS[s]).then(r => { if (alive) setLists(l => ({ ...l, [s]: r.data })) }).catch(() => {})
}
return () => { alive = false }
}, [sources])
const zones = lists.prep_zones ?? []
const categories = lists.categories ?? []
const printers = lists.printers ?? []
const looks = lists.display_looks ?? []
const playlists = lists.signage_playlists ?? []
const slides = lists.signage_slides?.slides ?? [] // the Slides library answers { slides, media }
const schedules = lists.signage_schedules ?? []
const tables = lists.tables ?? []
if (!fields.length) return null
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, categories, printers, looks, playlists, slides, schedules, tables, devices, selfId })]} />
</Field>
)
}
if (f.type === 'color') {
return (
<ColourField key={f.key} label={label} hint={hint} value={v || '#000000'} onChange={c => set(f, c)} opacity={false} testId={`config-${f.key}`} />
)
}
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-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>
)
}