3ee3565d6d
Final consumer migration of the responsiveness plan: the 35 files still fetching fiscal periods, settings, accounts, cash accounts, dimensions or templates on their own now read lib/reference-data, and every client write site invalidates the shared cache instead of refetching locally. Settings and registries: FiscalYearsManager, FiscalPeriodEditor (period snapshotted once per company so a revalidation cannot reset dates being edited), BookingTemplatesPanel, ChartOfAccounts, ChartOfAccountsManager, EditAccountDialog, CorrectionEntryDialog, StrikeLinesDialog, InvoicePaymentAccountsSettings; the dimensions registry (DimensionsManager, DimensionCombobox, LineDimensionFields, DimensionFilter, bookkeeping/[id]) reads useDimensions and the ad-hoc fetchDimensions/fetchDimensionsCached helpers are deleted. Pages and pickers: CashAccountSelector (FyPicker-shaped restore, once per company load), use-account-names, FiscalYearGapNotice, OpeningBalancePeriodStep, BankFileConfirmStep, ImportReviewStep, the import page (invalidates accounts + periods after a SIE execute), customers list, invoices list + detail, pending, salary employee, asset dispose, year-end and periodisering pages (invalidate periods after closing), reports DimensionPnlView (its pivot picker read the wrong payload key and was always empty; it now populates), SkatteverketPanel, TemplatePicker, ArticleForm (vat_registered). Invoice dialogs and extensions: SendInvoiceDialog, PaymentBookingDialog (init reduced to the credit-note lookup + catalogue, proposal and voucher preview fire on open when cached; a local getSession replaces the network getUser for the fallback CC), InvoiceInboxWorkspace, TicWorkspace, ArcimMigrationWorkspace (invalidates after each SIE import step), enable-banking AccountPickerDialog. raw-reference-fetch ratchet: 35 -> 0 files. Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
79 lines
3.0 KiB
TypeScript
79 lines
3.0 KiB
TypeScript
'use client'
|
|
|
|
import { useMemo } from 'react'
|
|
import { Label } from '@/components/ui/label'
|
|
import DimensionCombobox from '@/components/dimensions/DimensionCombobox'
|
|
import { useDimensions } from '@/lib/reference-data/hooks'
|
|
|
|
interface LineDimensionFieldsProps {
|
|
/** Current dimensions map ({sie_dim_no: object_code}), a line's map or the header default. */
|
|
dimensions: Record<string, string> | undefined
|
|
/** Fired per dimension; `code === null` clears the value. */
|
|
onChange: (sieDimNo: string, code: string | null) => void
|
|
disabled?: boolean
|
|
/** Vertical layout for narrow containers (row popover); default is a 2-col grid. */
|
|
stacked?: boolean
|
|
/** Extra classes merged into the combobox inputs (pass 'h-8' for dense contexts). */
|
|
inputClassName?: string
|
|
}
|
|
|
|
/**
|
|
* While the registry loads (or if the fetch fails) we render the seeded
|
|
* system pair (SIE dims 1/6) so the tagging affordance never disappears:
|
|
* the registry always contains at least these two.
|
|
*/
|
|
const FALLBACK_FIELDS: { sieDimNo: string; label: string }[] = [
|
|
{ sieDimNo: '1', label: 'Kostnadsställe' },
|
|
{ sieDimNo: '6', label: 'Projekt' },
|
|
]
|
|
|
|
/**
|
|
* Registry-driven dimension comboboxes used by the voucher form's header
|
|
* default, the per-row tag popover, and the mobile line cards. One combobox
|
|
* per active registry dimension, ordered by sort_order then sie_dim_no (the
|
|
* seeded 1/6 pair sorts first). Labels are the registry dimension names and
|
|
* hardcoded-Swedish fallbacks: the component mounts on the voucher editor,
|
|
* a stays-Swedish surface per .claude/rules/i18n.md (same convention as
|
|
* DimensionCombobox).
|
|
*/
|
|
export default function LineDimensionFields({
|
|
dimensions,
|
|
onChange,
|
|
disabled,
|
|
stacked,
|
|
inputClassName,
|
|
}: LineDimensionFieldsProps) {
|
|
// Registry from the session cache (lib/reference-data): one entry shared
|
|
// by every line picker on the page; empty while loading or on failure,
|
|
// which keeps the hardcoded 1/6 fallback below.
|
|
const { dimensions: registry } = useDimensions()
|
|
|
|
const fields = useMemo(() => {
|
|
const active = registry.filter((d) => d.is_active)
|
|
if (active.length === 0) return FALLBACK_FIELDS
|
|
return [...active]
|
|
.sort((a, b) => a.sort_order - b.sort_order || a.sie_dim_no - b.sie_dim_no)
|
|
.map((d) => ({ sieDimNo: String(d.sie_dim_no), label: d.name }))
|
|
}, [registry])
|
|
|
|
return (
|
|
<div className={stacked ? 'space-y-3' : 'grid grid-cols-2 gap-3'}>
|
|
{fields.map((field) => (
|
|
<div key={field.sieDimNo}>
|
|
{/* data-ph-mask: the label is the user's own dimension name, not chrome */}
|
|
<Label data-ph-mask="" className="text-xs text-muted-foreground">{field.label}</Label>
|
|
<div className="mt-1">
|
|
<DimensionCombobox
|
|
sieDimNo={field.sieDimNo}
|
|
value={dimensions?.[field.sieDimNo] ?? null}
|
|
onChange={(code) => onChange(field.sieDimNo, code)}
|
|
disabled={disabled}
|
|
className={inputClassName}
|
|
/>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)
|
|
}
|