mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
fix(dashboard): paint the blood-glucose tile for untagged readings
Tile eligibility filtered the four named contexts against the per-context summaries and asked whether any of them held readings. An account whose source records no meal time matched none of them, so the tile was omitted with the module on, the layout toggle on, and a reading from today. Nothing warned; the strip was simply short one card. Move the gate out of the page into `resolveGlucoseTiles`, which walks the shared bucket list — untagged included — and hand the caller the label key with the summary. Both summary producers group through the shared resolver, so `UNSPECIFIED` reaches the wire with its own count, latest value and trend, and a tagged account still gets its per-context breakdown. Refs #943
This commit is contained in:
1 parent
9a2b1f0955
commit
5ab7a2ca81
8 files changed
+162
-51
No files matched your search
@@ -34,6 +34,7 @@ import {
|
||||
GLUCOSE_PANEL_WINDOW_DAYS,
|
||||
type GlucoseClinicalMetrics,
|
||||
} from "@/lib/analytics/glucose-metrics";
|
||||
import { groupByGlucoseContext } from "@/lib/glucose";
|
||||
import {
|
||||
decisionForEvidence,
|
||||
PATTERN_FAMILIES,
|
||||
@@ -495,16 +496,16 @@ async function buildAnalyticsResponse(user: AuthedUser, locale: Locale) {
|
||||
orderBy: { measuredAt: "asc" },
|
||||
select: { value: true, measuredAt: true, glucoseContext: true },
|
||||
});
|
||||
// #943 — grouped through the shared bucket resolver, so readings with no
|
||||
// meal-time tag land in `UNSPECIFIED` instead of being dropped on the floor.
|
||||
const glucoseByContext: Record<string, ReturnType<typeof summarize>> = {};
|
||||
if (glucoseRows.length > 0) {
|
||||
const contexts = ["FASTING", "POSTPRANDIAL", "RANDOM", "BEDTIME"] as const;
|
||||
for (const ctx of contexts) {
|
||||
const ctxRows = glucoseRows.filter((r) => r.glucoseContext === ctx);
|
||||
if (ctxRows.length === 0) continue;
|
||||
glucoseByContext[ctx] = summarize(
|
||||
ctxRows.map((r): DataPoint => ({ date: r.measuredAt, value: r.value })),
|
||||
);
|
||||
}
|
||||
for (const [bucket, ctxRows] of groupByGlucoseContext(
|
||||
glucoseRows,
|
||||
(r) => r.glucoseContext,
|
||||
)) {
|
||||
glucoseByContext[bucket] = summarize(
|
||||
ctxRows.map((r): DataPoint => ({ date: r.measuredAt, value: r.value })),
|
||||
);
|
||||
}
|
||||
|
||||
// v1.17.0 — server-authoritative glucose clinical panel. The TIR / GMI /
|
||||
|
||||
+11
-22
@@ -174,6 +174,7 @@ import {
|
||||
resolveConfiguredTileCount,
|
||||
resolveChartRowPlaceholderCount,
|
||||
pickHrvSummary,
|
||||
resolveGlucoseTiles,
|
||||
} from "@/components/dashboard/dashboard-gates";
|
||||
|
||||
/**
|
||||
@@ -725,23 +726,12 @@ export default function DashboardPageClient({
|
||||
const glucoseWidgetVisible = isTileVisible("glucose");
|
||||
const displayGlucoseUnit = resolveGlucoseUnit(user?.glucoseUnit ?? null);
|
||||
const glucoseByContext = data?.glucoseByContext ?? {};
|
||||
const glucoseContexts = [
|
||||
"FASTING",
|
||||
"POSTPRANDIAL",
|
||||
"RANDOM",
|
||||
"BEDTIME",
|
||||
] as const;
|
||||
const glucoseSummariesPresent = glucoseContexts.filter(
|
||||
(ctx) => (glucoseByContext[ctx]?.count ?? 0) > 0,
|
||||
);
|
||||
const showGlucoseCards =
|
||||
glucoseWidgetVisible && glucoseSummariesPresent.length > 0;
|
||||
const glucoseLabelKey: Record<string, string> = {
|
||||
FASTING: "targets.glucoseFasting",
|
||||
POSTPRANDIAL: "targets.glucosePostprandial",
|
||||
RANDOM: "targets.glucoseRandom",
|
||||
BEDTIME: "targets.glucoseBedtime",
|
||||
};
|
||||
// #943 — eligibility comes from `resolveGlucoseTiles`, which walks the
|
||||
// untagged bucket alongside the four named contexts. The gate used to be
|
||||
// an inline filter over the named contexts only, so an account whose
|
||||
// source never writes a meal-time tag saw nothing.
|
||||
const glucoseTiles = resolveGlucoseTiles(glucoseByContext);
|
||||
const showGlucoseCards = glucoseWidgetVisible && glucoseTiles.length > 0;
|
||||
// v1.18.6 — band / target math is computed SERVER-side in the snapshot
|
||||
// DTO (`targetBands`) so the client stops recomputing it from the
|
||||
// profile (audit finding #3). When snapshot mode is on, read the
|
||||
@@ -1634,16 +1624,15 @@ export default function DashboardPageClient({
|
||||
}
|
||||
if (showGlucoseCards) {
|
||||
const glucoseOrder = widgetOrder("glucose");
|
||||
glucoseSummariesPresent.forEach((ctx, idx) => {
|
||||
const s = glucoseByContext[ctx];
|
||||
glucoseTiles.forEach(({ bucket, labelKey, summary: s }, idx) => {
|
||||
trendCards.push({
|
||||
id: `glucose-${ctx}`,
|
||||
id: `glucose-${bucket}`,
|
||||
// sub-order so all glucose cards stay in a block and order stable
|
||||
order: glucoseOrder + idx / 1000,
|
||||
node: (
|
||||
<TrendCard
|
||||
key={`glucose-${ctx}`}
|
||||
label={t(glucoseLabelKey[ctx])}
|
||||
key={`glucose-${bucket}`}
|
||||
label={t(labelKey)}
|
||||
latest={
|
||||
s.latest != null
|
||||
? convertGlucose(s.latest, displayGlucoseUnit)
|
||||
|
||||
Reference in new issue
Block a user