Skip to content

Commit 276174a

Browse files
feat(chatbot): draw verified record citations as chips that open the cited section (#37485)
Fixes #37365 Clause-②: yes (a new reserved URL parameter `section`) Metadata-protocol: none ## 维护者速读 - 用户能看到什么变化:使用应用内 AI 的用户,在回答下方看到“引自记录”的引用条(每条显示摘句);点一条就打开那条记录,并滚到被引的那一节、高亮标出。 - 为什么做:记录 AI 问询专题的第 10b 行,让用户能从 AI 回答一键跳回原文核对。 - 出错会怎样:引用条不显示或跳到记录顶部,记录本身与数据不受影响;撤回本次合并即可恢复原样。 - 要你做什么:无。 ## What changes Governing text: ADR-0160 D9 as amended by #37363; ruling 7177410380 on #37144 (Q1 A: draw the persisted, already-verified list, never re-verify; Q3 A: a related-row quote opens the root record). - **Lift** (`plugin-chatbot/src/mapMessages.ts`): `extractRecordCitations(parts)` reads the last `data-record-citations` part (`RECORD_CITATIONS_PART_TYPE`) through the spec's `RecordCitationsSchema`. A part the schema refuses, or an empty list, is no list (the `detectAnswerSource` precedent). `uiMessageToChatMessage` carries it as `recordCitations`; `chatMessageAdapter.ts` names the new render-only key. - **Chips** (`plugin-chatbot/src/RecordCitations.tsx`, new; drawn in `ChatbotEnhanced.tsx` beside `AnswerSourceBlock`): one chip per citation showing the quote. A click calls `onOpenRecord({ objectName: object, recordId: id, anchor })`; `onOpenRecord`'s argument gains an optional `anchor`. Nothing is fetched or verified on display. - **Open** (`app-shell/src/console/ai/AiChatPage.tsx`): `openRecord` takes the optional `anchor` and navigates to `recordOpenTarget(app, …)` = `/apps/APP/OBJ/record/ID?section=ANCHOR`. The dock and the `/ai` page both draw this `ChatPane`. - **Param** (`app-shell/src/urlParams.ts`): `RECORD_SECTION_PARAM = 'section'`, in `RESERVED_URL_PARAMS` and the param table. `RECORD_SECTION_OPENED_STATE` is a history-state key, not a URL parameter (the `RECORD_COMMENTS_PUSHED_STATE` precedent). - **Record page** (`app-shell/src/views/recordSectionAnchor.ts`, new; wired in `RecordDetailView.tsx`): once the record is held, the spec's `headingsOf` runs on each long-text field (`markdown`, `html`/`richtext`, `textarea`) in field order; the first whose outline issues the anchor is the body. The heading element is found in that field's drawn face and scrolled to and marked (the linked-comment marking). The match is trusted only when the face draws exactly as many headings of that title as the outline lists. A `textarea` body, a heading that is not drawn within 4 s, a count that differs, or a heading with no letter or digit scrolls to the field. A stale anchor opens the top. The cleanup takes the mark off, so opening another section moves the mark. Each chip click carries a fresh history-state value (`RECORD_SECTION_OPENED_STATE`), so the same chip clicked again opens its section again; a navigation that keeps the state, such as a tab switch, does not. - **Field marker** (`plugin-detail/src/DetailSection.tsx`): each detail row carries `data-detail-field={field.name}`, which is how the page finds a field. One attribute, no behaviour change. - **i18n**: `chatbot.recordCitations.title` in all 11 `ui/packages/i18n` locales. - Docs: `content/docs/frontend/plugins/plugin-chatbot.mdx`, `ui/packages/plugin-chatbot/README.md`; changeset `.changeset/37365-record-citation-chips.md` (patch, four `@object-ui/*` packages). Read first, by risk: 1. `ui/packages/app-shell/src/views/recordSectionAnchor.ts`: `locateSection` (how a drawn heading is matched) and `focusRecordSection` (observer and settle timer). 2. `ui/packages/plugin-chatbot/src/mapMessages.ts`: `extractRecordCitations` (the parse gate). 3. `ui/packages/app-shell/src/views/RecordDetailView.tsx`: the effect beside `holdsRouteRecord`. ## Tests Head `c1b30e6a0b`. Every run went through `scripts/pm/os-verify-lock.sh` on a shared box. - New pins: `plugin-chatbot/src/__tests__/ChatbotEnhanced.recordCitations-37365.test.tsx` (lift through the spec schema; chips; a refused part draws nothing with a CONTROL leg; no fetch on display; related-row quote opens the root record; record-link grammar still refuses a fragment, with a CONTROL); `app-shell/src/views/recordSectionAnchor.test.tsx` (anchor derived as the server derives it; matching by reading with repeats; a same-titled heading the outline does not list, a listed heading the face does not draw, and a heading with no letter or digit each open the field, each with a CONTROL; textarea opens at the field; a heading never drawn settles on the field; stale anchor moves nothing, with a CONTROL; the cleanup unmarks, keeping a class the heading already had; the same section opened again scrolls and marks again); `app-shell/src/views/RecordDetailView.citedSection-37365.test.tsx` (the REAL `RecordDetailView` and the real markdown face: `?section=scope` marks and scrolls the first Scope, `scope-2` the second, a textarea body scrolls to the field, a stale anchor opens the top with a CONTROL, a setext `Scope` above the cited `# Scope` opens the field with a CONTROL, a second chip moves the mark and the same chip again scrolls again, CONTROL a state-keeping replace does not); a new describe in `AiChatPage.recordLink-13037.test.tsx` (the real `ChatPane`: the chip opens `/apps/APP/OBJ/record/ID?section=scope` under a `/_console` and a root mount; each click carries a fresh opened-state value; a related-row quote opens the root record with no section). <details><summary>Whole suites of the four touched packages, at c1b30e6</summary> - `@object-ui/plugin-chatbot`: `Test Files 104 passed (104) · Tests 1089 passed (1089)` - `@object-ui/i18n`: `Test Files 111 passed (111) · Tests 2028 passed | 13 skipped (2041)` - `@object-ui/plugin-detail`: `Test Files 419 passed | 1 skipped (420) · Tests 3968 passed | 18 skipped (3986)` - `@object-ui/app-shell`: `Test Files 2437 passed | 1 skipped (2438) · Tests 23428 passed | 9 skipped (23437)` - All four ran in one lock hold: `VERDICT command-exit 0`, each package exit 0. - `type-check`: app-shell exit 0 at `c1b30e6a0b`. plugin-chatbot, plugin-detail and i18n exit 0 at `60981028c`; this round changes no source of theirs. - Derived gate families: 73 derived, 73 run, every one recorded `exit 0` (`dispatch-gates --ran`: "a DERIVED zero"), `check:type-check-debt` included. </details> <details><summary>Ablation of the parse gate (round 1, at 6098102)</summary> `node scripts/ablation-replace.mjs` replaced the `RecordCitationsSchema.safeParse` lines in `extractRecordCitations` with a bare `Array.isArray` pass-through (anchor x1 to x0, blob `0354c5b73c28` to `400078723215`). The chip test then went red: `Tests 5 failed | 9 passed (14)`; the failing tests were the four refused-part cases and "a part that fails the parse draws nothing". Restored: blob equals HEAD (`0354c5b73c28`) and `git diff HEAD` is empty. plugin-chatbot resolves to `src` through the vitest alias, so no `dist` rebuild was involved. This round does not touch that file. </details> <details><summary>Mutation of the count check (round 2, at c1b30e6)</summary> `node scripts/ablation-replace.mjs` replaced `drawn.length === candidate.count ? drawn[candidate.ordinal] : undefined` in `locateSection` with `drawn[candidate.ordinal]` (anchor x1 to x0, blob `20eec4db25ed` to `f4f48f4f6379`). The two section test files then went red: `Tests 3 failed | 21 passed (24)`. The failures were the same-titled unlisted heading and the listed-not-drawn heading pins in `recordSectionAnchor.test.tsx`, and the setext pin in `RecordDetailView.citedSection-37365.test.tsx`. Restored with `git checkout HEAD --`: blob equals HEAD (`20eec4db25ed`) and `git diff HEAD` is empty. app-shell tests import their own `src`, so no `dist` was involved. </details> ## Acceptance notes - **Which field is the body.** The URL carries only `section`, so the page cannot read the citation's `context` pack. It runs `headingsOf` on every long-text field the record holds (`markdown`, `html`, `richtext`, `textarea`), in field order, and the first whose outline issues the anchor is the body. When the pack's body field holds the anchor, the result is the same. Another long-text field earlier in the field order that has a heading with the same anchor would be opened instead. The alternative, reading the pack's `body.field`, would need `context` on the URL as well; it was not taken. - **A2 (measured: holds only in part).** The drawn face shows headings that `headingsOf` does not list: setext headings, an empty `#`, headings inside a quote or a list, an indented ATX heading, and empty `h1`-`h6` in html. The outline also lists headings the face does not draw, such as a `#` line inside a raw HTML block or a four-backtick fence. With a bare Nth-element rule, each of these shifts every later heading. The rule taken (`locateSection`) has two parts. First, among the field's drawn heading elements, it picks those whose letters and digits read the same as the outline's heading and indexes them by the outline's repeat count. Second, it trusts that index only when the face draws exactly as many headings of that reading as the outline lists. Otherwise it opens the field, and it also opens the field for a heading with no letter or digit. So a differing heading of another title shifts nothing. A same-titled one, or a listed one the face does not draw, opens the field rather than a heading that may be another. A heading whose raw text carries letters the face does not draw (a link's URL) reads differently and opens at the field too. Two headings that normalise alike (`C` and `C++`) are told apart by order, which both sides share. - **Moving the mark (round 2).** The focus cleanup takes the attribute and only the classes the mark added. A second citation on the open record, or the record left, leaves no stale mark. The chat opener puts a fresh `RECORD_SECTION_OPENED_STATE` value on each chip click, and the record page keys the focus on record, anchor and that value. So the same chip clicked again (same URL) scrolls and marks again. The tab and comment writers replace the URL keeping `location.state`, so they do not re-scroll. - **Files beyond the claim's surface.** (1) `ui/packages/plugin-detail/src/DetailSection.tsx` gets one `data-detail-field` attribute on each detail row. Without it the page has no way to find a field, so the textarea and not-drawn cases could not open at the field. (2) `ui/packages/plugin-chatbot/src/chatMessageAdapter.ts` gets one key on `RuntimeOnlyMessageKeys`, the declared place for a new render-only message key. (3) The new helper `ui/packages/app-shell/src/views/recordSectionAnchor.ts`. (4) The chatbot docs page and README. overlap-check is clean against `origin/main` and against #37436, which shares `DetailSection.tsx` and the 11 locale files (disjoint hunks), and #37422, which shares the 11 locale files. - **Not covered: a reload.** The chips are drawn from the live stream. When the `/ai` page rebuilds history, it drops any `data-*` part other than charts: `hydratedMessagesToChatMessages`, then `useObjectChat`'s `initialMessages` rebuild, then the browser display cache (`sanitizeChatMessagesForCache`). So a persisted citation list does not come back after a reload yet; #37487 carries it. Nothing on `main` emits the part before cloud 10c. The changeset and both doc pages say so: the console draws a verified citations part when a live answer carries one. - Clause-②: yes because a new console URL parameter is reserved. `onOpenRecord`'s argument gains an optional member (widening). No spec file changed. ## Verification - Browser: **NOT MEASURED** here. The seat carries it on #37487's acceptance: scroll under the sticky chrome, ring visibility, the lazy face against the 4 s settle, the phone row, and `html`/`richtext` bodies. In its place, `RecordDetailView.citedSection-37365.test.tsx` renders the real record page with the real markdown face. - Two-minute check: in the console, ask the assistant something an answer with a `data-record-citations` part covers (cloud 10c). Click a chip. Expected: the address is `/apps/APP/OBJ/record/ID?section=ANCHOR`, the cited heading is scrolled into view with the accent ring, and an edited-away heading opens the record at its top. --- _Generated by [Claude Code](https://claude.ai/code/session_01Utp6CbeF2saT6wUBV4E9uc)_ <!-- signed: repo:objectstack#5 · os-bill · session_01Utp6CbeF2saT6wUBV4E9uc --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 59571b2 commit 276174a

27 files changed

Lines changed: 1274 additions & 12 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@object-ui/plugin-chatbot': patch
3+
'@object-ui/app-shell': patch
4+
'@object-ui/plugin-detail': patch
5+
'@object-ui/i18n': patch
6+
---
7+
8+
feat(chatbot): when an answer carries a verified record-citations part, the console draws it as chips, and a chip opens the record at the cited section
9+
10+
Clause-②: yes (a new reserved URL parameter `section`)
11+
Metadata-protocol: none
12+
13+
When an assistant answer carries a `data-record-citations` part (ADR-0160 D9), the console draws it: the part, read through `@objectstack/spec/ai`'s `RecordCitationsSchema`, becomes one chip per citation beside the "How this was computed" block, each showing the quoted passage (`extractRecordCitations` in `@object-ui/plugin-chatbot`, `RecordCitations`). The chips draw the part as it arrives and verify nothing again on display. A part the schema refuses draws nothing. Nothing in this release emits the part yet, and a conversation reloaded from history does not redraw it yet: the chips appear on a live answer whose stream carries the part.
14+
15+
A chip calls the chat's `onOpenRecord` with the citation's `object` and `id` (the context pack's root record, also when the passage came from a related-list row) and its `anchor`; `onOpenRecord`'s argument gains an optional `anchor`. The console's assistant (the `/ai` page and the dock) opens `/apps/APP/OBJECT/record/ID?section=ANCHOR`.
16+
17+
`section` is a new reserved console URL parameter (`RECORD_SECTION_PARAM`, listed in `RESERVED_URL_PARAMS`). The record page reads it: the spec's `headingsOf` runs on each long-text field of the record (`markdown`, `html`, `richtext`, `textarea`), the first field whose outline issues the anchor is the body, and its heading is scrolled to and marked; opening another section moves the mark, and the same chip clicked again opens the section again. A `textarea` body, a heading the field does not draw, or a body that draws a different number of headings of that title than its outline lists, opens at the field; an anchor no heading issues any more opens the record at its top. A record detail row now carries `data-detail-field` with the field's name, which is how the page finds the field.
18+
19+
The record-link grammar in answers is unchanged: a fragment or a query string is still refused.

‎content/docs/frontend/plugins/plugin-chatbot.mdx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,8 @@ By default, `ChatbotEnhanced` renders tool invocations as a compact agent activi
493493

494494
In every mode, an answer whose data tools returned a `source` block ends with one collapsed "How this was computed" block: per tool, the object, the filter, the grouping, the aggregations, how many records the figures cover, and whether only the reader's visible records were read. An answer computed through `query_dataset` draws that tool's `provenance` block in the same place instead: the dataset, each metric by its label with its name beside it, the grouping, and the filter the question added (a dataset's own filter is never shown, so no added filter reads as such rather than as all records). It draws that block alone, never the rest of the tool payload.
495495

496+
When an answer carries a verified record-citations part (the `data-record-citations` part, `RecordCitationsSchema` in `@objectstack/spec/ai`), the console draws it beside that block as one chip per citation, each showing the quoted passage, and verifies nothing again on display; a part that does not parse draws nothing. The chips appear on a live answer whose stream carries the part; a conversation reloaded from history does not redraw them yet. A chip calls `onOpenRecord({ objectName, recordId, anchor })` with the citation's own record (the root record, even when the passage came from a related-list row) and the body section it cites. The console opens the record at `/apps/APP/OBJECT/record/ID?section=ANCHOR`: the record page scrolls to that heading of the body and marks it, opens a `textarea` body at the field, and opens at the top when the anchor names no heading any more.
497+
496498
Each step is named by the locale pack's `chatbot.tool.<tool_name>` entry, a
497499
short sentence in the user's language ("List the existing objects"). A tool
498500
the pack has no entry for falls back to its name, title-cased.

‎ui/packages/app-shell/src/console/ai/AiChatPage.tsx‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ import {
169169
type OutboundAgentTextKey,
170170
} from './outboundAgentText.js';
171171
import { resolveApiBase } from './resolveApiBase.js';
172+
import { RECORD_SECTION_OPENED_STATE, RECORD_SECTION_PARAM } from '../../urlParams.js';
172173
import { AiUnavailable } from './AiUnavailable.js';
173174
import { recordWriteFormTarget } from '../../utils/recordFormAiDraft.js';
174175
import { useUpload } from '@object-ui/fields';
@@ -216,6 +217,30 @@ export function listLinkTarget(
216217
return `/apps/${encodeURIComponent(app)}/${encodeURIComponent(target.objectName)}${query ? `?${query}` : ''}`;
217218
}
218219

220+
/**
221+
* cloud#1658, ADR-0160 D9 — the console address of a record the chat opens:
222+
* `/apps/APP/OBJECT/record/ID`, plus `?section=ANCHOR` (`RECORD_SECTION_PARAM`)
223+
* when a record citation names a section of the record's body. A link with no
224+
* anchor (an `open_record` hand-off, a record link in an answer) opens the
225+
* record as before.
226+
*/
227+
export function recordOpenTarget(
228+
app: string,
229+
target: { objectName: string; recordId: string; anchor?: string },
230+
): string {
231+
const path = `/apps/${encodeURIComponent(app)}/${encodeURIComponent(target.objectName)}/record/${encodeURIComponent(target.recordId)}`;
232+
if (!target.anchor) return path;
233+
return `${path}?${new URLSearchParams({ [RECORD_SECTION_PARAM]: target.anchor }).toString()}`;
234+
}
235+
236+
let sectionOpenings = 0;
237+
238+
/** A history-state value no earlier chip click of this page load carried. */
239+
function nextSectionOpening(): string {
240+
sectionOpenings += 1;
241+
return `${Date.now().toString(36)}.${sectionOpenings}`;
242+
}
243+
219244
function partString(part: HydratedUIMessagePart, key: string): string | undefined {
220245
const value = part[key];
221246
return typeof value === 'string' && value.length > 0 ? value : undefined;
@@ -1917,11 +1942,19 @@ export function ChatPane({
19171942
// owning package on click — one same-origin metadata read — instead of
19181943
// burdening the agent with an id it may not know. `setup` is the fallback
19191944
// shell for an object no package claims.
1945+
//
1946+
// ADR-0160 D9 — a record citation's chip passes the `anchor` of the body
1947+
// section it cites; it rides as `?section=` (`RECORD_SECTION_PARAM`), and
1948+
// the record page opens at that heading. The record opened is always the
1949+
// citation's own `object`/`id`, the pack's root record. Each click carries a
1950+
// fresh `RECORD_SECTION_OPENED_STATE`, so clicking the same chip again opens
1951+
// the section again.
19201952
const openRecord = useCallback(
1921-
async (handoff: { objectName: string; recordId: string }) => {
1953+
async (handoff: { objectName: string; recordId: string; anchor?: string }) => {
19221954
const app = await appOfObject(handoff.objectName);
19231955
navigate(
1924-
`/apps/${encodeURIComponent(app)}/${encodeURIComponent(handoff.objectName)}/record/${encodeURIComponent(handoff.recordId)}`,
1956+
recordOpenTarget(app, handoff),
1957+
handoff.anchor ? { state: { [RECORD_SECTION_OPENED_STATE]: nextSectionOpening() } } : undefined,
19251958
);
19261959
},
19271960
[navigate],

‎ui/packages/app-shell/src/console/ai/__tests__/AiChatPage.recordLink-13037.test.tsx‎

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
1919
import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
2020
import { BrowserRouter } from 'react-router-dom';
2121
import React from 'react';
22+
import { RECORD_SECTION_OPENED_STATE } from '../../../urlParams';
2223

2324
const ANSWER = 'Top customer: [Wayne Enterprises](/record/account/acc_42).';
2425

@@ -29,7 +30,7 @@ const ANSWER = 'Top customer: [Wayne Enterprises](/record/account/acc_42).';
2930
*/
3031
const LIST_FILTER = { logic: 'and', conditions: [{ field: 'stage', operator: 'equals', value: 'open' }] };
3132
const LIST_ANSWER = `There are [12 open opportunities](/list/opportunity?view=all&uf__filter=${encodeURIComponent(JSON.stringify(LIST_FILTER))}).`;
32-
const answerNow = vi.hoisted(() => ({ content: '' }));
33+
const answerNow = vi.hoisted(() => ({ content: '', recordCitations: undefined as unknown }));
3334

3435
vi.mock('@object-ui/plugin-chatbot', async (importOriginal) => {
3536
const actual = await importOriginal<Record<string, unknown>>();
@@ -38,7 +39,12 @@ vi.mock('@object-ui/plugin-chatbot', async (importOriginal) => {
3839
useObjectChat: () => ({
3940
messages: [
4041
{ id: 'u1', role: 'user', content: 'analyse my customers' },
41-
{ id: 'a1', role: 'assistant', content: answerNow.content || ANSWER },
42+
{
43+
id: 'a1',
44+
role: 'assistant',
45+
content: answerNow.content || ANSWER,
46+
...(answerNow.recordCitations ? { recordCitations: answerNow.recordCitations } : {}),
47+
},
4248
],
4349
isLoading: false,
4450
error: undefined,
@@ -112,7 +118,9 @@ beforeEach(() => {
112118
? { item: { name: 'account', _packageId: 'com.acme.crm' } }
113119
: String(input).endsWith('/api/v1/meta/object/opportunity')
114120
? { item: { name: 'opportunity', _packageId: 'com.acme.crm' } }
115-
: { success: true, data: [] };
121+
: String(input).endsWith('/api/v1/meta/object/policy')
122+
? { item: { name: 'policy', _packageId: 'com.acme.compliance' } }
123+
: { success: true, data: [] };
116124
return new Response(JSON.stringify(body), {
117125
status: 200,
118126
headers: { 'Content-Type': 'application/json' },
@@ -122,6 +130,7 @@ beforeEach(() => {
122130
});
123131
afterEach(() => {
124132
answerNow.content = '';
133+
answerNow.recordCitations = undefined;
125134
cleanup();
126135
vi.unstubAllGlobals();
127136
window.history.replaceState(null, '', '/');
@@ -168,3 +177,65 @@ describe('objectstack#31869 — a list link in an answer opens the filtered list
168177
});
169178
}
170179
});
180+
181+
/**
182+
* objectstack#37365 (ADR-0160 D9) — a record citation's chip opens the cited
183+
* record through the same opener, at the cited section: `?section=ANCHOR`.
184+
* The console's assistant dock draws this same `ChatPane`, so the dock and
185+
* the `/ai` page open a citation alike. A quote from a related row opens the
186+
* root record the citation names, with no section.
187+
*/
188+
describe('objectstack#37365 — a record citation opens the record at the cited section', () => {
189+
const CITATIONS = [
190+
{ object: 'policy', id: 'pol_7', context: 'policy_document', anchor: 'scope', quote: 'Applies to every contractor.' },
191+
{ object: 'policy', id: 'pol_7', context: 'policy_document', quote: 'Revision 3 published' },
192+
];
193+
194+
for (const [mount, basename, prefix] of [
195+
['a /_console/ mount', '/_console', '/_console'],
196+
['a root mount', '/', ''],
197+
] as const) {
198+
it(`under ${mount}: the chip opens /apps/APP/OBJ/record/ID?section=ANCHOR`, async () => {
199+
answerNow.recordCitations = CITATIONS;
200+
renderPane(basename);
201+
const chip = await screen.findByRole('button', { name: 'Applies to every contractor.' });
202+
await act(async () => {
203+
fireEvent.click(chip);
204+
});
205+
await waitFor(() => expect(window.location.pathname).toBe(`${prefix}/apps/com.acme.compliance/policy/record/pol_7`));
206+
expect(window.location.search).toBe('?section=scope');
207+
});
208+
}
209+
210+
it('each click of a chip carries a fresh opened-state value, so the same chip opens the section again', async () => {
211+
answerNow.recordCitations = CITATIONS;
212+
renderPane('/');
213+
const opened = () => (window.history.state?.usr as Record<string, unknown> | undefined)?.[RECORD_SECTION_OPENED_STATE];
214+
const click = async () => {
215+
await act(async () => {
216+
fireEvent.click(await screen.findByRole('button', { name: 'Applies to every contractor.' }));
217+
});
218+
await waitFor(() => expect(typeof opened()).toBe('string'));
219+
return opened();
220+
};
221+
const first = await click();
222+
expect(window.location.search).toBe('?section=scope');
223+
await act(async () => {
224+
window.history.replaceState(null, '', window.location.href);
225+
});
226+
const second = await click();
227+
expect(window.location.search).toBe('?section=scope');
228+
expect(second).not.toBe(first);
229+
});
230+
231+
it('a quote from a related row opens the root record, with no section', async () => {
232+
answerNow.recordCitations = CITATIONS;
233+
renderPane('/');
234+
const chip = await screen.findByRole('button', { name: 'Revision 3 published' });
235+
await act(async () => {
236+
fireEvent.click(chip);
237+
});
238+
await waitFor(() => expect(window.location.pathname).toBe('/apps/com.acme.compliance/policy/record/pol_7'));
239+
expect(window.location.search).toBe('');
240+
});
241+
});

‎ui/packages/app-shell/src/urlParams.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ import { STUDIO_RETURN_PARAM } from './views/studio-design/studioAddress.js';
6363
* | | at it (a comment notice's link, #36410). | |
6464
* | `comment` | With `comments`: the comment in that thread to | with |
6565
* | | scroll to (objectstack#36410). | `comments` |
66+
* | `section` | On a record route: the body heading to open at | with the |
67+
* | | and mark, by the anchor the body outline | record link |
68+
* | | issued (ADR-0160 D9; a cited passage opened | |
69+
* | | from the assistant). A stale one opens the top.| |
6670
* | `from` | Ancestor breadcrumb trail for a record route, | push (with |
6771
* | | so drilling record→related-record keeps a | the drill-in) |
6872
* | | clickable path back (`Account → #p → Invoice`).| |
@@ -164,6 +168,25 @@ export const RECORD_COMMENTS_PARAM = 'comments';
164168
*/
165169
export const RECORD_COMMENT_PARAM = 'comment';
166170

171+
/**
172+
* On a record route (ADR-0160 D9): the heading of the record's body to open
173+
* at, scrolled to and marked — by the `anchor` the body outline issued, which
174+
* the spec's `headingsOf` derives from the body on the server and here alike.
175+
* Written by the assistant's citation chips (`onOpenRecord`'s `anchor`). An
176+
* anchor that names no heading of the record opens it at its top; a
177+
* `textarea` body, or a heading the field does not draw, opens at the field.
178+
* Read by `RecordDetailView` (`recordSectionAnchor.ts`).
179+
*/
180+
export const RECORD_SECTION_PARAM = 'section';
181+
182+
/**
183+
* History-state value beside {@link RECORD_SECTION_PARAM}: a distinct value per
184+
* chip click, so a second click of the same citation (the same URL) opens the
185+
* section again. Not a URL parameter; an entry reached by a reload or a shared
186+
* link carries none and opens the section once.
187+
*/
188+
export const RECORD_SECTION_OPENED_STATE = '__sectionOpened';
189+
167190
/**
168191
* History-state flag beside {@link RECORD_COMMENTS_PARAM}: the record view
169192
* pushed this `?comments=` entry, so 「‹」 pops it. Not a URL parameter; an
@@ -224,6 +247,7 @@ export const RESERVED_URL_PARAMS: readonly string[] = [
224247
RECORD_RELATED_ENLARGE_PARAM,
225248
RECORD_COMMENTS_PARAM,
226249
RECORD_COMMENT_PARAM,
250+
RECORD_SECTION_PARAM,
227251
COMMAND_PALETTE_PARAM,
228252
KEYBOARD_SHORTCUTS_PARAM,
229253
RECORD_TRAIL_PARAM,

0 commit comments

Comments
 (0)