feat: Refactor activity session metrics handling and enhance activity listing
- Updated the `replace_activity_session_metrics` function to improve validation logic and error handling for required fields. - Enhanced the activity listing query to order results by date, start time, and ID, ensuring consistent output. - Modified the frontend to handle null values in metrics payload and improved the display of activity statistics, including total entries in profile and sample size.
This commit is contained in:
1 parent
1f51c32521
commit
9fdb02ff8b
3 files changed
+58
-16
No files matched your search
@@ -66,6 +66,7 @@ function buildMetricsPayload(schema, draft) {
|
||||
if (s.data_type === 'boolean') {
|
||||
if (raw === '' || raw === null || raw === undefined) {
|
||||
if (s.required) throw new Error(`Pflichtfeld: ${s.name_de}`)
|
||||
out.push({ parameter_key: s.key, value: null })
|
||||
continue
|
||||
}
|
||||
out.push({ parameter_key: s.key, value: !!raw })
|
||||
@@ -73,6 +74,7 @@ function buildMetricsPayload(schema, draft) {
|
||||
}
|
||||
if (raw === '' || raw === null || raw === undefined) {
|
||||
if (s.required) throw new Error(`Pflichtfeld: ${s.name_de}`)
|
||||
out.push({ parameter_key: s.key, value: null })
|
||||
continue
|
||||
}
|
||||
let v = raw
|
||||
@@ -335,7 +337,14 @@ export default function ActivityPage() {
|
||||
setListHasMore(false)
|
||||
return
|
||||
}
|
||||
setEntries((prev) => [...prev, ...more])
|
||||
const prev = entriesRef.current
|
||||
const seen = new Set(prev.map((r) => r.id))
|
||||
const add = more.filter((r) => r.id && !seen.has(r.id))
|
||||
if (add.length === 0) {
|
||||
setListHasMore(false)
|
||||
return
|
||||
}
|
||||
setEntries((p) => [...p, ...add])
|
||||
setListHasMore(more.length === n)
|
||||
} finally {
|
||||
setListLoadingMore(false)
|
||||
@@ -433,7 +442,10 @@ export default function ActivityPage() {
|
||||
if (!col || !ACTIVITY_LOG_PAYLOAD_KEYS.has(col)) continue
|
||||
if (!(s.key in metricDraft)) continue
|
||||
const raw = metricDraft[s.key]
|
||||
if (raw === '' || raw === null || raw === undefined) continue
|
||||
if (raw === '' || raw === null || raw === undefined) {
|
||||
payload[col] = null
|
||||
continue
|
||||
}
|
||||
let v = raw
|
||||
if (s.data_type === 'integer') {
|
||||
v = parseInt(String(raw), 10)
|
||||
@@ -506,12 +518,19 @@ export default function ActivityPage() {
|
||||
</div>
|
||||
|
||||
{/* Übersicht */}
|
||||
{stats && stats.count>0 && (
|
||||
{stats && (stats.total_in_profile > 0 || stats.count > 0) && (
|
||||
<div className="card section-gap">
|
||||
<div style={{ fontSize: 11, color: 'var(--text3)', marginBottom: 8, lineHeight: 1.45 }}>
|
||||
<strong>{stats.total_in_profile ?? '–'}</strong> Einträge im Profil (gleicher Filter wie diese Seite). Die Summen
|
||||
Kcal/Stunden beziehen sich auf die <strong>neuesten {stats.sample_size ?? stats.count}</strong> Einträge (max.
|
||||
30).
|
||||
</div>
|
||||
<div style={{display:'flex',gap:8,flexWrap:'wrap'}}>
|
||||
{[['Trainings',stats.count,'var(--text1)'],
|
||||
['Kcal gesamt',Math.round(stats.total_kcal),'#EF9F27'],
|
||||
['Stunden',Math.round(stats.total_min/60*10)/10,'#378ADD']].map(([l,v,c])=>(
|
||||
{[
|
||||
['Neueste (max. 30)', stats.count, 'var(--text1)'],
|
||||
['Kcal (darin)', Math.round(stats.total_kcal), '#EF9F27'],
|
||||
['Stunden (darin)', Math.round(stats.total_min / 60 * 10) / 10, '#378ADD'],
|
||||
].map(([l, v, c]) => (
|
||||
<div key={l} style={{flex:1,minWidth:80,background:'var(--surface2)',borderRadius:8,padding:'8px 10px',textAlign:'center'}}>
|
||||
<div style={{fontSize:18,fontWeight:700,color:c}}>{v}</div>
|
||||
<div style={{fontSize:10,color:'var(--text3)'}}>{l}</div>
|
||||
|
||||
Reference in new issue
Block a user