Files
accounted/components/import/OpeningBalanceColumnMappingStep.tsx
T
Mattsson f8db38f989 fix(analytics): mask session replays by default, chrome-only unmask (#1639)
* fix(analytics): mask session replays by default, chrome-only unmask

Invert PostHog session-replay masking from visible-by-default with pattern
masking to deny-by-default: every input value is masked wholesale (rrweb
maskAllInputs, no maskInputFn) and every text node is masked unless it sits
under data-ph-unmask chrome or a table column header (th). Chrome tags live
on the shared UI primitives (PageHeader, Label, Button except combobox
triggers, TabsTrigger, Badge, Card/Dialog/Sheet titles, tooltips, help
popovers, empty states, settings labels), and tagged chrome is still
pattern-scrubbed for amounts and person-/organisationsnummer. data-ph-mask
beats data-ph-unmask, so call sites that interpolate user data into chrome
stay masked; a very-thorough audit swept every unmasked primitive and each
found site got a call-site mask. Confirm-dialog wrappers and toasts stay
masked centrally: their copy describes user objects by design. Untagged new
UI over-masks instead of leaking. Privacy policy, RoPA and decision log
updated in the same change.

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

* fix(analytics): tag detail-section chrome merged from main

The register-detail primitives landed on main after the replay-masking
audit ran: kickers and DefRow labels are static i18n chrome, values stay
masked.

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

* fix(analytics): close skeptic and review findings on replay masking

Explicit data-ph tags now resolve before the th chrome fallback, so a th
nested inside a data-ph-mask container masks correctly (regression test
added). Seven missed text-leak sites get call-site masks: delete-invoice
and credit-page invoice numbers, IB-correction voucher reference, TIC
orgnr (served unnormalized, so the separator-based scrub cannot be relied
on), articles search-term empty state, dimension segment labels, and
activate-account buttons. The attribute channel is closed with rrweb's
blockClass: inputs whose placeholder carries an effective user value
(salary overrides, correction description, danger-zone confirms, credit
confirm) get ph-no-capture, removing the element from recordings while
the prefill UX stays intact; the pivot-th title attribute is dropped.
Privacy-policy effective date bumped to 2026-08-17.

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

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 11:32:45 +02:00

239 lines
8.2 KiB
TypeScript

'use client'
import { useState } from 'react'
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import { Label } from '@/components/ui/label'
import type { DetectedColumns, BalanceColumnLayout } from '@/lib/import/opening-balance/types'
interface OpeningBalanceColumnMappingStepProps {
headers: string[]
previewRows: string[][]
detectedColumns: DetectedColumns
onConfirm: (columns: DetectedColumns) => void
onBack: () => void
}
export default function OpeningBalanceColumnMappingStep({
headers,
previewRows,
detectedColumns,
onConfirm,
onBack,
}: OpeningBalanceColumnMappingStepProps) {
const [accountNumberCol, setAccountNumberCol] = useState(
detectedColumns.account_number_col,
)
const [accountNameCol, setAccountNameCol] = useState<number | null>(
detectedColumns.account_name_col,
)
const [layout, setLayout] = useState<BalanceColumnLayout>(
detectedColumns.layout,
)
const [balanceCol, setBalanceCol] = useState<number | null>(
detectedColumns.balance_col,
)
const [debitCol, setDebitCol] = useState<number | null>(
detectedColumns.debit_col,
)
const [creditCol, setCreditCol] = useState<number | null>(
detectedColumns.credit_col,
)
const columnOptions = headers.map((h, i) => ({
value: String(i),
label: `${i + 1}: ${h || '(tom)'}`,
}))
const canContinue =
accountNumberCol >= 0 &&
(layout === 'net' ? balanceCol !== null : debitCol !== null && creditCol !== null)
const handleConfirm = () => {
onConfirm({
account_number_col: accountNumberCol,
account_name_col: accountNameCol,
layout,
balance_col: layout === 'net' ? balanceCol : null,
debit_col: layout === 'debit_credit' ? debitCol : null,
credit_col: layout === 'debit_credit' ? creditCol : null,
confidence: 1, // User-confirmed
})
}
return (
<Card>
<CardHeader>
<CardTitle>Kolumnmappning</CardTitle>
<CardDescription>
Vi kunde inte automatiskt identifiera alla kolumner. Ange vilka kolumner
som innehåller kontonummer och belopp.
</CardDescription>
</CardHeader>
<CardContent className="space-y-6">
{/* Layout toggle */}
<div className="space-y-2">
<Label>Beloppslayout</Label>
<Select value={layout} onValueChange={(v) => setLayout(v as BalanceColumnLayout)}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="net">Nettobelopp (en kolumn)</SelectItem>
<SelectItem value="debit_credit">Debet &amp; kredit (två kolumner)</SelectItem>
</SelectContent>
</Select>
</div>
{/* Required mappings */}
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div className="space-y-2">
<Label>Kontonummer *</Label>
<Select
value={String(accountNumberCol)}
onValueChange={(v) => setAccountNumberCol(Number(v))}
>
<SelectTrigger>
<SelectValue placeholder="Välj kolumn" />
</SelectTrigger>
<SelectContent>
{columnOptions.map((opt) => (
<SelectItem key={opt.value} value={opt.value}>
{opt.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label>Kontonamn</Label>
<Select
value={accountNameCol !== null ? String(accountNameCol) : 'none'}
onValueChange={(v) => setAccountNameCol(v === 'none' ? null : Number(v))}
>
<SelectTrigger>
<SelectValue placeholder="Välj kolumn" />
</SelectTrigger>
<SelectContent>
<SelectItem value="none">(ingen)</SelectItem>
{columnOptions.map((opt) => (
<SelectItem key={opt.value} value={opt.value}>
{opt.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{layout === 'net' && (
<div className="space-y-2">
<Label>Saldo/Belopp *</Label>
<Select
value={balanceCol !== null ? String(balanceCol) : ''}
onValueChange={(v) => setBalanceCol(Number(v))}
>
<SelectTrigger>
<SelectValue placeholder="Välj kolumn" />
</SelectTrigger>
<SelectContent>
{columnOptions.map((opt) => (
<SelectItem key={opt.value} value={opt.value}>
{opt.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
)}
{layout === 'debit_credit' && (
<>
<div className="space-y-2">
<Label>Debet *</Label>
<Select
value={debitCol !== null ? String(debitCol) : ''}
onValueChange={(v) => setDebitCol(Number(v))}
>
<SelectTrigger>
<SelectValue placeholder="Välj kolumn" />
</SelectTrigger>
<SelectContent>
{columnOptions.map((opt) => (
<SelectItem key={opt.value} value={opt.value}>
{opt.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label>Kredit *</Label>
<Select
value={creditCol !== null ? String(creditCol) : ''}
onValueChange={(v) => setCreditCol(Number(v))}
>
<SelectTrigger>
<SelectValue placeholder="Välj kolumn" />
</SelectTrigger>
<SelectContent>
{columnOptions.map((opt) => (
<SelectItem key={opt.value} value={opt.value}>
{opt.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</>
)}
</div>
{/* Preview */}
{previewRows.length > 0 && (
<div className="space-y-2">
<Label className="text-muted-foreground">Förhandsgranskning (5 första raderna)</Label>
<div className="overflow-x-auto rounded-lg border">
<table className="w-full text-sm">
<thead className="[&_th]:font-medium [&_th]:text-[11px] [&_th]:uppercase [&_th]:tracking-wider [&_th]:text-muted-foreground">
<tr className="border-b">
{headers.map((h, i) => (
/* data-ph-mask: CSV headers are user data */
<th key={i} data-ph-mask="" className="px-3 py-2 text-left whitespace-nowrap">
{h || `Kolumn ${i + 1}`}
</th>
))}
</tr>
</thead>
<tbody>
{previewRows.slice(0, 5).map((row, ri) => (
<tr key={ri} className="border-b last:border-0">
{row.map((cell, ci) => (
<td key={ci} className="px-3 py-1.5 whitespace-nowrap tabular-nums">
{cell}
</td>
))}
</tr>
))}
</tbody>
</table>
</div>
</div>
)}
{/* Actions */}
<div className="flex justify-between">
<Button variant="ghost" onClick={onBack}>
Tillbaka
</Button>
<Button onClick={handleConfirm} disabled={!canContinue}>
Fortsätt
</Button>
</div>
</CardContent>
</Card>
)
}