From bc468372411510da6f006f17a80aca1af99dcc00 Mon Sep 17 00:00:00 2001 From: Douwe de Vries Date: Sat, 14 Nov 2026 18:13:57 +0100 Subject: [PATCH] feat(ui): one labelled toggle for the panel beside a draft, and Generate shows only the Note it uses - The arrow show and close buttons become one toggle in the draft header, named for what the panel shows; its panel icon fills while open. The panel closes with a plain X. - Under Write the panel's choice is a labelled Showing field with record counts. - Under Generate the panel shows only the Note with "Generate uses this Note.", and the form says "Generates from: Note (N words, M screenshots)". Write brings back the chosen record. Execution details call the material Note. Co-Authored-By: Claude Opus 5.5 --- .../src/app/AppShell.creationNote.test.tsx | 40 ++++++++++++--- frontend/src/app/AppShell.tsx | 7 ++- frontend/src/styles/collections.css | 25 +++------- frontend/src/views/CreationGenerate.tsx | 10 +++- frontend/src/views/CreationNotePanel.tsx | 50 ++++++++++++------- frontend/src/views/CreationTools.tsx | 14 +++--- frontend/src/workflows/generationSetup.tsx | 2 +- 7 files changed, 93 insertions(+), 55 deletions(-) diff --git a/frontend/src/app/AppShell.creationNote.test.tsx b/frontend/src/app/AppShell.creationNote.test.tsx index 311b7e0..44a878e 100644 --- a/frontend/src/app/AppShell.creationNote.test.tsx +++ b/frontend/src/app/AppShell.creationNote.test.tsx @@ -3,6 +3,7 @@ import { fireEvent, render, screen, waitFor, within } from '@testing-library/rea import { afterEach, beforeEach, expect, it, vi } from 'vitest' import { creationNoteStorageKey } from '../hooks/useRememberedVisible' import { draftFixture, entryFixture, findingFixture } from '../test/fixtures' +import { creationMode } from '../test/creationModes' import { cleanupControllerTest, getTauriMock, setupControllerTest, useAppController } from './useAppController.testHarness' const { AppShell } = await import('./AppShell') @@ -37,7 +38,8 @@ it('shows the Note read-only beside a new draft in place of the record list, whi expect(screen.queryByRole('button', { name: 'Hide list' })).not.toBeInTheDocument() expect(screen.queryByRole('textbox', { name: 'Search Findings' })).not.toBeInTheDocument() expect(screen.queryByRole('combobox', { name: 'Sort' })).not.toBeInTheDocument() - expect(screen.queryByRole('button', { name: 'Show Note' })).not.toBeInTheDocument() + // One toggle in the draft header, named for what shows, says the panel is open. + expect(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Note' })).toHaveAttribute('aria-expanded', 'true') fireEvent.click(screen.getByRole('button', { name: 'Cancel' })) await waitFor(() => expect(screen.queryByRole('complementary', { name: 'Note' })).not.toBeInTheDocument()) @@ -45,7 +47,7 @@ it('shows the Note read-only beside a new draft in place of the record list, whi expect(screen.getByRole('textbox', { name: 'Search Findings' })).toBeInTheDocument() }) -it('remembers that the Note was closed for the next draft, and brings it back from the draft header', async () => { +it('remembers that the Note was closed for the next draft, and brings it back from the toggle in the draft header', async () => { render() await createFinding() fireEvent.click(within(await screen.findByRole('complementary', { name: 'Note' })).getByRole('button', { name: 'Close Note' })) @@ -57,7 +59,9 @@ it('remembers that the Note was closed for the next draft, and brings it back fr fireEvent.click(screen.getByRole('button', { name: 'Cancel' })) await createFinding() expect(screen.queryByRole('complementary', { name: 'Note' })).not.toBeInTheDocument() - fireEvent.click(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Show Note' })) + const toggle = within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Note' }) + expect(toggle).toHaveAttribute('aria-expanded', 'false') + fireEvent.click(toggle) expect(await screen.findByRole('complementary', { name: 'Note' })).toHaveTextContent('Pay with a saved card.') expect(window.localStorage.getItem(creationNoteStorageKey)).toBe('shown') }) @@ -76,9 +80,9 @@ it('says so in the panel when the Session has no Note, and the draft still saves 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' }) + const choice = within(await screen.findByRole('complementary', { name: 'Note' })).getByRole('combobox', { name: 'Showing' }) // The draft's own kind is listed first. - expect(within(choice).getAllByRole('group').map(group => group.getAttribute('label'))).toEqual(['Findings', 'Test cases']) + expect(within(choice).getAllByRole('group').map(group => group.getAttribute('label'))).toEqual(['Findings (1)', 'Test cases (1)']) fireEvent.change(choice, { target: { value: 'testware:draft-saved' } }) const testCase = await screen.findByRole('complementary', { name: 'Checkout test cases' }) @@ -86,9 +90,10 @@ it('shows a saved test case or Finding beside the draft in place of the Note, ch 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. + // The toggle is named for what shows, open or closed. + expect(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Test case' })).toHaveAttribute('aria-expanded', 'true') 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.click(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: '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.')) @@ -97,3 +102,24 @@ it('shows a saved test case or Finding beside the draft in place of the Note, ch await createFinding() expect(await screen.findByRole('complementary', { name: 'Note' })).toHaveTextContent('Pay with a saved card.') }) + +it('shows only the Note under Generate, the source it uses, and the chosen record again under Write', async () => { + render() + await createFinding() + fireEvent.change(within(await screen.findByRole('complementary', { name: 'Note' })).getByRole('combobox', { name: 'Showing' }), { target: { value: 'testware:draft-saved' } }) + await screen.findByRole('complementary', { name: 'Checkout test cases' }) + + fireEvent.click(await waitFor(() => creationMode('Generate'))) + const note = await screen.findByRole('complementary', { name: 'Note' }) + expect(within(note).getByRole('heading', { name: 'Note' })).toBeInTheDocument() + expect(within(note).queryByRole('combobox')).not.toBeInTheDocument() + expect(note).toHaveTextContent('Generate uses this Note.') + await waitFor(() => expect(note).toHaveTextContent('Pay with a saved card.')) + expect(within(screen.getByRole('article', { name: 'New finding' })).getByRole('button', { name: 'Note' })).toHaveAttribute('aria-expanded', 'true') + expect(screen.getByRole('article', { name: 'New finding' })).toHaveTextContent('Generates from: Note (5 words, 0 screenshots)') + + fireEvent.click(creationMode('Write')) + const testCase = await screen.findByRole('complementary', { name: 'Checkout test cases' }) + expect(within(testCase).getByRole('combobox', { name: 'Showing' })).toHaveValue('testware:draft-saved') + expect(testCase).not.toHaveTextContent('Generate uses this Note.') +}) diff --git a/frontend/src/app/AppShell.tsx b/frontend/src/app/AppShell.tsx index 8b5955c..1657ed1 100644 --- a/frontend/src/app/AppShell.tsx +++ b/frontend/src/app/AppShell.tsx @@ -2,6 +2,7 @@ import { ActionButton } from '../components/ActionButton' import { CreationWorkspace } from '../views/CreationTools' import { CreationNotePanel } from '../views/CreationNotePanel' import { referenceLabel, useCreationReference } from './creationReference' +import { creationAiActive, shownCreationMode } from './creationMode' import { useCreationNoteVisible } from '../hooks/useCreationNoteVisible' import { useEffect, useRef, useState, type KeyboardEvent } from 'react' import { catalogSelectorEnabled } from '../settings/catalog' @@ -58,8 +59,10 @@ export function AppShell(c: AppController) { const [reference, setReference] = useCreationReference(shownDraft?.id ?? null) const referenceRecords = { testware: c.testwareDrafts, finding: c.findings } const askAiVisible = c.askAi.visible && !shownDraft + // Under Generate the panel shows only the Note, the source Generate uses; the choice of record comes back under Write. + const generatingFromNote = shownDraft ? shownCreationMode(shownDraft, creationAiActive(c)) === 'generate' : false const composer = c.creationIntent && !creationResultReady ? : null + panel={shownDraft ? { label: generatingFromNote ? 'Note' : referenceLabel(reference, referenceRecords), open: noteVisible, onToggle: toggleNote } : undefined} /> : 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 @@ -286,7 +289,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/styles/collections.css b/frontend/src/styles/collections.css index 256c829..1fbd12c 100644 --- a/frontend/src/styles/collections.css +++ b/frontend/src/styles/collections.css @@ -1074,28 +1074,17 @@ overflow-wrap: anywhere; } -/* Show Note sits right of Copy, level with it, while the Note beside the draft is closed. */ +/* The toggle for the panel beside the draft sits right of Copy, level with it. */ .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 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); } +/* Under Write its header is the labelled choice of what shows, a field like any other; Close lines up with the field. */ +.side-panel-header:has(> .creation-reference-field) { align-items: end; } +.creation-reference-field { flex: 1; min-width: 0; } +.creation-reference-field select { width: 100%; text-overflow: ellipsis; } +.creation-note-source { margin: 0; color: var(--text-secondary); } +.creation-generate-source { margin: 0; } .creation-note-body { display: grid; diff --git a/frontend/src/views/CreationGenerate.tsx b/frontend/src/views/CreationGenerate.tsx index 6abbd1f..597a59b 100644 --- a/frontend/src/views/CreationGenerate.tsx +++ b/frontend/src/views/CreationGenerate.tsx @@ -51,6 +51,8 @@ export function useCreationGenerate(intent: CreationIntent, c: AppController) { selectionAdvisories: [...execution.advisories.map((warning) => warning.message), ...(customAdvisory ? [customAdvisory] : [])], } const authored = creationIsAuthored(intent) + const screenshots = `${setup.noteScreenshotCount} screenshot${setup.noteScreenshotCount === 1 ? '' : 's'}` + const withCriteria = intent.kind === 'testware' && Boolean(sessionCriteria(intent, c)) function confirm() { if (busy || !ready) return setConfirming(true) @@ -60,6 +62,7 @@ export function useCreationGenerate(intent: CreationIntent, c: AppController) { } return { form: <> +

