mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
feat(dashboard): let the top card be switched off
The layout settings gain a switch for the dashboard's top card (the Today card above the tiles). Stored server-side on the layout blob as `todayCardVisible`: missing means shown, only an explicit false hides it, the default is omitted from storage, a save that omits the field keeps the stored choice, and a layout reset shows the card again. Hidden, the card leaves no skeleton or error card behind. The flag rides the account-settings backup with the rest of the layout. The field is deliberately not `heroVisible`, the retired opt-in hero's flag that older stored layouts may still carry. An end-to-end journey on its own account switches the card off and on and walks the score histories' range tabs.
This commit is contained in:
1 parent
62140a4aee
commit
668f568289
21 files changed
+714
-10
No files matched your search
@@ -929,7 +929,9 @@ describe("DELETE /api/dashboard/widgets — web-owned reset scope", () => {
|
||||
selectedScoreRings: ["READINESS", "SLEEP_SCORE"],
|
||||
heroRingOrder: ["SLEEP_SCORE", "HEALTH_SCORE", "READINESS"],
|
||||
enabledHeroItemKinds: ["milestone"],
|
||||
todayCardVisible: false,
|
||||
});
|
||||
expect(stored.todayCardVisible).toBe(false);
|
||||
const advanced = new Date("2026-07-24T12:00:00.000Z");
|
||||
transactionUser.findUnique.mockResolvedValue({
|
||||
dashboardWidgetsJson: stored,
|
||||
@@ -958,6 +960,10 @@ describe("DELETE /api/dashboard/widgets — web-owned reset scope", () => {
|
||||
expect(
|
||||
Object.prototype.hasOwnProperty.call(persisted, "enabledHeroItemKinds"),
|
||||
).toBe(false);
|
||||
// A reset brings a hidden top card back; shown is stored by omission.
|
||||
expect(
|
||||
Object.prototype.hasOwnProperty.call(persisted, "todayCardVisible"),
|
||||
).toBe(false);
|
||||
expect(persisted.comparisonBaseline).toBe("lastYear");
|
||||
expect(persisted.chartOverlayPrefs).toEqual({
|
||||
weight: {
|
||||
@@ -1076,6 +1082,96 @@ describe("dashboard widgets — hero primary content", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("dashboard widgets — the top card switch", () => {
|
||||
const weightOnly = [
|
||||
{ id: "weight" as const, visible: true, tileVisible: true, order: 0 },
|
||||
];
|
||||
|
||||
function persistedLayout() {
|
||||
const updateArg = vi.mocked(prisma.user.update).mock
|
||||
.calls[0]?.[0] as unknown as {
|
||||
data: { dashboardWidgetsJson: { todayCardVisible?: boolean } };
|
||||
};
|
||||
return updateArg.data.dashboardWidgetsJson;
|
||||
}
|
||||
|
||||
it("accepts and persists todayCardVisible: false", async () => {
|
||||
vi.mocked(prisma.user.findUnique).mockResolvedValue({
|
||||
dashboardWidgetsJson: null,
|
||||
} as never);
|
||||
vi.mocked(prisma.user.update).mockResolvedValue({} as never);
|
||||
|
||||
const res = await callPut(
|
||||
makeReq({ version: 1, widgets: weightOnly, todayCardVisible: false }),
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
expect(persistedLayout().todayCardVisible).toBe(false);
|
||||
const body = (await res.json()) as {
|
||||
data: { todayCardVisible?: boolean };
|
||||
};
|
||||
expect(body.data.todayCardVisible).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects a non-boolean with 422", async () => {
|
||||
vi.mocked(prisma.user.findUnique).mockResolvedValue({
|
||||
dashboardWidgetsJson: null,
|
||||
} as never);
|
||||
vi.mocked(prisma.user.update).mockResolvedValue({} as never);
|
||||
|
||||
const res = await callPut(
|
||||
makeReq({ version: 1, widgets: weightOnly, todayCardVisible: "no" }),
|
||||
);
|
||||
expect(res.status).toBe(422);
|
||||
expect(vi.mocked(prisma.user.update)).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps a hidden top card hidden when the client omits the field", async () => {
|
||||
// A save from a client that predates the field must not bring it back.
|
||||
const stored = serializeDashboardLayout({
|
||||
version: 1,
|
||||
widgets: weightOnly,
|
||||
todayCardVisible: false,
|
||||
});
|
||||
vi.mocked(prisma.user.findUnique).mockResolvedValue({
|
||||
dashboardWidgetsJson: stored,
|
||||
} as never);
|
||||
vi.mocked(prisma.user.update).mockResolvedValue({} as never);
|
||||
|
||||
const res = await callPut(makeReq({ version: 1, widgets: weightOnly }));
|
||||
expect(res.status).toBe(200);
|
||||
expect(persistedLayout().todayCardVisible).toBe(false);
|
||||
});
|
||||
|
||||
it("stores showing it again as the omitted default", async () => {
|
||||
const stored = serializeDashboardLayout({
|
||||
version: 1,
|
||||
widgets: weightOnly,
|
||||
todayCardVisible: false,
|
||||
});
|
||||
vi.mocked(prisma.user.findUnique).mockResolvedValue({
|
||||
dashboardWidgetsJson: stored,
|
||||
} as never);
|
||||
vi.mocked(prisma.user.update).mockResolvedValue({} as never);
|
||||
|
||||
const res = await callPut(
|
||||
makeReq({ version: 1, widgets: weightOnly, todayCardVisible: true }),
|
||||
);
|
||||
expect(res.status).toBe(200);
|
||||
expect(persistedLayout()).not.toHaveProperty("todayCardVisible");
|
||||
});
|
||||
|
||||
it("GET answers true for a layout that never chose", async () => {
|
||||
vi.mocked(prisma.user.findUnique).mockResolvedValue({
|
||||
dashboardWidgetsJson: serializeDashboardLayout(DEFAULT_DASHBOARD_LAYOUT),
|
||||
} as never);
|
||||
const res = await callGet();
|
||||
const body = (await res.json()) as {
|
||||
data: { todayCardVisible?: boolean };
|
||||
};
|
||||
expect(body.data.todayCardVisible).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("a toggle that cannot do anything is not offered", () => {
|
||||
// A switch that is on over a tile that can never paint, with nothing
|
||||
// saying why, is the defect the HRV fallback exists to remove — so the
|
||||
|
||||
@@ -170,6 +170,10 @@ const layoutSchema = z.object({
|
||||
// Same preserve-when-absent contract as `comparisonBaseline`; the
|
||||
// resolver drops unknown stored values back to "score" on read.
|
||||
hero: z.enum(HERO_PRIMARY_CONTENTS).optional(),
|
||||
// v1.42 — whether the dashboard shows its top card. Same additive,
|
||||
// preserve-when-absent contract as `hero`; the default (shown) is omitted
|
||||
// from storage.
|
||||
todayCardVisible: z.boolean().optional(),
|
||||
// v1.32.16 (issue #581) — the optimistic-concurrency base token used to
|
||||
// live here. v1.32.21 (R5a) moved it to the shared `takeBaseToken` helper,
|
||||
// which strips it BEFORE this parse: the token is transport, not a layout
|
||||
@@ -503,6 +507,8 @@ export const DELETE = apiHandler(async () => {
|
||||
...existingLayout,
|
||||
widgets: DEFAULT_DASHBOARD_LAYOUT.widgets,
|
||||
enabledHeroItemKinds: DEFAULT_DASHBOARD_LAYOUT.enabledHeroItemKinds,
|
||||
// A reset brings a hidden top card back.
|
||||
todayCardVisible: DEFAULT_DASHBOARD_LAYOUT.todayCardVisible,
|
||||
});
|
||||
|
||||
const updated = await tx.user.update({
|
||||
|
||||
Reference in new issue
Block a user