Files
accounted/components/dimensions/LineDimensionFields.tsx
T
Mattsson f633349c8d feat(analytics): show form field labels in session replays (#1416)
* feat(analytics): show form field labels in session replays

Replays showed the sidebar after #1412 but form pages were still fully
masked, so you could not tell WHICH field a user was interacting with.
Tag the shared Label primitive (components/ui/label.tsx, used by every
form in the app) with data-ph-unmask: field labels are static i18n
chrome, and maskAllInputs keeps every typed value hidden.

The one Label whose text is user data, the user-defined dimension name
in LineDimensionFields, gets data-ph-mask, which wins even on the same
element because maskTextFn checks it first.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(analytics): re-mask three Labels that render user data

Completing the audit the PR review asked for: a multiline sweep over
every Label child found three call sites whose label text is user
data, missed by the first single-line pass. Danger-zone confirm
labels interpolate the user's email (AccountDangerZone) and the
company name (CompanyDangerZone), and the periodisering auto-detect
row label is counterparty name + invoice number. All three now carry
data-ph-mask. Currency-code and row-count interpolations were
reviewed and left visible: categorical UI state, not books data.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-05 15:18:07 +02:00

93 lines
3.2 KiB
TypeScript

'use client'
import { useEffect, useMemo, useState } from 'react'
import { Label } from '@/components/ui/label'
import DimensionCombobox from '@/components/dimensions/DimensionCombobox'
import {
fetchDimensionsCached,
type DimensionDto,
} from '@/components/dimensions/types'
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) {
const [registry, setRegistry] = useState<DimensionDto[] | null>(null)
useEffect(() => {
let cancelled = false
fetchDimensionsCached()
.then((dims) => {
if (!cancelled) setRegistry(dims)
})
.catch(() => {
/* keep the hardcoded 1/6 fallback */
})
return () => {
cancelled = true
}
}, [])
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>
)
}