feat(dashboard): the daily-overview band becomes opt-in

The hero renders only when the layout carries the literal
heroVisible: true. Legacy blobs without the field, malformed values,
and fresh accounts all keep it off; the Settings toggle persists an
explicit opt-in through the existing layout PUT.
This commit is contained in:
Marc-André Bombeck committed 2026-06-12 19:03:32 +02:00
1 parent 7eeab2ae98
commit 8a5a26b49a
8 files changed
+51 -50

No files matched your search

+20 -19
View File
@@ -380,59 +380,60 @@ describe("resolveDashboardLayout() — chartOverlayPrefs (v1.4.18)", () => {
/**
* Dashboard hero (daily verdict) visibility — `heroVisible` piggy-backs
* on the layout blob like the B8 comparison baseline. Resolver contract:
* anything that is not the literal `false` clamps back to `true`
* (default-on for legacy blobs; a stale client cannot poison the field
* with a non-boolean). Serializer persists the resolved boolean
* explicitly so a re-read never has to guess the default.
* anything that is not the literal `true` clamps back to `false`
* (the hero is opt-in; legacy blobs keep it off and a stale client
* cannot poison the field with a non-boolean). Serializer persists the
* resolved boolean explicitly so a re-read never has to guess the
* default.
*/
describe("resolveDashboardLayout() — heroVisible", () => {
it("defaults to true for legacy layouts (no field saved)", () => {
it("defaults to false for legacy layouts (no field saved)", () => {
const legacy = {
version: 1,
widgets: [{ id: "weight", visible: true, order: 0 }],
};
expect(resolveDashboardLayout(legacy).heroVisible).toBe(true);
expect(resolveDashboardLayout(legacy).heroVisible).toBe(false);
});
it("respects an explicit heroVisible: false", () => {
it("respects an explicit heroVisible: true", () => {
const saved = {
version: 1,
widgets: [{ id: "weight", visible: true, order: 0 }],
heroVisible: false,
heroVisible: true,
};
expect(resolveDashboardLayout(saved).heroVisible).toBe(false);
expect(resolveDashboardLayout(saved).heroVisible).toBe(true);
});
it("clamps non-boolean values back to true", () => {
for (const poisoned of ["false", 0, null, 1, {}]) {
it("clamps non-boolean values back to false", () => {
for (const poisoned of ["true", 0, null, 1, {}]) {
const saved = {
version: 1,
widgets: [{ id: "weight", visible: true, order: 0 }],
heroVisible: poisoned,
};
expect(resolveDashboardLayout(saved).heroVisible).toBe(true);
expect(resolveDashboardLayout(saved).heroVisible).toBe(false);
}
});
it("defaults heroVisible to true in DEFAULT_DASHBOARD_LAYOUT", () => {
expect(DEFAULT_DASHBOARD_LAYOUT.heroVisible).toBe(true);
it("defaults heroVisible to false in DEFAULT_DASHBOARD_LAYOUT", () => {
expect(DEFAULT_DASHBOARD_LAYOUT.heroVisible).toBe(false);
});
it("preserves heroVisible: false through serialize → resolve round-trip", () => {
it("preserves heroVisible: true through serialize → resolve round-trip", () => {
const layout: DashboardLayout = {
...DEFAULT_DASHBOARD_LAYOUT,
heroVisible: false,
heroVisible: true,
};
const resolved = resolveDashboardLayout(serializeDashboardLayout(layout));
expect(resolved.heroVisible).toBe(false);
expect(resolved.heroVisible).toBe(true);
});
it("serializer derives true when the field is missing on input", () => {
it("serializer derives false when the field is missing on input", () => {
const layout: DashboardLayout = {
version: 1,
widgets: [{ id: "weight", visible: true, order: 0 }],
};
expect(serializeDashboardLayout(layout).heroVisible).toBe(true);
expect(serializeDashboardLayout(layout).heroVisible).toBe(false);
});
});
+10 -10
View File
@@ -324,9 +324,9 @@ export interface DashboardLayout {
/**
* Dashboard hero (daily verdict) visibility. Piggy-backs on the
* layout blob like the B8 comparison baseline — a UI affordance, not
* an analytical attribute, so no Prisma migration. The resolver
* clamps anything that is not the literal `false` back to `true`
* (legacy blobs without the field render the hero by default; a
* an analytical attribute, so no Prisma migration. Opt-in: the
* resolver clamps anything that is not the literal `true` back to
* `false` (legacy blobs without the field keep the hero off; a
* stale client cannot poison it with a non-boolean), and the
* serializer persists the resolved boolean explicitly.
*/
@@ -342,9 +342,9 @@ const DASHBOARD_LAYOUT_VERSION = 1;
*/
export const DEFAULT_DASHBOARD_LAYOUT: DashboardLayout = {
version: DASHBOARD_LAYOUT_VERSION,
// Hero (daily verdict) is on by default; users opt out via
// Hero (daily verdict) is off by default; users opt in via
// Settings → Dashboard.
heroVisible: true,
heroVisible: false,
widgets: [
{ id: "weight", visible: true, tileVisible: true, order: 0 },
{ id: "bp", visible: true, tileVisible: true, order: 1 },
@@ -462,10 +462,10 @@ export function resolveDashboardLayout(raw: unknown): DashboardLayout {
// client cannot poison the dashboard with values the renderer
// doesn't know how to draw.
chartOverlayPrefs: coerceChartOverlayPrefsMap(candidate.chartOverlayPrefs),
// Hero visibility — anything that is not the literal `false`
// clamps to `true` (default-on for legacy blobs and malformed
// values alike).
heroVisible: candidate.heroVisible !== false,
// Hero visibility — anything that is not the literal `true`
// clamps to `false` (default-off for legacy blobs and malformed
// values alike; the hero is opt-in).
heroVisible: candidate.heroVisible === true,
};
}
@@ -495,6 +495,6 @@ export function serializeDashboardLayout(
chartOverlayPrefs: coerceChartOverlayPrefsMap(layout.chartOverlayPrefs),
// Persist hero visibility explicitly (same clamp as the resolver)
// so a re-read never has to guess the default.
heroVisible: layout.heroVisible !== false,
heroVisible: layout.heroVisible === true,
};
}