feat: Extend widget configuration for activity overview and improve validation
- Added support for the "activity_overview" widget in the dashboard configuration, allowing for chart_days validation. - Refactored validation logic to streamline error handling for both "body_overview" and "activity_overview" widgets. - Updated the widget catalog description to reflect the new configuration options. - Enhanced the DashboardLabPage to manage chart_days input for both widgets, improving user experience. - Bumped app_dashboard version to 1.3.0 to reflect these enhancements.
This commit is contained in:
1 parent
4493b140bd
commit
b617212145
9 files changed
+164
-60
No files matched your search
@@ -4,11 +4,14 @@ import dayjs from 'dayjs'
|
||||
import { api } from '../../utils/api'
|
||||
import { useProfile } from '../../context/ProfileContext'
|
||||
import TrainingTypeDistribution from '../TrainingTypeDistribution'
|
||||
import {
|
||||
BODY_CHART_DAYS_DEFAULT,
|
||||
normalizeBodyChartDays,
|
||||
} from '../../widgetSystem/bodyChartDays'
|
||||
import PilotRuleCard from './PilotRuleCard'
|
||||
|
||||
const PERIOD = 30
|
||||
|
||||
export default function PilotActivitySection({ refreshTick = 0 }) {
|
||||
export default function PilotActivitySection({ refreshTick = 0, chartDays = BODY_CHART_DAYS_DEFAULT }) {
|
||||
const periodDays = normalizeBodyChartDays(chartDays)
|
||||
const { activeProfile } = useProfile()
|
||||
const globalQualityLevel = activeProfile?.quality_filter_level
|
||||
const [activities, setActivities] = useState([])
|
||||
@@ -18,7 +21,8 @@ export default function PilotActivitySection({ refreshTick = 0 }) {
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
try {
|
||||
const a = await api.listActivity(120)
|
||||
const fetchDays = Math.max(120, periodDays + 60)
|
||||
const a = await api.listActivity(fetchDays)
|
||||
if (!cancelled) setActivities(Array.isArray(a) ? a : [])
|
||||
} catch {
|
||||
if (!cancelled) setActivities([])
|
||||
@@ -29,15 +33,15 @@ export default function PilotActivitySection({ refreshTick = 0 }) {
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [refreshTick, globalQualityLevel])
|
||||
}, [refreshTick, globalQualityLevel, periodDays])
|
||||
|
||||
const cutoff = dayjs().subtract(PERIOD, 'day').format('YYYY-MM-DD')
|
||||
const cutoff = dayjs().subtract(periodDays, 'day').format('YYYY-MM-DD')
|
||||
const filtA = (activities || []).filter((d) => d.date >= cutoff)
|
||||
|
||||
const daysWithAct = new Set(filtA.map((a) => a.date)).size
|
||||
const totalDays =
|
||||
filtA.length > 0
|
||||
? Math.min(PERIOD, dayjs().diff(dayjs(filtA[filtA.length - 1]?.date), 'day') + 1)
|
||||
? Math.min(periodDays, dayjs().diff(dayjs(filtA[filtA.length - 1]?.date), 'day') + 1)
|
||||
: 0
|
||||
const consistency = totalDays > 0 ? Math.round((daysWithAct / totalDays) * 100) : 0
|
||||
|
||||
@@ -46,7 +50,7 @@ export default function PilotActivitySection({ refreshTick = 0 }) {
|
||||
status: consistency >= 70 ? 'good' : consistency >= 40 ? 'warn' : 'bad',
|
||||
icon: '📅',
|
||||
category: 'Konsistenz',
|
||||
title: `${consistency}% aktive Tage (${daysWithAct}/${Math.min(PERIOD, totalDays || PERIOD)} Tage)`,
|
||||
title: `${consistency}% aktive Tage (${daysWithAct}/${Math.min(periodDays, totalDays || periodDays)} Tage)`,
|
||||
detail:
|
||||
consistency >= 70
|
||||
? 'Ausgezeichnete Regelmäßigkeit.'
|
||||
@@ -77,7 +81,7 @@ export default function PilotActivitySection({ refreshTick = 0 }) {
|
||||
>
|
||||
<h2 style={{ fontSize: 17, fontWeight: 700, margin: 0, color: 'var(--text1)' }}>Bereich Aktivität</h2>
|
||||
<p style={{ fontSize: 12, color: 'var(--text2)', margin: '6px 0 0', lineHeight: 1.5 }}>
|
||||
Trainingstyp-Verteilung {PERIOD} Tage · Bewertung Konsistenz wie im Verlauf
|
||||
Trainingstyp-Verteilung {periodDays} Tage · Bewertung Konsistenz wie im Verlauf
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -102,7 +106,7 @@ export default function PilotActivitySection({ refreshTick = 0 }) {
|
||||
|
||||
<div className="card section-gap">
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 8 }}>Trainingstyp-Verteilung</div>
|
||||
<TrainingTypeDistribution days={PERIOD} />
|
||||
<TrainingTypeDistribution days={periodDays} />
|
||||
<div style={{ marginTop: 8, textAlign: 'right' }}>
|
||||
<Link to="/history" state={{ tab: 'activity' }} style={{ fontSize: 12, color: 'var(--accent)' }}>
|
||||
Vollständiger Verlauf Aktivität →
|
||||
|
||||
Reference in new issue
Block a user