On this page
Two page-level patterns that are not part of the plugin contract. Each is a short recipe for a page author; the plugin contract is in Plugin development.
Add an export to a page#
Exports go through @yng/exports, <ExportMenu> and useExportMenu. PDF renders server-side from the page's own URL. Reader view: Exports: CSV, Excel, PDF.
Tabular export (CSV and Excel): build items from typed rows, headers from
t().const { items } = useExportMenu<OrderRow>({ locale, filename: 'orders', excludePdf: true, // operations lists are tabular only table: { sheet: { name: t('orders.export.sheet'), columns: [ { header: t('orders.col.id'), value: (r) => r.id }, { header: t('orders.col.amount'), value: (r) => r.amountVnd }, // integer VND { header: t('orders.col.placedAt'), value: (r) => r.placedAt }, // Date to ISO ], rows, }, }, }); return <ExportMenu label={t('common.export')} items={items} />;PDF of a server page: wrap the body in
<PdfExportPage filename="…" pdfTitle="…">from@/lib/page-export-wrapper; itsheaderprop places the action in the page header.PDF plus tabular: pass
pdfRefandpdfTitlewithtable. A multi-tab deck passespdfWholeDeckfor one whole-deck PDF.File names go through
safeFilename(): no diacritics, at most 64 characters, an ISO date suffix.
Wire period comparison into a report#
Comparison state lives in the URL; @yng/ui/compare-period is the one period implementation for filter bar and server. Reader view: Explore and period comparison.
Parse the URL with
parseReportFilters()(apps/web/src/app/(dashboard)/reports/_lib/report-filters.ts):compare=1pluscomparePreset(previous,year-ago,custom) yieldsfilters.compare.Fetch the primary and comparison windows in parallel:
const filters = parseReportFilters(await searchParams, 45); const compareFilters = filters.compare ? { ...filters, from: filters.compare.from, to: filters.compare.to } : null; const [report, compareReport] = await Promise.all([ caller.reports.settlement(filters), compareFilters ? caller.reports.settlement(compareFilters) : Promise.resolve(null), ]);Render each KPI delta through the shared delta formatter: a dash for a zero or non-finite baseline.
On an Explore-style page, pass
compareFromandcompareTotoexplore.query; the response carriessummary.previousValueandpreviousTimeSeries.
Verify#
pnpm run typecheck && pnpm run lint
python3 scripts/audit/compare-period-helper.py