mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
feat(integrations): let the ledger hold every failing leg at once
`failing_leg` was one slot, so two legs of the same provider failing in overlapping windows overwrote each other. The row remembered whichever failed last, and that leg recovering then cleared an error the other one was still causing — the ledger forgot a live failure and painted the card green over it. The slot becomes a set. A failure adds its leg, a success removes its own, and the error state, the per-kind buckets and the streak anchor clear only once the set is empty. The array is ordered oldest failure first, so the last element is the leg that wrote the message `last_error` holds; when that leg recovers while others are still failing, the message is cleared rather than left describing a leg that is now healthy. An unattributed failure adds nothing and removes nothing. A single-leg provider therefore behaves exactly as before, and a multi-leg provider no longer loses what its other legs already reported. The column never reached a client — it is absent from the status serialiser and from the OpenAPI contract — so it is replaced rather than shimmed.
This commit is contained in:
1 parent
3088753a92
commit
06935256b0
18 files changed
+433
-58
No files matched your search
@@ -201,7 +201,13 @@ export function IntegrationStatusPill({
|
||||
? "destructive"
|
||||
: "outline"
|
||||
}
|
||||
aria-label={t("settings.integrationPill.ariaLabel")}
|
||||
// No `aria-label` here. One used to sit on the badge and, being a
|
||||
// generic string, it REPLACED the accessible name with itself — a screen
|
||||
// reader announced the same words for "connected · 4 minutes ago" as for
|
||||
// "error", which is the one distinction the pill exists to make. The
|
||||
// visible label is the accessible name; the relative time stays
|
||||
// `aria-hidden` because it is decoration on top of a state that already
|
||||
// reads.
|
||||
className={cn(
|
||||
"max-w-full whitespace-nowrap",
|
||||
state === "connected" && connectedChipClass,
|
||||
|
||||
@@ -18,7 +18,10 @@ import { HeartPulse, Upload } from "lucide-react";
|
||||
|
||||
import { SettingsCardHeader } from "@/components/settings/_card-header";
|
||||
import { SettingsCard } from "@/components/settings/settings-card";
|
||||
import { IntegrationStatusPill } from "@/components/settings/integration-status-pill";
|
||||
import {
|
||||
formatRelative,
|
||||
IntegrationStatusPill,
|
||||
} from "@/components/settings/integration-status-pill";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { apiGet } from "@/lib/api/api-fetch";
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
@@ -31,12 +34,84 @@ import { queryKeys } from "@/lib/query-keys";
|
||||
import { MetricFreshnessDisclosure } from "./metric-freshness-disclosure";
|
||||
import { IntegrationErrorMessage, pillStateForVerdict } from "./shared";
|
||||
|
||||
type SyncTrigger = "foreground" | "background" | "push";
|
||||
|
||||
interface HealthKitStatus {
|
||||
lastSyncedAt: string | null;
|
||||
/** What the client said woke it for the most recent accepted batch. */
|
||||
lastSyncTrigger?: SyncTrigger | null;
|
||||
/** When data last arrived without the app being opened. */
|
||||
lastBackgroundSyncAt?: string | null;
|
||||
syncHealth?: SyncHealth;
|
||||
metricFreshness?: MetricFreshnessEntry[];
|
||||
}
|
||||
|
||||
const TRIGGER_KEYS: Record<SyncTrigger, string> = {
|
||||
foreground: "settings.appleHealth.delivery.trigger.foreground",
|
||||
background: "settings.appleHealth.delivery.trigger.background",
|
||||
push: "settings.appleHealth.delivery.trigger.push",
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether the phone is delivering on its own, or only while someone is looking
|
||||
* at it. `lastSyncedAt` cannot tell those apart — a card that reports nothing
|
||||
* but "last sync 10 minutes ago" reads identically in both cases, which is why
|
||||
* "is background delivery working?" was unanswerable from either side. The
|
||||
* trigger of the most recent batch and the date of the last background arrival
|
||||
* are the two facts that settle it, and each is shown only when it exists: a
|
||||
* client that reports no trigger says so rather than being guessed at.
|
||||
*/
|
||||
function DeliveryDiagnostic({
|
||||
status,
|
||||
t,
|
||||
}: {
|
||||
status: HealthKitStatus;
|
||||
t: (key: string, params?: Record<string, string | number>) => string;
|
||||
}) {
|
||||
const trigger = status.lastSyncTrigger ?? null;
|
||||
const triggerLabel = t(
|
||||
trigger
|
||||
? TRIGGER_KEYS[trigger]
|
||||
: "settings.appleHealth.delivery.trigger.unknown",
|
||||
);
|
||||
const backgroundAt = status.lastBackgroundSyncAt;
|
||||
|
||||
return (
|
||||
<div className="space-y-2" data-testid="apple-health-delivery">
|
||||
<h3 className="text-sm font-semibold">
|
||||
{t("settings.appleHealth.delivery.title")}
|
||||
</h3>
|
||||
{status.lastSyncedAt ? (
|
||||
<dl className="space-y-1 text-sm">
|
||||
<div className="flex flex-wrap gap-x-2">
|
||||
<dt className="text-muted-foreground">
|
||||
{t("settings.appleHealth.delivery.lastTriggerLabel")}
|
||||
</dt>
|
||||
<dd data-testid="apple-health-last-trigger">{triggerLabel}</dd>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-x-2">
|
||||
<dt className="text-muted-foreground">
|
||||
{t("settings.appleHealth.delivery.lastBackgroundLabel")}
|
||||
</dt>
|
||||
<dd data-testid="apple-health-last-background">
|
||||
{backgroundAt
|
||||
? formatRelative(
|
||||
Math.max(0, Date.now() - new Date(backgroundAt).getTime()),
|
||||
t,
|
||||
)
|
||||
: t("settings.appleHealth.delivery.backgroundNever")}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
) : (
|
||||
<p className="text-muted-foreground text-sm">
|
||||
{t("settings.appleHealth.delivery.noSyncYet")}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function AppleHealthCard({ enabled }: { enabled: boolean }) {
|
||||
const { t } = useTranslations();
|
||||
const {
|
||||
@@ -96,6 +171,8 @@ export function AppleHealthCard({ enabled }: { enabled: boolean }) {
|
||||
</p>
|
||||
)}
|
||||
|
||||
{showPill && <DeliveryDiagnostic status={status} t={t} />}
|
||||
|
||||
<MetricFreshnessDisclosure
|
||||
entries={status?.metricFreshness}
|
||||
idPrefix="apple-health"
|
||||
|
||||
Reference in new issue
Block a user