feat(manager): products and categories on v2, a product in several categories, allergens (platform-v2 step 6.3)

- Management/ProductsTab + ProductFormModal (3.1k lines) → src/pages/products/: category tree,
  list/grid, toolbar + filters (search folds accents and Latin letters), bulk actions, category
  dialogs; the editor in editor/ (details, sold at, cost, fiscal; the waiter's choices).
  Arithmetic in productsLogic.js / editor/formLogic.js (tests/products.test.mjs).
- Several categories per product with a main one (D-23): edited in the editor, "also in" on the
  rows, each category's list ordered on its own (drag or up/down → PUT /reorder with category_id);
  bulk "move to" / "also list in". The waiter's picker now shows a product in every category.
- Allergens: products.allergens (Alembic 0032, core/allergens.py: 14 EU, contains | may_contain,
  catalog.allergen), in the API, POS menu, menu tablet, catalogue bundles and the cloud snapshot
  (C-2); @xenia/access allergens.js + <Allergens> shown on the phone, the counter, the tablet.
- Bell: only the newest load sets the list (an older answer could hide a live notification).
- e2e: manager (two categories, order per category, allergens), terminal / menu tablet / waiter
  (allergens shown); media saves by test id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 10:04:35 +02:00
co-authored by Claude Opus 5.5
parent 8a02173450
commit 5048f82a4c
53 changed files with 2812 additions and 3179 deletions
+3 -1
View File
@@ -6,7 +6,9 @@
"description": "Bootstrap provider, module/permission hooks and guards, and the manager-approval dialog (plan step 2.5).",
"main": "src/index.js",
"exports": {
".": "./src/index.js"
".": "./src/index.js",
"./salesPoints": "./src/salesPoints.js",
"./allergens": "./src/allergens.js"
},
"dependencies": {
"@xenia/api": "^0.0.0",
+33
View File
@@ -0,0 +1,33 @@
// A product's allergens for staff and guests (plan step 6.3): one small chip each, what it
// contains first (warning tone), then what it may contain (outlined), under a title. Styled with
// the @xenia/ui tokens inline, so every app (waiter, terminal, manager) shows it the same way.
// Nothing when none are declared, unless `showNone`.
import { useTranslation } from '@xenia/i18n'
import { allergenList } from './allergens.js'
const chip = level => ({
display: 'inline-flex', alignItems: 'center', gap: 4, padding: '2px 8px',
borderRadius: 999, fontSize: 'var(--x-text-caption)', fontWeight: 600, lineHeight: 1.6,
...(level === 'contains'
? { background: 'var(--x-warning-soft)', color: 'var(--x-warning-ink)', border: '1px solid transparent' }
: { background: 'transparent', color: 'var(--x-ink-2)', border: '1px dashed var(--x-line-strong)' }),
})
export function Allergens({ allergens, showNone = false, title = true, className, style }) {
const { t } = useTranslation('common')
const items = allergenList(allergens)
if (items.length === 0 && !showNone) return null
const groups = ['contains', 'may_contain'].map(level => [level, items.filter(i => i.level === level)]).filter(([, list]) => list.length)
return (
<div className={className} style={{ display: 'grid', gap: 6, ...style }} data-testid="allergens" data-count={items.length}>
{title && <div style={{ fontSize: 'var(--x-text-caption)', fontWeight: 700, textTransform: 'uppercase', letterSpacing: '0.04em', color: 'var(--x-ink-3)' }}>{t('allergens.title')}</div>}
{items.length === 0 && <div style={{ fontSize: 'var(--x-text-label)', color: 'var(--x-ink-3)' }}>{t('allergens.none')}</div>}
{groups.map(([level, list]) => (
<div key={level} style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 4 }}>
<span style={{ fontSize: 'var(--x-text-caption)', color: 'var(--x-ink-2)', marginRight: 2 }}>{t(`allergens.level.${level}`)}:</span>
{list.map(i => <span key={i.key} style={chip(level)} data-allergen={i.key} data-level={level}>{t(`allergens.${i.key}`)}</span>)}
</div>
))}
</div>
)
}
+27
View File
@@ -0,0 +1,27 @@
// Allergens (plan step 6.3): the 14 that EU Regulation 1169/2011 (Annex II) requires a venue to
// declare. The same fixed list and order as the backend's core/allergens.py (a backend test
// compares them). A product carries `allergens` = { key: 'contains' | 'may_contain' }.
// Labels: common:allergens.<key>, common:allergens.level.<level>.
export const ALLERGENS = ['gluten', 'crustaceans', 'eggs', 'fish', 'peanuts', 'soybeans', 'milk', 'nuts', 'celery', 'mustard', 'sesame', 'sulphites', 'lupin', 'molluscs']
export const ALLERGEN_LEVELS = ['contains', 'may_contain']
/** A product's allergens as a list to show: what it contains first, then traces; list order within each. */
export function allergenList(map) {
const m = map && typeof map === 'object' ? map : {}
return ALLERGEN_LEVELS.flatMap(level => ALLERGENS.filter(k => m[k] === level).map(key => ({ key, level })))
}
/** The next level when a manager taps an allergen: none → contains → may contain → none. */
export function nextAllergenLevel(level) {
return level === 'contains' ? 'may_contain' : level === 'may_contain' ? null : 'contains'
}
/** Set (or with null, clear) one allergen; a new object in the list's order. */
export function setAllergen(map, key, level) {
const out = {}
for (const k of ALLERGENS) {
const v = k === key ? level : map?.[k]
if (v) out[k] = v
}
return out
}
+3
View File
@@ -9,6 +9,7 @@
// <Can perm="…" fallback={…}> · <RequireModule module="…">
//
// SALES_POINTS, IN_PERSON, DIGITAL where an order is sold (phase 3S)
// ALLERGENS, allergenList, setAllergen the 14 EU allergens (6.3)
//
// UI hiding only: the backend checks every request (CS-14).
@@ -17,3 +18,5 @@ export { useAccess, useModule, useCan, can, useAllowed, allowed } from './hooks.
export { Can, RequireModule, ModuleOff, NoAccess } from './guards.jsx'
export { OverrideHost } from './OverrideHost.jsx'
export { SALES_POINTS, IN_PERSON, DIGITAL, normalizeSalesPoints } from './salesPoints.js'
export { ALLERGENS, ALLERGEN_LEVELS, allergenList, nextAllergenLevel, setAllergen } from './allergens.js'
export { Allergens } from './Allergens.jsx'
+23
View File
@@ -0,0 +1,23 @@
// The allergen list and its helpers (plan step 6.3).
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { ALLERGENS, allergenList, nextAllergenLevel, setAllergen } from '../src/allergens.js'
test('the 14 EU allergens', () => {
assert.equal(ALLERGENS.length, 14)
assert.equal(new Set(ALLERGENS).size, 14)
})
test('what to show: contains first, then traces, in the list order', () => {
assert.deepEqual(allergenList({ sesame: 'may_contain', milk: 'contains', gluten: 'contains', pollen: 'contains' }),
[{ key: 'gluten', level: 'contains' }, { key: 'milk', level: 'contains' }, { key: 'sesame', level: 'may_contain' }])
assert.deepEqual(allergenList(null), [])
})
test('tapping cycles none → contains → may contain → none', () => {
assert.equal(nextAllergenLevel(undefined), 'contains')
assert.equal(nextAllergenLevel('contains'), 'may_contain')
assert.equal(nextAllergenLevel('may_contain'), null)
assert.deepEqual(setAllergen({ milk: 'contains' }, 'gluten', 'may_contain'), { gluten: 'may_contain', milk: 'contains' })
assert.deepEqual(setAllergen({ milk: 'contains' }, 'milk', null), {})
})