feat(products): every menu text per language, the editor's language picker, service item dialog

- Alembic 0042: a `translations` column on every choice (groups, quick options,
  extras, ingredients, preference sets and choices; sub-choices and shared
  sub-sets in their JSON); the texts typed so far become the text in their
  language (Greek letters → el, else the venue's); the product's old quick map
  moves onto the quick options. API, catalogue bundle and the cloud's quick
  option names carry them; names are checked before anything is replaced.
- Editor: a language picker beside the close button (Default = the venue's
  language, plus every menu language) drives every name and description, left
  and right; an empty language shows what is used instead as its placeholder.
  The shown name is the venue language's, else any (never mixed).
- Choices: one name field; the shared controls at one height (heart red when on,
  several / compact… chips coloured when on, delete red on hover); "+ Preference"
  at the right end of the tab strip; preference groups made inside a preference.
- Categories: the shared dropdown to add one; the category dialog per language.
- The service item switch is gone: "New service item" opens its own small dialog.
- UI: Dialog headerEnd; a toned toggle keeps its colour while pressed.
- Tests: backend (choice names, migration 0042), access, editor logic, e2e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-20 18:21:50 +02:00
co-authored by Claude Opus 5.5
parent 301502965c
commit 15413dea1b
30 changed files with 853 additions and 313 deletions
+1 -1
View File
@@ -20,4 +20,4 @@ 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'
export { MENU_LANGUAGES, translatedLanguages, inLanguage } from './menuLanguages.js'
export { DEFAULT_LANGUAGE, MENU_LANGUAGES, inLanguage, shownText, slotOf, translatedLanguages } from './menuLanguages.js'
+17 -2
View File
@@ -1,6 +1,8 @@
// The menu's languages (plan step 6.4, owner 2026-11-18): English and Greek, the same list as the
// backend's core/menu_languages.py. A product's own name is its base text; a translation adds
// the other language; a missing translation shows the base text.
// backend's core/menu_languages.py. Since 2026-11-21 every menu text is kept per language, the
// venue's own included; "Default" in the editors is the venue's language. What is shown for an
// item: the venue language's text, else the first language that has one (never mixed, never
// machine-translated).
export const MENU_LANGUAGES = ['el', 'en']
/** The languages a venue translates its menu into: every menu language but its own. */
@@ -9,3 +11,16 @@ export const translatedLanguages = venueLanguage => MENU_LANGUAGES.filter(l => l
/** A product's or category's text in a language: `names` / `descriptions` {lang: text} as the
* backend resolves them for customer screens, else the base text. */
export const inLanguage = (texts, lang, base) => (texts && texts[lang]) || base
/** The editors' "Default" (owner 2026-11-21): the venue's language. */
export const DEFAULT_LANGUAGE = 'default'
/** The language a picker's choice edits: "default" → the venue's language. */
export const slotOf = (lang, venueLanguage) => (!lang || lang === DEFAULT_LANGUAGE ? (MENU_LANGUAGES.includes(venueLanguage) ? venueLanguage : MENU_LANGUAGES[0]) : lang)
const filled = v => (typeof v === 'string' && v.trim() ? v.trim() : '')
/** The text shown for an item {language: text}: the venue language's, else the first language
* that has one, else `fallback` (the row's stored text, for items never given a language). */
export const shownText = (texts, venueLanguage, fallback = '') =>
filled(texts?.[venueLanguage]) || MENU_LANGUAGES.map(l => filled(texts?.[l])).find(Boolean) || filled(fallback)
@@ -0,0 +1,20 @@
// Menu texts per language (owner 2026-11-21): "Default" is the venue's language; what is shown is
// the venue language's text, else the first language that has one, else the stored text.
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { DEFAULT_LANGUAGE, shownText, slotOf } from '../src/menuLanguages.js'
test('"Default" edits the venue language', () => {
assert.equal(slotOf(DEFAULT_LANGUAGE, 'el'), 'el')
assert.equal(slotOf(DEFAULT_LANGUAGE, 'en'), 'en')
assert.equal(slotOf('en', 'el'), 'en')
assert.equal(slotOf(DEFAULT_LANGUAGE, 'xx'), 'el') // an unknown venue language: the first menu language
})
test('shown: the venue language, else any, never mixed', () => {
assert.equal(shownText({ el: 'Πίτα', en: 'Pie' }, 'el'), 'Πίτα')
assert.equal(shownText({ el: 'Πίτα', en: 'Pie' }, 'en'), 'Pie')
assert.equal(shownText({ el: 'Πίτα' }, 'en'), 'Πίτα') // the venue went English: the only text there is
assert.equal(shownText({ el: ' ' }, 'en', 'Old'), 'Old') // nothing in any language: what was stored
assert.equal(shownText({}, 'en'), '')
})
+4
View File
@@ -1929,6 +1929,7 @@
"view_list": "Λίστα",
"view_grid": "Πλέγμα",
"new": "Νέο προϊόν",
"newService": "Νέο είδος σερβιρίσματος",
"price": "Τιμή",
"from": "από",
"to": "έως",
@@ -2046,6 +2047,9 @@
"done_other": "{{count}} προϊόντα ενημερώθηκαν"
},
"editor": {
"serviceNewTitle": "Νέο είδος σερβιρίσματος",
"langDefault": "Προεπιλογή ({{language}})",
"langDefaultHint": "Η γλώσσα του καταστήματος",
"newTitle": "Νέο προϊόν",
"editTitle": "Επεξεργασία: {{name}}",
"copy": "Αντιγραφή",
+4
View File
@@ -1929,6 +1929,7 @@
"view_list": "List",
"view_grid": "Grid",
"new": "New product",
"newService": "New service item",
"price": "Price",
"from": "from",
"to": "to",
@@ -2046,6 +2047,9 @@
"done_other": "{{count}} products updated"
},
"editor": {
"serviceNewTitle": "New service item",
"langDefault": "Default ({{language}})",
"langDefaultHint": "The venue's language",
"newTitle": "New product",
"editTitle": "Edit: {{name}}",
"copy": "Copy",
+3
View File
@@ -58,6 +58,8 @@
.x-btn--tone { color: var(--x-ink-2); }
.x-btn--tone:hover:not(:disabled), .x-btn--tone:focus-visible { color: rgb(var(--x-tone-ink)); }
.x-btn--icon.x-btn--tone { background: var(--x-surface-2); }
/* a toned toggle that is on (a favourite's heart) keeps its colour */
.x-btn--tone[aria-pressed="true"] { color: rgb(var(--x-tone-ink)); }
.x-btn--icon.x-btn--tone:hover:not(:disabled) { background: var(--x-surface-3); }
.x-btn--tone-danger { --x-tone: var(--x-danger-rgb); --x-tone-soft: var(--x-danger-soft-rgb); --x-tone-ink: var(--x-danger-ink-rgb); }
.x-btn--tone-warning { --x-tone: var(--x-warning-rgb); --x-tone-soft: var(--x-warning-soft-rgb); --x-tone-ink: var(--x-warning-ink-rgb); }
@@ -124,6 +126,7 @@
.x-modal__titles { flex: 1; min-width: 0; padding-top: var(--x-space-1-5); }
.x-modal__title { margin: 0; font-size: var(--x-text-title); line-height: var(--x-leading-title); font-weight: var(--x-weight-semibold); }
.x-modal__description { margin: var(--x-space-1) 0 0; font-size: var(--x-text-body); line-height: var(--x-leading-body); color: var(--x-ink-2); }
.x-modal__header-end { flex-shrink: 0; display: flex; align-items: center; gap: var(--x-space-2); }
.x-modal__close { margin: calc(-1 * var(--x-space-1)) calc(-1 * var(--x-space-1)) 0 0; }
.x-modal__toolbar { flex-shrink: 0; padding: var(--x-space-2) var(--x-space-6) var(--x-space-3); border-bottom: var(--x-border-width) solid var(--x-line); }
.x-modal__body {
+4 -2
View File
@@ -13,7 +13,7 @@ const CloseIcon = () => (
/** The shared body of Dialog and Sheet: backdrop, panel, header with ×, toolbar, body, footer. */
export function ModalFrame({
open, onClose, title, description, toolbar, children, footer,
open, onClose, title, description, headerEnd, toolbar, children, footer,
dismissible = true, closeLabel, initialFocus,
overlayClass, panelClass, grip = false, bodyClass,
}) {
@@ -41,12 +41,14 @@ export function ModalFrame({
className={panelClass}
>
{grip && <div className="x-sheet__grip" aria-hidden="true" />}
{(title || description || showClose) && (
{(title || description || showClose || headerEnd) && (
<div className="x-modal__header">
<div className="x-modal__titles">
{title && <h2 id={titleId} className="x-modal__title">{title}</h2>}
{description && <p id={descId} className="x-modal__description">{description}</p>}
</div>
{/* headerEnd: beside the close button (a language picker…) */}
{headerEnd && <div className="x-modal__header-end">{headerEnd}</div>}
{showClose && (
<IconButton label={closeLabel ?? labels.close} size="sm" className="x-modal__close" onClick={onClose} data-x-autofocus-skip="">
<CloseIcon />