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, useRef, useCallback } from 'react'
import { createPortal } from 'react-dom'
import { X, Plus } from 'lucide-react'
@@ -37,7 +38,7 @@ export function BagCard({ bag, bagItems, totalWeight, pct, tripId, tripMembers,
<div style={{ display: 'flex', alignItems: 'center', gap: sz.gap }}>
<span style={{ width: sz.dot, height: sz.dot, borderRadius: '50%', background: bag.color, flexShrink: 0 }} />
{editingName && canEdit ? (
<input autoFocus value={nameVal} onChange={e => setNameVal(e.target.value)}
<input ref={focusRevealedEditor} value={nameVal} onChange={e => setNameVal(e.target.value)}
onBlur={saveName} onKeyDown={e => { if (e.key === 'Enter') saveName(); if (e.key === 'Escape') cancelName() }}
style={{ flex: 1, fontSize: sz.name, fontWeight: 600, padding: '1px 4px', borderRadius: 4, border: '1px solid var(--border-primary)', outline: 'none', fontFamily: 'inherit', color: 'var(--text-primary)', background: 'transparent' }} />
) : (
@@ -101,7 +102,7 @@ export function BagCard({ bag, bagItems, totalWeight, pct, tripId, tripMembers,
{editingLimit && canEdit ? (
<>
<span>/</span>
<input autoFocus value={limitVal} onChange={e => setLimitVal(e.target.value)}
<input ref={focusRevealedEditor} value={limitVal} onChange={e => setLimitVal(e.target.value)}
onBlur={saveLimit}
onKeyDown={e => { if (e.key === 'Enter') saveLimit(); if (e.key === 'Escape') cancelLimit() }}
inputMode="decimal" aria-label={t('packing.bagLimit')} placeholder={t('packing.bagLimit')}
@@ -1,3 +1,4 @@
import { focusRevealedEditor } from '../shared/dialogFocus'
import { X, Plus } from 'lucide-react'
import type { PackingState } from './usePackingListPanel'
import { bagFillPct, bagLoadSummary, packedWeight, perPersonLoads } from './packingListPanel.helpers'
@@ -72,7 +73,7 @@ export function BagModal(S: PackingState) {
{/* Add bag */}
{canEdit && (showAddBag ? (
<div style={{ display: 'flex', gap: 6, marginTop: 14 }}>
<input autoFocus value={newBagName} onChange={e => setNewBagName(e.target.value)}
<input ref={focusRevealedEditor} value={newBagName} onChange={e => setNewBagName(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') void handleCreateBag(); if (e.key === 'Escape') { setShowAddBag(false); setNewBagName('') } }}
placeholder={t('packing.bagName')}
style={{ flex: 1, padding: '8px 12px', borderRadius: 10, border: '1px solid var(--border-primary)', fontSize: 'calc(13px * var(--fs-scale-body, 1))', fontFamily: 'inherit', outline: 'none' }} />
@@ -1,3 +1,4 @@
import { focusRevealedEditor } from '../shared/dialogFocus'
import { useCallback, useRef } from 'react'
import { Briefcase, Plus, X } from 'lucide-react'
import type { PackingState } from './usePackingListPanel'
@@ -47,7 +48,7 @@ export function BagSidebar(S: PackingState) {
{canEdit && showAddBag && (
<div ref={composerRef} style={{ ...COMPOSER, margin: '10px 10px 0', paddingBlock: 4, paddingInlineEnd: 4, paddingInlineStart: 10 }}>
<span aria-hidden style={{ width: 10, height: 10, borderRadius: '50%', border: '1.5px dashed var(--text-faint)', flexShrink: 0 }} />
<input autoFocus value={newBagName} onChange={e => setNewBagName(e.target.value)}
<input ref={focusRevealedEditor} value={newBagName} onChange={e => setNewBagName(e.target.value)}
onKeyDown={e => { if (e.key === 'Enter') void handleCreateBag(); if (e.key === 'Escape') closeComposer() }}
placeholder={t('packing.bagName')}
style={{ flex: 1, minWidth: 0, padding: '5px 0', border: 'none', fontSize: 'calc(12.5px * var(--fs-scale-body, 1))', fontWeight: 500, fontFamily: 'inherit', outline: 'none', color: 'var(--text-primary)', background: 'transparent' }} />
@@ -1,3 +1,4 @@
import { focusRevealedEditor } from '../shared/dialogFocus'
import React, { useState, useRef, useEffect } from 'react'
import { useTripStore } from '../../store/tripStore'
import { useToast } from '../shared/Toast'
@@ -140,7 +141,7 @@ export function KategorieGruppe({ kategorie, items, tripId, allCategories, onRen
{editingName && canEdit ? (
<input
autoFocus value={editKatName}
ref={focusRevealedEditor} value={editKatName}
onChange={e => setEditKatName(e.target.value)}
onBlur={handleSaveKatName}
onKeyDown={e => { if (e.key === 'Enter') void handleSaveKatName(); if (e.key === 'Escape') { setEditingName(false); setEditKatName(kategorie) } }}
@@ -319,7 +320,6 @@ export function KategorieGruppe({ kategorie, items, tripId, allCategories, onRen
<span aria-hidden style={{ width: 20, height: 20, borderRadius: 6, border: '1.5px solid var(--text-faint)', flexShrink: 0 }} />
<input
ref={addItemRef}
autoFocus
value={newItemName}
onChange={e => setNewItemName(e.target.value)}
onKeyDown={e => {
@@ -404,8 +404,7 @@ function CategoryGrip({ drag, kategorie, label }: { drag?: CategoryDrag; kategor
return (
<span
draggable
role="button"
aria-label={label}
aria-hidden="true"
title={label}
onDragStart={e => {
e.dataTransfer.effectAllowed = 'move'
@@ -1,3 +1,4 @@
import { replaceInlineMarkdownLinks } from '@trek/shared'
import type { PackingBag, PackingItem } from '../../types'
import { KAT_COLORS, PACKING_PLACEHOLDER_NAME } from './packingListPanel.constants'
@@ -7,7 +8,7 @@ export function katColor(kat: string, allCategories?: string[]): string {
if (idx >= 0) return KAT_COLORS[idx % KAT_COLORS.length]
// Fallback: hash-based
let h = 0
for (let i = 0; i < kat.length; i++) h = ((h << 5) - h + (kat.codePointAt(i) ?? 0)) | 0
for (let i = 0; i < kat.length; i++) h = Math.imul((h << 5) - h + (kat.codePointAt(i) ?? 0), 1)
return KAT_COLORS[Math.abs(h) % KAT_COLORS.length]
}
@@ -148,7 +149,7 @@ const MD_WEIGHT = /\((\d+(?:[.,]\d+)?)\s?(g|kg)\)$/i
/** Links, emphasis and code marks as plain text: a list copied from a notes app is full of them. */
const plainMarkdown = (text: string): string =>
text.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1').replace(/\*\*|__|~~|`/g, '').trim()
replaceInlineMarkdownLinks(text, (label) => label, true).replace(/\*\*|__|~~|`/g, '').trim()
/**
* Whether pasted text is a Markdown list rather than CSV rows (#875): any heading or