mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat(walkthrough): move source picker into the panel header
This commit is contained in:
1 parent
b01d3ab6db
commit
0d65edfa44
4 files changed
+61
-46
No files matched your search
@@ -27,6 +27,7 @@ vi.mock('@/components/session/ChangesWalkthroughSheet', () => ({
|
||||
ChangesWalkthroughProvider: ({ children }: { children: ReactNode }) => <>{children}</>,
|
||||
ChangesWalkthroughNav: () => null,
|
||||
ChangesWalkthroughRegenerate: () => null,
|
||||
ChangesWalkthroughSourcePicker: () => null,
|
||||
ChangesWalkthroughView: () => <div>walkthrough-tool</div>,
|
||||
}))
|
||||
|
||||
|
||||
@@ -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({
|
||||
<h2 className="min-w-0 flex-1 truncate text-sm font-semibold text-foreground">{activeLabel}</h2>
|
||||
{activeTool === 'walkthrough' ? (
|
||||
<>
|
||||
<ChangesWalkthroughSourcePicker />
|
||||
<ChangesWalkthroughRegenerate />
|
||||
<ChangesWalkthroughNav />
|
||||
</>
|
||||
|
||||
@@ -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 }))
|
||||
|
||||
@@ -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 (
|
||||
<div className="space-y-2">
|
||||
<Select
|
||||
value={sourceKind}
|
||||
onValueChange={(value) => handleKindChange(value as WalkthroughSource['kind'])}
|
||||
<Select value={sourceKind} onValueChange={(value) => handleKindChange(value as WalkthroughSource['kind'])}>
|
||||
<SelectTrigger
|
||||
aria-label="Changes to walk through"
|
||||
className="h-7 w-auto gap-1 px-2 text-xs md:text-xs"
|
||||
>
|
||||
<SelectTrigger aria-label="Changes to walk through">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{WALKTHROUGH_SOURCE_OPTIONS.map((option) => (
|
||||
<SelectItem key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{WALKTHROUGH_SOURCE_OPTIONS.map((option) => (
|
||||
<SelectItem key={option.value} value={option.value}>
|
||||
{option.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)
|
||||
})
|
||||
|
||||
{sourceKind === 'branch' || sourceKind === 'pullRequest' ? (
|
||||
<Input
|
||||
aria-label="Base branch"
|
||||
placeholder="Default branch"
|
||||
value={baseInput}
|
||||
onChange={(event) => 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 (
|
||||
<div className="space-y-2">
|
||||
<Input
|
||||
aria-label="Base branch"
|
||||
placeholder="Default branch"
|
||||
value={baseInput}
|
||||
onChange={(event) => setBaseInput(event.target.value)}
|
||||
onBlur={commitInputs}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'Enter') commitInputs()
|
||||
}}
|
||||
/>
|
||||
|
||||
{sourceKind === 'pullRequest' ? (
|
||||
<Input
|
||||
@@ -421,7 +421,7 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() {
|
||||
if (sourcePending) {
|
||||
return (
|
||||
<div className="min-h-0 flex-1 space-y-4 overflow-y-auto p-4">
|
||||
<WalkthroughSourcePicker />
|
||||
<WalkthroughSourceInputs />
|
||||
<p className="text-sm text-muted-foreground">Enter a pull request number</p>
|
||||
</div>
|
||||
)
|
||||
@@ -429,7 +429,7 @@ export const ChangesWalkthroughView = memo(function ChangesWalkthroughView() {
|
||||
|
||||
return (
|
||||
<div ref={scrollRef} className="min-h-0 flex-1 space-y-4 overflow-y-auto p-4">
|
||||
<WalkthroughSourcePicker />
|
||||
<WalkthroughSourceInputs />
|
||||
|
||||
{error ? (
|
||||
<div className="space-y-2">
|
||||
@@ -569,6 +569,7 @@ export function ChangesWalkthroughSheet({ sessionId, open, onOpenChange }: Chang
|
||||
onClose={close}
|
||||
actions={
|
||||
<>
|
||||
<ChangesWalkthroughSourcePicker />
|
||||
<ChangesWalkthroughRegenerate />
|
||||
<ChangesWalkthroughNav />
|
||||
</>
|
||||
|
||||
Reference in new issue
Block a user