feat: printing problems shown and handled; printing set-up on v2 (platform-v2 step 6.10)
- a ticket that doesn't print is a problem for whoever sent it and the managers: GET /api/print-problems (the order, table, dishes, printer, since when, tries, last error, who sent it) and three ways out: print again, send to another printer, handled (services/print_problems.py; print_jobs.resolved_by / redirected_to, Alembic 0036); live event print.problems from the print paths - phone: the red printer button opens the problems sheet, the table page warns (usePrintProblems replaces the 8 s poll); counter POS: a red button under the modes with the shared panel (@xenia/ordering PrintProblemsPanel + pure rules); manager: a card on the overview (top), the Tables page and the order page - manager: Settings -> Printing (printers with reachability, test print, network scan; ticket layout + test ticket, beep, fonts with previews, dot leader, dividers) and Management -> Prep zones (cards + zone dialog with the ticket language, printers, copies, sorting, category order, kitchen screen) rebuilt in src/pages/printing; v1 PrintFontsTab, PrepZonesConfigPage, PendingPrints and /api/orders/pending-prints removed - access: printer add/edit/delete/scan need core.settings.manage, prep zone changes catalog.menu.manage (were any dashboard user) - tests: test_print_problems.py, @xenia/ordering printProblems, manager printing.test.mjs, e2e print_problems.mjs (done-when) + manager.mjs printing Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
// The tickets that didn't print (plan step 6.10), for the manager and the counter POS: per
|
||||
// ticket where it belongs, which printer, since when, how many tries, what's on it and who sent
|
||||
// it; then Print again, Send to another printer, or Handled (told the kitchen another way).
|
||||
// `run(kind, problem, printerId)` does the request and resolves (or throws the API error);
|
||||
// the list itself comes back through the live event, so this keeps no copy of it.
|
||||
import { useState } from 'react'
|
||||
import { CheckCheck, Printer, RotateCw, Send } from 'lucide-react'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useFormat, useTranslation } from '@xenia/i18n'
|
||||
import { Button, Select } from '@xenia/ui'
|
||||
import { itemsText, otherPrinters, placeOf } from './printProblems.js'
|
||||
|
||||
export function PrintProblemsPanel({ problems, printers = [], run, onOpen, showPlace = true }) {
|
||||
return (
|
||||
<ul className="divide-y divide-line" data-testid="print-problems">
|
||||
{problems.map(p => (
|
||||
<Problem key={p.job_id} problem={p} printers={printers} run={run} onOpen={onOpen} showPlace={showPlace} />
|
||||
))}
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
||||
function Problem({ problem: p, printers, run, onOpen, showPlace }) {
|
||||
const { t } = useTranslation('common')
|
||||
const { formatTime } = useFormat()
|
||||
const others = otherPrinters(p, printers)
|
||||
const [to, setTo] = useState(others[0] ? String(others[0].id) : '')
|
||||
const [busy, setBusy] = useState(null)
|
||||
const [error, setError] = useState(null)
|
||||
|
||||
async function act(kind, printerId) {
|
||||
setBusy(kind)
|
||||
setError(null)
|
||||
try { await run(kind, p, printerId) } catch (err) { setError(errorMessage(err, t)) } finally { setBusy(null) }
|
||||
}
|
||||
|
||||
return (
|
||||
<li className="px-4 py-3 grid gap-2" data-testid="print-problem" data-job={p.job_id} data-order={p.order_id}>
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-1">
|
||||
{showPlace && (
|
||||
<button type="button" className="text-body-lg font-bold text-ink hover:underline disabled:no-underline" disabled={!onOpen} onClick={() => onOpen?.(p)}>
|
||||
{placeOf(p)}
|
||||
</button>
|
||||
)}
|
||||
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-danger-soft text-danger-ink text-caption font-semibold">
|
||||
<Printer size={12} aria-hidden="true" />{t('printProblems.notOn', { printer: p.printer.name })}
|
||||
</span>
|
||||
<span className="text-caption text-ink-2">
|
||||
{t('printProblems.since', { time: formatTime(p.since) })} · {t('printProblems.tries', { count: p.attempts })}
|
||||
{p.sent_by?.length > 0 && ` · ${t('printProblems.sentBy', { names: p.sent_by.join(', ') })}`}
|
||||
</span>
|
||||
</div>
|
||||
<div className="text-body text-ink">{itemsText(p)}</div>
|
||||
{p.error && <div className="text-caption text-ink-3 truncate" title={p.error}>{p.error}</div>}
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<Button size="sm" variant="secondary" icon={<RotateCw size={14} />} loading={busy === 'retry'} disabled={!!busy} onClick={() => act('retry')} data-testid="problem-retry">
|
||||
{t('printProblems.retry')}
|
||||
</Button>
|
||||
{others.length > 0 && (
|
||||
<span className="flex items-center gap-1">
|
||||
<Select size="sm" value={to} onChange={e => setTo(e.target.value)} aria-label={t('printProblems.sendTo')} data-testid="problem-printer"
|
||||
options={others.map(o => ({ value: String(o.id), label: o.name }))} />
|
||||
<Button size="sm" icon={<Send size={14} />} loading={busy === 'redirect'} disabled={!!busy || !to} onClick={() => act('redirect', Number(to))} data-testid="problem-redirect">
|
||||
{t('printProblems.send')}
|
||||
</Button>
|
||||
</span>
|
||||
)}
|
||||
<Button size="sm" variant="ghost" icon={<CheckCheck size={14} />} loading={busy === 'handled'} disabled={!!busy} onClick={() => act('handled')} data-testid="problem-handled"
|
||||
title={t('printProblems.handledHint')}>
|
||||
{t('printProblems.handled')}
|
||||
</Button>
|
||||
</div>
|
||||
{error && <p role="alert" className="text-label text-danger-ink">{error}</p>}
|
||||
</li>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
// @xenia/ordering (plan step 6.9): what a person chooses for a product and how it becomes a line
|
||||
// the server prices (line ids, 4.4), one implementation for the counter POS, the menu tablet and
|
||||
// the manager's ordering. Pure rules in ./cart (Node-testable); the dialog and the quote hook.
|
||||
// the manager's ordering. Pure rules in ./cart (Node-testable); the dialog and the quote hook;
|
||||
// printing problems (6.10): their pure rules and the panel the manager and the counter show.
|
||||
export * from './cart.js'
|
||||
export { ProductDialog } from './ProductDialog.jsx'
|
||||
export { useQuote } from './useQuote.js'
|
||||
export * from './printProblems.js'
|
||||
export { PrintProblemsPanel } from './PrintProblemsPanel.jsx'
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// Printing problems (plan step 6.10), as plain data for every app: GET /api/print-problems
|
||||
// gives { problems, printers }; a problem is one ticket (an order's lines for one printer)
|
||||
// that didn't print. Node-tested (tests/printProblems.test.mjs).
|
||||
|
||||
export const PRINT_EVENT = 'print.problems'
|
||||
|
||||
/** The problems of one order (the order and table pages show only theirs). */
|
||||
export const problemsOf = (problems = [], orderId) => problems.filter(p => p.order_id === orderId)
|
||||
|
||||
/** The printers this ticket can be sent to instead (any but its own). */
|
||||
export const otherPrinters = (problem, printers = []) => printers.filter(p => p.id !== problem.printer.id)
|
||||
|
||||
/** "2× Burger, Freddo": what the ticket holds. */
|
||||
export function itemsText(problem) {
|
||||
return problem.items.map(i => (i.quantity !== 1 || i.unit_type !== 'piece' ? `${i.quantity}× ${i.name}` : i.name)).join(', ')
|
||||
}
|
||||
|
||||
/** Where the ticket belongs: the table's name, else the order number. */
|
||||
export const placeOf = problem => problem.table_name || `#${problem.order_id}`
|
||||
|
||||
/** Minutes since the first try (whole minutes, never negative). */
|
||||
export function minutesSince(problem, now = Date.now()) {
|
||||
const t = problem.since ? new Date(/[zZ]|[+-]\d\d:?\d\d$/.test(problem.since) ? problem.since : `${problem.since}Z`).getTime() : now
|
||||
return Math.max(0, Math.floor((now - t) / 60_000))
|
||||
}
|
||||
|
||||
/** One line per printer with how many tickets wait on it (the counter's and the phones' summary). */
|
||||
export function byPrinter(problems = []) {
|
||||
const out = new Map()
|
||||
for (const p of problems) {
|
||||
const e = out.get(p.printer.id) ?? { printer: p.printer, count: 0 }
|
||||
e.count += 1
|
||||
out.set(p.printer.id, e)
|
||||
}
|
||||
return [...out.values()]
|
||||
}
|
||||
|
||||
/** The request for an action: 'retry' | 'redirect' (with a printer) | 'handled'. → [url, body] */
|
||||
export function actionRequest(kind, problem, printerId) {
|
||||
const base = `/api/print-problems/${problem.job_id}`
|
||||
if (kind === 'redirect') return [`${base}/redirect`, { printer_id: printerId }]
|
||||
return [`${base}/${kind}`, {}]
|
||||
}
|
||||
Reference in New Issue
Block a user