feat: feature enforcement imports (#37/#38) and Universal CSV validation (#71)
Activity and nutrition legacy CSV imports enforce tier limits with UsageBadge UI; Universal CSV gets mapping validation on copy/import, format-check parity, and structured error_details. version: 0.9u module: activity 1.2.1, nutrition 1.0.3, csv_import 0.4.0 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
532e17c4cd
commit
79ec249bc3
27 files changed
+690
-95
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import { Upload, CheckCircle, TrendingUp, Info } from 'lucide-react'
|
||||
import UsageBadge from '../components/UsageBadge'
|
||||
import {
|
||||
LineChart, Line, BarChart, Bar, XAxis, YAxis, Tooltip,
|
||||
ResponsiveContainer, CartesianGrid, Legend, ReferenceLine, ScatterChart, Scatter
|
||||
@@ -433,15 +434,17 @@ function ImportHistory() {
|
||||
}
|
||||
|
||||
// ── Import Panel ──────────────────────────────────────────────────────────────
|
||||
function ImportPanel({ onImported }) {
|
||||
function ImportPanel({ onImported, usage = null }) {
|
||||
const fileRef = useRef()
|
||||
const [status, setStatus] = useState(null)
|
||||
const [error, setError] = useState(null)
|
||||
const [dragging,setDragging]= useState(false)
|
||||
const [tab, setTab] = useState('file') // 'file' | 'paste'
|
||||
const [pasteText, setPasteText] = useState('')
|
||||
const atLimit = usage && !usage.allowed
|
||||
|
||||
const runImport = async (file) => {
|
||||
if (atLimit) return
|
||||
setStatus('loading'); setError(null)
|
||||
try {
|
||||
const result = await nutritionApi.importCsv(file)
|
||||
@@ -468,7 +471,7 @@ function ImportPanel({ onImported }) {
|
||||
}
|
||||
|
||||
const handlePasteImport = async () => {
|
||||
if (!pasteText.trim()) return
|
||||
if (!pasteText.trim() || atLimit) return
|
||||
const blob = new Blob([pasteText], { type: 'text/csv' })
|
||||
const file = new File([blob], 'paste.csv', { type: 'text/csv' })
|
||||
await runImport(file)
|
||||
@@ -476,7 +479,10 @@ function ImportPanel({ onImported }) {
|
||||
|
||||
return (
|
||||
<div className="card section-gap">
|
||||
<div className="card-title">📥 FDDB CSV Import</div>
|
||||
<div className="card-title badge-container-right">
|
||||
<span>📥 FDDB CSV Import</span>
|
||||
{usage && <UsageBadge {...usage} />}
|
||||
</div>
|
||||
<p style={{fontSize:13,color:'var(--text2)',marginBottom:10,lineHeight:1.6}}>
|
||||
In FDDB: <strong>Mein Tagebuch → Exportieren → CSV</strong> — dann hier importieren.
|
||||
</p>
|
||||
@@ -498,23 +504,26 @@ function ImportPanel({ onImported }) {
|
||||
<>
|
||||
{/* Drag & Drop Zone */}
|
||||
<div
|
||||
onDragOver={e=>{e.preventDefault();setDragging(true)}}
|
||||
onDragOver={e=>{ if(!atLimit){ e.preventDefault(); setDragging(true) }}}
|
||||
onDragLeave={()=>setDragging(false)}
|
||||
onDrop={handleDrop}
|
||||
onClick={()=>fileRef.current.click()}
|
||||
onDrop={e=>{ e.preventDefault(); setDragging(false); if(atLimit) return; handleDrop(e) }}
|
||||
onClick={()=>{ if(!atLimit) fileRef.current?.click() }}
|
||||
title={atLimit ? `Limit erreicht (${usage.used}/${usage.limit})` : ''}
|
||||
style={{
|
||||
border:`2px dashed ${dragging?'var(--accent)':'var(--border2)'}`,
|
||||
borderRadius:10, padding:'24px 16px', textAlign:'center',
|
||||
background: dragging?'var(--accent-light)':'var(--surface2)',
|
||||
cursor:'pointer', transition:'all 0.15s',
|
||||
cursor:atLimit?'not-allowed':'pointer', opacity:atLimit?0.65:1, transition:'all 0.15s',
|
||||
}}>
|
||||
<Upload size={28} style={{color:dragging?'var(--accent)':'var(--text3)',marginBottom:8}}/>
|
||||
<div style={{fontSize:14,fontWeight:500,color:dragging?'var(--accent-dark)':'var(--text2)'}}>
|
||||
{dragging ? 'Datei loslassen…' : 'CSV hierher ziehen oder tippen zum Auswählen'}
|
||||
{atLimit
|
||||
? '🔒 Limit erreicht — Import nicht möglich'
|
||||
: dragging ? 'Datei loslassen…' : 'CSV hierher ziehen oder tippen zum Auswählen'}
|
||||
</div>
|
||||
<div style={{fontSize:11,color:'var(--text3)',marginTop:4}}>.csv Dateien</div>
|
||||
</div>
|
||||
<input ref={fileRef} type="file" accept=".csv" style={{display:'none'}} onChange={handleFile}/>
|
||||
<input ref={fileRef} type="file" accept=".csv" style={{display:'none'}} disabled={atLimit} onChange={handleFile}/>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -523,14 +532,20 @@ function ImportPanel({ onImported }) {
|
||||
<textarea
|
||||
style={{width:'100%',minHeight:120,padding:10,fontFamily:'monospace',fontSize:11,
|
||||
background:'var(--surface2)',border:'1.5px solid var(--border2)',borderRadius:8,
|
||||
color:'var(--text1)',resize:'vertical',boxSizing:'border-box'}}
|
||||
color:'var(--text1)',resize:'vertical',boxSizing:'border-box',
|
||||
opacity:atLimit?0.65:1}}
|
||||
placeholder="datum_tag_monat_jahr_stunde_minute;bezeichnung; 13.03.2026 21:54;50 g Hähnchen;..."
|
||||
value={pasteText}
|
||||
onChange={e=>setPasteText(e.target.value)}
|
||||
disabled={atLimit}
|
||||
/>
|
||||
<button className="btn btn-primary btn-full" style={{marginTop:8}}
|
||||
onClick={handlePasteImport} disabled={status==='loading'||!pasteText.trim()}>
|
||||
{status==='loading'
|
||||
onClick={handlePasteImport}
|
||||
disabled={status==='loading'||!pasteText.trim()||atLimit}
|
||||
title={atLimit ? `Limit erreicht (${usage.used}/${usage.limit})` : ''}>
|
||||
{atLimit
|
||||
? '🔒 Limit erreicht'
|
||||
: status==='loading'
|
||||
? <><div className="spinner" style={{width:14,height:14}}/> Importiere…</>
|
||||
: <><Upload size={15}/> CSV-Text importieren</>}
|
||||
</button>
|
||||
@@ -781,6 +796,14 @@ export default function NutritionPage() {
|
||||
const [loading, setLoad] = useState(true)
|
||||
const [hasData, setHasData]= useState(false)
|
||||
const [importHistoryKey, setImportHistoryKey] = useState(Date.now()) // BUG-004 fix
|
||||
const [nutritionUsage, setNutritionUsage] = useState(null)
|
||||
|
||||
const loadUsage = () => {
|
||||
nutritionApi.getFeatureUsage().then(features => {
|
||||
const nutritionFeature = features.find(f => f.feature_id === 'nutrition_entries')
|
||||
setNutritionUsage(nutritionFeature ?? null)
|
||||
}).catch(err => console.error('Failed to load usage:', err))
|
||||
}
|
||||
|
||||
const load = async () => {
|
||||
setLoad(true)
|
||||
@@ -800,7 +823,7 @@ export default function NutritionPage() {
|
||||
finally { setLoad(false) }
|
||||
}
|
||||
|
||||
useEffect(() => { load() }, [])
|
||||
useEffect(() => { load(); loadUsage() }, [])
|
||||
|
||||
return (
|
||||
<div className="capture-page">
|
||||
@@ -822,7 +845,10 @@ export default function NutritionPage() {
|
||||
{/* Import Panel + History */}
|
||||
{inputTab==='import' && (
|
||||
<>
|
||||
<ImportPanel onImported={() => { load(); setImportHistoryKey(Date.now()) }}/>
|
||||
<ImportPanel
|
||||
usage={nutritionUsage}
|
||||
onImported={() => { load(); loadUsage(); setImportHistoryKey(Date.now()) }}
|
||||
/>
|
||||
<ImportHistory key={importHistoryKey}/>
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user