feat(setup): title imports, restore the package-manager card, keep the review dialog inside the viewport

This commit is contained in:
Neil
2026-11-08 23:04:40 -08:00
parent 1e2ae86ac7
commit 46886103c4
17 changed files with 167 additions and 176 deletions
@@ -2,9 +2,8 @@
import '@testing-library/jest-dom/vitest'
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, expect, it, vi } from 'vitest'
import { afterEach, expect, it } from 'vitest'
import { SetupScriptCodeBlock } from './SetupScriptCodeBlock'
import { SetupScriptReviewDialog } from './SetupScriptReviewDialog'
afterEach(cleanup)
@@ -35,28 +34,3 @@ it('shows a short script in full with no toggle', () => {
expect(screen.getByLabelText('Setup script')).toHaveTextContent('echo step-5')
expect(screen.queryByRole('button')).toBeNull()
})
it('enables Save in the review dialog only after a long script is expanded', () => {
const onSave = vi.fn()
render(
<SetupScriptReviewDialog
open
onOpenChange={() => {}}
repoDisplayName="acme-web"
setup={script(40)}
archive="echo bye"
skippedFields={['postStartCommand']}
provenance=".devcontainer/devcontainer.json"
isSaving={false}
onSave={onSave}
/>
)
const save = screen.getByRole('button', { name: 'Save local setup' })
expect(save).toBeDisabled()
fireEvent.click(screen.getByRole('button', { name: 'Show 35 more lines' }))
fireEvent.click(screen.getByRole('button', { name: 'Show less' }))
expect(save).toBeEnabled()
fireEvent.click(save)
expect(onSave).toHaveBeenCalledTimes(1)
})
@@ -10,21 +10,12 @@ const LINE_HEIGHT_PX = 20
// py-1.5 plus room for a horizontal scrollbar, so the last line is never clipped.
const BLOCK_PADDING_PX = 20
export function isSetupScriptCollapsible(script: string): boolean {
return (
countScriptTextareaLines(script, SETUP_SCRIPT_COLLAPSED_LINES + 1) >
SETUP_SCRIPT_COLLAPSED_LINES
)
}
export function SetupScriptCodeBlock({
heading,
script,
onExpand
script
}: {
heading: string
script: string
onExpand?: () => void
}): React.JSX.Element {
const t = useTranslate()
const contentId = useId()
@@ -39,14 +30,11 @@ export function SetupScriptCodeBlock({
// Collapsing keeps the scroll offset, so reset it to show the script's first lines.
preRef.current.scrollTop = 0
}
if (!expanded) {
onExpand?.()
}
setExpanded(!expanded)
}
return (
<section className="min-w-0 overflow-hidden rounded-md border border-border/70 bg-muted/35">
<section className="min-w-0 shrink-0 overflow-hidden rounded-md border border-border/70 bg-muted/35">
<h3 className="px-3 pt-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground">
{heading}
</h3>
@@ -12,6 +12,12 @@ const longSetup = Array.from({ length: 40 }, (_, index) => {
: `pnpm --filter @acme/pkg-${step} run setup`
}).join('\n')
const hugeSetup = Array.from(
{ length: 2000 },
(_, index) =>
`echo "step ${index + 1}" && ./scripts/run-step.sh --index=${index + 1} ${'--flag=value '.repeat(20)}`
).join('\n')
const base = {
repoBadgeColor: '#7c3aed',
repoDisplayName: 'acme-web',
@@ -97,19 +103,45 @@ export const devcontainerReview = defineFixture({
interact: openReview
})
async function openReviewExpanded(frame: HTMLElement): Promise<void> {
await openReview(frame)
for (const toggle of document.querySelectorAll<HTMLButtonElement>(
'button[aria-expanded="false"][aria-controls]'
)) {
toggle.click()
}
await new Promise((resolve) => setTimeout(resolve, 400))
if (document.activeElement instanceof HTMLElement) {
document.activeElement.blur()
}
}
export const devcontainerReviewExpanded = defineFixture({
...devcontainer,
width: 720,
interact: async (frame) => {
await openReview(frame)
document
.querySelector<HTMLButtonElement>('button[aria-expanded="false"][aria-controls]')
?.click()
await new Promise((resolve) => setTimeout(resolve, 400))
if (document.activeElement instanceof HTMLElement) {
document.activeElement.blur()
}
}
interact: openReviewExpanded
})
// 2,000 long lines in setup and archive: the dialog must stay within the viewport with Save visible.
export const hugeReviewExpanded = defineFixture({
width: 720,
render: () => (
<Frame>
<SetupScriptPromptCardShell
{...base}
isPackageManagerSuggestion={false}
candidateSource="GitHub Copilot setup steps"
candidateProvenance=".github/workflows/copilot-setup-steps.yml"
detectedSetupPreview={{
setup: hugeSetup,
archive: hugeSetup,
editable: false,
skippedFields: Array.from({ length: 30 }, (_, index) => `steps.${index}.uses`)
}}
/>
</Frame>
),
interact: openReviewExpanded
})
export const packageManager = defineFixture({
@@ -51,6 +51,7 @@ export function SetupScriptPromptCardShell({
const t = useTranslate()
const [reviewOpen, setReviewOpen] = useState(false)
const showDetected = !isInspectionError && !sharedSetupIgnored && detectedSetupPreview !== null
const isImport = showDetected && !detectedSetupPreview.editable
return (
<div
data-setup-script-prompt-layer=""
@@ -59,7 +60,12 @@ export function SetupScriptPromptCardShell({
<div className="pointer-events-auto rounded-lg border border-border bg-popover p-3 text-popover-foreground shadow-[0_10px_24px_rgba(0,0,0,0.18)]">
<div className="flex items-center justify-between gap-2">
<p className="text-sm font-semibold leading-snug">
{t('auto.components.sidebar.SetupScriptPromptCard.ff1e819a11', 'Add a setup script')}
{isImport
? t(
'auto.components.sidebar.SetupScriptPromptCard.importTitle',
'Import setup script'
)
: t('auto.components.sidebar.SetupScriptPromptCard.ff1e819a11', 'Add a setup script')}
</p>
<DismissButton onDismiss={onDismiss} />
</div>
@@ -82,6 +88,7 @@ export function SetupScriptPromptCardShell({
<DetectedSetupPreview
setup={detectedSetupPreview.setup}
onSetupChange={onSetupDraftChange}
provenance={candidateProvenance}
/>
) : null}
@@ -101,8 +108,8 @@ export function SetupScriptPromptCardShell({
<ConfigureOnlyAction onConfigure={onConfigure} />
) : null}
</div>
{/* Imported scripts are saved verbatim, so saving only happens after the full text is on screen. */}
{showDetected && !detectedSetupPreview.editable ? (
{/* Imported scripts are saved verbatim, so saving happens from a dialog that can show all of the text. */}
{isImport && detectedSetupPreview ? (
<SetupScriptReviewDialog
open={reviewOpen}
onOpenChange={setReviewOpen}
@@ -1,5 +1,5 @@
import React from 'react'
import { Check, LoaderCircle, RefreshCw, ScrollText, Settings, X } from 'lucide-react'
import { Check, LoaderCircle, PackageCheck, RefreshCw, ScrollText, Settings, X } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
import { cn } from '@/lib/utils'
@@ -41,25 +41,47 @@ function DismissButton({ onDismiss }: DismissButtonProps): React.JSX.Element {
export type DetectedSetupPreviewProps = {
setup: string
onSetupChange: (value: string) => void
provenance: string | null
}
// Package-manager guesses only: imports are summarized in one line and reviewed in a dialog.
export function DetectedSetupPreview({
setup,
onSetupChange
onSetupChange,
provenance
}: DetectedSetupPreviewProps): React.JSX.Element {
const t = useTranslate()
return (
<textarea
value={setup}
aria-label={t(
'auto.components.sidebar.SetupScriptPromptCardViews.fdbc6cb064',
'Detected setup script'
)}
onChange={(event) => onSetupChange(event.target.value)}
spellCheck={false}
rows={getDetectedSetupScriptTextareaRows(setup)}
className="setup-script-prompt-command mt-2 max-h-28 w-full resize-y overflow-auto scrollbar-sleek rounded-md border border-worktree-sidebar-border px-2 py-1.5 font-mono text-[11px] leading-5 text-foreground shadow-xs outline-none focus-visible:ring-1 focus-visible:ring-ring"
/>
<div className="mt-3 border-t border-worktree-sidebar-border pt-3">
<div className="mb-2 flex items-center gap-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground">
<PackageCheck className="size-3.5" />
{t('auto.components.sidebar.SetupScriptPromptCardViews.7275f674cc', 'Detected setup')}
</div>
<textarea
value={setup}
aria-label={t(
'auto.components.sidebar.SetupScriptPromptCardViews.fdbc6cb064',
'Detected setup script'
)}
onChange={(event) => onSetupChange(event.target.value)}
spellCheck={false}
rows={getDetectedSetupScriptTextareaRows(setup)}
className="setup-script-prompt-command max-h-28 w-full resize-y overflow-auto scrollbar-sleek rounded-md border border-worktree-sidebar-border px-2 py-1.5 font-mono text-[11px] leading-5 text-foreground shadow-xs outline-none focus-visible:ring-1 focus-visible:ring-ring"
/>
{provenance ? (
<p className="mt-1.5 text-[11px] text-muted-foreground">
<Trans
i18n={i18n}
defaults={t(
'auto.components.sidebar.SetupScriptPromptCardViews.detectedFromSource',
'Detected from <file>{{source}}</file>'
)}
values={{ source: provenance }}
components={{ file: <code className="rounded bg-muted px-1 py-0.5" /> }}
/>
</p>
) : null}
</div>
)
}
@@ -173,17 +195,7 @@ export function SetupScriptPromptBody({
}
const sourceElement = <span className="break-words text-foreground" />
if (isPackageManagerSuggestion) {
return candidateSource ? (
<Trans
i18n={i18n}
defaults={t(
'auto.components.sidebar.SetupScriptPromptCardViews.suggestedFromSource',
'Suggested from <file>{{source}}</file>. Save it to run for new worktrees.'
)}
values={{ source: candidateSource }}
components={{ file: sourceElement }}
/>
) : (
return (
<>
{t(
'auto.components.sidebar.SetupScriptPromptCardViews.aef6c0a213',
@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React from 'react'
import { Download, LoaderCircle } from 'lucide-react'
import { Trans } from 'react-i18next'
import {
@@ -13,7 +13,7 @@ import { Button } from '@/components/ui/button'
import { cn } from '@/lib/utils'
import { i18n } from '@/i18n/i18n'
import { useTranslate } from '@/i18n/use-translate'
import { isSetupScriptCollapsible, SetupScriptCodeBlock } from './SetupScriptCodeBlock'
import { SetupScriptCodeBlock } from './SetupScriptCodeBlock'
export type SetupScriptReviewDialogProps = {
open: boolean
@@ -67,8 +67,9 @@ export function SetupScriptReviewDialog({
const t = useTranslate()
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent scrollable className="sm:max-w-xl">
<DialogHeader>
{/* Viewport-capped column: only the middle scrolls, so the title and Save stay visible for any script length. */}
<DialogContent className="flex max-h-[calc(100vh-2rem)] flex-col overflow-hidden sm:max-w-xl">
<DialogHeader className="shrink-0">
<DialogTitle size="compact">
{t('auto.components.sidebar.SetupScriptReviewDialog.title', 'Review setup script')}
</DialogTitle>
@@ -93,87 +94,43 @@ export function SetupScriptReviewDialog({
</DialogDescription>
</DialogHeader>
<ReviewedScripts
// A re-inspected candidate is new text, so it must be revealed again.
key={`${setup}\0${archive ?? ''}`}
setup={setup}
archive={archive}
skippedFields={skippedFields}
isSaving={isSaving}
onCancel={() => onOpenChange(false)}
onSave={onSave}
/>
<div className="-mx-6 flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto scrollbar-sleek px-6">
<SetupScriptCodeBlock
heading={t(
'auto.components.sidebar.SetupScriptReviewDialog.setupScript',
'Setup script'
)}
script={setup}
/>
{archive ? (
<SetupScriptCodeBlock
heading={t(
'auto.components.sidebar.SetupScriptReviewDialog.archiveScript',
'Archive script'
)}
script={archive}
/>
) : null}
{skippedFields.length > 0 ? <SkippedFieldsList fields={skippedFields} /> : null}
</div>
<DialogFooter className="shrink-0">
<Button variant="outline" onClick={() => onOpenChange(false)}>
{t('common.cancel', 'Cancel')}
</Button>
<Button onClick={onSave} disabled={isSaving}>
{isSaving ? (
<LoaderCircle className="size-3.5 animate-spin" />
) : (
<Download className="size-3.5" />
)}
<span className={cn(isSaving && 'text-muted-foreground')}>
{t('auto.components.sidebar.SetupScriptReviewDialog.save', 'Save local setup')}
</span>
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
// Lives inside DialogContent, which unmounts on close, so every opening starts unrevealed.
function ReviewedScripts({
setup,
archive,
skippedFields,
isSaving,
onCancel,
onSave
}: {
setup: string
archive: string | null
skippedFields: readonly string[]
isSaving: boolean
onCancel: () => void
onSave: () => void
}): React.JSX.Element {
const t = useTranslate()
const [setupRevealed, setSetupRevealed] = useState(false)
const [archiveRevealed, setArchiveRevealed] = useState(false)
// Imported scripts are saved verbatim, so Save waits until every collapsed line has been shown.
const fullyShown =
(setupRevealed || !isSetupScriptCollapsible(setup)) &&
(archive === null || archiveRevealed || !isSetupScriptCollapsible(archive))
return (
<>
<SetupScriptCodeBlock
heading={t('auto.components.sidebar.SetupScriptReviewDialog.setupScript', 'Setup script')}
script={setup}
onExpand={() => setSetupRevealed(true)}
/>
{archive ? (
<SetupScriptCodeBlock
heading={t(
'auto.components.sidebar.SetupScriptReviewDialog.archiveScript',
'Archive script'
)}
script={archive}
onExpand={() => setArchiveRevealed(true)}
/>
) : null}
{skippedFields.length > 0 ? <SkippedFieldsList fields={skippedFields} /> : null}
<DialogFooter className="sm:items-center">
{fullyShown ? null : (
<p className="text-xs text-muted-foreground sm:mr-auto">
{t(
'auto.components.sidebar.SetupScriptReviewDialog.showFullToSave',
'Show the full script to save it.'
)}
</p>
)}
<Button variant="outline" onClick={onCancel}>
{t('common.cancel', 'Cancel')}
</Button>
<Button onClick={onSave} disabled={isSaving || !fullyShown}>
{isSaving ? (
<LoaderCircle className="size-3.5 animate-spin" />
) : (
<Download className="size-3.5" />
)}
<span className={cn(isSaving && 'text-muted-foreground')}>
{t('auto.components.sidebar.SetupScriptReviewDialog.save', 'Save local setup')}
</span>
</Button>
</DialogFooter>
</>
)
}
+3 -1
View File
@@ -6183,7 +6183,9 @@
"822ff300ad": "Ausblenden",
"5bfd5c8779": "Setup-Skripte ausblenden",
"ignoresSharedSetup": "Dieses Repo ignoriert gemeinsame Einrichtungsskripte aus <yaml>orca.yaml</yaml>. Einen lokalen Befehl hinzufügen oder die Quelle in den Einstellungen ändern.",
"reviewSetupScript": "Einrichtungsskript prüfen"
"reviewSetupScript": "Einrichtungsskript prüfen",
"7275f674cc": "Erkanntes Setup",
"detectedFromSource": "In <file>{{source}}</file> erkannt"
},
"SetupScriptReviewDialog": {
"title": "Einrichtungsskript prüfen",
+5 -4
View File
@@ -6447,7 +6447,8 @@
"888b83bf78": "Failed to save setup script",
"a49196d538": "Runs when Orca creates a new worktree.",
"savedSetupCommand": "Saved the setup command.",
"savedInProjectSettings": "Saved in this <settings>project's settings</settings>"
"savedInProjectSettings": "Saved in this <settings>project's settings</settings>",
"importTitle": "Import setup script"
},
"SetupScriptPromptCardViews": {
"3933401d28": "Configure",
@@ -6464,7 +6465,8 @@
"ignoresSharedSetup": "This repo ignores shared <yaml>orca.yaml</yaml> setup scripts. Add a local command, or change the source in Settings.",
"reviewSetupScript": "Review setup script",
"foundSetupScriptIn": "Found a setup script in <file>{{source}}</file>.",
"suggestedFromSource": "Suggested from <file>{{source}}</file>. Save it to run for new worktrees."
"7275f674cc": "Detected setup",
"detectedFromSource": "Detected from <file>{{source}}</file>"
},
"SetupScriptReviewDialog": {
"title": "Review setup script",
@@ -6474,8 +6476,7 @@
"save": "Save local setup",
"descriptionWithSource": "From <file>{{source}}</file>. Saving runs this whenever Orca creates a worktree for {{repo}}.",
"notImported": "Not imported",
"notImportedHint": "These settings have no Orca equivalent and won't be saved.",
"showFullToSave": "Show the full script to save it."
"notImportedHint": "These settings have no Orca equivalent and won't be saved."
},
"SidebarFeedbackDialog": {
"8bf619e4cf": "Cancel",
+3 -1
View File
@@ -5782,7 +5782,9 @@
"822ff300ad": "Descartar",
"5bfd5c8779": "Descartar scripts de configuración",
"ignoresSharedSetup": "Este repositorio ignora los scripts de configuración compartidos de <yaml>orca.yaml</yaml>. Añade un comando local o cambia la fuente en Ajustes.",
"reviewSetupScript": "Revisar script de configuración"
"reviewSetupScript": "Revisar script de configuración",
"7275f674cc": "Setup detectado",
"detectedFromSource": "Detectado en <file>{{source}}</file>"
},
"SetupScriptReviewDialog": {
"title": "Revisar script de configuración",
+3 -1
View File
@@ -6022,7 +6022,9 @@
"822ff300ad": "Ignorer",
"5bfd5c8779": "Ignorer les scripts de setup",
"ignoresSharedSetup": "Ce dépôt ignore les scripts de setup partagés de <yaml>orca.yaml</yaml>. Ajoutez une commande locale ou changez la source dans les paramètres.",
"reviewSetupScript": "Vérifier le script de setup"
"reviewSetupScript": "Vérifier le script de setup",
"7275f674cc": "Setup détecté",
"detectedFromSource": "Détecté dans <file>{{source}}</file>"
},
"SetupScriptReviewDialog": {
"title": "Vérifier le script de setup",
+3 -1
View File
@@ -5538,7 +5538,9 @@
"822ff300ad": "閉じる",
"5bfd5c8779": "セットアップスクリプトを閉じる",
"ignoresSharedSetup": "このリポジトリは共有の <yaml>orca.yaml</yaml> セットアップスクリプトを無視します。ローカルコマンドを追加するか、設定でソースを変更してください。",
"reviewSetupScript": "セットアップスクリプトを確認"
"reviewSetupScript": "セットアップスクリプトを確認",
"7275f674cc": "検出されたセットアップ",
"detectedFromSource": "<file>{{source}}</file> から検出"
},
"SetupScriptReviewDialog": {
"title": "セットアップスクリプトを確認",
+3 -1
View File
@@ -5538,7 +5538,9 @@
"822ff300ad": "닫기",
"5bfd5c8779": "설정 스크립트 닫기",
"ignoresSharedSetup": "이 저장소는 공유 <yaml>orca.yaml</yaml> 설정 스크립트를 무시합니다. 로컬 명령을 추가하거나 설정에서 소스를 변경하세요.",
"reviewSetupScript": "설정 스크립트 검토"
"reviewSetupScript": "설정 스크립트 검토",
"7275f674cc": "감지된 설정",
"detectedFromSource": "<file>{{source}}</file>에서 감지됨"
},
"SetupScriptReviewDialog": {
"title": "설정 스크립트 검토",
+3 -1
View File
@@ -11810,7 +11810,9 @@
"822ff300ad": "Descartar",
"5bfd5c8779": "Descartar scripts de configuração",
"ignoresSharedSetup": "Este repositório ignora scripts de configuração compartilhados de <yaml>orca.yaml</yaml>. Adicione um comando local ou altere a origem em Configurações.",
"reviewSetupScript": "Revisar script de configuração"
"reviewSetupScript": "Revisar script de configuração",
"7275f674cc": "Configuração detectada",
"detectedFromSource": "Detectado em <file>{{source}}</file>"
},
"SetupScriptReviewDialog": {
"title": "Revisar script de configuração",
+3 -1
View File
@@ -6467,7 +6467,9 @@
"822ff300ad": "Скрыть",
"5bfd5c8779": "Скрыть скрипты настройки",
"ignoresSharedSetup": "Этот репозиторий игнорирует общие скрипты настройки из <yaml>orca.yaml</yaml>. Добавьте локальную команду или измените источник в настройках.",
"reviewSetupScript": "Проверить скрипт настройки"
"reviewSetupScript": "Проверить скрипт настройки",
"7275f674cc": "Найденная настройка",
"detectedFromSource": "Обнаружено в <file>{{source}}</file>"
},
"SetupScriptReviewDialog": {
"title": "Проверить скрипт настройки",
+3 -1
View File
@@ -6167,7 +6167,9 @@
"822ff300ad": "Kapat",
"5bfd5c8779": "Kurulum betiklerini kapat",
"ignoresSharedSetup": "Bu repo, paylaşılan <yaml>orca.yaml</yaml> kurulum betiklerini yok sayıyor. Yerel bir komut ekleyin veya Ayarlar bölümünde kaynağı değiştirin.",
"reviewSetupScript": "Kurulum betiğini incele"
"reviewSetupScript": "Kurulum betiğini incele",
"7275f674cc": "Algılanan kurulum",
"detectedFromSource": "<file>{{source}}</file> kaynağından algılandı"
},
"SetupScriptReviewDialog": {
"title": "Kurulum betiğini incele",
+3 -1
View File
@@ -6024,7 +6024,9 @@
"822ff300ad": "關閉",
"5bfd5c8779": "關閉設定指令碼",
"ignoresSharedSetup": "此存放庫會忽略共用的 <yaml>orca.yaml</yaml> 設定指令碼。請新增本機命令,或在「設定」中變更來源。",
"reviewSetupScript": "檢查設定指令碼"
"reviewSetupScript": "檢查設定指令碼",
"7275f674cc": "已偵測的設定",
"detectedFromSource": "從 <file>{{source}}</file> 偵測到"
},
"SetupScriptReviewDialog": {
"title": "檢查設定指令碼",
+3 -1
View File
@@ -5538,7 +5538,9 @@
"822ff300ad": "关闭",
"5bfd5c8779": "关闭安装脚本",
"ignoresSharedSetup": "此仓库会忽略共享的 <yaml>orca.yaml</yaml> 设置脚本。请添加本地命令,或在“设置”中更改来源。",
"reviewSetupScript": "查看设置脚本"
"reviewSetupScript": "查看设置脚本",
"7275f674cc": "已检测的设置",
"detectedFromSource": "从 <file>{{source}}</file> 已检测"
},
"SetupScriptReviewDialog": {
"title": "查看设置脚本",