feat(csv-import): Enhance CSV import functionality with new modules and tests
- Added support for new CSV import modules: sleep and vitals_baseline, expanding the import capabilities. - Implemented backend logic for handling CSV imports related to sleep and vitals baseline, including error handling and data processing. - Updated frontend components to include new modules in the CSV import interface, improving user experience. - Introduced unit tests for the new import functionalities to ensure reliability and correctness. - Enhanced existing CSV analysis features to accommodate the new modules, ensuring consistent behavior across the application.
This commit is contained in:
1 parent
b4cc3cb934
commit
26ab11eb7b
14 files changed
+1261
-340
No files matched your search
@@ -9,6 +9,8 @@ const MODULE_LABEL = {
|
||||
weight: 'Gewicht',
|
||||
blood_pressure: 'Blutdruck',
|
||||
activity: 'Aktivität',
|
||||
sleep: 'Schlaf',
|
||||
vitals_baseline: 'Vitalwerte (Baseline)',
|
||||
}
|
||||
|
||||
function SampleTable({ sampleRows, columns }) {
|
||||
|
||||
@@ -8,6 +8,8 @@ const MODULE_LABEL = {
|
||||
weight: 'Gewicht',
|
||||
blood_pressure: 'Blutdruck',
|
||||
activity: 'Aktivität',
|
||||
sleep: 'Schlaf',
|
||||
vitals_baseline: 'Vitalwerte (Baseline)',
|
||||
}
|
||||
|
||||
export default function AdminCsvTemplatesPage() {
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
import { useState, useMemo } from 'react'
|
||||
import { useState, useMemo, useRef } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { ArrowLeft, FileSpreadsheet, Loader2 } from 'lucide-react'
|
||||
import { ArrowLeft, FileSpreadsheet, Loader2, Upload } from 'lucide-react'
|
||||
import { api } from '../utils/api'
|
||||
import { csvPreviewTdStyle } from '../utils/csvPreviewCells'
|
||||
|
||||
/** Ziele, die der Universal-Executor bereits schreiben kann (ohne manuelle Modul-Wahl). */
|
||||
const EXECUTOR_READY = new Set(['nutrition', 'weight', 'blood_pressure'])
|
||||
const EXECUTOR_READY = new Set([
|
||||
'nutrition',
|
||||
'weight',
|
||||
'blood_pressure',
|
||||
'activity',
|
||||
'sleep',
|
||||
'vitals_baseline',
|
||||
])
|
||||
|
||||
const MODULE_LABEL = {
|
||||
nutrition: 'Ernährung',
|
||||
weight: 'Gewicht',
|
||||
blood_pressure: 'Blutdruck',
|
||||
activity: 'Aktivität',
|
||||
sleep: 'Schlaf',
|
||||
vitals_baseline: 'Vitalwerte (Baseline)',
|
||||
}
|
||||
|
||||
function mergeMappingChoices(detected, mapData) {
|
||||
@@ -98,7 +107,9 @@ function SampleTable({ sampleRows, columns }) {
|
||||
|
||||
export default function UniversalCsvImportPage() {
|
||||
const navigate = useNavigate()
|
||||
const fileInputRef = useRef(null)
|
||||
const [file, setFile] = useState(null)
|
||||
const [dragActive, setDragActive] = useState(false)
|
||||
const [analyzeResult, setAnalyzeResult] = useState(null)
|
||||
const [mappingChoices, setMappingChoices] = useState([])
|
||||
const [mappingId, setMappingId] = useState('')
|
||||
@@ -113,6 +124,21 @@ export default function UniversalCsvImportPage() {
|
||||
)
|
||||
const importAllowed = selectedChoice && EXECUTOR_READY.has(selectedChoice.module)
|
||||
|
||||
const assignCsvFile = (f) => {
|
||||
if (!f) return
|
||||
const name = (f.name || '').toLowerCase()
|
||||
if (!name.endsWith('.csv')) {
|
||||
setError('Bitte eine .csv-Datei wählen.')
|
||||
return
|
||||
}
|
||||
setFile(f)
|
||||
setAnalyzeResult(null)
|
||||
setMappingChoices([])
|
||||
setMappingId('')
|
||||
setSuccess(null)
|
||||
setError(null)
|
||||
}
|
||||
|
||||
const handleAnalyze = async () => {
|
||||
if (!file) {
|
||||
setError('Bitte eine CSV-Datei wählen')
|
||||
@@ -153,7 +179,7 @@ export default function UniversalCsvImportPage() {
|
||||
return
|
||||
}
|
||||
if (!importAllowed) {
|
||||
setError('Diese Vorlage kann hier noch nicht importiert werden (z. B. Aktivität → Seite „Aktivität“).')
|
||||
setError('Diese Vorlage wird vom Universal-Importer noch nicht unterstützt.')
|
||||
return
|
||||
}
|
||||
setLoadingImport(true)
|
||||
@@ -197,19 +223,11 @@ export default function UniversalCsvImportPage() {
|
||||
CSV-Import
|
||||
</h1>
|
||||
<p style={{ fontSize: 14, color: 'var(--text2)', marginBottom: 20, lineHeight: 1.55 }}>
|
||||
Datei hochladen: Die App vergleicht die Spalten-Struktur mit allen gespeicherten Vorlagen und schlägt
|
||||
passende Ziele vor (Ernährung, Gewicht, Blutdruck, …). Du bestätigst nur noch die Vorlage — ohne
|
||||
vorher ein „Modul“ raten zu müssen.{' '}
|
||||
<strong>Später:</strong> eine Datei, mehrere Zieltabellen. Trainingseinheiten aktuell weiter unter{' '}
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
style={{ padding: '2px 8px', fontSize: 13 }}
|
||||
onClick={() => navigate('/activity')}
|
||||
>
|
||||
Aktivität
|
||||
</button>
|
||||
.
|
||||
CSV hier ablegen oder die Fläche antippen: Die App vergleicht die Spalten mit gespeicherten Vorlagen
|
||||
(Ernährung, Gewicht, Blutdruck, Aktivität, Schlaf, Vitalwerte) und schlägt passende Ziele vor. Du
|
||||
bestätigst die Vorlage — ohne zuerst ein Modell raten zu müssen. Schlaf-Import erwartet das
|
||||
Apple-Health-Schlaf-CSV (Segment- oder Zusammenfassungs-Export).{' '}
|
||||
<strong>Ausblick:</strong> Eine Datei → mehrere Zieltabellen.
|
||||
</p>
|
||||
|
||||
{error && (
|
||||
@@ -243,18 +261,58 @@ export default function UniversalCsvImportPage() {
|
||||
<div className="card" style={{ marginBottom: 16, padding: 16 }}>
|
||||
<div className="form-label">1. CSV-Datei</div>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept=".csv,text/csv"
|
||||
className="form-input"
|
||||
style={{ marginTop: 8, width: '100%' }}
|
||||
onChange={(e) => {
|
||||
setFile(e.target.files?.[0] || null)
|
||||
setAnalyzeResult(null)
|
||||
setMappingChoices([])
|
||||
setMappingId('')
|
||||
setSuccess(null)
|
||||
}}
|
||||
style={{ position: 'absolute', width: 0, height: 0, opacity: 0, pointerEvents: 'none' }}
|
||||
onChange={(e) => assignCsvFile(e.target.files?.[0] || null)}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
onDragEnter={(e) => {
|
||||
e.preventDefault()
|
||||
setDragActive(true)
|
||||
}}
|
||||
onDragOver={(e) => {
|
||||
e.preventDefault()
|
||||
setDragActive(true)
|
||||
}}
|
||||
onDragLeave={(e) => {
|
||||
e.preventDefault()
|
||||
if (!e.currentTarget.contains(e.relatedTarget)) setDragActive(false)
|
||||
}}
|
||||
onDrop={(e) => {
|
||||
e.preventDefault()
|
||||
setDragActive(false)
|
||||
assignCsvFile(e.dataTransfer?.files?.[0] || null)
|
||||
}}
|
||||
className="btn btn-secondary"
|
||||
style={{
|
||||
marginTop: 8,
|
||||
width: '100%',
|
||||
minHeight: 120,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
gap: 10,
|
||||
border: `2px dashed ${dragActive ? 'var(--accent)' : 'var(--border)'}`,
|
||||
borderRadius: 12,
|
||||
background: dragActive ? 'var(--surface2)' : 'var(--surface)',
|
||||
cursor: 'pointer',
|
||||
padding: 16,
|
||||
}}
|
||||
>
|
||||
<Upload size={28} strokeWidth={1.75} color="var(--accent)" />
|
||||
<span style={{ fontSize: 15, color: 'var(--text1)', fontWeight: 600 }}>
|
||||
Datei ablegen oder tippen zum Auswählen
|
||||
</span>
|
||||
<span style={{ fontSize: 13, color: 'var(--text3)' }}>
|
||||
{file ? file.name : 'Noch keine Datei gewählt'}
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary"
|
||||
@@ -367,8 +425,7 @@ export default function UniversalCsvImportPage() {
|
||||
|
||||
{selectedChoice && !importAllowed && (
|
||||
<p style={{ fontSize: 13, color: 'var(--text3)', marginTop: 10 }}>
|
||||
Diese Vorlage passt strukturell, wird aber an der passenden Stelle importiert (z. B. Aktivität →
|
||||
Apple-Health-CSV dort).
|
||||
Diese Vorlage passt strukturell; dieser Import-Weg unterstützt das Zielmodul noch nicht.
|
||||
</p>
|
||||
)}
|
||||
|
||||
|
||||
Reference in new issue
Block a user