mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
Eleven touch-disjoint waves landed on develop plus a six-axis QA reconcile round before tagging. See CHANGELOG.md for the user-facing prose; this commit message documents the wave + report inventory for release-management traceability. Waves shipped (each with a phase report under .planning/): - phase-W-POOL-v1440-report.md — p-limit(4) wrapper around the analytics 15-way fan-out + pg.Pool max raised 10 -> 20. Closes the v1.4.39 empirical-trace finding #1 (Prisma pool starvation). - phase-W-DELETED-v1440-report.md — 11 reader-tier helpers + 3 integration contracts close audit Critical Finding #3 (soft-delete invisibility) across dashboard, analytics, summaries, rollup tiers, and the Coach snapshot path. - phase-W-INSIGHTS-v1440-report.md — mood-rollup swap on the three /api/insights/{features,targets,cards} routes plus the compliance-rollup hook gap closure for bulk-projection mints; the post-QA reconcile patch closes the six remaining measurement.findMany sites in the cluster that still leaked tombstoned rows. - phase-W-INFRA-v1440-report.md — rollup helper umbrella consolidation under src/lib/rollups/* with zero orphan re-exports; lint, typecheck, knip, and 93/93 rollup tests green post-restructure. - phase-W-RSC-v1440-report.md — per-tile Suspense boundaries plus the queryKey factory-bypass walker test (extended to comparison/ in the reconcile pass). - phase-W-PRIVACY-v1440-report.md — bilingual /privacy page with 17 paired-section tests pinning the 9 SB-3 disclosure requirements. - phase-W-AASA-v1440-report.md — /.well-known/apple-app-site-association endpoint pinned to S8WDX4W5KX.dev.healthlog.app with app-ID parity assertions guarding against split rotation. - phase-W-APNS-NOTIFY-v1440-report.md — MEDICATION_REMINDER time-sensitive APNs payload (priority 10 + interruption-level) scoped via a parameterised test that pins all 6 other event-types do not bypass Focus. AP-2 .p8 install gates real delivery. - phase-W-CONSENT-v1440-report.md — AI consent receipts CRUD with append-only invariant pinned in test; revoke-then-regrant leaves both rows; idempotent DELETE returns 200 + receipt: null. - phase-W-WMY-WIRE-v1440-report.md — three previously-dead WMY readers (week/month/year) wired through summaries-slice and health-score-fast-path with a linear-composability parity test pinning the cross-consumer routing contract. - phase-W-GHOSTS-v1440-report.md — ~1 177 lines of dead code removed across 9 atomic commits; startOfUtcDay + wallClockInTz consolidation eliminates a sibling-drift risk; knip whitelist trimmed to three files pending follow-up. QA reconcile patches applied per the v1.4.40 QA round (six reports under .planning/round-v1440-QA-*-findings.md): - senior C1 — dashboard-suspense-boundaries regex aligned with the post-W-INFRA Thread 2 userTimezone-local lift. - senior H1 — soft-delete filter added to the six remaining insights measurement.findMany sites. - specialist H1 — Promise.allSettled around bulk-projection compliance recompute on both /api/medications/intake and /api/dashboard/summary. - ux H1 — compare-toggle migrated to queryKeys.dashboardWidgets factory; walker test extended to src/components/comparison/. - security M1 — consent artefact 64 KB cap enforced via Buffer.byteLength (UTF-8 bytes, not UTF-16 code units). Quality gates green at tag: pnpm typecheck, pnpm lint, pnpm knip --include files,dependencies,binaries,unlisted, pnpm test --run (4726 passing / 1 skipped). Tests 4525 -> 4726 unit + 1 skipped over the v1.4.39 -> v1.4.40 span. User-facing prose: see CHANGELOG.md.
114 lines
5.1 KiB
TypeScript
114 lines
5.1 KiB
TypeScript
"use client";
|
|
|
|
import { useMemo, type ReactNode } from "react";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
|
|
import { useAuth } from "@/hooks/use-auth";
|
|
import { useFeatureFlags } from "@/hooks/use-feature-flags";
|
|
import { useWorkouts } from "@/hooks/use-workouts";
|
|
import { InsightsTabStrip } from "@/components/insights/insights-tab-strip";
|
|
import { useInsightsAdvisorQuery } from "@/components/insights/use-insights-advisor";
|
|
import { useAnalyticsQuery } from "@/lib/queries/use-analytics-query";
|
|
import { queryKeys } from "@/lib/query-keys";
|
|
import type { InsightInputs } from "@/lib/insights/metric-availability";
|
|
|
|
/**
|
|
* v1.4.25 W4 — client shell for `src/app/insights/layout.tsx`.
|
|
*
|
|
* Owns the advisor query so the regenerate button on the sticky tab
|
|
* strip works from every Insights surface (mother + the seven sub-
|
|
* pages). TanStack Query dedup keeps the cost negligible: the mother
|
|
* page's own `useInsightsAdvisorQuery` consumer shares the same
|
|
* `queryKeys.insightsAdvisor()` key, so the two consumers reuse the
|
|
* same cache entry without extra network traffic.
|
|
*
|
|
* v1.4.27 F19 — also owns the analytics + comprehensive reads that
|
|
* power the tab-strip availability gate. The analytics consumer goes
|
|
* through the shared `useAnalyticsQuery({ slice: "summaries" })` hook
|
|
* (v1.4.33 IW2); the comprehensive consumer still owns its bespoke
|
|
* fetch but shares its cache key with the sub-page consumers so the
|
|
* payload lands once per route, dedup-shared across consumers.
|
|
*
|
|
* CRITICAL — the `<CoachDrawer>` does NOT mount here. It lives only in
|
|
* `src/app/insights/page.tsx` body so navigating into a sub-page
|
|
* unmounts the drawer.
|
|
*/
|
|
interface ComprehensivePayload {
|
|
moodSummary: { count: number } | null;
|
|
medications: Array<{ id: string }>;
|
|
}
|
|
|
|
export function InsightsLayoutShell({ children }: { children: ReactNode }) {
|
|
const { isAuthenticated } = useAuth();
|
|
// v1.4.33 F18 — gate the advisor POST on the operator's assistant
|
|
// feature flag. Pre-fix, every /insights mount fired POST
|
|
// /api/insights/generate even when the operator had disabled the
|
|
// briefing surface or the user had no AI provider configured. The
|
|
// server returned 422 in that case and the regenerate button on the
|
|
// tab strip rendered a non-functional spinner. Reading the flag
|
|
// matrix off `/api/feature-flags` keeps the hot path one fetch
|
|
// (shared `["feature-flags"]` cache, 60s staleTime) and skips the
|
|
// advisor request entirely when the operator has the briefing gate
|
|
// off. The fail-open default in `useFeatureFlags` means a network
|
|
// hiccup still renders the advisor — the gate only takes effect when
|
|
// the operator has explicitly turned the surface off.
|
|
const flags = useFeatureFlags();
|
|
const advisorEnabled =
|
|
isAuthenticated && flags.enabled && flags.briefing;
|
|
const advisor = useInsightsAdvisorQuery(advisorEnabled);
|
|
|
|
// Shared analytics fetch — the layout shell only reads
|
|
// `summaries[METRIC].count` for the tab-strip availability gate, so
|
|
// it lands on IW1's slim `?slice=summaries` branch (2 SQL passes,
|
|
// no correlations / health-score / bp-in-target tail).
|
|
const analyticsQuery = useAnalyticsQuery({ slice: "summaries" });
|
|
|
|
// Shared comprehensive fetch — mood + medication signals for the
|
|
// event-driven gating branches. Sub-pages read the same key so the
|
|
// payload lands once per route.
|
|
const comprehensiveQuery = useQuery({
|
|
queryKey: queryKeys.insightsComprehensive(),
|
|
queryFn: async () => {
|
|
const res = await fetch("/api/insights/comprehensive");
|
|
if (!res.ok) throw new Error("Failed");
|
|
const json = await res.json();
|
|
return json.data as ComprehensivePayload;
|
|
},
|
|
enabled: isAuthenticated,
|
|
});
|
|
|
|
// v1.4.32 — workout-presence gate. The workouts pill gates on at
|
|
// least one canonical row in the list-endpoint response. The
|
|
// single-row probe shares its cache slot with the list page +
|
|
// dashboard tile so navigation between surfaces is a free cache hit.
|
|
const workoutsProbe = useWorkouts({ limit: 1 });
|
|
|
|
// v1.4.31 — memoise the `availability` prop so an unchanged
|
|
// payload doesn't recreate the object on every cache-write of
|
|
// analytics or comprehensive. The strip is wrapped in
|
|
// `React.memo` and would still rerun `buildTabs(availability)` on
|
|
// every parent render if this prop kept arriving as a fresh
|
|
// reference. Per
|
|
// `.planning/research/v15-insights-blocking-bug.md` fix 2.
|
|
const summaries = analyticsQuery.data?.summaries;
|
|
const hasMood = (comprehensiveQuery.data?.moodSummary?.count ?? 0) > 0;
|
|
const hasMedication =
|
|
(comprehensiveQuery.data?.medications?.length ?? 0) > 0;
|
|
const hasWorkouts = (workoutsProbe.data?.workouts.length ?? 0) > 0;
|
|
const availability: InsightInputs | undefined = useMemo(() => {
|
|
if (!isAuthenticated) return undefined;
|
|
return { summaries, hasMood, hasMedication, hasWorkouts };
|
|
}, [isAuthenticated, summaries, hasMood, hasMedication, hasWorkouts]);
|
|
|
|
return (
|
|
<div className="space-y-8">
|
|
<InsightsTabStrip
|
|
onRegenerate={advisorEnabled ? advisor.regenerate : undefined}
|
|
regenerating={advisor.isRegenerating}
|
|
availability={availability}
|
|
/>
|
|
{children}
|
|
</div>
|
|
);
|
|
}
|