mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
chore(release): v1.4.29
A targeted performance + polish patch. The headline is a faster dashboard on data-rich accounts: the pulse chart drops up to ~5 000 raw rows per range tab in favour of one row per day, the duplicate `/api/dashboard/widgets` fetch on every mount collapses to one, and three long-running analytics reads are bounded to the trailing window the tile path actually needs. Two production regressions close — the `aggregate=daily|weekly|monthly` path on `/api/measurements` 500'd for every grain, and the same path averaged cumulative step counts instead of summing.
This commit is contained in:
1 parent
232ea43d99
commit
d76c0b56e7
25 files changed
+3250
-65
No files matched your search
@@ -84,6 +84,36 @@ describe("<HealthChart> — bounded range fetch", () => {
|
||||
expect(measurementsUrl!).toMatch(/type=PULSE/);
|
||||
// Guard against the legacy unbounded paginator returning.
|
||||
expect(measurementsUrl!).not.toMatch(/offset=/);
|
||||
// v1.4.29 C3 — the default 30-day window must request server-
|
||||
// side daily aggregation so the client doesn't pay for ~5000
|
||||
// raw pulse rows on every range-tab change.
|
||||
expect(measurementsUrl!).toMatch(/aggregate=daily/);
|
||||
});
|
||||
|
||||
it("omits aggregate=daily on windows of 7 days or fewer", async () => {
|
||||
// v1.4.29 C3 — short windows keep raw fetching so the user can
|
||||
// see hour-by-hour detail on the 7-day view.
|
||||
const { I18nProvider } = await import("@/lib/i18n/context");
|
||||
const { HealthChart } = await import("../health-chart");
|
||||
|
||||
renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
<HealthChart
|
||||
types={["PULSE"]}
|
||||
title="Pulse"
|
||||
unit="bpm"
|
||||
windowOverride="last7days"
|
||||
/>
|
||||
</I18nProvider>,
|
||||
);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
const measurementsUrl = fetchCalls.find((u) =>
|
||||
u.includes("/api/measurements"),
|
||||
);
|
||||
expect(measurementsUrl).toBeDefined();
|
||||
expect(measurementsUrl!).not.toMatch(/aggregate=daily/);
|
||||
});
|
||||
|
||||
it("re-keys the query when the range window changes", async () => {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { Activity } from "lucide-react";
|
||||
|
||||
import { TrendCard } from "../trend-card";
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
|
||||
/**
|
||||
* v1.4.29 — mobile tile equal-height contract.
|
||||
*
|
||||
* On `<sm` viewports each dashboard tile pins to `--tile-h: 140px`
|
||||
* via the strip wrapper. The tile-internal callout slot reserves
|
||||
* `min-h-[18px]` even when no callout is rendered, and the sub-row
|
||||
* pair switches to `flex-nowrap overflow-hidden` so a narrow tile
|
||||
* cannot grow vertically.
|
||||
*
|
||||
* Per R-C §6 this contract pins regardless of which combination of
|
||||
* `compareDelta` / `trend7Delta` / sub-rows the tile is rendering.
|
||||
*/
|
||||
|
||||
const RISING = { slope: 0.5, direction: "up" as const, confidence: 0.8 };
|
||||
|
||||
function render(node: React.ReactNode) {
|
||||
return renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">{node}</I18nProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
describe("<TrendCard> mobile tile equal-height contract", () => {
|
||||
const baseProps = {
|
||||
label: "Pulse",
|
||||
latest: 72,
|
||||
unit: "bpm",
|
||||
avg7: 70,
|
||||
avg30: 71,
|
||||
icon: Activity,
|
||||
slope30: RISING,
|
||||
};
|
||||
|
||||
it("renders the callout slot with min-h-[18px] reserved", () => {
|
||||
const html = render(<TrendCard {...baseProps} />);
|
||||
// The callout slot wrapper sits between value row + sub-rows and
|
||||
// reserves a fixed minimum height so sibling tiles don't drift
|
||||
// when the callout is absent.
|
||||
expect(html).toContain("min-h-[18px]");
|
||||
});
|
||||
|
||||
it("clamps the comparison callout to one line at <sm", () => {
|
||||
const html = render(
|
||||
<TrendCard
|
||||
{...baseProps}
|
||||
compareBaseline="lastMonth"
|
||||
compareDelta={1.2}
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain("line-clamp-1");
|
||||
expect(html).toContain('data-slot="tile-compare-delta"');
|
||||
});
|
||||
|
||||
it("renders the sub-row pair with flex-nowrap + overflow-hidden", () => {
|
||||
const html = render(<TrendCard {...baseProps} />);
|
||||
expect(html).toContain("flex-nowrap");
|
||||
expect(html).toContain("overflow-hidden");
|
||||
});
|
||||
});
|
||||
@@ -41,7 +41,7 @@ import type {
|
||||
import { ChartOverlayControls } from "./chart-overlay-controls";
|
||||
import { useChartOverlayPrefs } from "@/hooks/use-chart-overlay-prefs";
|
||||
import { useViewportWidth } from "@/hooks/use-viewport-width";
|
||||
import { chooseTickInterval } from "@/lib/charts/x-axis-density";
|
||||
import { computeTickPositions } from "@/lib/charts/x-axis-density";
|
||||
|
||||
const TIME_RANGES_KEYS = [
|
||||
{
|
||||
@@ -577,6 +577,15 @@ export function HealthChart({
|
||||
typeParams.set("from", fetchWindow.from);
|
||||
typeParams.set("to", fetchWindow.to);
|
||||
typeParams.set("limit", "5000");
|
||||
// v1.4.29 C3 — windows over 7 days ask the server to bucket
|
||||
// daily. Caps the chart's per-type payload at ~365 rows
|
||||
// instead of ~5 000 for high-density types (pulse), and drops
|
||||
// Recharts paint cost ~50× on continuous-monitoring accounts.
|
||||
// Short windows keep raw fetching so hour-by-hour detail
|
||||
// stays visible.
|
||||
if (fetchWindow.windowDays > 7) {
|
||||
typeParams.set("aggregate", "daily");
|
||||
}
|
||||
|
||||
const res = await fetch(`/api/measurements?${typeParams}`);
|
||||
if (!res.ok) return;
|
||||
@@ -1272,8 +1281,13 @@ export function HealthChart({
|
||||
),
|
||||
)
|
||||
}
|
||||
interval={chooseTickInterval(
|
||||
chartData?.length ?? 0,
|
||||
// v1.4.29 — Recharts ignores `interval` on numeric
|
||||
// axes (`type="number"`). Hand explicit tick
|
||||
// positions through the `ticks` prop so the legacy
|
||||
// day-aware density policy stays effective on the
|
||||
// pulse chart.
|
||||
ticks={computeTickPositions(
|
||||
chartData ?? [],
|
||||
viewportWidth,
|
||||
)}
|
||||
padding={{ left: 10, right: 10 }}
|
||||
|
||||
@@ -36,7 +36,7 @@ import type {
|
||||
import { ChartOverlayControls } from "./chart-overlay-controls";
|
||||
import { useChartOverlayPrefs } from "@/hooks/use-chart-overlay-prefs";
|
||||
import { useViewportWidth } from "@/hooks/use-viewport-width";
|
||||
import { chooseTickInterval } from "@/lib/charts/x-axis-density";
|
||||
import { computeTickPositions } from "@/lib/charts/x-axis-density";
|
||||
import { CHART_HEIGHT_PX } from "@/lib/charts/constants";
|
||||
import { moodLabelKeyForScore } from "@/lib/mood/labels";
|
||||
|
||||
@@ -748,8 +748,10 @@ export function MoodChart({
|
||||
),
|
||||
)
|
||||
}
|
||||
interval={chooseTickInterval(
|
||||
chartData?.length ?? 0,
|
||||
// v1.4.29 — Recharts ignores `interval` on numeric
|
||||
// axes; pass explicit tick positions instead.
|
||||
ticks={computeTickPositions(
|
||||
chartData ?? [],
|
||||
viewportWidth,
|
||||
)}
|
||||
padding={{ left: 10, right: 10 }}
|
||||
|
||||
@@ -265,11 +265,16 @@ export function TrendCard({
|
||||
flex-wrap on the sibling row + this callout's `mt-1`
|
||||
horizontal-row layout absorb the overflow without crowding
|
||||
the headline value above. */}
|
||||
{compareBaseline !== "none" && compareDelta != null && (
|
||||
<div className="mt-1">
|
||||
{/* v1.4.29 — clamp the callout to one line at `<sm` so the
|
||||
tile's overall height stays inside the 140-px contract.
|
||||
`min-h-[18px]` reserves the slot when no callout is being
|
||||
rendered so the sub-row pair below pins to the same y
|
||||
across every tile. `sm:` releases both bounds. */}
|
||||
<div className="mt-1 min-h-[18px] sm:min-h-0">
|
||||
{compareBaseline !== "none" && compareDelta != null && (
|
||||
<span
|
||||
className={cn(
|
||||
"inline-block max-w-full text-xs leading-snug font-medium [overflow-wrap:anywhere] tabular-nums",
|
||||
"line-clamp-1 inline-block max-w-full text-xs leading-snug font-medium tabular-nums sm:line-clamp-none sm:[overflow-wrap:anywhere]",
|
||||
comparisonDeltaColor,
|
||||
)}
|
||||
data-slot="tile-compare-delta"
|
||||
@@ -286,10 +291,14 @@ export function TrendCard({
|
||||
: "comparison.captionLastYear",
|
||||
)}`}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
</div>
|
||||
<TooltipProvider>
|
||||
<div className="text-muted-foreground mt-auto flex min-w-0 flex-wrap gap-x-3 gap-y-1 pt-1 text-xs leading-snug">
|
||||
{/* v1.4.29 — sub-row pair clips rather than wraps at `<sm`
|
||||
so a narrow tile cannot grow vertically beyond the
|
||||
140-px contract. `sm:` releases back to the original
|
||||
wrap behaviour. */}
|
||||
<div className="text-muted-foreground mt-auto flex min-w-0 flex-nowrap items-baseline gap-x-3 overflow-hidden pt-1 text-xs leading-snug sm:flex-wrap sm:gap-y-1">
|
||||
<span className="max-w-full min-w-0 [overflow-wrap:anywhere]">
|
||||
{t(avg7LabelKey)}:{" "}
|
||||
{avg7Hint ? (
|
||||
|
||||
@@ -252,15 +252,23 @@ export function DashboardLayoutSection({ id }: { id: string }) {
|
||||
chart in the lower row. the maintainer wanted independent control
|
||||
of the two surfaces (per feedback_dashboard_top_tiles
|
||||
_selectable.md). */}
|
||||
<div className="text-muted-foreground flex items-center gap-3 px-3 pb-1 text-[10px] font-medium tracking-wide uppercase">
|
||||
<span className="w-11" aria-hidden="true" />
|
||||
<span className="flex-1" />
|
||||
{/* v1.4.29 — column-header alignment for the new
|
||||
horizontal arrow pair on the trailing edge. The
|
||||
right-hand spacer reserves the width of two
|
||||
size-11/sm:size-9 buttons so the Tile / Chart column
|
||||
headers continue to line up with the switches below. */}
|
||||
<div className="text-muted-foreground flex items-center gap-2 px-3 pb-1 text-[10px] font-medium tracking-wide uppercase">
|
||||
<span className="flex-1" aria-hidden="true" />
|
||||
<span className="w-12 text-center">
|
||||
{t("dashboard.layoutTileColumn")}
|
||||
</span>
|
||||
<span className="w-12 text-center">
|
||||
{t("dashboard.layoutChartColumn")}
|
||||
</span>
|
||||
<span
|
||||
className="w-22 sm:w-18"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
{[...layout.widgets]
|
||||
.sort((a, b) => a.order - b.order)
|
||||
@@ -271,37 +279,24 @@ export function DashboardLayoutSection({ id }: { id: string }) {
|
||||
? widget.tileVisible
|
||||
: widget.visible;
|
||||
return (
|
||||
// v1.4.29 — drag-list row compactness. The legacy
|
||||
// vertical 44+44-px arrow stack inflated each row
|
||||
// to ~116 px; the horizontal arrow pair on the
|
||||
// trailing edge drops the row to 48 px (`min-h-12`)
|
||||
// while preserving the 44-px mobile tap target
|
||||
// (`size-11`). `sm:size-9` shrinks the buttons
|
||||
// visually on desktop where pointer accuracy is
|
||||
// higher.
|
||||
<div
|
||||
key={widget.id}
|
||||
className="border-border bg-background/30 flex items-center gap-3 rounded-md border p-3"
|
||||
className="border-border bg-background/30 flex min-h-12 items-center gap-2 rounded-md border px-3 py-2"
|
||||
>
|
||||
<div className="flex flex-col gap-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="size-11"
|
||||
onClick={() => move(widget.id, -1)}
|
||||
disabled={index === 0 || saveMutation.isPending}
|
||||
aria-label={t("dashboard.moveUp")}
|
||||
>
|
||||
<ArrowUp className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="size-11"
|
||||
onClick={() => move(widget.id, 1)}
|
||||
disabled={
|
||||
index === arr.length - 1 || saveMutation.isPending
|
||||
}
|
||||
aria-label={t("dashboard.moveDown")}
|
||||
>
|
||||
<ArrowDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<span className="flex-1 text-sm">{t(labelKey)}</span>
|
||||
<span
|
||||
className="flex-1 truncate text-sm"
|
||||
title={t(labelKey)}
|
||||
>
|
||||
{t(labelKey)}
|
||||
</span>
|
||||
<div className="flex w-12 justify-center">
|
||||
<Switch
|
||||
checked={tileChecked}
|
||||
@@ -320,6 +315,30 @@ export function DashboardLayoutSection({ id }: { id: string }) {
|
||||
data-slot="widget-chart-switch"
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="size-11 sm:size-9"
|
||||
onClick={() => move(widget.id, -1)}
|
||||
disabled={index === 0 || saveMutation.isPending}
|
||||
aria-label={t("dashboard.moveUp")}
|
||||
>
|
||||
<ArrowUp className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="size-11 sm:size-9"
|
||||
onClick={() => move(widget.id, 1)}
|
||||
disabled={
|
||||
index === arr.length - 1 || saveMutation.isPending
|
||||
}
|
||||
aria-label={t("dashboard.moveDown")}
|
||||
>
|
||||
<ArrowDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
Reference in new issue
Block a user