diff --git a/frontend/src/app/AppShell.creationNote.test.tsx b/frontend/src/app/AppShell.creationNote.test.tsx
index d8560cc..311b7e0 100644
--- a/frontend/src/app/AppShell.creationNote.test.tsx
+++ b/frontend/src/app/AppShell.creationNote.test.tsx
@@ -2,7 +2,7 @@ import '@testing-library/jest-dom/vitest'
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react'
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
import { creationNoteStorageKey } from '../hooks/useRememberedVisible'
-import { entryFixture, findingFixture } from '../test/fixtures'
+import { draftFixture, entryFixture, findingFixture } from '../test/fixtures'
import { cleanupControllerTest, getTauriMock, setupControllerTest, useAppController } from './useAppController.testHarness'
const { AppShell } = await import('./AppShell')
@@ -13,7 +13,8 @@ beforeEach(() => {
setupControllerTest()
window.localStorage.removeItem(creationNoteStorageKey)
HTMLElement.prototype.scrollIntoView = vi.fn()
- tauri.listFindings.mockResolvedValue([findingFixture({ title: 'Saved finding' })])
+ tauri.listFindings.mockResolvedValue([findingFixture({ id: 'finding-saved', title: 'Saved finding', body: '
Card payment fails at checkout.
' })])
+ tauri.listDrafts.mockResolvedValue([draftFixture({ id: 'draft-saved', title: 'Checkout test cases', body: 'Pay with an expired card.
' })])
tauri.readNoteSource.mockResolvedValue({ entry: entryFixture({ body: 'Checkout
' }), revision: 0 })
})
afterEach(cleanupControllerTest)
@@ -71,3 +72,28 @@ it('says so in the panel when the Session has no Note, and the draft still saves
fireEvent.change(screen.getByRole('textbox', { name: 'Finding title' }), { target: { value: 'Written without a Note' } })
expect(screen.getByRole('button', { name: 'Save finding' })).toBeEnabled()
})
+
+it('shows a saved test case or Finding beside the draft in place of the Note, chosen per draft', async () => {
+ render()
+ await createFinding()
+ const choice = within(await screen.findByRole('complementary', { name: 'Note' })).getByRole('combobox', { name: 'Show beside the draft' })
+ // The draft's own kind is listed first.
+ expect(within(choice).getAllByRole('group').map(group => group.getAttribute('label'))).toEqual(['Findings', 'Test cases'])
+
+ fireEvent.change(choice, { target: { value: 'testware:draft-saved' } })
+ const testCase = await screen.findByRole('complementary', { name: 'Checkout test cases' })
+ await waitFor(() => expect(testCase).toHaveTextContent('Pay with an expired card.'))
+ expect(within(testCase).getByRole('textbox', { name: 'Checkout test cases content' })).toHaveAttribute('aria-readonly', 'true')
+ expect(testCase).not.toHaveTextContent('Pay with a saved card.')
+
+ // Closed, the panel is brought back by what it shows.
+ fireEvent.click(within(testCase).getByRole('button', { name: 'Close test case' }))
+ fireEvent.click(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Show test case' }))
+ fireEvent.change(within(await screen.findByRole('complementary', { name: 'Checkout test cases' })).getByRole('combobox'), { target: { value: 'finding:finding-saved' } })
+ await waitFor(() => expect(screen.getByRole('complementary', { name: 'Saved finding' })).toHaveTextContent('Card payment fails at checkout.'))
+
+ // A new draft starts with the Note again.
+ fireEvent.click(screen.getByRole('button', { name: 'Cancel' }))
+ await createFinding()
+ expect(await screen.findByRole('complementary', { name: 'Note' })).toHaveTextContent('Pay with a saved card.')
+})
diff --git a/frontend/src/app/AppShell.tsx b/frontend/src/app/AppShell.tsx
index 1670ec8..8b5955c 100644
--- a/frontend/src/app/AppShell.tsx
+++ b/frontend/src/app/AppShell.tsx
@@ -1,6 +1,7 @@
import { ActionButton } from '../components/ActionButton'
import { CreationWorkspace } from '../views/CreationTools'
import { CreationNotePanel } from '../views/CreationNotePanel'
+import { referenceLabel, useCreationReference } from './creationReference'
import { useCreationNoteVisible } from '../hooks/useCreationNoteVisible'
import { useEffect, useRef, useState, type KeyboardEvent } from 'react'
import { catalogSelectorEnabled } from '../settings/catalog'
@@ -54,8 +55,20 @@ export function AppShell(c: AppController) {
&& c.activeView === (c.creationIntent.kind === 'finding' ? 'findings' : 'testware') ? c.creationIntent : null
const contentRef = useRef(null)
const [noteVisible, toggleNote] = useCreationNoteVisible(shownDraft?.id ?? null, contentRef)
+ const [reference, setReference] = useCreationReference(shownDraft?.id ?? null)
+ const referenceRecords = { testware: c.testwareDrafts, finding: c.findings }
const askAiVisible = c.askAi.visible && !shownDraft
- const composer = c.creationIntent && !creationResultReady ? : null
+ const composer = c.creationIntent && !creationResultReady ? : null
+
+ // The panel lists both kinds of saved record, and each kind loads with its own tab, so load the other one here.
+ const { loadDraftsForSession, loadFindingsForSession } = c
+ const referenceSessionId = shownDraft && noteVisible ? shownDraft.sessionId : null
+ useEffect(() => {
+ if (!referenceSessionId) return
+ void loadDraftsForSession(referenceSessionId).catch(() => undefined)
+ void loadFindingsForSession(referenceSessionId).catch(() => undefined)
+ }, [referenceSessionId, loadDraftsForSession, loadFindingsForSession])
const { loadDraftLibrary, loadFindingLibrary, sessionLibraryComplete } = c
// Startup loads only recent Sessions; the palette searches every Session without changing the sidebar.
@@ -273,7 +286,7 @@ export function AppShell(c: AppController) {
/>
) : null}
- {shownDraft && noteVisible ? void c.creation.reviewSource()} onClose={toggleNote} /> : null}
+ {shownDraft && noteVisible ? void c.creation.reviewSource()} onClose={toggleNote} /> : null}
runCommand('ai.configure')} />
diff --git a/frontend/src/app/creationReference.ts b/frontend/src/app/creationReference.ts
new file mode 100644
index 0000000..ca81478
--- /dev/null
+++ b/frontend/src/app/creationReference.ts
@@ -0,0 +1,33 @@
+import { useState } from 'react'
+import type { StoredRichBody } from '../editor/editorDocument'
+import type { CreationKind } from '../tauri'
+
+/** A saved test case or Finding that can show beside a new draft in place of the Note. */
+export type ReferenceRecord = StoredRichBody & { id: string; title: string }
+export type ReferenceRecords = Record>
+/** What shows beside the draft: the Note, or a saved record of either kind. */
+export type CreationReference = { kind: 'note' } | { kind: CreationKind; id: string }
+
+export const noteReference: CreationReference = { kind: 'note' }
+export const kindLabels: Record = {
+ testware: { group: 'Test cases', one: 'test case' },
+ finding: { group: 'Findings', one: 'Finding' },
+}
+export const referenceValue = (reference: CreationReference) => reference.kind === 'note' ? 'note' : `${reference.kind}:${reference.id}`
+
+/** What shows beside each draft, kept per draft: a new draft starts with the Note. */
+export function useCreationReference(draftId: string | null): [CreationReference, (reference: CreationReference) => void] {
+ const [chosen, setChosen] = useState<{ draftId: string; reference: CreationReference } | null>(null)
+ const reference = chosen && chosen.draftId === draftId ? chosen.reference : noteReference
+ return [reference, (next) => { if (draftId) setChosen({ draftId, reference: next }) }]
+}
+
+/** The saved record a reference names, or null for the Note or a record that is gone. */
+export function referencedRecord(reference: CreationReference, records: ReferenceRecords) {
+ return reference.kind === 'note' ? null : records[reference.kind].find(record => record.id === reference.id) ?? null
+}
+
+/** Names what the panel shows: the Note, or the kind of record it shows. */
+export function referenceLabel(reference: CreationReference, records: ReferenceRecords): string {
+ return reference.kind !== 'note' && referencedRecord(reference, records) ? kindLabels[reference.kind].one : 'Note'
+}
diff --git a/frontend/src/hooks/useCreationNoteVisible.ts b/frontend/src/hooks/useCreationNoteVisible.ts
index a741b8c..de86663 100644
--- a/frontend/src/hooks/useCreationNoteVisible.ts
+++ b/frontend/src/hooks/useCreationNoteVisible.ts
@@ -2,7 +2,6 @@ import { useLayoutEffect, useState, type RefObject } from 'react'
import { creationNoteStorageKey, useRememberedVisible } from './useRememberedVisible'
export const creationNotePanelId = 'creation-note'
-export const showNoteLabel = 'Show Note'
/** The workspace width at or below which a side panel covers the document area: the container query in ask-ai.css. */
const narrowWorkspace = 850
@@ -21,7 +20,7 @@ function useNarrowWorkspace(workspace: RefObject): boolean {
}
/**
- * Whether the Note shows beside the open draft. In a wide workspace the choice is remembered. In a narrow one
+ * Whether the panel beside the open draft (the Note, or a saved record) shows. In a wide workspace the choice is remembered. In a narrow one
* the Note would cover the draft, so it is closed until opened for this draft, and that choice is not kept.
*/
export function useCreationNoteVisible(draftId: string | null, workspace: RefObject): [boolean, () => void] {
@@ -34,7 +33,7 @@ export function useCreationNoteVisible(draftId: string | null, workspace: RefObj
if (narrow) setChosen({ draftId, visible: !visible })
else { setChosen(null); remember(!visible) }
// Focus follows the Note: into the panel when it opens, back to the button that brings it back when it closes.
- requestAnimationFrame(() => document.querySelector(visible ? `[aria-label="${showNoteLabel}"]` : `#${creationNotePanelId} button`)?.focus())
+ requestAnimationFrame(() => document.querySelector(visible ? '.creation-note-toggle' : `#${creationNotePanelId} :is(select, button)`)?.focus())
}
return [visible, toggle]
}
diff --git a/frontend/src/styles/collections.css b/frontend/src/styles/collections.css
index 1557bdd..256c829 100644
--- a/frontend/src/styles/collections.css
+++ b/frontend/src/styles/collections.css
@@ -1078,7 +1078,25 @@
.creation-composer > .record-title-row:has(> .creation-note-toggle) { grid-template-columns: minmax(0, 1fr) auto auto; }
.creation-composer > .record-title-row > .creation-note-toggle { grid-column: 3; grid-row: 1; margin-block: calc((23px * 1.2 - var(--control-lg)) / 2); }
-/* The Note beside a new draft (CreationNotePanel, a side-panel): read-only, scrolling on its own. */
+/* The panel beside a new draft (CreationNotePanel, a side-panel): the Note or a saved record, read-only, scrolling on its own. */
+/* The choice of what shows reads as the panel's heading: quiet until pointed at. The panel's colour behind it, for WebKitGTK. */
+.creation-reference-select {
+ flex: 1;
+ min-width: 0;
+ height: var(--control-lg);
+ margin-left: calc(-1 * var(--space-2));
+ padding-left: var(--space-2);
+ color: var(--text-primary);
+ font-family: var(--font-display);
+ font-size: var(--font-size-lg);
+ font-weight: 650;
+ text-overflow: ellipsis;
+ background-color: var(--surface-panel);
+ border: 1px solid transparent;
+ border-radius: var(--radius-md);
+}
+.creation-reference-select:hover { border-color: var(--border-default); }
+
.creation-note-body {
display: grid;
flex: 1;
diff --git a/frontend/src/views/CreationNotePanel.tsx b/frontend/src/views/CreationNotePanel.tsx
index d22ea78..c7f458d 100644
--- a/frontend/src/views/CreationNotePanel.tsx
+++ b/frontend/src/views/CreationNotePanel.tsx
@@ -3,37 +3,72 @@ import { FileText, PanelRightClose, PanelRightOpen } from 'lucide-react'
import { ActionButton } from '../components/ActionButton'
import { StatePanel } from '../components/Common'
import { RichTextEditor } from '../editor/RichTextEditor'
-import { richEditorDocumentFromHtml } from '../editor/editorDocument'
+import { richEditorDocumentFromHtml, richEditorDocumentFromStoredBody, withoutRepeatedTitleHeading } from '../editor/editorDocument'
import { htmlHasContent } from '../editor/editorHtml'
-import { creationNotePanelId, showNoteLabel } from '../hooks/useCreationNoteVisible'
+import { creationNotePanelId } from '../hooks/useCreationNoteVisible'
import type { CreationIntent } from '../app/creationIntent'
+import type { CreationKind } from '../tauri'
+import { kindLabels, noteReference, referencedRecord, referenceLabel, referenceValue, type CreationReference, type ReferenceRecord, type ReferenceRecords } from '../app/creationReference'
-export function ShowNoteButton({ onShow }: { onShow: () => void }) {
- return
+export function ShowNoteButton({ label, onShow }: { label: string; onShow: () => void }) {
+ const tooltip = `Show ${label}`
+ return
}
-/** The Session's Note, read-only on the right of a new draft: the source Generate uses. */
-export function CreationNotePanel({ intent, noteReadOnly, onReadNote, onClose }: {
+/**
+ * Read-only on the right of a new draft: the Session's Note, the source Generate uses, or a saved test case or
+ * Finding of this Session to write from. Records of the draft's own kind are listed first.
+ */
+export function CreationNotePanel({ intent, records, reference, onReferenceChange, noteReadOnly, onReadNote, onClose }: {
intent: CreationIntent
+ records: ReferenceRecords
+ reference: CreationReference
+ onReferenceChange: (reference: CreationReference) => void
noteReadOnly: boolean
onReadNote: () => void
onClose: () => void
}) {
- const body = intent.source?.entry.body
- const written = body !== undefined && htmlHasContent(body)
- const note = useMemo(() => body === undefined ? null : richEditorDocumentFromHtml(body), [body])
- return