fix(quality): resolve reliability findings on dev

The Sonar quality gate rated new code D. Preserve focus and keyboard interaction through native controls and shared dialog behavior. Replace ambiguous regex scans with bounded parsing and make numeric coercion and initialization explicit.
This commit is contained in:
Maurice
2026-12-01 21:06:05 +01:00
parent 0d6a432967
commit e539860530
127 changed files with 548 additions and 338 deletions
@@ -1,3 +1,4 @@
import { focusRevealedEditor } from '../shared/dialogFocus'
import { useState } from 'react'
import { Plus, X, MapPin } from 'lucide-react'
import { useTranslation } from '../../i18n'
@@ -40,7 +41,7 @@ export function MobileAddPlaceButton({ dayId, places, assignments, onAssign, onA
<div style={{ borderRadius: 14, border: '1px solid var(--border-primary)', background: 'var(--bg-card)', overflow: 'hidden' }}>
<div style={{ padding: '8px 10px', borderBottom: '1px solid var(--border-faint)', display: 'flex', gap: 6 }}>
<input
autoFocus
ref={focusRevealedEditor}
value={search}
onChange={e => setSearch(e.target.value)}
placeholder={t('dayplan.mobile.searchPlaces')}
@@ -4,6 +4,7 @@ import type { Category, Place } from '../../types';
import { safeHexColor } from '../../utils/safeColor';
import type { StopKind } from '../Roadtrip/stopKinds';
import { getCategoryIcon } from '../shared/categoryIcons';
import { focusRevealedEditor } from '../shared/dialogFocus';
import { PillSelect } from '../shared/dialogParts';
import { PILL } from '../shared/DialogShell';
import { NavigationMenu } from '../shared/NavigationMenu';
@@ -185,7 +186,7 @@ function NewCategoryField({ inputId, name, setName, create, setOpen, t }: NewCat
<input
id={inputId}
type="text"
autoFocus
ref={focusRevealedEditor}
value={name}
onChange={(e) => setName(e.target.value)}
onKeyDown={(e) => {
@@ -644,7 +644,7 @@ export default function PlaceFormModal(props: PlaceFormModalProps) {
type="text"
// A new place starts at the search; an edit or a place brought
// in from the map already has what the search would give.
autoFocus={!place && !prefillCoords}
data-initial-focus={(!place && !prefillCoords) || undefined}
value={mapsSearch}
onChange={e => { setMapsSearch(e.target.value); S.setEmptySearch(null) }}
onKeyDown={handleSearchKeyDown}
@@ -81,7 +81,7 @@ export function ListImportModal(S: SidebarState) {
onChange={e => setListImportUrl(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter' && !listImportLoading) void handleListImport() }}
placeholder={google ? 'https://maps.app.goo.gl/...' : 'https://naver.me/...'}
autoFocus
data-initial-focus
className={INPUT}
/>
</EditorField>
@@ -848,7 +848,7 @@ describe('ReservationsPanel', () => {
const user = userEvent.setup();
const onEdit = vi.fn();
render(<ReservationsPanel {...defaultProps} reservations={[transitJourney()]} onEdit={onEdit} />);
await user.click(screen.getByRole('article', { name: /Hamburg Hbf/ }));
await user.click(screen.getByRole('button', { name: /Hamburg Hbf/ }));
const detail = await screen.findByRole('dialog');
expect(onEdit).not.toHaveBeenCalled();
await user.click(within(detail).getByRole('button', { name: 'Edit' }));
@@ -274,11 +274,11 @@ describe('ReservationsPanel views', () => {
it('FE-PLANNER-RESVIEW-016: a card opens the detail on click or Enter, and Close shuts it', async () => {
const user = userEvent.setup();
renderPanel();
await user.click(screen.getByRole('article', { name: 'LH 716' }));
await user.click(within(screen.getByRole('article', { name: 'LH 716' })).getByRole('button', { name: 'LH 716' }));
expect(screen.getByRole('dialog', { name: 'LH 716' })).toBeInTheDocument();
await user.click(within(screen.getByRole('dialog', { name: 'LH 716' })).getByRole('button', { name: 'Close' }));
expect(screen.queryByRole('dialog', { name: 'LH 716' })).toBeNull();
screen.getByRole('article', { name: 'LH 716' }).focus();
within(screen.getByRole('article', { name: 'LH 716' })).getByRole('button', { name: 'LH 716' }).focus();
await user.keyboard('{Enter}');
expect(screen.getByRole('dialog', { name: 'LH 716' })).toBeInTheDocument();
});
@@ -286,7 +286,7 @@ describe('ReservationsPanel views', () => {
it('FE-PLANNER-RESVIEW-017: deleting the booking the detail shows closes the detail first', async () => {
const user = userEvent.setup();
renderPanel();
await user.click(screen.getByRole('article', { name: 'Kaiseki dinner' }));
await user.click(within(screen.getByRole('article', { name: 'Kaiseki dinner' })).getByRole('button', { name: 'Kaiseki dinner' }));
expect(screen.getByRole('dialog', { name: 'Kaiseki dinner' })).toBeInTheDocument();
await user.click(within(screen.getByRole('article', { name: 'Kaiseki dinner' })).getByRole('button', { name: 'Delete' }));
const deletes = screen.getAllByRole('button', { name: 'Delete' });
@@ -49,112 +49,112 @@ export default function BookingCard(p: BookingCardProps) {
const { t, locale } = useTranslation()
const tone = toneOf(r)
const transit = r.type === 'transit'
const title = displayTitle(r)
return (
<article
tabIndex={0}
onClick={p.onSelect}
onKeyDown={e => { if (e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); p.onSelect() } }}
aria-label={displayTitle(r)}
className={`group flex cursor-pointer flex-col overflow-hidden rounded-2xl border bg-surface-secondary transition-shadow hover:shadow-md focus-visible:outline focus-visible:outline-2 focus-visible:outline-[color:var(--text-primary)] ${p.selected ? 'border-[color:var(--text-primary)]' : 'border-edge-faint'}`}
aria-label={title}
className={`group flex cursor-pointer flex-col overflow-hidden rounded-2xl border bg-surface-secondary transition-shadow hover:shadow-md ${p.selected ? 'border-[color:var(--text-primary)]' : 'border-edge-faint'}`}
>
<div className="flex items-center gap-2 border-b border-edge-faint px-3 py-2.5" style={{ background: toneTint(tone) }}>
<StatusDot r={r} canToggle={p.canEdit} onToggle={p.onToggleStatus} />
<TypeChip type={r.type} />
<span className="flex min-w-0 flex-1 items-center gap-1.5">
<span className="min-w-0 truncate font-bold text-content" style={fs(13.5, 'body')}>{displayTitle(r)}</span>
{!!r.needs_review && <ReviewPill />}
</span>
<AirTrailPill r={r} />
{p.canEdit && <RoundAction label={t('common.edit')} onClick={p.onEdit}><Pencil size={12} strokeWidth={2} /></RoundAction>}
{p.canEdit && <RoundAction label={t('common.delete')} onClick={p.onDelete} danger><Trash2 size={12} strokeWidth={2} /></RoundAction>}
</div>
<div role="presentation" onClick={p.onSelect} className="flex flex-1 flex-col">
<div className="flex items-center gap-2 border-b border-edge-faint px-3 py-2.5" style={{ background: toneTint(tone) }}>
<StatusDot r={r} canToggle={p.canEdit} onToggle={p.onToggleStatus} />
<TypeChip type={r.type} />
<button type="button" aria-label={title} className="flex min-w-0 flex-1 items-center gap-1.5 rounded text-start focus-visible:outline focus-visible:outline-2 focus-visible:outline-[color:var(--text-primary)]">
<span className="min-w-0 truncate font-bold text-content" style={fs(13.5, 'body')}>{title}</span>
{!!r.needs_review && <ReviewPill />}
</button>
<AirTrailPill r={r} />
{p.canEdit && <RoundAction label={t('common.edit')} onClick={p.onEdit}><Pencil size={12} strokeWidth={2} /></RoundAction>}
{p.canEdit && <RoundAction label={t('common.delete')} onClick={p.onDelete} danger><Trash2 size={12} strokeWidth={2} /></RoundAction>}
</div>
<div className="flex flex-1 flex-col gap-2 px-3 pb-3 pt-2.5">
<WhenFields facts={facts} />
<FlightLiveStrip tripId={p.tripId} reservationId={r.id} type={r.type} />
<div className="flex flex-1 flex-col gap-2 px-3 pb-3 pt-2.5">
<WhenFields facts={facts} />
<FlightLiveStrip tripId={p.tripId} reservationId={r.id} type={r.type} />
{transit ? <TransitBody r={r} /> : (
<>
{r.confirmation_number && (
<Field label={t('reservations.confirmationCode')} tabular>
<BlurredCode className="font-geist">{r.confirmation_number}</BlurredCode>
</Field>
)}
<RouteBox type={r.type} facts={facts} />
{facts.legCodes.length > 0 && (
<Block label={t('reservations.segmentCodes')}>
<div className={`${BOX} flex flex-col gap-1 px-[10px] py-2`}>
{facts.legCodes.map((l, i) => (
<div key={i} className="flex items-center gap-2" style={fs(12, 'body')}>
<span className="min-w-0 flex-1 truncate font-medium text-content-secondary">{l.route || t('reservations.confirmationCode')}</span>
<BlurredCode className="font-geist tabular-nums text-content-muted">{l.code}</BlurredCode>
</div>
))}
{transit ? <TransitBody r={r} /> : (
<>
{r.confirmation_number && (
<Field label={t('reservations.confirmationCode')} tabular>
<BlurredCode className="font-geist">{r.confirmation_number}</BlurredCode>
</Field>
)}
<RouteBox type={r.type} facts={facts} />
{facts.legCodes.length > 0 && (
<Block label={t('reservations.segmentCodes')}>
<div className={`${BOX} flex flex-col gap-1 px-[10px] py-2`}>
{facts.legCodes.map((l, i) => (
<div key={i} className="flex items-center gap-2" style={fs(12, 'body')}>
<span className="min-w-0 flex-1 truncate font-medium text-content-secondary">{l.route || t('reservations.confirmationCode')}</span>
<BlurredCode className="font-geist tabular-nums text-content-muted">{l.code}</BlurredCode>
</div>
))}
</div>
</Block>
)}
{facts.cells.length > 0 && (
<div className="grid grid-cols-3 gap-2">
{facts.cells.map((c, i) => <Field key={i} label={c.label}>{c.value}</Field>)}
</div>
</Block>
)}
{facts.cells.length > 0 && (
<div className="grid grid-cols-3 gap-2">
{facts.cells.map((c, i) => <Field key={i} label={c.label}>{c.value}</Field>)}
)}
</>
)}
{facts.place && <Field label={t('reservations.locationAddress')}>{facts.place}</Field>}
{facts.accommodation && <Field label={t('reservations.meta.linkAccommodation')}>{facts.accommodation}</Field>}
{facts.linked && <Field label={t('reservations.linkedTo')}>{facts.linked}</Field>}
{facts.url && (
<Field label={t('reservations.urlLabel')}>
{facts.url.href
? <a href={facts.url.href} target="_blank" rel="noopener noreferrer" onClick={e => e.stopPropagation()} className="text-content hover:underline">{facts.url.href}</a>
: facts.url.text}
</Field>
)}
{r.notes && (
<Block label={t('reservations.notes')}>
<div className={`${BOX} collab-note-md line-clamp-4 px-[10px] py-2 text-content-muted`} style={fs(12, 'body')}>
<Markdown remarkPlugins={[remarkGfm, remarkBreaks]} components={markdownLinkComponents}>{r.notes}</Markdown>
</div>
)}
</>
)}
</Block>
)}
{facts.place && <Field label={t('reservations.locationAddress')}>{facts.place}</Field>}
{facts.accommodation && <Field label={t('reservations.meta.linkAccommodation')}>{facts.accommodation}</Field>}
{facts.linked && <Field label={t('reservations.linkedTo')}>{facts.linked}</Field>}
{facts.url && (
<Field label={t('reservations.urlLabel')}>
{facts.url.href
? <a href={facts.url.href} target="_blank" rel="noopener noreferrer" onClick={e => e.stopPropagation()} className="text-content hover:underline">{facts.url.href}</a>
: facts.url.text}
</Field>
)}
{(r.travelers || []).length > 0 && (
<Block label={t('reservations.travelers.label')}>
<TravelerChips travelers={r.travelers || []} />
</Block>
)}
{r.notes && (
<Block label={t('reservations.notes')}>
<div className={`${BOX} collab-note-md line-clamp-4 px-[10px] py-2 text-content-muted`} style={fs(12, 'body')}>
<Markdown remarkPlugins={[remarkGfm, remarkBreaks]} components={markdownLinkComponents}>{r.notes}</Markdown>
{p.files.length > 0 && (
<Block label={t('files.title')}>
<FileRows files={p.files} />
</Block>
)}
{p.costs.length > 0 && (
<div className="mt-auto flex flex-wrap justify-end gap-1.5 pt-0.5">
{p.costs.map(c => (
<span key={c.currency} className="inline-flex items-center gap-1 rounded-full bg-surface-tertiary px-2.5 py-[3px] font-geist font-semibold tabular-nums text-content-secondary" style={fs(11.5)}>
<Wallet size={11} strokeWidth={2} className="text-content-faint" />
{formatMoney(c.amount, c.currency, locale)}
</span>
))}
</div>
</Block>
)}
)}
</div>
{(r.travelers || []).length > 0 && (
<Block label={t('reservations.travelers.label')}>
<TravelerChips travelers={r.travelers || []} />
</Block>
)}
{p.files.length > 0 && (
<Block label={t('files.title')}>
<FileRows files={p.files} />
</Block>
)}
{p.costs.length > 0 && (
<div className="mt-auto flex flex-wrap justify-end gap-1.5 pt-0.5">
{p.costs.map(c => (
<span key={c.currency} className="inline-flex items-center gap-1 rounded-full bg-surface-tertiary px-2.5 py-[3px] font-geist font-semibold tabular-nums text-content-secondary" style={fs(11.5)}>
<Wallet size={11} strokeWidth={2} className="text-content-faint" />
{formatMoney(c.amount, c.currency, locale)}
</span>
<PluginCardFooter items={p.contributions} tripId={p.tripId} />
{p.showFrames && p.detailPlugins.length > 0 && (
<div role="presentation" onClick={e => e.stopPropagation()} className="flex flex-col gap-2 px-3 pb-3">
{p.detailPlugins.map(pl => (
<div key={pl.id} className={`${BOX} overflow-hidden`}>
<PluginFrame pluginId={pl.id} tripId={String(p.tripId)} reservationId={String(r.id)} title={pl.name} surface="detail-slot" />
</div>
))}
</div>
)}
</div>
<PluginCardFooter items={p.contributions} tripId={p.tripId} />
{p.showFrames && p.detailPlugins.length > 0 && (
<div role="presentation" onClick={e => e.stopPropagation()} className="flex flex-col gap-2 px-3 pb-3">
{p.detailPlugins.map(pl => (
<div key={pl.id} className={`${BOX} overflow-hidden`}>
<PluginFrame pluginId={pl.id} tripId={String(p.tripId)} reservationId={String(r.id)} title={pl.name} surface="detail-slot" />
</div>
))}
</div>
)}
</article>
)
}
@@ -163,7 +163,7 @@ function usePopover() {
function Menu({ children, onClose, width = 260 }: { children: ReactNode; onClose: () => void; width?: number }) {
return (
<div role="menu" onKeyDown={e => { if (e.key === 'Escape') onClose() }} className="absolute end-0 top-11 z-30" style={{ ...POPOVER, width }}>
<div role="menu" tabIndex={-1} onKeyDown={e => { if (e.key === 'Escape') onClose() }} className="absolute end-0 top-11 z-30" style={{ ...POPOVER, width }}>
{children}
</div>
)
@@ -35,7 +35,7 @@ export default function BookingsList(p: BookingsListProps) {
const rootRef = useRef<HTMLDivElement>(null)
const flat = p.groups.flatMap(g => (p.collapsed(g.id) ? [] : g.items))
const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
const onNavigate = (e: KeyboardEvent<HTMLElement>) => {
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return
e.preventDefault()
const focused = document.activeElement instanceof HTMLElement ? Number(document.activeElement.dataset.row) : Number.NaN
@@ -45,13 +45,13 @@ export default function BookingsList(p: BookingsListProps) {
}
return (
<div ref={rootRef} onKeyDown={onKeyDown} className="flex flex-col gap-6">
<div ref={rootRef} className="flex flex-col gap-6">
{p.groups.map(g => {
const open = !p.collapsed(g.id)
return (
<section key={g.id} className="overflow-hidden rounded-2xl border border-edge-faint bg-surface-card">
{g.label && (
<button type="button" onClick={() => p.onToggleGroup(g.id)} aria-expanded={open}
<button type="button" onClick={() => p.onToggleGroup(g.id)} onKeyDown={onNavigate} aria-expanded={open}
className="flex w-full items-center gap-2 bg-surface-secondary px-3.5 py-2.5 text-start">
<span className={EYEBROW} style={fs(10.5)}>{g.label}</span>
{g.sub && <span className="truncate font-geist font-medium text-content-muted" style={fs(11.5)}>{g.sub}</span>}
@@ -59,7 +59,7 @@ export default function BookingsList(p: BookingsListProps) {
</button>
)}
{open && g.items.map(r => (
<Row key={r.id} r={r} p={p} facts={p.factsOf(r)} files={p.filesCount(r)} costs={p.costsOf(r)} t={t} locale={locale} />
<Row key={r.id} r={r} p={p} facts={p.factsOf(r)} files={p.filesCount(r)} costs={p.costsOf(r)} t={t} locale={locale} onNavigate={onNavigate} />
))}
</section>
)
@@ -68,7 +68,7 @@ export default function BookingsList(p: BookingsListProps) {
)
}
function Row({ r, p, facts, files, costs, t, locale }: {
function Row({ r, p, facts, files, costs, t, locale, onNavigate }: {
r: Reservation
p: BookingsListProps
facts: BookingFacts
@@ -76,6 +76,7 @@ function Row({ r, p, facts, files, costs, t, locale }: {
costs: CostTotal[]
t: (k: string, v?: Record<string, string | number>) => string
locale: string
onNavigate: (e: KeyboardEvent<HTMLElement>) => void
}) {
const selected = p.selectedId === r.id
const transit = r.type === 'transit'
@@ -93,7 +94,10 @@ function Row({ r, p, facts, files, costs, t, locale }: {
aria-pressed={selected}
aria-label={displayTitle(r)}
onClick={() => p.onSelect(r)}
onKeyDown={e => { if (e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); p.onSelect(r) } }}
onKeyDown={e => {
if (e.target === e.currentTarget && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); p.onSelect(r) }
else onNavigate(e)
}}
className={`group relative grid cursor-pointer grid-cols-[22px_32px_minmax(0,1fr)_minmax(118px,auto)_auto] items-center gap-3 border-t border-edge-faint px-3.5 py-2.5 first:border-t-0 hover:bg-surface-hover focus-visible:outline-none focus-visible:bg-surface-hover ${selected ? 'bg-surface-hover shadow-[inset_3px_0_0_0_var(--text-primary)]' : ''}`}
>
<StatusDot r={r} canToggle={p.canEdit} onToggle={() => p.onToggleStatus(r)} />
@@ -1,4 +1,4 @@
import { normalizePlaceWebsite, parsePlaceHours } from '@trek/shared';
import { normalizePlaceWebsite, parsePlaceHours, stripPreviewTags } from '@trek/shared';
import type { PlaceFormData } from './PlaceFormModal.helpers';
import { cleanWeek, weekFromPeriods, writeWeek } from './placeHours';
@@ -23,8 +23,7 @@ const text = (value: unknown): string => (typeof value === 'string' ? value.trim
/** A description as plain words: the editor stores markup, the lookup sends text. */
const plain = (value: string): string =>
value
.replace(/<[^>]*>/g, ' ')
stripPreviewTags(value)
.replace(/[*_`~#>]/g, '')
.replace(/\s+/g, ' ')
.trim();