Skip to content

Commit 3346393

Browse files
committed
feat(app-shell): the drawer header's star favourites the conversation in view
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibxdwshRvTk3qXc7A6A
1 parent 8aa3720 commit 3346393

5 files changed

Lines changed: 300 additions & 4 deletions

File tree

‎.changeset/37863-favourite-conversations.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
'@object-ui/i18n': patch
44
---
55

6-
feat(app-shell): favourite conversations open in the assistant drawer in place, from the sidebar's Favorites
6+
feat(app-shell): the assistant drawer's ☆ favourites a conversation, and the sidebar's Favorites open it in the drawer in place
77

88
Clause-②: no
99
Metadata-protocol: none
1010

11+
- **The drawer header's ☆.** Once the first message has created the conversation, the header's ☆ (before +) adds it to the user's favourites, and is pressed while it is one; pressed again, it removes it. It is drawn in the side panel, the full window and the phone sheet. While the conversation is a favourite, its stored label follows the header's title.
1112
- **A conversation can be a favourite.** `FavoriteItem` gains the `conversation` type, id `conversation:ID`, with the conversation's id and agent (`conversationId`, `agent`); its `href` is the conversation's `/ai…` address. Conversation favourites count against the same cap of 20 as the other content favourites.
1213
- **The sidebar row opens the drawer in place.** A favourite conversation is a row of the sidebar's Favorites section, with the chat-bubble icon. Clicking it opens the assistant drawer on that conversation, the way its history row does, and the page stays where it is. The address is followed only where no drawer can take it: a page without the drawer, the app's AI inquiry page, or a click that opens a new tab.
1314
- **The label follows the conversation.** The sidebar reads each favourite conversation once and keeps the label its history row shows (the server's title, else the latest message the user wrote).

‎ui/packages/app-shell/src/layout/ChatDock.tsx‎

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
SheetHeader,
4040
SheetTitle,
4141
} from '@object-ui/components';
42-
import { History, Maximize2, MessagesSquare, Minimize2, MoreHorizontal, Plus, Share2, X } from 'lucide-react';
42+
import { History, Maximize2, MessagesSquare, Minimize2, MoreHorizontal, Plus, Share2, Star, X } from 'lucide-react';
4343
import { formatNumber, useObjectTranslation } from '@object-ui/i18n';
4444
import { useAgents } from '@object-ui/plugin-chatbot/core';
4545
import { resolveApiBase } from '../console/ai/resolveApiBase.js';
@@ -48,6 +48,8 @@ import { useAiUsage } from '../hooks/useAiUsage.js';
4848
import { cloudConsoleUrl } from '../console/marketplace/marketplaceApi.js';
4949
import { getUpgradeUrl } from '../runtime-config.js';
5050
import { usePlanApprovalPending } from '../assistant/assistantBus.js';
51+
import { useFavorites } from '../context/FavoritesProvider.js';
52+
import { conversationFavoriteId, conversationFavoriteItem } from './conversationFavorites.js';
5153
import type { ChatSurfaceContext } from './chatSurfaceContext.js';
5254
import {
5355
readStoredDockFullWindow,
@@ -394,7 +396,64 @@ interface DockHeaderButtonsProps {
394396
}
395397

396398
/**
397-
* ui ADR-0057 Amendment A5 — the header's + and history buttons, as icons:
399+
* objectstack#37863 — the header's ☆: adds the thread in view to the user's
400+
* favourites, or removes it (pressed while it is one). Drawn once the first
401+
* send has created the thread. While it is a favourite, the stored label
402+
* follows the label the header reads.
403+
*/
404+
function DockFavoriteButton({
405+
actions,
406+
box,
407+
icon,
408+
testId,
409+
}: {
410+
actions: ChatDockConversationActions;
411+
box: string;
412+
icon: string;
413+
testId: string;
414+
}) {
415+
const { t } = useObjectTranslation();
416+
const { isFavorite, toggleFavorite, refreshLabel } = useFavorites();
417+
const conversationId = actions.conversationId as string;
418+
const id = conversationFavoriteId(conversationId);
419+
const starred = isFavorite(id);
420+
const label = actions.labelPending ? undefined : actions.label;
421+
const refreshLabelRef = React.useRef(refreshLabel);
422+
React.useLayoutEffect(() => {
423+
refreshLabelRef.current = refreshLabel;
424+
});
425+
React.useEffect(() => {
426+
if (starred && label) refreshLabelRef.current(id, label);
427+
}, [starred, id, label]);
428+
const name = starred
429+
? t('common.removeFromFavorites', { defaultValue: 'Remove from favorites' })
430+
: t('common.addToFavorites', { defaultValue: 'Add to favorites' });
431+
return (
432+
<Button
433+
variant="ghost"
434+
size="icon"
435+
className={cn(box, 'text-muted-foreground hover:text-foreground', starred && 'text-amber-500 hover:text-amber-600')}
436+
onClick={() =>
437+
toggleFavorite(
438+
conversationFavoriteItem({
439+
conversationId,
440+
agent: actions.agent as string,
441+
label: label ?? t('console.ai.newConversation', { defaultValue: 'New conversation' }),
442+
}),
443+
)
444+
}
445+
aria-pressed={starred}
446+
aria-label={name}
447+
title={name}
448+
data-testid={testId}
449+
>
450+
<Star className={cn(icon, starred && 'fill-current')} />
451+
</Button>
452+
);
453+
}
454+
455+
/**
456+
* ui ADR-0057 Amendment A5 — the header's ☆ (objectstack#37863), + and history buttons, as icons:
398457
* + starts a new conversation on the agent in use, the clock shows the
399458
* history over the chat (pressed while it does) and goes back to the chat.
400459
*/
@@ -409,6 +468,14 @@ function DockHeaderButtons({ actions, history, size, onStartNew }: DockHeaderBut
409468
: t('console.ai.dock.history', { defaultValue: 'History' });
410469
return (
411470
<>
471+
{actions?.conversationId && actions.agent ? (
472+
<DockFavoriteButton
473+
actions={actions}
474+
box={box}
475+
icon={icon}
476+
testId={size === 'sheet' ? 'chat-dock-mobile-favorite' : 'chat-dock-favorite'}
477+
/>
478+
) : null}
412479
{startNew ? (
413480
<Button
414481
variant="ghost"

‎ui/packages/app-shell/src/layout/ChatDockConversation.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,10 @@ export function ChatDockConversation({
337337
label: paneConversationId ? headerLabel : undefined,
338338
labelPending,
339339
startNew,
340+
agent: activeAgentRoute,
340341
},
341342
);
342-
}, [onActionsChange, inert, conversationId, paneConversationId, headerLabel, labelPending, startNew]);
343+
}, [onActionsChange, inert, conversationId, paneConversationId, headerLabel, labelPending, startNew, activeAgentRoute]);
343344

344345
// OSS / no AI seat → the whole dock body is inert (the robot is gated too).
345346
if (inert) return null;
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* objectstack#37863 — the drawer header's ☆ (ui ADR-0057 Amendment A5's
6+
* header: title, ☆, +, history, ⋯, ×).
7+
*
8+
* - Once the first send has created the thread, the header draws ☆ first
9+
* among its buttons, in the rail, the full window and the phone sheet.
10+
* Before it, there is nothing to keep and no ☆.
11+
* - ☆ adds the thread to the user's favourites as a `conversation` favourite
12+
* (its id, its agent by route name, the header's label, its `/ai…` address)
13+
* and is pressed while it is one; pressed again, it removes it.
14+
* - While the thread is a favourite, the stored label follows the label the
15+
* header reads; a label still being read writes nothing, and a thread that
16+
* is not a favourite is written nowhere.
17+
*
18+
* Harness: the chrome stand-ins of `ChatDock.test.tsx` (the default body
19+
* reports its actions and draws nothing) under the real `FavoritesProvider`,
20+
* signed out, so the store is the provider's local key.
21+
*/
22+
// AiChatPage reads a dropped spreadsheet through `import('@object-ui/plugin-grid')`; load it
23+
// here so collection pays that transform, not a clocked case (check-test-source-alias).
24+
import '@object-ui/plugin-grid';
25+
import '@testing-library/jest-dom/vitest';
26+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
27+
import { act, render, screen, fireEvent, waitFor, within } from '@testing-library/react';
28+
import React from 'react';
29+
import { ChatDockPanel, ChatDockMobileSheet, type ChatDockState } from '../ChatDock';
30+
import type { ChatDockConversationActions } from '../chatDockTarget';
31+
import { FavoritesProvider, type FavoriteItem } from '../../context/FavoritesProvider';
32+
33+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
34+
...(await importOriginal<Record<string, unknown>>()),
35+
useObjectTranslation: () => ({
36+
t: (key: string, options?: Record<string, unknown>) => String(options?.defaultValue ?? key),
37+
}),
38+
}));
39+
vi.mock('@object-ui/auth', async (importOriginal) => ({
40+
...(await importOriginal<Record<string, unknown>>()),
41+
useAuth: () => ({ user: null, activeOrganization: null }),
42+
}));
43+
vi.mock('../../console/ai/AiChatPage', () => ({
44+
ChatPane: () => null,
45+
resolveApiBase: (explicit?: string) => explicit ?? '/api/v1/ai',
46+
}));
47+
vi.mock('@object-ui/plugin-chatbot/core', async (importOriginal) => ({
48+
...(await importOriginal<typeof import('@object-ui/plugin-chatbot/core')>()),
49+
useAgents: () => ({ agents: [], isLoading: false, error: undefined }),
50+
}));
51+
vi.mock('../../hooks', () => ({
52+
useChatConversation: () => ({ conversationId: undefined, initialMessages: [] }),
53+
}));
54+
vi.mock('../../hooks/useAiUsage', () => ({
55+
useAiUsage: () => ({ usage: null, isLoading: false, error: undefined, refetch: () => {} }),
56+
}));
57+
58+
// What the default body reports to the chrome; `report` re-reports it.
59+
const bodyState: { actions: ChatDockConversationActions | undefined; report?: (a: ChatDockConversationActions | undefined) => void } = {
60+
actions: undefined,
61+
};
62+
vi.mock('../ChatDockConversation', async () => {
63+
const ReactActual = await import('react');
64+
return {
65+
ChatDockConversation: (props: { onActionsChange?: (a: unknown) => void }) => {
66+
const { onActionsChange } = props;
67+
ReactActual.useEffect(() => {
68+
bodyState.report = (a) => onActionsChange?.(a);
69+
onActionsChange?.(bodyState.actions);
70+
}, [onActionsChange]);
71+
return <div data-testid="default-dock-body" />;
72+
},
73+
};
74+
});
75+
76+
function dockState(overrides: Partial<ChatDockState> = {}): ChatDockState {
77+
return {
78+
expanded: true,
79+
width: 420,
80+
dragging: false,
81+
fullWindow: false,
82+
setFullWindow: vi.fn(),
83+
toggle: vi.fn(),
84+
expand: vi.fn(),
85+
collapse: vi.fn(),
86+
onResizePointerDown: vi.fn(),
87+
...overrides,
88+
};
89+
}
90+
91+
/** The provider's local key for a signed-out session. */
92+
const STORE_KEY = 'objectui-favorites';
93+
const stored = (): FavoriteItem[] => JSON.parse(localStorage.getItem(STORE_KEY) ?? '[]');
94+
95+
const SENT: ChatDockConversationActions = {
96+
conversationId: 'c1',
97+
showDebug: false,
98+
label: 'Quarterly revenue',
99+
startNew: () => {},
100+
agent: 'ask',
101+
};
102+
103+
function headerControls(): string[] {
104+
return Array.from(screen.getByTestId('chat-dock-header').querySelectorAll('button')).map(
105+
(b) => b.getAttribute('aria-label') ?? b.textContent ?? '',
106+
);
107+
}
108+
109+
function renderRail(overrides: Partial<ChatDockState> = {}) {
110+
return render(
111+
<FavoritesProvider>
112+
<ChatDockPanel dock={dockState(overrides)} />
113+
</FavoritesProvider>,
114+
);
115+
}
116+
117+
beforeEach(() => {
118+
localStorage.clear();
119+
});
120+
afterEach(() => {
121+
bodyState.actions = undefined;
122+
bodyState.report = undefined;
123+
});
124+
125+
describe('the drawer header ☆ (objectstack#37863)', () => {
126+
it('the rail: ☆ leads the buttons once the thread exists', async () => {
127+
bodyState.actions = SENT;
128+
renderRail();
129+
await screen.findByTestId('default-dock-body');
130+
expect(headerControls()).toEqual(['Add to favorites', 'New conversation', 'History', 'More actions', 'Close']);
131+
const star = screen.getByTestId('chat-dock-favorite');
132+
expect(star).toHaveAttribute('aria-pressed', 'false');
133+
expect(star.querySelector('svg.lucide-star')).not.toBeNull();
134+
});
135+
136+
it('before the first send there is no ☆', async () => {
137+
bodyState.actions = { showDebug: false, startNew: () => {}, agent: 'ask' };
138+
renderRail();
139+
await screen.findByTestId('default-dock-body');
140+
expect(screen.queryByTestId('chat-dock-favorite')).toBeNull();
141+
expect(headerControls()).toEqual(['New conversation', 'History', 'More actions', 'Close']);
142+
});
143+
144+
it('☆ stores the thread as a conversation favourite, pressed while it is one; pressed again, removes it', async () => {
145+
bodyState.actions = { ...SENT, agent: 'data_chat' };
146+
renderRail();
147+
await screen.findByTestId('default-dock-body');
148+
fireEvent.click(screen.getByTestId('chat-dock-favorite'));
149+
expect(stored()).toEqual([
150+
expect.objectContaining({
151+
id: 'conversation:c1',
152+
type: 'conversation',
153+
conversationId: 'c1',
154+
agent: 'ask',
155+
label: 'Quarterly revenue',
156+
href: '/ai/ask/c1',
157+
}),
158+
]);
159+
const star = screen.getByTestId('chat-dock-favorite');
160+
expect(star).toHaveAttribute('aria-pressed', 'true');
161+
expect(star).toHaveAccessibleName('Remove from favorites');
162+
163+
fireEvent.click(star);
164+
expect(stored()).toEqual([]);
165+
expect(screen.getByTestId('chat-dock-favorite')).toHaveAttribute('aria-pressed', 'false');
166+
});
167+
168+
it('starred while the label is still read, it is stored as "New conversation" and then takes the label', async () => {
169+
bodyState.actions = { ...SENT, label: undefined, labelPending: true };
170+
renderRail();
171+
await screen.findByTestId('default-dock-body');
172+
fireEvent.click(screen.getByTestId('chat-dock-favorite'));
173+
expect(stored()[0].label).toBe('New conversation');
174+
act(() => bodyState.report?.({ ...SENT, label: 'Quarterly revenue' }));
175+
await waitFor(() => expect(stored()[0].label).toBe('Quarterly revenue'));
176+
});
177+
178+
it('a favourite thread\'s stored label follows the header; a label still being read writes nothing', async () => {
179+
localStorage.setItem(
180+
STORE_KEY,
181+
JSON.stringify([
182+
{ id: 'conversation:c1', label: 'old words', href: '/ai/ask/c1', type: 'conversation', conversationId: 'c1', agent: 'ask', favoritedAt: '2026-11-27T00:00:00.000Z' },
183+
]),
184+
);
185+
bodyState.actions = { ...SENT, label: undefined, labelPending: true };
186+
renderRail();
187+
await screen.findByTestId('default-dock-body');
188+
expect(screen.getByTestId('chat-dock-favorite')).toHaveAttribute('aria-pressed', 'true');
189+
expect(stored()[0].label).toBe('old words');
190+
act(() => bodyState.report?.(SENT));
191+
await waitFor(() => expect(stored()[0].label).toBe('Quarterly revenue'));
192+
});
193+
194+
it('control: a thread that is not a favourite is written nowhere', async () => {
195+
bodyState.actions = SENT;
196+
renderRail();
197+
await screen.findByTestId('default-dock-body');
198+
act(() => bodyState.report?.({ ...SENT, label: 'Renamed' }));
199+
expect(stored()).toEqual([]);
200+
});
201+
202+
it('the full window draws ☆ too', async () => {
203+
bodyState.actions = SENT;
204+
renderRail({ fullWindow: true });
205+
await screen.findByTestId('default-dock-body');
206+
expect(headerControls()).toEqual(['Add to favorites', 'New conversation', 'More actions', 'Close']);
207+
});
208+
209+
it('the phone sheet: ☆ first, finger-sized', async () => {
210+
bodyState.actions = SENT;
211+
render(
212+
<FavoritesProvider>
213+
<ChatDockMobileSheet open onOpenChange={() => {}} />
214+
</FavoritesProvider>,
215+
);
216+
await screen.findByTestId('default-dock-body');
217+
const sheet = screen.getByTestId('chat-dock-mobile-sheet');
218+
const names = Array.from(sheet.querySelectorAll('button')).map((b) => b.getAttribute('aria-label') ?? b.textContent?.trim() ?? '');
219+
expect(names.slice(0, 4)).toEqual(['Add to favorites', 'New conversation', 'History', 'More actions']);
220+
const star = within(sheet).getByTestId('chat-dock-mobile-favorite');
221+
expect(star).toHaveClass('h-9', 'w-9');
222+
fireEvent.click(star);
223+
expect(stored().map((f) => f.id)).toEqual(['conversation:c1']);
224+
});
225+
});

‎ui/packages/app-shell/src/layout/chatDockTarget.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export interface ChatDockConversationActions {
8989
labelPending?: boolean;
9090
/** The header's +: a new conversation, on the agent in use. */
9191
startNew?: () => void;
92+
/** The agent in use, by route name: what the header's ☆ stores with the thread (objectstack#37863). */
93+
agent?: string;
9294
}
9395

9496
/**

0 commit comments

Comments
 (0)