Files
fusion/packages/dashboard/app/utils/projectStorage.ts
gsxdsm 29255a4a6a feat(FN-1276): scope dashboard persistence by project
- Add a project storage utility with scoped key helpers and key inventories for global vs project state
- Scope dashboard/task view, list preferences, quick-entry drafts, agent/tree state, terminal tabs, usage view, and modal draft persistence to projectId
- Reload persisted UI state when project context changes so per-project settings and drafts do not leak across projects
- Update and expand dashboard tests, including new projectStorage coverage and scoped persistence regression fixes
2026-04-08 10:39:38 -07:00

57 lines
1.5 KiB
TypeScript

export const GLOBAL_STORAGE_KEYS: string[] = [
"kb-dashboard-theme-mode",
"kb-dashboard-color-theme",
"kb-dashboard-view-mode",
"kb-dashboard-current-project",
"kb-dashboard-recent-projects",
];
export const PROJECT_STORAGE_KEYS: string[] = [
"kb-dashboard-task-view",
"kb-dashboard-list-columns",
"kb-dashboard-hide-done",
"kb-dashboard-list-collapsed",
"kb-dashboard-selected-tasks",
"kb-quick-entry-text",
"kb-inline-create-text",
"kb-agent-view",
"kb-agent-tree-expanded",
"kb-terminal-tabs",
"kb-planning-last-description",
"kb-subtask-last-description",
"kb-mission-last-goal",
"kb-usage-view-mode",
];
export function scopedKey(baseKey: string, projectId?: string): string {
if (typeof projectId !== "string" || projectId.length === 0) {
return baseKey;
}
return `kb:${projectId}:${baseKey}`;
}
export function getScopedItem(baseKey: string, projectId?: string): string | null {
if (typeof window === "undefined") {
return null;
}
return window.localStorage.getItem(scopedKey(baseKey, projectId));
}
export function setScopedItem(baseKey: string, value: string, projectId?: string): void {
if (typeof window === "undefined") {
return;
}
window.localStorage.setItem(scopedKey(baseKey, projectId), value);
}
export function removeScopedItem(baseKey: string, projectId?: string): void {
if (typeof window === "undefined") {
return;
}
window.localStorage.removeItem(scopedKey(baseKey, projectId));
}