diff --git a/site/src/pages/AgentsPage/AgentChatPage.test.ts b/site/src/pages/AgentsPage/AgentChatPage.test.ts index 0306703fcb..21b7853879 100644 --- a/site/src/pages/AgentsPage/AgentChatPage.test.ts +++ b/site/src/pages/AgentsPage/AgentChatPage.test.ts @@ -3,14 +3,10 @@ import { createRef } from "react"; import { beforeEach, describe, expect, it, vi } from "vitest"; import type { ChatQueuedMessage } from "#/api/typesGenerated"; import { - clearPersistedSidebarTabId, draftInputStorageKeyPrefix, getPersistedDraftInputValue, - getPersistedSidebarTabId, - lastActiveSidebarTabStorageKeyPrefix, restoreOptimisticRequestSnapshot, runPromoteQueuedMessage, - savePersistedSidebarTabId, submitEditAndScroll, useConversationEditingState, waitForPendingChatSettingsSyncs, @@ -18,6 +14,12 @@ import { import type { ChatMessageInputRef } from "./components/AgentChatInput"; import { createChatStore } from "./components/ChatConversation/chatStore"; import type { PendingAttachment } from "./components/ChatPageContent"; +import { + clearPersistedSidebarTabId, + getPersistedSidebarTabId, + lastActiveSidebarTabStorageKeyPrefix, + savePersistedSidebarTabId, +} from "./utils/sidebarTabStorage"; type MockChatInputHandle = { handle: ChatMessageInputRef; diff --git a/site/src/pages/AgentsPage/AgentChatPage.tsx b/site/src/pages/AgentsPage/AgentChatPage.tsx index 5840dec74b..3e01bdb2a8 100644 --- a/site/src/pages/AgentsPage/AgentChatPage.tsx +++ b/site/src/pages/AgentsPage/AgentChatPage.tsx @@ -103,8 +103,6 @@ export const RIGHT_PANEL_OPEN_KEY = "agents.right-panel-open"; const lastModelConfigIDStorageKey = "agents.last-model-config-id"; /** @internal Exported for testing. */ export const draftInputStorageKeyPrefix = "agents.draft-input."; -/** @internal localStorage key prefix for the per-chat active sidebar tab. Exported for testing. */ -export const lastActiveSidebarTabStorageKeyPrefix = "agents.last-active-tab."; const clearChatPlanMode = "" satisfies ChatPlanModeOrClear; @@ -126,49 +124,6 @@ export function getPersistedDraftInputValue( ).text; } -/** - * Read the persisted active sidebar tab ID for a given chat. Returns - * `null` when no value is stored or the chat ID is missing. - */ -export function getPersistedSidebarTabId( - chatID: string | undefined, -): string | null { - if (!chatID) { - return null; - } - return localStorage.getItem( - `${lastActiveSidebarTabStorageKeyPrefix}${chatID}`, - ); -} - -/** - * Persist the active sidebar tab ID for a given chat so it can be - * restored across session switches. No-op when the chat ID is missing. - */ -export function savePersistedSidebarTabId( - chatID: string | undefined, - tabID: string, -): void { - if (!chatID) { - return; - } - localStorage.setItem( - `${lastActiveSidebarTabStorageKeyPrefix}${chatID}`, - tabID, - ); -} - -/** - * Remove the persisted active sidebar tab ID for a given chat. Called - * when a chat is archived so a future unarchive starts fresh. - */ -export function clearPersistedSidebarTabId(chatID: string | undefined): void { - if (!chatID) { - return; - } - localStorage.removeItem(`${lastActiveSidebarTabStorageKeyPrefix}${chatID}`); -} - /** @internal Exported for testing. */ export const restoreOptimisticRequestSnapshot = ( store: Pick< diff --git a/site/src/pages/AgentsPage/AgentChatPageView.stories.tsx b/site/src/pages/AgentsPage/AgentChatPageView.stories.tsx index 8c3f3ee7ee..0dac5029f1 100644 --- a/site/src/pages/AgentsPage/AgentChatPageView.stories.tsx +++ b/site/src/pages/AgentsPage/AgentChatPageView.stories.tsx @@ -16,7 +16,6 @@ import { withProxyProvider, withWebSocket, } from "#/testHelpers/storybook"; -import { lastActiveSidebarTabStorageKeyPrefix } from "./AgentChatPage"; import { AgentChatPageLoadingView, AgentChatPageNotFoundView, @@ -28,6 +27,7 @@ import { useChatSelector, } from "./components/ChatConversation/chatStore"; import type { ModelSelectorOption } from "./components/ChatElements"; +import { lastActiveSidebarTabStorageKeyPrefix } from "./utils/sidebarTabStorage"; import type { ChatDetailError } from "./utils/usageLimitMessage"; // --------------------------------------------------------------------------- diff --git a/site/src/pages/AgentsPage/AgentChatPageView.tsx b/site/src/pages/AgentsPage/AgentChatPageView.tsx index 69dc835df5..ca8c2dbce9 100644 --- a/site/src/pages/AgentsPage/AgentChatPageView.tsx +++ b/site/src/pages/AgentsPage/AgentChatPageView.tsx @@ -18,10 +18,6 @@ import type { } from "#/api/typesGenerated"; import { cn } from "#/utils/cn"; import { pageTitle } from "#/utils/page"; -import { - getPersistedSidebarTabId, - savePersistedSidebarTabId, -} from "./AgentChatPage"; import { AgentChatInput, type ChatMessageInputRef, @@ -46,6 +42,10 @@ import { getWorkspaceStatus, StatusIcon } from "./components/StatusIcon"; import { TerminalPanel } from "./components/TerminalPanel"; import { ChatWorkspaceContext } from "./context/ChatWorkspaceContext"; import { chatWidthClass, useChatFullWidth } from "./hooks/useChatFullWidth"; +import { + getPersistedSidebarTabId, + savePersistedSidebarTabId, +} from "./utils/sidebarTabStorage"; import type { ChatDetailError } from "./utils/usageLimitMessage"; type ChatStoreHandle = ReturnType["store"]; diff --git a/site/src/pages/AgentsPage/AgentsPage.tsx b/site/src/pages/AgentsPage/AgentsPage.tsx index aa3ce27ab7..c8562c664f 100644 --- a/site/src/pages/AgentsPage/AgentsPage.tsx +++ b/site/src/pages/AgentsPage/AgentsPage.tsx @@ -40,7 +40,6 @@ import { ConfirmDialog } from "#/components/Dialogs/ConfirmDialog/ConfirmDialog" import { DeleteDialog } from "#/components/Dialogs/DeleteDialog/DeleteDialog"; import { useAuthenticated } from "#/hooks/useAuthenticated"; import { createReconnectingWebSocket } from "#/utils/reconnectingWebSocket"; -import { clearPersistedSidebarTabId } from "./AgentChatPage"; import { AgentsPageView } from "./AgentsPageView"; import { emptyInputStorageKey } from "./components/AgentCreateForm"; import { useAgentsPageKeybindings } from "./hooks/useAgentsPageKeybindings"; @@ -53,6 +52,7 @@ import { } from "./utils/agentWorkspaceUtils"; import { maybePlayChime } from "./utils/chime"; import { getModelOptionsFromConfigs } from "./utils/modelOptions"; +import { clearPersistedSidebarTabId } from "./utils/sidebarTabStorage"; import { type ChatDetailError, chatDetailErrorsEqual, diff --git a/site/src/pages/AgentsPage/utils/sidebarTabStorage.ts b/site/src/pages/AgentsPage/utils/sidebarTabStorage.ts new file mode 100644 index 0000000000..76a00f00de --- /dev/null +++ b/site/src/pages/AgentsPage/utils/sidebarTabStorage.ts @@ -0,0 +1,32 @@ +export const lastActiveSidebarTabStorageKeyPrefix = "agents.last-active-tab."; + +export function getPersistedSidebarTabId( + chatID: string | undefined, +): string | null { + if (!chatID) { + return null; + } + return localStorage.getItem( + `${lastActiveSidebarTabStorageKeyPrefix}${chatID}`, + ); +} + +export function savePersistedSidebarTabId( + chatID: string | undefined, + tabID: string, +): void { + if (!chatID) { + return; + } + localStorage.setItem( + `${lastActiveSidebarTabStorageKeyPrefix}${chatID}`, + tabID, + ); +} + +export function clearPersistedSidebarTabId(chatID: string | undefined): void { + if (!chatID) { + return; + } + localStorage.removeItem(`${lastActiveSidebarTabStorageKeyPrefix}${chatID}`); +}