Skip to content

Commit df8d6f7

Browse files
committed
fix(app-shell): a phone sheet open on arrival at the AI inquiry page closes; pin the ConsoleLayout wiring
Claude-Session: https://claude.ai/code/session_016WV4czF5gqc48r9LUsmRpw Co-authored-by: Claude <noreply@anthropic.com>
1 parent fba5d1b commit df8d6f7

4 files changed

Lines changed: 152 additions & 4 deletions

File tree

‎.changeset/37788-app-ai-inquiry-page.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ feat(app-shell): an app's AI inquiry page — the `ai:chat` menu entry opens a h
88
Clause-②: no
99
Metadata-protocol: none
1010

11-
An app can now put the platform's AI inquiry page on its menu, as ui ADR-0057 Amendment A4 records: a `type: 'component'` navigation entry with `componentRef: 'ai:chat'`. Placed first, it is the app's home. Before, that entry drew "Component not registered".
11+
An app can now put the platform's AI inquiry page on its menu, as ui ADR-0057 Amendment A4 records: a `type: 'component'` navigation entry with `componentRef: 'ai:chat'`. It is the app's home by the app's existing landing rule: a declared `landing` comes first; with none, from 768 px up the first entry shown lands, so an entry placed first is the home; below 768 px the app root is the app's menu, and the page is one row of it. Before, that entry drew "Component not registered".
1212

