mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +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
@@ -621,3 +621,44 @@ describe("<DashboardLayoutSection> — hero content", () => {
|
||||
expect(html).toContain("Notification settings are managed separately.");
|
||||
});
|
||||
});
|
||||
|
||||
describe("<DashboardLayoutSection> — the top card switch", () => {
|
||||
function control(html: string): string {
|
||||
const match = html.match(/<button[^>]*data-slot="today-card-switch"[^>]*>/);
|
||||
expect(match).not.toBeNull();
|
||||
return match![0];
|
||||
}
|
||||
|
||||
it("offers one labelled switch, on by default", () => {
|
||||
const html = render(<DashboardLayoutSection id="dashboard-layout" />);
|
||||
expect(html.match(/data-slot="today-card-switch"/g)).toHaveLength(1);
|
||||
expect(control(html)).toContain('data-state="checked"');
|
||||
const id = control(html).match(/id="([^"]+)"/)![1];
|
||||
expect(html).toContain(`for="${id}"`);
|
||||
expect(html).toContain("Show the top card");
|
||||
expect(html).toContain("Using default layout");
|
||||
});
|
||||
|
||||
it("reads a layout that predates the field as shown", () => {
|
||||
const legacy: DashboardLayout = { ...DEFAULT_DASHBOARD_LAYOUT };
|
||||
delete legacy.todayCardVisible;
|
||||
queryState.layout = legacy;
|
||||
const html = render(<DashboardLayoutSection id="dashboard-layout" />);
|
||||
expect(control(html)).toContain('data-state="checked"');
|
||||
});
|
||||
|
||||
it("shows a hidden top card as off, and as a customised layout", () => {
|
||||
queryState.layout = {
|
||||
...DEFAULT_DASHBOARD_LAYOUT,
|
||||
todayCardVisible: false,
|
||||
};
|
||||
const html = render(<DashboardLayoutSection id="dashboard-layout" />);
|
||||
expect(control(html)).toContain('data-state="unchecked"');
|
||||
expect(html).toContain("Custom layout active");
|
||||
});
|
||||
|
||||
it("labels it in German", () => {
|
||||
const html = render(<DashboardLayoutSection id="dashboard-layout" />, "de");
|
||||
expect(html).toContain("Obere Karte anzeigen");
|
||||
});
|
||||
});
|
||||
@@ -207,6 +207,7 @@ export function DashboardLayoutSection({ id }: { id: string }) {
|
||||
const heroDescriptionId = useId();
|
||||
const heroNotificationNoteId = useId();
|
||||
const heroContentSelectId = useId();
|
||||
const todayCardSwitchId = useId();
|
||||
// v1.34 — the "Today highlights" fieldset below is gated on `layout`,
|
||||
// which can be truthy on the very first client render whenever a
|
||||
// returning visitor's browser already has a warm, offline-persisted
|
||||
@@ -404,6 +405,12 @@ export function DashboardLayoutSection({ id }: { id: string }) {
|
||||
});
|
||||
}
|
||||
|
||||
/** v1.42 — the server-persisted on/off switch for the dashboard's top card. */
|
||||
function setTodayCardVisible(visible: boolean) {
|
||||
if (!layout) return;
|
||||
setDraft({ ...layout, todayCardVisible: visible });
|
||||
}
|
||||
|
||||
/**
|
||||
* Hero primary content — the server-persisted `hero` field on the layout
|
||||
* blob. The value set is closed ("score" | "reminders"); anything else a
|
||||
@@ -483,6 +490,20 @@ export function DashboardLayoutSection({ id }: { id: string }) {
|
||||
<p id={heroDescriptionId} className="text-muted-foreground text-xs">
|
||||
{t("dashboard.heroItemsDescription")}
|
||||
</p>
|
||||
{/* v1.42 — the top card itself can be switched off. Shown is the
|
||||
default; the choices below shape the card while it is shown. */}
|
||||
<div className="flex min-h-11 items-center justify-between gap-3">
|
||||
<Label htmlFor={todayCardSwitchId} className="text-sm font-medium">
|
||||
{t("dashboard.todayCardVisible")}
|
||||
</Label>
|
||||
<Switch
|
||||
id={todayCardSwitchId}
|
||||
checked={layout.todayCardVisible !== false}
|
||||
onCheckedChange={setTodayCardVisible}
|
||||
disabled={saveMutation.isPending}
|
||||
data-slot="today-card-switch"
|
||||
/>
|
||||
</div>
|
||||
{/* Hero primary content — a single labelled select beside the
|
||||
highlight toggles. "score" keeps the health-score read;
|
||||
"reminders" promotes the highlight rail into the hero slot. */}
|
||||
@@ -758,6 +779,7 @@ export function DashboardLayoutSection({ id }: { id: string }) {
|
||||
<Button
|
||||
size="sm"
|
||||
className="min-h-11 sm:min-h-9"
|
||||
data-slot="settings-dashboard-layout-save"
|
||||
onClick={() => layout && saveMutation.mutate(layout)}
|
||||
disabled={saveMutation.isPending}
|
||||
>
|
||||
@@ -777,7 +799,8 @@ export function DashboardLayoutSection({ id }: { id: string }) {
|
||||
JSON.stringify(DEFAULT_DASHBOARD_LAYOUT.widgets) &&
|
||||
JSON.stringify(layout.enabledHeroItemKinds ?? PRIORITY_ITEM_KINDS) ===
|
||||
JSON.stringify(DEFAULT_DASHBOARD_LAYOUT.enabledHeroItemKinds) &&
|
||||
(layout.hero ?? "score") === DEFAULT_DASHBOARD_LAYOUT.hero
|
||||
(layout.hero ?? "score") === DEFAULT_DASHBOARD_LAYOUT.hero &&
|
||||
layout.todayCardVisible !== false
|
||||
? t("dashboard.layoutUsingDefaults")
|
||||
: t("dashboard.layoutCustomized")}
|
||||
</p>
|
||||
|
||||
Reference in new issue
Block a user