Generates from: Note ({setup.noteWordCount} words, {screenshots}){withCriteria ? ' and the acceptance criteria' : ''}

The AI result is saved as {intent.kind === 'finding' ? 'a new finding' : 'new test cases'} and opens for you to review.{authored ? ' What you wrote under Write is discarded when that succeeds, and kept if it fails or you cancel.' : ''}

@@ -96,11 +99,16 @@ function creationSourceWarning(intent: CreationIntent, c: AppController): string if (Object.keys(intent.imageOperations).length) return 'Finish adding images under Write, or continue without the failed ones there, before generating.' if (c.noteReadOnly) return 'Recover the Session Note before using it as a source.' if (intent.sourceNoteId && !intent.source) return 'Wait for the Note to show beside the draft before generating.' - const criteria = c.activeSession?.id === intent.sessionId ? c.activeSession.acceptanceCriteria?.trim() : null + const criteria = sessionCriteria(intent, c) const material = intent.source && (htmlHasContent(intent.source.entry.body) || (intent.kind === 'testware' && Boolean(criteria))) return material ? null : 'Write a Note first. There is nothing to generate from yet.' } +/** The draft's Session acceptance criteria, which Generate sends for test cases, when that Session is open. */ +function sessionCriteria(intent: CreationIntent, c: AppController): string | null { + return c.activeSession?.id === intent.sessionId ? c.activeSession.acceptanceCriteria?.trim() || null : null +} + function withDraftFormat(preferences: TestwareGenerationPreferences, intent: CreationIntent): TestwareGenerationPreferences { return intent.format.kind === 'testware' ? { ...preferences, outputFormat: intent.format.outputFormat } : preferences } diff --git a/frontend/src/views/CreationNotePanel.tsx b/frontend/src/views/CreationNotePanel.tsx index c7f458d..67a8fb2 100644 --- a/frontend/src/views/CreationNotePanel.tsx +++ b/frontend/src/views/CreationNotePanel.tsx @@ -1,5 +1,5 @@ import { useMemo } from 'react' -import { FileText, PanelRightClose, PanelRightOpen } from 'lucide-react' +import { createLucideIcon, FileText, PanelRight, X } from 'lucide-react' import { ActionButton } from '../components/ActionButton' import { StatePanel } from '../components/Common' import { RichTextEditor } from '../editor/RichTextEditor' @@ -10,44 +10,56 @@ 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({ label, onShow }: { label: string; onShow: () => void }) { - const tooltip = `Show ${label}` - return +/** The side-panel icon with its right pane filled: the panel beside the draft is open. */ +const PanelRightShown = createLucideIcon('panel-right-shown', [ + ['rect', { width: '18', height: '18', x: '3', y: '3', rx: '2', key: 'frame' }], + ['path', { d: 'M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4z', fill: 'currentColor', key: 'pane' }], +]) + +/** One toggle in the draft header for the panel beside the draft, named for what the panel shows. Its right pane fills while open. */ +export function CreationPanelToggle({ label, open, onToggle }: { label: string; open: boolean; onToggle: () => void }) { + return {label.charAt(0).toUpperCase() + label.slice(1)} } /** - * 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. + * Read-only on the right of a new draft. Under Write: the Session's Note or a saved test case or Finding of this + * Session to write from, records of the draft's own kind listed first. Under Generate: only the Note, which Generate uses. */ -export function CreationNotePanel({ intent, records, reference, onReferenceChange, noteReadOnly, onReadNote, onClose }: { +export function CreationNotePanel({ intent, records, reference, onReferenceChange, generating, noteReadOnly, onReadNote, onClose }: { intent: CreationIntent records: ReferenceRecords reference: CreationReference onReferenceChange: (reference: CreationReference) => void + /** Generate mode: the Note shows, without the choice. The choice comes back under Write. */ + generating: boolean noteReadOnly: boolean onReadNote: () => void onClose: () => void }) { // A record deleted while it is shown leaves the Note in its place. - const record = referencedRecord(reference, records) + const record = generating ? null : referencedRecord(reference, records) const shown = record ? reference : noteReference const label = referenceLabel(shown, records) const kinds: CreationKind[] = intent.kind === 'finding' ? ['finding', 'testware'] : ['testware', 'finding'] return diff --git a/frontend/src/views/CreationTools.tsx b/frontend/src/views/CreationTools.tsx index 95a81f0..6851ae7 100644 --- a/frontend/src/views/CreationTools.tsx +++ b/frontend/src/views/CreationTools.tsx @@ -4,28 +4,28 @@ import { CreationComposer } from './CreationComposer' import { useCreationGenerate } from './CreationGenerate' import { creationAiActive, shownCreationMode } from '../app/creationMode' import { FindingFields } from './FindingsView' -import { ShowNoteButton } from './CreationNotePanel' +import { CreationPanelToggle } from './CreationNotePanel' import type { CreationIntent, CreationMode } from '../app/creationIntent' import type { AppController } from '../app/useAppController' const creationModes = [{ value: 'write', label: 'Write', icon: PenLine }, { value: 'generate', label: 'Generate', icon: Sparkles }] satisfies ReadonlyArray> -/** `showPanel` brings back the closed panel beside the draft, named for what it shows. */ -export type ShowPanel = { label: string; onShow: () => void } +/** The panel beside the draft: what it shows, whether it is open, and its toggle. */ +export type CreationPanel = { label: string; open: boolean; onToggle: () => void } -export function CreationWorkspace({ c, showPanel }: { c: AppController; showPanel?: ShowPanel }) { +export function CreationWorkspace({ c, panel }: { c: AppController; panel?: CreationPanel }) { const intent = c.creationIntent if (!intent) return null - return + return } /** A new draft: written by hand, or, when AI is ready, generated from the Note shown beside it. */ -function CreationDraft({ intent, c, showPanel }: { intent: CreationIntent; c: AppController; showPanel?: ShowPanel }) { +function CreationDraft({ intent, c, panel }: { intent: CreationIntent; c: AppController; panel?: CreationPanel }) { const generation = useCreationGenerate(intent, c) const aiActive = creationAiActive(c) const mode = shownCreationMode(intent, aiActive) return : undefined} + headerAction={panel ? : undefined} modeSwitch={aiActive ? { diff --git a/frontend/src/workflows/generationSetup.tsx b/frontend/src/workflows/generationSetup.tsx index 3f3f49c..a375bd8 100644 --- a/frontend/src/workflows/generationSetup.tsx +++ b/frontend/src/workflows/generationSetup.tsx @@ -142,7 +142,7 @@ export function GenerationSetup({
{sessionTitle.trim() || 'Untitled session'}
-
Material
+
Note
{noteWordCount} words, {screenshots}