1313
- **Home state.** The entry's `params` (`AiChatNavParamsSchema`, `@objectstack/spec/ui`) give the welcome title and subtitle, the question box's placeholder and up to four suggested questions; a key the entry omits falls back to neutral platform copy, and nothing is read from the URL. A static badge says answers prefer this app's data. Clicking a suggestion asks it.
1414
- **Conversation.** The first question turns the same page into the conversation, with the platform `ask` agent (a maker gets `ask` here too), bound to the app's package (`context.activeApp`) under the conversation key `app:PKG:ask`. The conversation create sends `metadata: { activePackageId: PKG }`, and the page's address carries `?c=ID` from then on, so a reload restores it. A `?c=` that names a conversation that is not the caller's, or that this app's page did not create, opens the home state: no error, and nothing of it is shown. "New conversation" returns to the home state.
15-
- **No second conversation on the page.** While the page is the active route the assistant drawer is closed, the top-bar robot is not drawn, and Ctrl/Cmd+Shift+I opens nothing; a build hand-off from the page still opens the drawer. On every other page the drawer is as the user left it.
15+
- **No second conversation on the page.** While the page is the active route the assistant drawer is closed, the top-bar robot is not drawn, and Ctrl/Cmd+Shift+I opens nothing; a build hand-off from the page still opens the drawer. On every other page the desktop drawer is as the user left it; a phone's sheet, which already closes when the user moves to another page, stays closed after the page.
1616
- **No AI for this person** (no AI on the deployment, or no seat): the page shows the existing "AI assistant unavailable" state.
1717
- `useChatConversation` takes an optional `createMetadata`, the `metadata` its first-send create carries; every other caller still sends an empty body.
1818
- `@object-ui/i18n`: one new string, `console.ai.askPage.scopeBadge`, in every locale.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#37788 (ui ADR-0057 Amendment A4) — on an app's AI inquiry page
5+
* (`ai:chat`) the drawer is closed and the assistant's standing entry is not
6+
* drawn; on every other page both are as the user left them.
7+
*
8+
* The dock hook's own cases (`useConsoleChatDock.phoneCollapseOnNavigate-37556`)
9+
* tell the hook the route themselves; this file pins the one place the console
10+
* tells it: `ConsoleLayout` reading the address.
11+
*
12+
* ## Real subjects
13+
*
14+
* `ConsoleLayout` with its real `AppShell`, the real `useConsoleChatDock`
15+
* host, the real `useChatDockState` and the real `AssistantTopBarButton`,
16+
* drawn in the page as the page header's button group draws it from 768 px up.
17+
* The rail body is a stand-in: which chrome mounts is the subject here.
18+
*/
19+
20+
import '@testing-library/jest-dom/vitest';
21+
// The layout reaches `import('@objectstack/lint')` (the draft bar's publish
22+
// preflight); pay its first load at collection, never inside a clocked case.
23+
import '@objectstack/lint';
24+
// AiChatPage reads a dropped spreadsheet through `import('@object-ui/plugin-grid')`; load it
25+
// here so collection pays that transform, not a clocked case (check-test-source-alias).
26+
import '@object-ui/plugin-grid';
27+
import { describe, it, expect, vi, afterEach } from 'vitest';
28+
import React from 'react';
29+
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
30+
import { MemoryRouter, useNavigate } from 'react-router-dom';
31+
32+
vi.mock('@object-ui/i18n', async (importOriginal) => ({
33+
...(await importOriginal<Record<string, unknown>>()),
34+
useObjectTranslation: () => ({
35+
t: (key: string, options?: Record<string, unknown>) => String(options?.defaultValue ?? key),
36+
language: 'en',
37+
}),
38+
}));
39+
40+
vi.mock('../ChatDock', async (importOriginal) => ({
41+
...(await importOriginal<Record<string, unknown>>()),
42+
ChatDockPanel: () => <aside data-testid="chat-dock-panel" />,
43+
ChatDockMobileSheet: () => null,
44+
}));
45+
46+
vi.mock('../../hooks/useAiSurface', () => ({
47+
useAiSurfaceEnabled: () => ({ enabled: true, isLoading: false }),
48+
}));
49+
50+
// Chrome this card does not touch.
51+
vi.mock('../UnifiedSidebar', () => ({ UnifiedSidebar: () => null }));
52+
vi.mock('../AppHeader', () => ({ AppHeader: () => <div data-testid="app-header-stub" /> }));
53+
vi.mock('../ConsoleNotificationBanners', () => ({ ConsoleNotificationBanners: () => null }));
54+
vi.mock('../../preview/DraftPreviewBar', () => ({ DraftPreviewBar: () => null }));
55+
vi.mock('../../preview/UnpublishedAppBar', () => ({ UnpublishedAppBar: () => null }));
56+
57+
import { ConsoleLayout } from '../ConsoleLayout';
58+
import { AssistantTopBarButton } from '../AssistantTopBarButton';
59+
import { NavigationProvider } from '../../context/NavigationContext';
60+
61+
const APP = { name: 'crm', label: 'CRM', active: true, navigation: [] };
62+
const LIST = '/apps/crm/opportunity';
63+
const ASK_PAGE = '/apps/crm/component/ai/chat';
64+
65+
function Links() {
66+
const navigate = useNavigate();
67+
return (
68+
<>
69+
<button data-testid="to-ask-page" onClick={() => navigate(ASK_PAGE)} />
70+
<button data-testid="to-list" onClick={() => navigate(LIST)} />
71+
</>
72+
);
73+
}
74+
75+
function mountConsole(entry: string) {
76+
return render(
77+
<MemoryRouter initialEntries={[entry]}>
78+
<NavigationProvider>
79+
<ConsoleLayout activeAppName="crm" activeApp={APP} onAppChange={vi.fn()} objects={[]}>
80+
<AssistantTopBarButton />
81+
<Links />
82+
</ConsoleLayout>
83+
</NavigationProvider>
84+
</MemoryRouter>,
85+
);
86+
}
87+
88+
const robot = () => screen.queryByTestId('topbar-ai-assistant');
89+
const rail = () => screen.queryByTestId('chat-dock-panel');
90+
91+
afterEach(() => {
92+
cleanup();
93+
window.sessionStorage.clear();
94+
window.localStorage.clear();
95+
});
96+
97+
describe('ConsoleLayout tells the drawer it is on the AI inquiry page (objectstack#37788)', () => {
98+
it('on the ai:chat route the entry is not drawn; on another route it is back', () => {
99+
mountConsole(ASK_PAGE);
100+
expect(robot()).not.toBeInTheDocument();
101+
102+
fireEvent.click(screen.getByTestId('to-list'));
103+
expect(robot()).toBeInTheDocument();
104+
});
105+
106+
it('a drawer open on another page is closed on the ai:chat route and comes back after it', () => {
107+
mountConsole(LIST);
108+
fireEvent.click(robot()!);
109+
expect(rail()).toBeInTheDocument();
110+
111+
fireEvent.click(screen.getByTestId('to-ask-page'));
112+
expect(rail()).not.toBeInTheDocument();
113+
114+
fireEvent.click(screen.getByTestId('to-list'));
115+
expect(rail()).toBeInTheDocument();
116+
});
117+
});

