From 46886103c458394daa9fb6d29b714d49889b507a Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 8 Nov 2026 23:04:40 -0800 Subject: [PATCH] feat(setup): title imports, restore the package-manager card, keep the review dialog inside the viewport --- .../sidebar/SetupScriptCodeBlock.test.tsx | 28 +--- .../sidebar/SetupScriptCodeBlock.tsx | 16 +-- .../SetupScriptPromptCardShell.fixture.tsx | 52 ++++++-- .../sidebar/SetupScriptPromptCardShell.tsx | 13 +- .../sidebar/SetupScriptPromptCardViews.tsx | 60 +++++---- .../sidebar/SetupScriptReviewDialog.tsx | 125 ++++++------------ src/renderer/src/i18n/locales/de.json | 4 +- src/renderer/src/i18n/locales/en.json | 9 +- src/renderer/src/i18n/locales/es.json | 4 +- src/renderer/src/i18n/locales/fr.json | 4 +- src/renderer/src/i18n/locales/ja.json | 4 +- src/renderer/src/i18n/locales/ko.json | 4 +- src/renderer/src/i18n/locales/pt.json | 4 +- src/renderer/src/i18n/locales/ru.json | 4 +- src/renderer/src/i18n/locales/tr.json | 4 +- src/renderer/src/i18n/locales/zh-Hant.json | 4 +- src/renderer/src/i18n/locales/zh.json | 4 +- 17 files changed, 167 insertions(+), 176 deletions(-) diff --git a/src/renderer/src/components/sidebar/SetupScriptCodeBlock.test.tsx b/src/renderer/src/components/sidebar/SetupScriptCodeBlock.test.tsx index fd6cdc4ec11..ade3681d1b0 100644 --- a/src/renderer/src/components/sidebar/SetupScriptCodeBlock.test.tsx +++ b/src/renderer/src/components/sidebar/SetupScriptCodeBlock.test.tsx @@ -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( - {}} - 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) -}) diff --git a/src/renderer/src/components/sidebar/SetupScriptCodeBlock.tsx b/src/renderer/src/components/sidebar/SetupScriptCodeBlock.tsx index 0ae92af425c..4cbfc41961e 100644 --- a/src/renderer/src/components/sidebar/SetupScriptCodeBlock.tsx +++ b/src/renderer/src/components/sidebar/SetupScriptCodeBlock.tsx @@ -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 ( -
+

{heading}

diff --git a/src/renderer/src/components/sidebar/SetupScriptPromptCardShell.fixture.tsx b/src/renderer/src/components/sidebar/SetupScriptPromptCardShell.fixture.tsx index d90c96fda58..c61e94e88f0 100644 --- a/src/renderer/src/components/sidebar/SetupScriptPromptCardShell.fixture.tsx +++ b/src/renderer/src/components/sidebar/SetupScriptPromptCardShell.fixture.tsx @@ -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 { + await openReview(frame) + for (const toggle of document.querySelectorAll( + '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('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: () => ( + + `steps.${index}.uses`) + }} + /> + + ), + interact: openReviewExpanded }) export const packageManager = defineFixture({ diff --git a/src/renderer/src/components/sidebar/SetupScriptPromptCardShell.tsx b/src/renderer/src/components/sidebar/SetupScriptPromptCardShell.tsx index f5baa0c28a3..02f1f6ea069 100644 --- a/src/renderer/src/components/sidebar/SetupScriptPromptCardShell.tsx +++ b/src/renderer/src/components/sidebar/SetupScriptPromptCardShell.tsx @@ -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 (

- {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')}

@@ -82,6 +88,7 @@ export function SetupScriptPromptCardShell({ ) : null} @@ -101,8 +108,8 @@ export function SetupScriptPromptCardShell({ ) : null}
- {/* 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 ? ( 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 ( -