diff --git a/frontend/src/components/navigation/ToolSidePanel.test.tsx b/frontend/src/components/navigation/ToolSidePanel.test.tsx index e8e4edd6..4c2a292b 100644 --- a/frontend/src/components/navigation/ToolSidePanel.test.tsx +++ b/frontend/src/components/navigation/ToolSidePanel.test.tsx @@ -27,6 +27,7 @@ vi.mock('@/components/session/ChangesWalkthroughSheet', () => ({ ChangesWalkthroughProvider: ({ children }: { children: ReactNode }) => <>{children}, ChangesWalkthroughNav: () => null, ChangesWalkthroughRegenerate: () => null, + ChangesWalkthroughSourcePicker: () => null, ChangesWalkthroughView: () =>
walkthrough-tool
, })) diff --git a/frontend/src/components/navigation/ToolSidePanel.tsx b/frontend/src/components/navigation/ToolSidePanel.tsx index c44f89a0..26ae41bc 100644 --- a/frontend/src/components/navigation/ToolSidePanel.tsx +++ b/frontend/src/components/navigation/ToolSidePanel.tsx @@ -8,6 +8,7 @@ import { ChangesWalkthroughNav, ChangesWalkthroughProvider, ChangesWalkthroughRegenerate, + ChangesWalkthroughSourcePicker, ChangesWalkthroughView, } from '@/components/session/ChangesWalkthroughSheet' import { PreviewWorkspace } from '@/components/preview/PreviewPanel' @@ -167,6 +168,7 @@ export function ToolSidePanel({

{activeLabel}

{activeTool === 'walkthrough' ? ( <> + diff --git a/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx b/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx index cb78525f..97d13926 100644 --- a/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx +++ b/frontend/src/components/session/ChangesWalkthroughSheet.test.tsx @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeAll, beforeEach } from 'vitest' -import { render, screen, waitFor } from '@testing-library/react' +import { render, screen, waitFor, within } from '@testing-library/react' import userEvent from '@testing-library/user-event' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import type { ReactNode } from 'react' @@ -285,6 +285,17 @@ describe('ChangesWalkthroughSheet', () => { }) }) + it('renders the source picker in the drawer header before any walkthrough exists', async () => { + mocks.getChangeWalkthrough.mockResolvedValue(state({ walkthrough: null })) + renderSheet() + + const header = screen.getByRole('button', { name: 'Close' }).parentElement + expect(header).not.toBeNull() + expect( + within(header as HTMLElement).getByRole('combobox', { name: 'Changes to walk through' }), + ).toBeInTheDocument() + }) + it('sends the branch base', async () => { const user = userEvent.setup() mocks.getChangeWalkthrough.mockResolvedValue(state({ walkthrough: null })) diff --git a/frontend/src/components/session/ChangesWalkthroughSheet.tsx b/frontend/src/components/session/ChangesWalkthroughSheet.tsx index 4a2fd5e5..dd204acf 100644 --- a/frontend/src/components/session/ChangesWalkthroughSheet.tsx +++ b/frontend/src/components/session/ChangesWalkthroughSheet.tsx @@ -162,22 +162,9 @@ const WALKTHROUGH_SOURCE_OPTIONS: { value: WalkthroughSource['kind']; label: str { value: 'pullRequest', label: 'Pull request' }, ] -/** Chooses which set of changes the walkthrough covers; git sources commit as soon as they are valid. */ -const WalkthroughSourcePicker = memo(function WalkthroughSourcePicker() { - const { - sourceKind, - setSourceKind, - baseInput, - setBaseInput, - numberInput, - setNumberInput, - setSource, - } = useChangesWalkthrough() - - const commitInputs = useCallback(() => { - const next = toWalkthroughSource({ kind: sourceKind, base: baseInput, number: Number(numberInput) }) - if (next) setSource(next) - }, [sourceKind, baseInput, numberInput, setSource]) +/** Chooses which set of changes the walkthrough covers from the surrounding chrome; git sources commit as soon as they are valid. */ +export const ChangesWalkthroughSourcePicker = memo(function ChangesWalkthroughSourcePicker() { + const { sourceKind, setSourceKind, baseInput, setSource } = useChangesWalkthrough() const handleKindChange = useCallback( (next: WalkthroughSource['kind']) => { @@ -190,35 +177,48 @@ const WalkthroughSourcePicker = memo(function WalkthroughSourcePicker() { ) return ( -
- handleKindChange(value as WalkthroughSource['kind'])}> + - - - - - {WALKTHROUGH_SOURCE_OPTIONS.map((option) => ( - - {option.label} - - ))} - - + + + + {WALKTHROUGH_SOURCE_OPTIONS.map((option) => ( + + {option.label} + + ))} + + + ) +}) - {sourceKind === 'branch' || sourceKind === 'pullRequest' ? ( - setBaseInput(event.target.value)} - onBlur={commitInputs} - onKeyDown={(event) => { - if (event.key === 'Enter') commitInputs() - }} - /> - ) : null} +/** Collects the base branch or pull request number for git-backed walkthrough sources. */ +const WalkthroughSourceInputs = memo(function WalkthroughSourceInputs() { + const { sourceKind, baseInput, setBaseInput, numberInput, setNumberInput, setSource } = + useChangesWalkthrough() + + const commitInputs = useCallback(() => { + const next = toWalkthroughSource({ kind: sourceKind, base: baseInput, number: Number(numberInput) }) + if (next) setSource(next) + }, [sourceKind, baseInput, numberInput, setSource]) + + if (sourceKind !== 'branch' && sourceKind !== 'pullRequest') return null + + return ( +
+ setBaseInput(event.target.value)} + onBlur={commitInputs} + onKeyDown={(event) => { + if (event.key === 'Enter') commitInputs() + }} + /> {sourceKind === 'pullRequest' ? ( - +

Enter a pull request number

) @@ -429,7 +429,7 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() { return (
- + {error ? (
@@ -569,6 +569,7 @@ export function ChangesWalkthroughSheet({ sessionId, open, onOpenChange }: Chang onClose={close} actions={ <> +