fix(insights): leave mood out of the trends row when its module is off

The tab strip already hides the Mood pill when the mood module is off, but
the trends row still charted mood, both from a briefing finding and in its
blood pressure / weight / mood fallback. selectTrendCharts now takes the
metrics to leave out, and the overview passes mood when the module is off.

Refs #975
This commit is contained in:
Marc-André Bombeck committed 2026-09-16 12:56:09 +02:00
1 parent c7f7a2925f
commit 2b512501db
4 files changed
+46 -3

No files matched your search

@@ -157,3 +157,24 @@ describe("selectTrendCharts", () => {
expect(TREND_CHART_CONFIG.steps?.detailHref).toBe("/insights/steps");
});
});
describe("selectTrendCharts — hidden metrics", () => {
it("drops mood from the fallback triple when the mood module is off", () => {
const charts = selectTrendCharts(null, { hiddenMetrics: ["mood"] });
expect(charts.map((c) => c.metric)).not.toContain("mood");
expect(charts).toHaveLength(2);
});
it("skips a hidden metric the briefing flags", () => {
const charts = selectTrendCharts(briefing(["mood", "weight"]), {
hiddenMetrics: ["mood"],
});
expect(charts.map((c) => c.metric)).not.toContain("mood");
expect(charts).toHaveLength(1);
});
it("keeps mood when nothing is hidden", () => {
const charts = selectTrendCharts(null, { hiddenMetrics: [] });
expect(charts.map((c) => c.metric)).toContain("mood");
});
});
+11 -2
View File
@@ -267,16 +267,24 @@ export const DEFAULT_TREND_CHART_CAP = 3;
export interface SelectTrendChartsOptions {
/** Max number of charts to return. Defaults to {@link DEFAULT_TREND_CHART_CAP}. */
cap?: number;
/**
* Metrics whose module is switched off. They are skipped on both the
* briefing path and the fallback triple, so a disabled module never
* charts on the overview.
*/
hiddenMetrics?: ReadonlyArray<DailyBriefingKeyFinding["sourceMetric"]>;
}
function configsFor(
metrics: ReadonlyArray<DailyBriefingKeyFinding["sourceMetric"]>,
cap: number,
hidden: ReadonlySet<string>,
): TrendChartConfig[] {
const seen = new Set<string>();
const out: TrendChartConfig[] = [];
for (const metric of metrics) {
if (out.length >= cap) break;
if (hidden.has(metric)) continue; // module switched off
const config = TREND_CHART_CONFIG[metric];
if (!config) continue; // metric has no standalone trend chart
if (seen.has(config.metric)) continue; // dedupe
@@ -301,14 +309,15 @@ export function selectTrendCharts(
options: SelectTrendChartsOptions = {},
): TrendChartConfig[] {
const cap = Math.max(1, options.cap ?? DEFAULT_TREND_CHART_CAP);
const hidden = new Set<string>(options.hiddenMetrics ?? []);
const findingMetrics =
briefing?.keyFindings?.map((f) => f.sourceMetric) ?? [];
const fromBriefing = configsFor(findingMetrics, cap);
const fromBriefing = configsFor(findingMetrics, cap, hidden);
if (fromBriefing.length > 0) {
return fromBriefing;
}
return configsFor(DEFAULT_TREND_METRICS, cap);
return configsFor(DEFAULT_TREND_METRICS, cap, hidden);
}