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:
@@ -5,6 +5,7 @@ import useWaiterFavoritesStore from '../store/waiterFavoritesStore'
|
||||
import { assetUrl } from '../config/server'
|
||||
import { money } from '../i18n'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Allergens } from '@xenia/access'
|
||||
|
||||
const FAV_CAT_ID = '__favorites__'
|
||||
const SVC_CAT_ID = '__service__'
|
||||
@@ -144,12 +145,22 @@ function ProductDetailModal({ product, onClose }) {
|
||||
{product.description}
|
||||
</div>
|
||||
)}
|
||||
<Allergens allergens={product.allergens} style={{ borderTop: '1px solid var(--border)', paddingTop: 12, marginTop: 12 }} />
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
// A product is listed in every category of `category_ids` (plan step 6.3, D-23), each list in
|
||||
// its own order (`categories` [{category_id, sort_order}]); older data: just `category_id`.
|
||||
const cats = p => p.category_ids ?? (p.category_id ? [p.category_id] : [])
|
||||
function listOf(products, catId) {
|
||||
const pos = p => p.categories?.find(c => c.category_id === catId)?.sort_order ?? p.sort_order ?? 0
|
||||
return products.filter(p => cats(p).includes(catId)).sort((a, b) => pos(a) - pos(b))
|
||||
}
|
||||
|
||||
// ── useLongPress ──────────────────────────────────────────────────────────────
|
||||
function useLongPress(callback, delay = 2000) {
|
||||
const timerRef = useRef(null)
|
||||
@@ -432,7 +443,7 @@ export default function ProductPicker({ categories, products, onAdd, onQuickAdd:
|
||||
|
||||
const serviceProducts = products.filter(p => p.is_service_item)
|
||||
// Service items with a category also appear in that category view
|
||||
const regularProducts = products.filter(p => !p.is_service_item || p.category_id)
|
||||
const regularProducts = products.filter(p => !p.is_service_item || cats(p).length)
|
||||
|
||||
const topLevel = categories.filter(c => !c.parent_id).sort((a, b) => a.sort_order - b.sort_order)
|
||||
// Start on FAVORITES chip if there are any, otherwise first category
|
||||
@@ -459,9 +470,9 @@ export default function ProductPicker({ categories, products, onAdd, onQuickAdd:
|
||||
: []
|
||||
const hasSubcats = subcategories.length > 0
|
||||
|
||||
const directProducts = regularProducts.filter(p => p.category_id === activeCat)
|
||||
const directProducts = listOf(regularProducts, activeCat)
|
||||
// Products for the flat view (no sub-cats)
|
||||
const flatProducts = regularProducts.filter(p => p.category_id === activeCat)
|
||||
const flatProducts = directProducts
|
||||
|
||||
// Build sections for accordion view
|
||||
const sections = hasSubcats ? buildSections(activeParent, subcategories, directProducts) : []
|
||||
@@ -633,7 +644,7 @@ export default function ProductPicker({ categories, products, onAdd, onQuickAdd:
|
||||
const isOpen = !!expandedSubs[key]
|
||||
const sectionProducts = section._isGeneral
|
||||
? section.products
|
||||
: regularProducts.filter(p => p.category_id === section.id)
|
||||
: listOf(regularProducts, section.id)
|
||||
if (sectionProducts.length === 0) return null
|
||||
|
||||
// General products appear flat — no collapsible header
|
||||
|
||||
Reference in New Issue
Block a user