feat: Enhance Dashboard widget configuration and layout management
- Added validation for widget configuration in the DashboardWidgetEntry model to ensure proper data structure. - Updated the DashboardLayoutPayload to include widget configuration in the serialized output. - Improved the PilotBodySection and DashboardLabPage components to support dynamic chart days configuration for the body overview widget. - Refactored layout editor functions to normalize widget configurations for better handling. - Bumped app_dashboard version to 1.2.0 to reflect the new features and improvements.
This commit is contained in:
1 parent
f6c5f96768
commit
87c4cbc4b4
11 files changed
+298
-62
No files matched your search
@@ -16,11 +16,14 @@ import { api } from '../../utils/api'
|
||||
import { useProfile } from '../../context/ProfileContext'
|
||||
import { getInterpretation } from '../../utils/interpret'
|
||||
import { rollingAvg, fmtDate } from '../../pilot/pilotChartUtils'
|
||||
import {
|
||||
BODY_CHART_DAYS_DEFAULT,
|
||||
normalizeBodyChartDays,
|
||||
} from '../../widgetSystem/bodyChartDays'
|
||||
import PilotRuleCard from './PilotRuleCard'
|
||||
|
||||
const WINDOW_DAYS = 30
|
||||
|
||||
export default function PilotBodySection({ refreshTick = 0 }) {
|
||||
export default function PilotBodySection({ refreshTick = 0, chartDays = BODY_CHART_DAYS_DEFAULT }) {
|
||||
const windowDays = normalizeBodyChartDays(chartDays)
|
||||
const { activeProfile } = useProfile()
|
||||
const [weights, setWeights] = useState([])
|
||||
const [calipers, setCalipers] = useState([])
|
||||
@@ -31,10 +34,11 @@ export default function PilotBodySection({ refreshTick = 0 }) {
|
||||
let cancelled = false
|
||||
;(async () => {
|
||||
try {
|
||||
const fetchDays = Math.max(120, windowDays + 60)
|
||||
const [w, ca, ci] = await Promise.all([
|
||||
api.listWeight(120),
|
||||
api.listCaliper(30),
|
||||
api.listCirc(30),
|
||||
api.listWeight(fetchDays),
|
||||
api.listCaliper(Math.max(30, windowDays)),
|
||||
api.listCirc(Math.max(30, windowDays)),
|
||||
])
|
||||
if (!cancelled) {
|
||||
setWeights(Array.isArray(w) ? w : [])
|
||||
@@ -54,11 +58,9 @@ export default function PilotBodySection({ refreshTick = 0 }) {
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
}, [refreshTick])
|
||||
}, [refreshTick, windowDays])
|
||||
|
||||
const sex = activeProfile?.sex || 'm'
|
||||
const height = activeProfile?.height || 178
|
||||
const cutoff = dayjs().subtract(WINDOW_DAYS, 'day').format('YYYY-MM-DD')
|
||||
const cutoff = dayjs().subtract(windowDays, 'day').format('YYYY-MM-DD')
|
||||
|
||||
const filtW = [...(weights || [])]
|
||||
.sort((a, b) => a.date.localeCompare(b.date))
|
||||
@@ -111,7 +113,7 @@ export default function PilotBodySection({ refreshTick = 0 }) {
|
||||
>
|
||||
<h2 style={{ fontSize: 17, fontWeight: 700, margin: 0, color: 'var(--text1)' }}>Bereich Körper</h2>
|
||||
<p style={{ fontSize: 12, color: 'var(--text2)', margin: '6px 0 0', lineHeight: 1.5 }}>
|
||||
Fokus letzte {WINDOW_DAYS} Tage · Gewicht mit Ø 7 / Ø 14 Tage wie im Verlauf
|
||||
Fokus letzte {windowDays} Tage · Gewicht mit Ø 7 / Ø 14 Tage wie im Verlauf
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -128,7 +130,7 @@ export default function PilotBodySection({ refreshTick = 0 }) {
|
||||
<div className="card section-gap">
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 8 }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)' }}>
|
||||
Gewicht · {filtW.length} Messungen ({WINDOW_DAYS}T)
|
||||
Gewicht · {filtW.length} Messungen ({windowDays}T)
|
||||
</div>
|
||||
<Link to="/history" state={{ tab: 'body' }} className="btn btn-secondary" style={{ fontSize: 10, padding: '2px 8px', textDecoration: 'none' }}>
|
||||
Verlauf Körper <ChevronRight size={10} />
|
||||
|
||||
Reference in new issue
Block a user