Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ type ChatActionsMenuItemsProps = {
/** See {@link canManageChat}. When false, only the subagents toggle renders. */
readonly canManage: boolean;
readonly hasWorkspace: boolean;
readonly isArchiving?: boolean;
readonly isArchiveBlocked?: boolean;
readonly isArchiving: boolean;
readonly isArchiveBlocked: boolean;
readonly subagentCount?: number;
readonly isSubagentsExpanded?: boolean;
readonly onToggleSubagents?: () => void;
Expand All @@ -111,8 +111,8 @@ export const ChatActionsMenuItems: React.FC<ChatActionsMenuItemsProps> = ({
chat,
canManage,
hasWorkspace,
isArchiving = false,
isArchiveBlocked = false,
isArchiving,
isArchiveBlocked,
subagentCount = 0,
isSubagentsExpanded = false,
onToggleSubagents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ const meta: Meta<typeof ChatSummary> = {
createdAt: "2024-05-01T12:00:00Z",
updatedAt: "2024-05-02T15:30:00Z",
costMicros: 1_250_000,
isCostLoading: false,
costError: false,
showCost: true,
isSubagent: false,
},
decorators: [
(Story) => (
Expand Down
6 changes: 3 additions & 3 deletions site/src/pages/AgentsPage/components/ChatSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ type ChatSummaryProps = {
updatedAt: string;
/** Cost of the whole chat tree in microdollars (1 USD = 1,000,000). */
costMicros?: number | null;
isCostLoading?: boolean;
costError?: boolean;
isCostLoading: boolean;
costError: boolean;
/** Requests with usage the gateway could not price, so the reported cost is partial. */
unpricedRequestCount?: number;
showCost: boolean;
/** Subagent summaries are the agent's final report, persisted when it completes, so the empty state reads as pending rather than absent. */
isSubagent?: boolean;
isSubagent: boolean;
};

export const ChatSummary: React.FC<ChatSummaryProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,64 @@ const settingsRouting = [
...{ path: string; useStoryElement: boolean }[],
];

// The layout owns the rename dialog state in production; mirror that so
// opening "Rename chat" from the menu shows the dialog.
const ChatsSidebarWithRenameState = (
args: React.ComponentProps<typeof ChatsSidebar>,
) => {
const [chatPendingRename, setChatPendingRename] = useState(
args.chatPendingRename,
);
return (
<ChatsSidebar
{...args}
chatPendingRename={chatPendingRename}
onChatPendingRenameChange={(chat) => {
setChatPendingRename(chat);
args.onChatPendingRenameChange(chat);
}}
/>
);
};

const meta: Meta<typeof ChatsSidebar> = {
title: "pages/AgentsPage/ChatsSidebar",
component: ChatsSidebar,
decorators: [withAuthProvider, withDashboardProvider],
args: {
chatErrorReasons: {},
modelConfigs: defaultModelConfigs,
isLoadingModelConfigs: false,
onArchiveAgent: fn(),
onUnarchiveAgent: fn(),
onArchiveAndDeleteWorkspace: fn(),
onPinAgent: fn(),
onUnpinAgent: fn(),
onMarkChatRead: fn(),
onMarkChatUnread: fn(),
onReorderPinnedAgent: fn(),
onRenameTitle: fn(() => Promise.resolve()),
onProposeTitle: fn(async () => "Generated title"),
chatPendingRename: null,
onChatPendingRenameChange: fn(),
onBeforeNewAgent: fn(),
isSearchDialogOpen: false,
onSearchDialogOpenChange: fn(),
isCreating: false,
isArchiving: false,
isLoading: false,
onRetryLoad: fn(),
hasNextPage: false,
onLoadMore: fn(),
isFetchingNextPage: false,
onCollapse: fn(),
canManageAgentSettings: false,
currentUserId: MockUserOwner.id,
sidebarFilters: defaultSidebarFilters,
isPersonalModelOverridesEnabled: true,
onSidebarFiltersChange: fn(),
},
render: (args) => <ChatsSidebarWithRenameState {...args} />,
parameters: {
layout: "fullscreen",
user: MockUserOwner,
Expand All @@ -132,12 +166,12 @@ const ChatsSidebarWithKeybindings = (
};

useAgentsPageKeybindings({
onNewAgent: args.onBeforeNewAgent ?? (() => {}),
onNewAgent: args.onBeforeNewAgent,
onToggleSearch: () => handleSearchDialogOpenChange(!isSearchDialogOpen),
});

return (
<ChatsSidebar
<ChatsSidebarWithRenameState
{...args}
isSearchDialogOpen={isSearchDialogOpen}
onSearchDialogOpenChange={handleSearchDialogOpenChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,33 @@ const defaultProps: React.ComponentProps<typeof ChatsSidebar> = {
chats: [buildChat({ id: "chat-1", title: "Chat One" })],
chatErrorReasons: {},
modelConfigs: [],
isLoadingModelConfigs: false,
onArchiveAgent: vi.fn(),
onUnarchiveAgent: vi.fn(),
onArchiveAndDeleteWorkspace: vi.fn(),
onPinAgent: vi.fn(),
onUnpinAgent: vi.fn(),
onMarkChatRead: vi.fn(),
onMarkChatUnread: vi.fn(),
onReorderPinnedAgent: vi.fn(),
onRenameTitle: vi.fn(async () => {}),
onProposeTitle: vi.fn(async () => "Proposed title"),
chatPendingRename: null,
onChatPendingRenameChange: vi.fn(),
onBeforeNewAgent: vi.fn(),
isSearchDialogOpen: false,
onSearchDialogOpenChange: vi.fn(),
isCreating: false,
isArchiving: false,
isLoading: false,
onRetryLoad: vi.fn(),
hasNextPage: false,
onLoadMore: vi.fn(),
isFetchingNextPage: false,
sidebarFilters: defaultSidebarFilters,
onSidebarFiltersChange: vi.fn(),
onCollapse: vi.fn(),
canManageAgentSettings: false,
currentUserId: MockUserOwner.id,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useState } from "react";
import { useQuery } from "react-query";
import { useLocation, useParams } from "react-router";
import { userChatProviderConfigs } from "#/api/queries/chats";
Expand All @@ -17,48 +16,46 @@ type ChatsSidebarProps = {
chats: readonly Chat[];
chatErrorReasons: Record<string, string>;
modelConfigs: readonly ChatModel[];
isLoadingModelConfigs?: boolean;
isLoadingModelConfigs: boolean;
onArchiveAgent: (chatId: string) => void;
onUnarchiveAgent: (chatId: string) => void;
onArchiveAndDeleteWorkspace: (chatId: string, workspaceId: string) => void;
onPinAgent: (chatId: string) => void;
onUnpinAgent: (chatId: string) => void;
onMarkChatRead: (chatId: string) => void;
onMarkChatUnread: (chatId: string) => void;
onReorderPinnedAgent?: (chatId: string, pinOrder: number) => void;
onRenameTitle?: (chatId: string, title: string) => Promise<void>;
onProposeTitle?: (chatId: string) => Promise<string>;
onReorderPinnedAgent: (chatId: string, pinOrder: number) => void;
onRenameTitle: (chatId: string, title: string) => Promise<void>;
onProposeTitle: (chatId: string) => Promise<string>;
/**
* Controlled value for the rename-chat dialog. When provided alongside
* `onChatPendingRenameChange`, the dialog is opened by the parent so
* the chat top bar and the sidebar share a single dialog instance.
* Falls back to internal state when omitted.
* Chat shown in the rename-chat dialog. Owned by the parent so the chat
* top bar and the sidebar share a single dialog instance.
*/
chatPendingRename?: Chat | null;
onChatPendingRenameChange?: (chat: Chat | null) => void;
onBeforeNewAgent?: () => void;
chatPendingRename: Chat | null;
onChatPendingRenameChange: (chat: Chat | null) => void;
onBeforeNewAgent: () => void;
isSearchDialogOpen: boolean;
onSearchDialogOpenChange: (open: boolean) => void;
isCreating: boolean;
isArchiving?: boolean;
isArchiving: boolean;
archivingChatId?: string | null;
isLoading?: boolean;
isLoading: boolean;
loadError?: unknown;
onRetryLoad?: () => void;
hasNextPage?: boolean;
onLoadMore?: () => void;
isFetchingNextPage?: boolean;
onRetryLoad: () => void;
hasNextPage: boolean;
onLoadMore: () => void;
isFetchingNextPage: boolean;
sidebarFilters: AgentSidebarFilters;
onSidebarFiltersChange: (filters: AgentSidebarFilters) => void;
onCollapse?: () => void;
onCollapse: () => void;
isPersonalModelOverridesEnabled?: boolean;
isAdmin?: boolean;
/**
* Whether the user can open the Coder Agents settings page. Broader
* than isAdmin: organization model admins qualify without deployment
* config access.
*/
canManageAgentSettings?: boolean;
canManageAgentSettings: boolean;
currentUserId: string;
};

Expand All @@ -67,7 +64,7 @@ export const ChatsSidebar: React.FC<ChatsSidebarProps> = (props) => {
chats,
chatErrorReasons,
modelConfigs,
isLoadingModelConfigs = false,
isLoadingModelConfigs,
onArchiveAgent,
onUnarchiveAgent,
onArchiveAndDeleteWorkspace,
Expand All @@ -78,15 +75,15 @@ export const ChatsSidebar: React.FC<ChatsSidebarProps> = (props) => {
onReorderPinnedAgent,
onRenameTitle,
onProposeTitle,
chatPendingRename: chatPendingRenameProp,
chatPendingRename,
onChatPendingRenameChange,
onBeforeNewAgent,
isSearchDialogOpen,
onSearchDialogOpenChange,
isCreating,
isArchiving = false,
isArchiving,
archivingChatId = null,
isLoading = false,
isLoading,
loadError,
onRetryLoad,
hasNextPage,
Expand All @@ -97,7 +94,7 @@ export const ChatsSidebar: React.FC<ChatsSidebarProps> = (props) => {
onCollapse,
isPersonalModelOverridesEnabled = false,
isAdmin = false,
canManageAgentSettings = false,
canManageAgentSettings,
currentUserId,
} = props;
const { agentId, chatId } = useParams<{
Expand All @@ -116,19 +113,6 @@ export const ChatsSidebar: React.FC<ChatsSidebarProps> = (props) => {
const isApiKeysSection = isSettingsPanel && settingsSection === "api-keys";
const showApiKeysItem =
isAdmin || isApiKeysSection || Boolean(providerConfigsQuery.data?.length);
const [internalChatPendingRename, setInternalChatPendingRename] =
useState<Chat | null>(null);
const isControlled = chatPendingRenameProp !== undefined;
const chatPendingRename = isControlled
? chatPendingRenameProp
: internalChatPendingRename;
const setChatPendingRename = (chat: Chat | null) => {
if (isControlled) {
onChatPendingRenameChange?.(chat);
} else {
setInternalChatPendingRename(chat);
}
};

return (
<div className="relative flex size-full min-h-0 border-0 border-r border-solid overflow-hidden">
Expand All @@ -147,7 +131,7 @@ export const ChatsSidebar: React.FC<ChatsSidebarProps> = (props) => {
onReorderPinnedAgent={onReorderPinnedAgent}
onBeforeNewAgent={onBeforeNewAgent}
onOpenSearchDialog={() => onSearchDialogOpenChange(true)}
onOpenRenameDialog={onRenameTitle ? setChatPendingRename : undefined}
onOpenRenameDialog={onChatPendingRenameChange}
isCreating={isCreating}
isArchiving={isArchiving}
archivingChatId={archivingChatId}
Expand Down Expand Up @@ -185,16 +169,14 @@ export const ChatsSidebar: React.FC<ChatsSidebarProps> = (props) => {
location={location}
recentChats={chats}
/>
{onRenameTitle && (
<RenameChatDialog
chat={chatPendingRename}
onRename={onRenameTitle}
onPropose={onProposeTitle}
onOpenChange={(open: boolean) => {
if (!open) setChatPendingRename(null);
}}
/>
)}
<RenameChatDialog
chat={chatPendingRename}
onRename={onRenameTitle}
onPropose={onProposeTitle}
onOpenChange={(open: boolean) => {
if (!open) onChatPendingRenameChange(null);
}}
/>
</div>
);
};
Loading
Loading