feat: enhance body_history_viz widget configuration and validation
- Added new configuration options for the `body_history_viz` widget, including visibility settings for various charts and KPIs. - Implemented default values for the widget's configuration to streamline user experience. - Enhanced validation logic to ensure proper handling of configuration inputs, including error handling for unknown keys and visibility requirements. - Updated tests to cover new configuration scenarios and validation rules for the `body_history_viz` widget. - Bumped application version to reflect these changes.
This commit is contained in:
1 parent
01c0d1745f
commit
20f195aca1
11 files changed
+400
-50
No files matched your search
@@ -0,0 +1,91 @@
|
||||
import { BODY_HISTORY_VIZ_WIDGET_DEFAULTS, normalizeBodyHistoryVizConfig } from './bodyHistoryVizConfig'
|
||||
|
||||
const CHART_TOGGLES = [
|
||||
{ key: 'show_weight_chart', label: 'Gewichts-Chart' },
|
||||
{ key: 'show_body_fat_chart', label: 'Körperfett (Caliper)' },
|
||||
{ key: 'show_proportion_chart', label: 'Silhouette & Proportion' },
|
||||
{ key: 'show_circumference_index_chart', label: 'Umfänge — Index' },
|
||||
{ key: 'show_circumference_lines_chart', label: 'Umfänge — Linien (Fallback)' },
|
||||
]
|
||||
|
||||
const OTHER_TOGGLES = [
|
||||
{ key: 'show_goals_strip', label: 'Körper-Ziele (Strip)' },
|
||||
{ key: 'show_intro_blurb', label: 'Hinweistext unter Zielen' },
|
||||
{ key: 'show_layer_meta', label: 'Layer-2a-Hinweis (Meta)' },
|
||||
{ key: 'show_kpis', label: 'KPI-Kacheln' },
|
||||
]
|
||||
|
||||
/**
|
||||
* @param {{ config: Record<string, unknown>, onChange: (next: Record<string, unknown>) => void }} props
|
||||
*/
|
||||
export default function BodyHistoryVizConfigEditor({ config, onChange }) {
|
||||
const merged = normalizeBodyHistoryVizConfig(config)
|
||||
|
||||
const patch = (partial) => {
|
||||
const next = { ...merged, ...partial }
|
||||
const def = BODY_HISTORY_VIZ_WIDGET_DEFAULTS
|
||||
const stored = {}
|
||||
for (const k of Object.keys(def)) {
|
||||
if (next[k] !== def[k]) stored[k] = next[k]
|
||||
}
|
||||
onChange(stored)
|
||||
}
|
||||
|
||||
const setBool = (key, checked) => {
|
||||
patch({ [key]: checked })
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={{ marginTop: 10, marginLeft: 28 }}>
|
||||
<div style={{ fontSize: 12, color: 'var(--text2)', marginBottom: 8, lineHeight: 1.5 }}>
|
||||
<strong>Körper (Verlauf-Bundle):</strong> welche Blöcke auf der Übersicht erscheinen. Unbelegte Felder = schlanker
|
||||
Standard (nur KPI kompakt + Gewicht).
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--text2)', marginBottom: 6 }}>KPI-Umfang</div>
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 13, marginBottom: 10, cursor: 'pointer' }}>
|
||||
<input
|
||||
type="radio"
|
||||
name="body_hist_kpi_detail"
|
||||
checked={merged.kpi_detail === 'compact'}
|
||||
onChange={() => patch({ kpi_detail: 'compact' })}
|
||||
/>
|
||||
<span>Kompakt (Gewicht, KF%, Magermasse)</span>
|
||||
</label>
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 13, marginBottom: 12, cursor: 'pointer' }}>
|
||||
<input
|
||||
type="radio"
|
||||
name="body_hist_kpi_detail"
|
||||
checked={merged.kpi_detail === 'full'}
|
||||
onChange={() => patch({ kpi_detail: 'full' })}
|
||||
/>
|
||||
<span>Voll (wie Verlauf — alle Kacheln)</span>
|
||||
</label>
|
||||
<div style={{ fontSize: 12, color: 'var(--text2)', marginBottom: 6 }}>Bereiche</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
{OTHER_TOGGLES.map(({ key, label }) => (
|
||||
<label key={key} style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 13, cursor: 'pointer' }}>
|
||||
<input type="checkbox" checked={merged[key]} onChange={(e) => setBool(key, e.target.checked)} />
|
||||
<span>{label}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--text2)', margin: '12px 0 6px' }}>Charts</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||
{CHART_TOGGLES.map(({ key, label }) => (
|
||||
<label key={key} style={{ display: 'flex', alignItems: 'center', gap: 8, fontSize: 13, cursor: 'pointer' }}>
|
||||
<input type="checkbox" checked={merged[key]} onChange={(e) => setBool(key, e.target.checked)} />
|
||||
<span>{label}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-secondary"
|
||||
style={{ marginTop: 10, fontSize: 12, padding: '6px 12px' }}
|
||||
onClick={() => onChange({})}
|
||||
>
|
||||
Auf schlanken Standard zurück
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Sichtbarkeit / Umfang für body_history_viz (sync mit backend dashboard_widget_config).
|
||||
* `null` / fehlend → Verlauf: alles sichtbar (vollständige Parität zur History-Seite).
|
||||
*/
|
||||
|
||||
/** Verlauf-Tab Körper: volle Parität (kein Layout-Config). */
|
||||
export const BODY_HISTORY_VIZ_HISTORY_FULL = {
|
||||
chart_days: 90,
|
||||
show_goals_strip: true,
|
||||
show_intro_blurb: true,
|
||||
show_layer_meta: true,
|
||||
show_kpis: true,
|
||||
kpi_detail: 'full',
|
||||
show_weight_chart: true,
|
||||
show_body_fat_chart: true,
|
||||
show_proportion_chart: true,
|
||||
show_circumference_index_chart: true,
|
||||
show_circumference_lines_chart: true,
|
||||
}
|
||||
|
||||
/** Default für Dashboard-Widget (schlank). */
|
||||
export const BODY_HISTORY_VIZ_WIDGET_DEFAULTS = {
|
||||
chart_days: 30,
|
||||
show_goals_strip: false,
|
||||
show_intro_blurb: false,
|
||||
show_layer_meta: false,
|
||||
show_kpis: true,
|
||||
kpi_detail: 'compact',
|
||||
show_weight_chart: true,
|
||||
show_body_fat_chart: false,
|
||||
show_proportion_chart: false,
|
||||
show_circumference_index_chart: false,
|
||||
show_circumference_lines_chart: false,
|
||||
}
|
||||
|
||||
const BOOL_KEYS = [
|
||||
'show_goals_strip',
|
||||
'show_intro_blurb',
|
||||
'show_layer_meta',
|
||||
'show_kpis',
|
||||
'show_weight_chart',
|
||||
'show_body_fat_chart',
|
||||
'show_proportion_chart',
|
||||
'show_circumference_index_chart',
|
||||
'show_circumference_lines_chart',
|
||||
]
|
||||
|
||||
/**
|
||||
* @param {Record<string, unknown>|null|undefined} raw — aus Layout-Config (Backend liefert nach Save ggf. alle Keys)
|
||||
* @returns {typeof BODY_HISTORY_VIZ_WIDGET_DEFAULTS}
|
||||
*/
|
||||
export function normalizeBodyHistoryVizConfig(raw) {
|
||||
const base = { ...BODY_HISTORY_VIZ_WIDGET_DEFAULTS }
|
||||
if (!raw || typeof raw !== 'object') return base
|
||||
for (const k of BOOL_KEYS) {
|
||||
if (Object.prototype.hasOwnProperty.call(raw, k)) {
|
||||
base[k] = raw[k] === true
|
||||
}
|
||||
}
|
||||
if (raw.kpi_detail === 'full' || raw.kpi_detail === 'compact') {
|
||||
base.kpi_detail = raw.kpi_detail
|
||||
}
|
||||
if (raw.chart_days != null) {
|
||||
const n = Number(raw.chart_days)
|
||||
if (Number.isFinite(n)) {
|
||||
base.chart_days = Math.min(90, Math.max(7, Math.round(n)))
|
||||
}
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
const COMPACT_KPI_KEYS = new Set(['weight', 'bf', 'lean_ffmi'])
|
||||
|
||||
/**
|
||||
* @param {Array<{ key: string }>} tiles
|
||||
* @param {'compact'|'full'} detail
|
||||
*/
|
||||
export function filterBodyHistoryKpiTiles(tiles, detail) {
|
||||
if (detail === 'full' || !Array.isArray(tiles)) return tiles
|
||||
return tiles.filter((t) => COMPACT_KPI_KEYS.has(t.key))
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import TrendKcalWeightWidget from '../components/dashboard-widgets/TrendKcalWeig
|
||||
import NutritionActivitySummaryWidget from '../components/dashboard-widgets/NutritionActivitySummaryWidget'
|
||||
import NutritionDetailChartsWidget from '../components/dashboard-widgets/NutritionDetailChartsWidget'
|
||||
import BodyHistoryVizWidget from '../components/dashboard-widgets/BodyHistoryVizWidget'
|
||||
import { normalizeBodyHistoryVizConfig } from './bodyHistoryVizConfig'
|
||||
import RecoveryChartsPanelWidget from '../components/dashboard-widgets/RecoveryChartsPanelWidget'
|
||||
import ProgressPhotosWidget from '../components/dashboard-widgets/ProgressPhotosWidget'
|
||||
import RecoverySleepRestWidget from '../components/dashboard-widgets/RecoverySleepRestWidget'
|
||||
@@ -63,7 +64,7 @@ export function ensurePilotLabWidgetsRegistered() {
|
||||
Component: BodyHistoryVizWidget,
|
||||
mapProps: (ctx) => ({
|
||||
refreshTick: ctx.refreshTick,
|
||||
chartDays: ctx.layoutEntry?.config?.chart_days,
|
||||
bodyHistoryVizConfig: normalizeBodyHistoryVizConfig(ctx.layoutEntry?.config),
|
||||
}),
|
||||
})
|
||||
registerDashboardWidget({
|
||||
|
||||
Reference in new issue
Block a user