mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
fix(recovery): name what is missing on an Oura account's empty recovery page
An Oura ring fills the recovery page through its resilience level alone. The empty note listed every source that could fill the page, so a connected ring with no level read the same as no wearable at all. The note now follows the server's view of the Oura connection: when the grant leaves out the heart-health data the level sits behind, it asks for one reconnect and links to the integrations settings; when the grant covers it, it says Oura has not sent a level for this account yet. Refs #1204
This commit is contained in:
1 parent
7f2f473a58
commit
40b1389970
10 files changed
+362
-1
No files matched your search
@@ -0,0 +1,122 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
import type { DataSummary } from "@/lib/analytics/trends";
|
||||
|
||||
/**
|
||||
* The recovery page's empty note says what is missing for THIS account. An
|
||||
* Oura ring fills the page through its resilience level alone, so a connected
|
||||
* ring with an empty page is either a grant that leaves out the heart-health
|
||||
* data the level sits behind, or Oura not having sent a level yet. The
|
||||
* connection facts come from the server's integrations read; the page only
|
||||
* picks the sentence.
|
||||
*/
|
||||
|
||||
vi.mock("next/dynamic", () => ({
|
||||
default: () => {
|
||||
const Stub = () => <div data-slot="mini-chart-stub" />;
|
||||
Stub.displayName = "MiniChartStub";
|
||||
return Stub;
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/hooks/use-auth", () => ({
|
||||
useAuth: () => ({ user: { timezone: "UTC" }, isAuthenticated: true }),
|
||||
}));
|
||||
|
||||
const analyticsMock = vi.fn();
|
||||
vi.mock("@/hooks/use-insights-analytics", () => ({
|
||||
useInsightsAnalytics: () => analyticsMock(),
|
||||
}));
|
||||
|
||||
import { RecoverySection } from "../recovery/recovery-section";
|
||||
|
||||
function summary(count: number): DataSummary {
|
||||
return {
|
||||
count,
|
||||
latest: null,
|
||||
min: null,
|
||||
max: null,
|
||||
mean: null,
|
||||
median: null,
|
||||
avg7: null,
|
||||
avg30: null,
|
||||
slope7: null,
|
||||
slope30: null,
|
||||
anomalyCount: 0,
|
||||
};
|
||||
}
|
||||
|
||||
/** An Oura-only account: readiness, HRV and sleep, no resilience level. */
|
||||
const OURA_SUMMARIES = {
|
||||
SLEEP_DURATION: summary(30),
|
||||
RECOVERY_SCORE: summary(30),
|
||||
HRV_RMSSD: summary(30),
|
||||
};
|
||||
|
||||
function render(oura: Record<string, unknown> | null) {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false, staleTime: Infinity } },
|
||||
});
|
||||
queryClient.setQueryData(queryKeys.integrationsStatus(), {
|
||||
threshold: 3,
|
||||
integrations: oura ? [{ integration: "oura", ...oura }] : [],
|
||||
});
|
||||
return renderToStaticMarkup(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<I18nProvider initialLocale="en">
|
||||
<RecoverySection />
|
||||
</I18nProvider>
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
function health(unavailable: Array<{ item: string; cause: string }>) {
|
||||
return {
|
||||
state: unavailable.length > 0 ? "limited" : "ok",
|
||||
reason: unavailable.length > 0 ? "permission_limited" : "data_arriving",
|
||||
unavailable,
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
analyticsMock.mockReset();
|
||||
analyticsMock.mockReturnValue({
|
||||
data: { summaries: OURA_SUMMARIES },
|
||||
isLoading: false,
|
||||
isEmpty: false,
|
||||
error: null,
|
||||
refetch: () => {},
|
||||
});
|
||||
});
|
||||
|
||||
describe("<RecoverySection> empty note", () => {
|
||||
it("asks for the heart-health permission when the grant withholds resilience", () => {
|
||||
const html = render({
|
||||
connected: true,
|
||||
health: health([{ item: "resilience", cause: "permission" }]),
|
||||
});
|
||||
expect(html).toContain('data-empty-case="oura-permission"');
|
||||
expect(html).toContain("allow heart-health access");
|
||||
expect(html).toContain('href="/settings/integrations"');
|
||||
});
|
||||
|
||||
it("says Oura has sent no level yet when the grant covers it", () => {
|
||||
const html = render({
|
||||
connected: true,
|
||||
health: health([{ item: "spo2", cause: "permission" }]),
|
||||
});
|
||||
expect(html).toContain('data-empty-case="oura-no-resilience"');
|
||||
expect(html).toContain("has not sent a resilience level");
|
||||
expect(html).not.toContain('href="/settings/integrations"');
|
||||
});
|
||||
|
||||
it("keeps the general note for an account without Oura", () => {
|
||||
const html = render(null);
|
||||
expect(html).toContain('data-empty-case="general"');
|
||||
expect(html).toContain("WHOOP and Polar record");
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import {
|
||||
Activity,
|
||||
Battery,
|
||||
@@ -14,6 +15,12 @@ import { useInsightsAnalytics } from "@/hooks/use-insights-analytics";
|
||||
import { useAnalyticsQuery } from "@/lib/queries/use-analytics-query";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { EmptyState } from "@/components/ui/empty-state";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
pickStatus,
|
||||
useIntegrationStatuses,
|
||||
type IntegrationStatusViewModel,
|
||||
} from "@/components/settings/integrations/shared";
|
||||
import { ChartSkeleton } from "@/components/charts/chart-skeleton";
|
||||
import { RestModeBanner } from "@/components/insights/rest-mode-banner";
|
||||
import type { RestModeAnnotation } from "@/lib/analytics/score/types";
|
||||
@@ -39,6 +46,33 @@ interface BlockGroup {
|
||||
blocks: BlockSpec[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Why this account's recovery page is empty, from the server's view of its
|
||||
* Oura connection. An Oura ring feeds this page through its resilience level
|
||||
* alone, so a connected ring with an empty page has exactly two causes: the
|
||||
* grant does not cover the heart-health data the level sits behind (the
|
||||
* server records that per collection and publishes it as an unavailable
|
||||
* item), or Oura has not sent a level for this account. Everyone else gets
|
||||
* the general note naming what fills the page.
|
||||
*/
|
||||
type RecoveryEmptyCase = "general" | "oura-permission" | "oura-no-resilience";
|
||||
|
||||
const EMPTY_COPY = {
|
||||
general: "insights.recovery.empty",
|
||||
"oura-permission": "insights.recovery.emptyOuraPermission",
|
||||
"oura-no-resilience": "insights.recovery.emptyOuraNoResilience",
|
||||
} as const satisfies Record<RecoveryEmptyCase, string>;
|
||||
|
||||
function recoveryEmptyCase(
|
||||
oura: IntegrationStatusViewModel | undefined,
|
||||
): RecoveryEmptyCase {
|
||||
if (!oura?.connected) return "general";
|
||||
const withheld = oura.health?.unavailable.some(
|
||||
(u) => u.item === "resilience" && u.cause === "permission",
|
||||
);
|
||||
return withheld ? "oura-permission" : "oura-no-resilience";
|
||||
}
|
||||
|
||||
/**
|
||||
* v1.17.1 → rebuilt v1.18.1 (B1–B3) — body of the `/insights/recovery`
|
||||
* sub-page.
|
||||
@@ -181,6 +215,13 @@ export function RecoverySection() {
|
||||
group.blocks.some((block) => (summaries[block.type]?.count ?? 0) > 0),
|
||||
));
|
||||
|
||||
// Only an empty page asks which connection could fill it, so a page with
|
||||
// data never pays for the integrations read.
|
||||
const statuses = useIntegrationStatuses(
|
||||
!isLoading && summaries != null && !hasAny,
|
||||
);
|
||||
const emptyCase = recoveryEmptyCase(pickStatus(statuses.data, "oura"));
|
||||
|
||||
if (isLoading || summaries == null) {
|
||||
return (
|
||||
<div className="space-y-3" data-slot="recovery-loading">
|
||||
@@ -193,9 +234,19 @@ export function RecoverySection() {
|
||||
return (
|
||||
<EmptyState
|
||||
data-slot="recovery-empty"
|
||||
data-empty-case={emptyCase}
|
||||
icon={<Heart className="size-6" />}
|
||||
title={t("insights.recovery.emptyTitle")}
|
||||
description={t("insights.recovery.empty")}
|
||||
description={t(EMPTY_COPY[emptyCase])}
|
||||
action={
|
||||
emptyCase === "oura-permission" ? (
|
||||
<Button size="sm" variant="outline" asChild>
|
||||
<Link href="/settings/integrations">
|
||||
{t("insights.recovery.emptyAction")}
|
||||
</Link>
|
||||
</Button>
|
||||
) : undefined
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user