mitai-jinkendo/frontend/src/widgetSystem/nutritionHistoryVizConfig.js
Lars db5557e4aa
Some checks failed
Deploy Development / deploy (push) Successful in 50s
Build Test / pytest-backend (push) Failing after 5s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 18s
feat: add nutrition_history_viz widget and enhance configuration handling
- Introduced the `nutrition_history_viz` widget to the dashboard, allowing users to visualize nutrition history data.
- Updated widget configuration to include `nutrition_history_viz` in the allowed widgets and added validation for its configuration.
- Enhanced the widget catalog with details for the new `nutrition_history_viz` entry.
- Implemented default values and validation logic for the widget's configuration, ensuring proper handling of user inputs.
- Added tests to ensure proper validation of the `nutrition_history_viz` widget configuration.
- Bumped application version to reflect the addition of the new widget.
2026-04-22 10:03:23 +02:00

80 lines
2.1 KiB
JavaScript

/**
* Sichtbarkeit für nutrition_history_viz (sync mit backend dashboard_widget_config).
* `visibility === undefined` → Verlauf-Tab: alles an.
*/
export const NUTRITION_HISTORY_VIZ_HISTORY_FULL = {
chart_days: 30,
show_goals_strip: true,
show_intro_blurb: true,
show_kpis: true,
kpi_detail: 'full',
show_kcal_vs_weight: true,
show_calorie_balance_chart: true,
show_protein_lean_chart: true,
show_heuristics: true,
show_macro_daily_bars: true,
show_macro_distribution_pair: true,
show_energy_protein_charts: true,
}
export const NUTRITION_HISTORY_VIZ_WIDGET_DEFAULTS = {
chart_days: 30,
show_goals_strip: false,
show_intro_blurb: false,
show_kpis: true,
kpi_detail: 'compact',
show_kcal_vs_weight: true,
show_calorie_balance_chart: false,
show_protein_lean_chart: false,
show_heuristics: false,
show_macro_daily_bars: true,
show_macro_distribution_pair: true,
show_energy_protein_charts: false,
}
const BOOL_KEYS = [
'show_goals_strip',
'show_intro_blurb',
'show_kpis',
'show_kcal_vs_weight',
'show_calorie_balance_chart',
'show_protein_lean_chart',
'show_heuristics',
'show_macro_daily_bars',
'show_macro_distribution_pair',
'show_energy_protein_charts',
]
/**
* @param {Record<string, unknown>|null|undefined} raw
*/
export function normalizeNutritionHistoryVizConfig(raw) {
const base = { ...NUTRITION_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
}
/**
* @param {Array<object>} kpiTiles
* @param {'compact'|'full'} detail
*/
export function filterNutritionHistoryKpiTiles(kpiTiles, detail) {
if (detail === 'full' || !Array.isArray(kpiTiles)) return kpiTiles
return kpiTiles.slice(0, 4)
}