‎ui/packages/app-shell/src/layout/__tests__/useConsoleChatDock.phoneCollapseOnNavigate-37556.test.tsx‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ const LIST_PAGE = '/apps/crm/account';
313313
function AskPageHost() {
314314
const location = useLocation();
315315
const navigate = useNavigate();
316-
const { control, rail } = useConsoleChatDock({
316+
const { control, rail, sheet } = useConsoleChatDock({
317317
enabled: true,
318318
appPackageId: 'crm',
319319
askPageActive: isAppAskPagePath(location.pathname),
@@ -327,6 +327,7 @@ function AskPageHost() {
327327
<button data-testid="to-ask-page" onClick={() => navigate(ASK_PAGE)} />
328328
<button data-testid="to-list" onClick={() => navigate(LIST_PAGE)} />
329329
{rail}
330+
{sheet}
330331
</ChatDockControlProvider>
331332
);
332333
}
@@ -386,6 +387,26 @@ describe('the AI inquiry page holds the one ask conversation on its screen (obje
386387
expect(rail()).toBeInTheDocument();
387388
});
388389

390+
it('on a phone, a sheet open on arrival is closed by the page and stays closed on the next page (objectstack#37556 kept)', () => {
391+
setWidth(375);
392+
mountAskPageHost(LIST_PAGE);
393+
click('open-ask');
394+
expect(sheet()).toHaveAttribute('data-open', 'true');
395+
396+
click('to-ask-page');
397+
expect(sheet()).toHaveAttribute('data-open', 'false');
398+
399+
click('to-list');
400+
expect(sheet()).toHaveAttribute('data-open', 'false');
401+
});
402+
403+
it('on a phone, a build hand-off from the page still opens the sheet', () => {
404+
setWidth(375);
405+
mountAskPageHost(ASK_PAGE);
406+
click('open-build');
407+
expect(sheet()).toHaveAttribute('data-open', 'true');
408+
});
409+
389410
it('a build hand-off from the page still opens the drawer', () => {
390411
setWidth(1024);
391412
mountAskPageHost(ASK_PAGE);

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,16 @@ export function useConsoleChatDock({
254254
}
255255
// A phone host's first render: `isMobile` is not measured yet.
256256
if (!isMobile) return;
257+
// ui ADR-0057 Amendment A4 — arriving on the AI inquiry page with the
258+
// sheet stored open closes it: the page hides it, and a phone sheet
259+
// closes on any move away anyway (above), so the next page must not
260+
// bring it back over itself. The desktop rail keeps its stored state.
261+
if (askPageActive && storedExpanded && !expanded) {
262+
movedAwayRef.current = false;
263+
writeSheetShownAt(null);
264+
collapse();
265+
return;
266+
}
257267
if (!expanded) {
258268
movedAwayRef.current = false;
259269
writeSheetShownAt(null);
@@ -266,7 +276,7 @@ export function useConsoleChatDock({
266276
return;
267277
}
268278
writeSheetShownAt(location.key);
269-
}, [enabled, isMobile, expanded, location.key, navigationType, collapse]);
279+
}, [enabled, isMobile, expanded, storedExpanded, askPageActive, location.key, navigationType, collapse]);
270280

271281
// A designer surface can ask the assistant to open through the assistant bus
272282
// (e.g. an "Ask AI" button).

0 commit comments

Comments
 (0)