From 0edfdd904cc8f4c3a8ae61f92e64db46d4b7b1a9 Mon Sep 17 00:00:00 2001 From: Alan Daniel Date: Sun, 12 Apr 2026 17:53:24 -0400 Subject: [PATCH] Fix dashboard tab persistence --- apps/dashboard/src/lib/tab-store.test.ts | 43 ++++++++++++++++++++++++ apps/dashboard/src/lib/tab-store.ts | 13 +++++-- 2 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 apps/dashboard/src/lib/tab-store.test.ts diff --git a/apps/dashboard/src/lib/tab-store.test.ts b/apps/dashboard/src/lib/tab-store.test.ts new file mode 100644 index 0000000..1388873 --- /dev/null +++ b/apps/dashboard/src/lib/tab-store.test.ts @@ -0,0 +1,43 @@ +// @vitest-environment jsdom + +import { afterEach, describe, expect, it } from "vitest"; +import { readStoredTabs, TABS_STORAGE_KEY, type Tab } from "./tab-store"; + +describe("readStoredTabs", () => { + afterEach(() => { + localStorage.clear(); + }); + + it("keeps persisted repo tabs", () => { + const storedTabs: Tab[] = [ + { + id: "repo:diffkit/app", + type: "repo", + title: "diffkit/app", + url: "/diffkit/app", + repo: "diffkit/app", + iconColor: "text-muted-foreground", + avatarUrl: "https://example.com/avatar.png", + }, + ]; + + localStorage.setItem(TABS_STORAGE_KEY, JSON.stringify(storedTabs)); + + expect(readStoredTabs()).toEqual(storedTabs); + }); + + it("clears storage when a tab type is unsupported", () => { + localStorage.setItem( + TABS_STORAGE_KEY, + JSON.stringify([ + { + id: "project:diffkit/app", + type: "project", + }, + ]), + ); + + expect(readStoredTabs()).toEqual([]); + expect(localStorage.getItem(TABS_STORAGE_KEY)).toBeNull(); + }); +}); diff --git a/apps/dashboard/src/lib/tab-store.ts b/apps/dashboard/src/lib/tab-store.ts index fc860ef..4d6e9b9 100644 --- a/apps/dashboard/src/lib/tab-store.ts +++ b/apps/dashboard/src/lib/tab-store.ts @@ -17,14 +17,23 @@ export interface Tab { export const TABS_STORAGE_KEY = "diffkit:tabs"; -const VALID_TAB_TYPES = new Set(["pull", "issue", "review"]); +const VALID_TAB_TYPES = { + pull: true, + issue: true, + review: true, + repo: true, +} satisfies Record; + +function isValidTabType(type: unknown): type is TabType { + return typeof type === "string" && type in VALID_TAB_TYPES; +} function isValidTab(t: unknown): t is Tab { return ( t !== null && typeof t === "object" && typeof (t as Tab).id === "string" && - VALID_TAB_TYPES.has((t as Tab).type) + isValidTabType((t as Tab).type) ); }