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
+21 -9
View File
@@ -4,7 +4,7 @@ import assert from 'node:assert/strict'
import {
SCOPES, applyFilters, bulkCategories, categoryTree, costOf, countIn, groupProducts, moveId, reorderBody, scopeProducts, stepBody, treeLabel,
} from '../src/pages/products/productsLogic.js'
import { addCategory, buildBody, buildForm, canSave, cleanTag, favourites, moveChoice, moveFavourite, removeCategory, removeChoice, removeGroup, setSub, toggleFavourite } from '../src/pages/products/editor/formLogic.js'
import { addCategory, buildBody, buildForm, canSave, cleanTag, cleanTexts, labelIn, favourites, moveChoice, moveFavourite, removeCategory, removeChoice, removeGroup, setSub, toggleFavourite } from '../src/pages/products/editor/formLogic.js'
const cats = [
{ id: 1, name: 'Coffees', sort_order: 0 },
@@ -110,12 +110,24 @@ test('the editor: favourites across lists, choices, groups', () => {
assert.equal(buildBody(removeGroup(f, 7)).ingredients[0].group_id, null)
})
test('the editor keeps the menu in other languages (6.4)', () => {
const f = buildForm({ name: 'Σουβλάκι', base_price: 3, quick_options: [{ name: 'Πίτα' }, { name: 'Σάλτσα' }],
translations: { en: { name: 'Skewer', quick: { 'Πίτα': 'Pitta' } } } })
assert.equal(f.translations.en.name, 'Skewer')
assert.equal(f.quick_options[0].tr.en, 'Pitta')
const renamed = { ...f, quick_options: [{ ...f.quick_options[0], name: 'Πίτα αραβική' }, f.quick_options[1]] }
assert.deepEqual(buildBody(renamed).translations, { en: { name: 'Skewer', quick: { 'Πίτα αραβική': 'Pitta' } } }) // kept by the new base name
assert.deepEqual(buildBody({ ...f, translations: { en: { name: ' ', description: '' } }, quick_options: [] }).translations, {})
test('the editor: every text per language; "Default" is the venue language (owner 2026-11-21)', () => {
const f = buildForm({ name: 'Σουβλάκι', base_price: 3, quick_options: [{ name: 'Πίτα', translations: { el: 'Πίτα' } }, { name: 'Σάλτσα' }],
translations: { el: { name: 'Σουβλάκι' }, en: { name: 'Skewer', quick: { 'Σάλτσα': 'Sauce' } } } })
assert.deepEqual(f.names, { el: 'Σουβλάκι', en: 'Skewer' })
assert.equal(f.quick_options[1].tr.en, 'Sauce') // the product's old quick map
// the venue speaks Greek: the shown name is the Greek one
let body = buildBody(f, 'el')
assert.equal(body.name, 'Σουβλάκι')
assert.deepEqual(body.translations, { el: { name: 'Σουβλάκι' }, en: { name: 'Skewer' } })
assert.deepEqual(body.quick_options[1].translations, { en: 'Sauce' })
// the venue switches to English: English is shown; with no English, the only text there is
assert.equal(buildBody(f, 'en').name, 'Skewer')
const greekOnly = { ...f, names: { el: 'Πίτα' } }
assert.equal(buildBody(greekOnly, 'en').name, 'Πίτα')
assert.equal(labelIn(f.quick_options[0], 'en', 'en'), 'Πίτα') // nothing in English: what is shown
// a choice typed only in English is called that
const typed = { ...f, ingredients: [{ name: '', tr: { en: 'Onion' }, extra_cost: 0, is_favorite: false, favorite_sort_order: 0, is_compact: false, group_id: null }] }
assert.deepEqual([buildBody(typed, 'el').ingredients[0].name, buildBody(typed, 'el').ingredients[0].translations], ['Onion', { en: 'Onion' }])
assert.equal(canSave({ ...f, names: {}, name: '' }, 'el'), false)
assert.deepEqual(cleanTexts({ el: ' ', en: ' x ', fr: 'y' }), { en: 'x' })
})