feat: Introduce quick capture widget configuration and validation
- Added support for the "quick_capture" widget, allowing users to configure visibility for weight and baseline vitals (resting HR, HRV, VO₂max). - Implemented validation logic to ensure correct configuration input and prevent errors. - Updated the widget catalog and dashboard layout to reflect the new quick capture features. - Removed the "training_type_distribution" widget from the catalog as part of the refactor. - Bumped app_dashboard version to 1.6.2 to incorporate these enhancements.
This commit is contained in:
1 parent
3d498d03c1
commit
7f833b2cb1
9 files changed
+267
-107
No files matched your search
@@ -1,25 +0,0 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import TrainingTypeDistribution from '../TrainingTypeDistribution'
|
||||
|
||||
/**
|
||||
* @param {{ refreshTick?: number, distributionDays?: number }} props
|
||||
*/
|
||||
export default function TrainingTypeDistributionWidget({ refreshTick = 0, distributionDays = 28 }) {
|
||||
const nav = useNavigate()
|
||||
const days = Math.max(7, Math.min(120, Number(distributionDays) || 28))
|
||||
|
||||
return (
|
||||
<div className="card section-gap" style={{ marginBottom: 16 }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
|
||||
<div>
|
||||
<div style={{ fontSize: 14, fontWeight: 700, color: 'var(--text1)' }}>Training</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--text3)' }}>Verteilung der Trainingstypen ({days} Tage)</div>
|
||||
</div>
|
||||
<button type="button" className="btn btn-secondary" style={{ fontSize: 12, padding: '6px 12px' }} onClick={() => nav('/activity')}>
|
||||
Details →
|
||||
</button>
|
||||
</div>
|
||||
<TrainingTypeDistribution key={`${refreshTick}-${days}`} days={days} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -6,8 +6,16 @@ import { api } from '../../utils/api'
|
||||
|
||||
/**
|
||||
* Schnelleingabe: Gewicht + Baseline Vitals (Ruhepuls, HRV, VO₂max) für heute.
|
||||
* @param {{ onSaved?: () => void, captureConfig?: Record<string, unknown> }} props
|
||||
* captureConfig: show_weight, show_resting_hr, show_hrv, show_vo2_max (false = ausblenden; fehlend = true)
|
||||
*/
|
||||
export default function PilotQuickCapture({ onSaved }) {
|
||||
export default function PilotQuickCapture({ onSaved, captureConfig }) {
|
||||
const cfgRaw = captureConfig && typeof captureConfig === 'object' ? captureConfig : {}
|
||||
const showWeight = cfgRaw.show_weight !== false
|
||||
const showRestingHr = cfgRaw.show_resting_hr !== false
|
||||
const showHrv = cfgRaw.show_hrv !== false
|
||||
const showVo2 = cfgRaw.show_vo2_max !== false
|
||||
const showVitalsBlock = showRestingHr || showHrv || showVo2
|
||||
const today = dayjs().format('YYYY-MM-DD')
|
||||
const [weightInput, setWeightInput] = useState('')
|
||||
const [weightSaving, setWeightSaving] = useState(false)
|
||||
@@ -77,12 +85,17 @@ export default function PilotQuickCapture({ onSaved }) {
|
||||
setVOk(false)
|
||||
try {
|
||||
const payload = { date: today }
|
||||
if (vForm.resting_hr) payload.resting_hr = parseInt(vForm.resting_hr, 10)
|
||||
if (vForm.hrv) payload.hrv = parseInt(vForm.hrv, 10)
|
||||
if (vForm.vo2_max) payload.vo2_max = parseFloat(vForm.vo2_max)
|
||||
if (showRestingHr && vForm.resting_hr) payload.resting_hr = parseInt(vForm.resting_hr, 10)
|
||||
if (showHrv && vForm.hrv) payload.hrv = parseInt(vForm.hrv, 10)
|
||||
if (showVo2 && vForm.vo2_max) payload.vo2_max = parseFloat(vForm.vo2_max)
|
||||
|
||||
if (!payload.resting_hr && !payload.hrv && !payload.vo2_max) {
|
||||
setVErr('Mindestens Ruhepuls, HRV oder VO₂max angeben.')
|
||||
const hint = [showRestingHr && 'Ruhepuls', showHrv && 'HRV', showVo2 && 'VO₂max'].filter(Boolean).join(', ')
|
||||
setVErr(
|
||||
hint
|
||||
? `Mindestens einen sichtbaren Wert angeben (${hint}).`
|
||||
: 'Keine Vitalfelder sichtbar.'
|
||||
)
|
||||
setVSaving(false)
|
||||
return
|
||||
}
|
||||
@@ -112,17 +125,34 @@ export default function PilotQuickCapture({ onSaved }) {
|
||||
background: 'var(--surface2)',
|
||||
}
|
||||
|
||||
if (!showWeight && !showVitalsBlock) {
|
||||
return (
|
||||
<div className="card section-gap">
|
||||
<div className="card-title">Schnelleingabe (heute)</div>
|
||||
<p style={{ fontSize: 13, color: 'var(--text3)', margin: 0 }}>
|
||||
Für dieses Widget sind keine Eingabebereiche aktiviert. Im Dashboard-Lab die Sichtbarkeit prüfen
|
||||
oder <Link to="/vitals">Vitalwerte-Seite</Link> nutzen.
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card section-gap">
|
||||
<div className="card-title">Schnelleingabe (heute)</div>
|
||||
<p style={{ fontSize: 12, color: 'var(--text2)', marginBottom: 12, lineHeight: 1.5 }}>
|
||||
Gewicht separat; Vitalwerte typischerweise gemeinsam.{' '}
|
||||
<Link to="/vitals" style={{ color: 'var(--accent)', fontSize: 12 }}>
|
||||
Volle Vitalwerte-Seite →
|
||||
</Link>
|
||||
</p>
|
||||
{(showWeight || showVitalsBlock) && (
|
||||
<p style={{ fontSize: 12, color: 'var(--text2)', marginBottom: 12, lineHeight: 1.5 }}>
|
||||
{showWeight && showVitalsBlock && 'Gewicht separat; Vitalwerte typischerweise gemeinsam. '}
|
||||
{showWeight && !showVitalsBlock && 'Gewicht für heute. '}
|
||||
{!showWeight && showVitalsBlock && 'Baseline-Vitalwerte für heute. '}
|
||||
<Link to="/vitals" style={{ color: 'var(--accent)', fontSize: 12 }}>
|
||||
Volle Vitalwerte-Seite →
|
||||
</Link>
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 12 }}>
|
||||
{showWeight && (
|
||||
<div style={cellStyle}>
|
||||
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>Gewicht</div>
|
||||
{weightErr && (
|
||||
@@ -152,35 +182,84 @@ export default function PilotQuickCapture({ onSaved }) {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div style={{ ...cellStyle, flex: '2 1 280px' }}>
|
||||
{showVitalsBlock && (
|
||||
<div style={{ ...cellStyle, flex: showWeight ? '2 1 280px' : '1 1 280px' }}>
|
||||
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>
|
||||
Vitalwerte (Baseline)
|
||||
</div>
|
||||
{vErr && <div style={{ fontSize: 11, color: 'var(--danger)', marginBottom: 6 }}>{vErr}</div>}
|
||||
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(88px, 1fr))', gap: 8 }}>
|
||||
<input
|
||||
type="number"
|
||||
className="form-input"
|
||||
placeholder="Ruhepuls"
|
||||
value={vForm.resting_hr}
|
||||
onChange={(e) => setVForm((f) => ({ ...f, resting_hr: e.target.value }))}
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
className="form-input"
|
||||
placeholder="HRV"
|
||||
value={vForm.hrv}
|
||||
onChange={(e) => setVForm((f) => ({ ...f, hrv: e.target.value }))}
|
||||
/>
|
||||
<input
|
||||
type="number"
|
||||
className="form-input"
|
||||
step={0.1}
|
||||
placeholder="VO₂max"
|
||||
value={vForm.vo2_max}
|
||||
onChange={(e) => setVForm((f) => ({ ...f, vo2_max: e.target.value }))}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'repeat(auto-fit, minmax(120px, 1fr))',
|
||||
gap: '12px 10px',
|
||||
}}
|
||||
>
|
||||
{showRestingHr && (
|
||||
<div>
|
||||
<label
|
||||
htmlFor="pqc-resting-hr"
|
||||
className="form-label"
|
||||
style={{ display: 'block', marginBottom: 4, fontSize: 11, fontWeight: 600, color: 'var(--text2)' }}
|
||||
>
|
||||
Ruhepuls
|
||||
<span style={{ fontWeight: 400, color: 'var(--text3)' }}> (bpm)</span>
|
||||
</label>
|
||||
<input
|
||||
id="pqc-resting-hr"
|
||||
type="number"
|
||||
className="form-input"
|
||||
style={{ width: '100%' }}
|
||||
inputMode="numeric"
|
||||
value={vForm.resting_hr}
|
||||
onChange={(e) => setVForm((f) => ({ ...f, resting_hr: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{showHrv && (
|
||||
<div>
|
||||
<label
|
||||
htmlFor="pqc-hrv"
|
||||
className="form-label"
|
||||
style={{ display: 'block', marginBottom: 4, fontSize: 11, fontWeight: 600, color: 'var(--text2)' }}
|
||||
>
|
||||
HRV
|
||||
<span style={{ fontWeight: 400, color: 'var(--text3)' }}> (ms)</span>
|
||||
</label>
|
||||
<input
|
||||
id="pqc-hrv"
|
||||
type="number"
|
||||
className="form-input"
|
||||
style={{ width: '100%' }}
|
||||
inputMode="numeric"
|
||||
value={vForm.hrv}
|
||||
onChange={(e) => setVForm((f) => ({ ...f, hrv: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{showVo2 && (
|
||||
<div>
|
||||
<label
|
||||
htmlFor="pqc-vo2"
|
||||
className="form-label"
|
||||
style={{ display: 'block', marginBottom: 4, fontSize: 11, fontWeight: 600, color: 'var(--text2)' }}
|
||||
>
|
||||
VO₂max
|
||||
</label>
|
||||
<input
|
||||
id="pqc-vo2"
|
||||
type="number"
|
||||
className="form-input"
|
||||
style={{ width: '100%' }}
|
||||
step={0.1}
|
||||
inputMode="decimal"
|
||||
value={vForm.vo2_max}
|
||||
onChange={(e) => setVForm((f) => ({ ...f, vo2_max: e.target.value }))}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
@@ -192,6 +271,7 @@ export default function PilotQuickCapture({ onSaved }) {
|
||||
{vOk ? '✓ Gespeichert' : vSaving ? '…' : 'Vitalwerte speichern'}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user