From 0c8d1422995441c08faca992daef507b9973fb10 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 10 Nov 2026 16:03:01 -0800 Subject: [PATCH] chore(cloud): composer-redo lint (file size, footer type, no stale state) --- .../components/NewWorkspaceComposerModal.tsx | 173 +++++++----------- .../NewWorkspaceComposerFooter.tsx | 11 +- .../NewWorkspaceComposerProjectSection.tsx | 36 ++-- .../new-workspace/RunTargetCombobox.tsx | 24 +-- .../new-workspace/RunTargetRowList.tsx | 7 +- .../composer-cloud-auto-start.tsx | 61 ++++++ .../run-on/use-cloud-start-composer.ts | 10 +- .../run-on/use-composer-cloud-start.ts | 17 +- .../orca-cloud-setup/CloudSetupPage.tsx | 48 +++-- .../cloud-setup-page-model.test.ts | 4 +- .../cloud-setup-page-model.ts | 10 +- .../orca-cloud-setup/use-cloud-setup-flow.ts | 20 +- 12 files changed, 240 insertions(+), 181 deletions(-) create mode 100644 src/renderer/src/components/new-workspace/composer-cloud-auto-start.tsx diff --git a/src/renderer/src/components/NewWorkspaceComposerModal.tsx b/src/renderer/src/components/NewWorkspaceComposerModal.tsx index 460cd81b925..7870613b944 100644 --- a/src/renderer/src/components/NewWorkspaceComposerModal.tsx +++ b/src/renderer/src/components/NewWorkspaceComposerModal.tsx @@ -39,9 +39,7 @@ import { getFolderWorkspacePrimaryActionLabel } from '@/components/sidebar/works import { useAgentMenuObservation } from '@/components/tab-bar/use-new-tab-agent-menu-rows' import { addAppKeyListener, removeAppKeyListener } from '@/lib/keyboard/app-keyboard-router' import { useComposerCloudStart } from './new-workspace/run-on/use-composer-cloud-start' - -/** How long a hidden Orca Cloud auto-start may take before the dialog shows instead. */ -const CLOUD_AUTO_START_REVEAL_MS = 8_000 +import { HiddenComposer, useCloudAutoStartReveal } from './new-workspace/composer-cloud-auto-start' // Keep Add Project’s clone/SSH machinery outside the composer entry render, matching App loading. const HostedAddRepoDialog = lazyWithRetry( @@ -83,34 +81,18 @@ function ComposerModalBody({ onClose() }, [onClose]) const isSubmissionCancelled = useCallback(() => submitCancelledRef.current, []) - // Orca Cloud setup finished on its page: submit with the dialog unseen. If the start can't run - // by itself (a form error, a revoked grant), the dialog appears with everything kept. - const [autoStartRevealed, setAutoStartRevealed] = useState(false) - useEffect(() => { - if (!modalData.cloudAutoStart) { - return - } - const timer = window.setTimeout(() => setAutoStartRevealed(true), CLOUD_AUTO_START_REVEAL_MS) - return () => window.clearTimeout(timer) - }, [modalData.cloudAutoStart]) - if (modalData.cloudAutoStart && !autoStartRevealed) { - return ( - // A closed Root still provides the title's context; nothing is portaled or shown. - -
- -
-
- ) + const visibleModalData = useCloudAutoStartReveal(modalData) + const body = (data: ComposerModalData): React.JSX.Element => ( + + ) + if (!visibleModalData) { + return {body(modalData)} } - const visibleModalData = modalData.cloudAutoStart - ? { ...modalData, cloudAutoStart: false } - : modalData return ( !open && handleDismiss()}> @@ -129,12 +111,7 @@ function ComposerModalBody({ getWorkspaceComposerInitialFocusTarget(content)?.focus({ preventScroll: true }) }} > - + {body(visibleModalData)} ) @@ -236,75 +213,67 @@ function QuickTabBody({ // `withoutAgent`: Orca Cloud with an agent that has no account there starts a plain terminal // instead of dropping the user into the agent's /login. - const handleCreate = useCallback(async (options?: { withoutAgent?: boolean }): Promise => { - if (createDisabled) { - return - } - const agent = options?.withoutAgent ? null : quickAgent - await submitQuick(agent, { - // Blank Terminal is the setup-only create: no agent, and no extra shell beside setup. - setupOnly: agent === null, - ...(agent === null ? {} : { launchChoice: launchSelection.choice }), - onLegacyPreparationFailure: (error) => { - if (isSubmissionCancelled()) { - return - } - const snapshot = { - ...modalData, - prefilledName: cardProps.name, - initialRepoId: cardProps.repoId, - initialBaseBranch: cardProps.baseBranch, - initialWorkspaceTarget: - cardProps.selectedProjectId && cardProps.selectedRepoExecutionHostId - ? { - projectId: cardProps.selectedProjectId, - hostId: cardProps.selectedRepoExecutionHostId, - projectHostSetupId: cardProps.selectedProjectHostSetupId ?? null + const handleCreate = useCallback( + async (options?: { withoutAgent?: boolean }): Promise => { + if (createDisabled) { + return + } + const agent = options?.withoutAgent ? null : quickAgent + await submitQuick(agent, { + // Blank Terminal is the setup-only create: no agent, and no extra shell beside setup. + setupOnly: agent === null, + ...(agent === null ? {} : { launchChoice: launchSelection.choice }), + onLegacyPreparationFailure: (error) => { + if (isSubmissionCancelled()) { + return + } + const snapshot = { + ...modalData, + prefilledName: cardProps.name, + initialRepoId: cardProps.repoId, + initialBaseBranch: cardProps.baseBranch, + initialWorkspaceTarget: + cardProps.selectedProjectId && cardProps.selectedRepoExecutionHostId + ? { + projectId: cardProps.selectedProjectId, + hostId: cardProps.selectedRepoExecutionHostId, + projectHostSetupId: cardProps.selectedProjectHostSetupId ?? null + } + : modalData.initialWorkspaceTarget, + linkedWorkItem: cardProps.linkedWorkItem, + recovery: { ...quickAgentPick, agent: quickAgent, note: cardProps.note } + } + toast.error(getWorkspaceCreateErrorToastMessage(formatWorkspaceCreateError(error)), { + action: { + label: translate('auto.lib.composerCreateHandoff.reopen', 'Reopen'), + onClick: () => { + if (!isSubmissionCancelled() && useAppStore.getState().activeModal === 'none') { + useAppStore.getState().openModal('new-workspace-composer', snapshot) } - : modalData.initialWorkspaceTarget, - linkedWorkItem: cardProps.linkedWorkItem, - recovery: { ...quickAgentPick, agent: quickAgent, note: cardProps.note } - } - toast.error(getWorkspaceCreateErrorToastMessage(formatWorkspaceCreateError(error)), { - action: { - label: translate('auto.lib.composerCreateHandoff.reopen', 'Reopen'), - onClick: () => { - if (!isSubmissionCancelled() && useAppStore.getState().activeModal === 'none') { - useAppStore.getState().openModal('new-workspace-composer', snapshot) } } - } - }) - }, - ...quickWorkspacePickerInputs( - pickerDraft, - quickAgentPick.entry, - launchSelection.choice?.executionHostId - ) - }) - }, [ - createDisabled, - quickAgent, - launchSelection.choice, - submitQuick, - pickerDraft, - quickAgentPick, - isSubmissionCancelled, - modalData, - cardProps - ]) - // The composer as it is now, for Orca Cloud's setup page (Back, and the start when it's done). - const composerSnapshot = useCallback( - (): ComposerModalData => ({ - ...modalData, - prefilledName: cardProps.name, - initialRepoId: cardProps.repoId, - initialBaseBranch: cardProps.baseBranch, - linkedWorkItem: cardProps.linkedWorkItem, - recovery: { ...quickAgentPick, agent: quickAgent, note: cardProps.note } - }), - [cardProps, modalData, quickAgent, quickAgentPick] + }) + }, + ...quickWorkspacePickerInputs( + pickerDraft, + quickAgentPick.entry, + launchSelection.choice?.executionHostId + ) + }) + }, + [ + createDisabled, + quickAgent, + launchSelection.choice, + submitQuick, + pickerDraft, + quickAgentPick, + isSubmissionCancelled, + modalData, + cardProps + ] ) + // The composer as it is now, for Orca Cloud's setup page (Back, and the start when it's done). const { cloudStart, primaryCreateDisabled, onPrimary } = useComposerCloudStart({ active, modalData, @@ -312,7 +281,7 @@ function QuickTabBody({ quickAgent, handleCreate, createDisabled, - composerSnapshot, + quickAgentPick, recordCreatedRef, onClose }) diff --git a/src/renderer/src/components/new-workspace/NewWorkspaceComposerFooter.tsx b/src/renderer/src/components/new-workspace/NewWorkspaceComposerFooter.tsx index 07f1534aa61..c041625c6e2 100644 --- a/src/renderer/src/components/new-workspace/NewWorkspaceComposerFooter.tsx +++ b/src/renderer/src/components/new-workspace/NewWorkspaceComposerFooter.tsx @@ -72,11 +72,14 @@ export function NewWorkspaceComposerFooter({ onClick={() => void onCreate()} disabled={createDisabled} size="sm" - className="ml-auto shrink-0 text-xs" + className="ml-auto shrink-0" > - {creating ? : null} - {primaryActionLabel} - + {/* The footer's compact type, as before; the Button keeps its own variant styling. */} + + {creating ? : null} + {primaryActionLabel} + + diff --git a/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.tsx b/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.tsx index 67078a12a40..d7f1e67462b 100644 --- a/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.tsx +++ b/src/renderer/src/components/new-workspace/NewWorkspaceComposerProjectSection.tsx @@ -38,24 +38,24 @@ type NewWorkspaceComposerProjectSectionProps = Pick< | 'orcaCloudAvailability' | 'cloudStart' > & { - disabled?: boolean - projectDescriptionId: string - onAddProject: () => void - focusNameInput: () => void - shouldShowRunTargetPicker: boolean - projectHostSetupOptions: NewWorkspaceComposerCardProps['projectHostSetupOptions'] - ephemeralVmRecipes: EphemeralVmRecipeOption[] - handleProjectHostSetupChange: (setupId: string) => void - handleAddSshHost: () => void - handleAddRemoteServer: () => void - handleConnectRunTargetHost: (option: NeedsProjectHostOption) => Promise - handleSetLocation: (option: NeedsProjectHostOption) => void - sshStatusLabel: string - connectButtonLabel: string - selectedProjectName: string - /** Fixtures pin Orca Cloud entitlement; the app reads it from billing. */ - orcaCloudAccess?: OrcaCloudRunTargetAccess - } + disabled?: boolean + projectDescriptionId: string + onAddProject: () => void + focusNameInput: () => void + shouldShowRunTargetPicker: boolean + projectHostSetupOptions: NewWorkspaceComposerCardProps['projectHostSetupOptions'] + ephemeralVmRecipes: EphemeralVmRecipeOption[] + handleProjectHostSetupChange: (setupId: string) => void + handleAddSshHost: () => void + handleAddRemoteServer: () => void + handleConnectRunTargetHost: (option: NeedsProjectHostOption) => Promise + handleSetLocation: (option: NeedsProjectHostOption) => void + sshStatusLabel: string + connectButtonLabel: string + selectedProjectName: string + /** Fixtures pin Orca Cloud entitlement; the app reads it from billing. */ + orcaCloudAccess?: OrcaCloudRunTargetAccess +} export function NewWorkspaceComposerProjectSection({ disabled = false, diff --git a/src/renderer/src/components/new-workspace/RunTargetCombobox.tsx b/src/renderer/src/components/new-workspace/RunTargetCombobox.tsx index ec6ce2b237c..c8e7a185a1d 100644 --- a/src/renderer/src/components/new-workspace/RunTargetCombobox.tsx +++ b/src/renderer/src/components/new-workspace/RunTargetCombobox.tsx @@ -9,7 +9,6 @@ import { type ReadyProjectHostSetupOption } from '@/lib/project-host-setup-options' import type { ExecutionHostId } from '../../../../shared/execution-host' -import { ORCA_CLOUD_RECIPE_ID } from '../../../../shared/hosted-sandbox/orca-cloud-recipe-id' import { isWithinComboboxRoot, useTypeAheadCombobox } from './use-type-ahead-combobox' import { COMBOBOX_POPOVER_SURFACE } from './type-ahead-combobox-styles' import { @@ -18,9 +17,6 @@ import { getRecipeSubmenuItemKey, getRunTargetSubmenuItemKeys, getRunTargetCurrentRowKey, - getOrcaCloudDetail, - ORCA_CLOUD_LABEL, - RUN_TARGET_ORCA_CLOUD_KEY, getRunTargetOptionId, RUN_TARGET_ADD_HOST_KEY, RUN_TARGET_ADD_REMOTE_SERVER_ITEM, @@ -110,13 +106,8 @@ export default function RunTargetCombobox({ // An unlisted target (e.g. a per-workspace VM) shows "Choose target", never another host's name (#38669). null const selectedRecipe = recipes.find((recipe) => recipe.id === recipeValue) ?? null - // Signed out, main lists no Orca Cloud recipe, yet the composer can still pick it. - const orcaCloudPicked = - selectedRecipe === null && recipeValue === ORCA_CLOUD_RECIPE_ID && Boolean(onSelectOrcaCloud) // Opening highlights the committed row, so only one row reads as chosen. - const currentRowKey = orcaCloudPicked - ? RUN_TARGET_ORCA_CLOUD_KEY - : getRunTargetCurrentRowKey(selectedRecipe, selectedHost) + const currentRowKey = getRunTargetCurrentRowKey(selectedRecipe, selectedHost) const hasAddHost = Boolean(onAddSshHost || onAddRemoteServer) const orcaCloudOffer = getRunTargetOrcaCloudOffer({ @@ -152,8 +143,7 @@ export default function RunTargetCombobox({ const { submenu, armedItemKey, openSubmenu, closeSubmenu, armItem, moveItemArm, armItemEdge } = useRunTargetSubmenu(submenuItemKeys) const armedRow = rows.find((row) => row.key === armedKey) ?? rows[0] ?? null - const committed = - query.length === 0 && (orcaCloudPicked || selectedRecipe !== null || selectedHost !== null) + const committed = query.length === 0 && (selectedRecipe !== null || selectedHost !== null) // Closing also drops any open submenu, which the shared hook doesn't know about. const close = useCallback((): void => { @@ -324,9 +314,7 @@ export default function RunTargetCombobox({ const activeDescendantId = activeDescendantKey ? optionIdFor(activeDescendantKey) : undefined const addHostOptionId = optionIdFor(RUN_TARGET_ADD_HOST_KEY) - const field = orcaCloudPicked - ? { label: ORCA_CLOUD_LABEL, detail: getOrcaCloudDetail(t), recipeKind: 'orca-cloud' as const } - : getRunTargetFieldText(selectedRecipe, selectedHost, t) + const field = getRunTargetFieldText(selectedRecipe, selectedHost, t) return ( @@ -342,7 +330,7 @@ export default function RunTargetCombobox({ onToggle={() => setOpen(!open)} committed={committed} recipeKind={field.recipeKind} - hostId={orcaCloudPicked ? null : (selectedHost?.hostId ?? null)} + hostId={selectedHost?.hostId ?? null} label={field.label} detail={field.detail} controlsId={submenu ? `${listId} ${listId}-${submenu}` : listId} @@ -396,8 +384,8 @@ export default function RunTargetCombobox({ onArm(row.key, null)} onSelect={() => onSelectOrcaCloud(row.recipe)} diff --git a/src/renderer/src/components/new-workspace/composer-cloud-auto-start.tsx b/src/renderer/src/components/new-workspace/composer-cloud-auto-start.tsx new file mode 100644 index 00000000000..c327e43e5c7 --- /dev/null +++ b/src/renderer/src/components/new-workspace/composer-cloud-auto-start.tsx @@ -0,0 +1,61 @@ +// The composer's side of the Orca Cloud setup page (composer-redo): the snapshot the page keeps for +// Back and for its auto-start, and the hidden composer that submits once setup is done. +import React, { useEffect, useState } from 'react' +import { Dialog } from '@/components/ui/dialog' +import type { ComposerModalData } from './composer-modal-data' + +/** How long a hidden Orca Cloud auto-start may take before the dialog shows instead. */ +const CLOUD_AUTO_START_REVEAL_MS = 8_000 + +/** The composer as it is now: prompt, project, base branch, linked item and agent pick. */ +export function buildComposerSnapshot( + modalData: ComposerModalData, + card: { + name: string + repoId: string + baseBranch?: string + linkedWorkItem?: ComposerModalData['linkedWorkItem'] + note: string + }, + agentPick: Omit, 'note'> +): ComposerModalData { + return { + ...modalData, + prefilledName: card.name, + initialRepoId: card.repoId, + ...(card.baseBranch ? { initialBaseBranch: card.baseBranch } : {}), + linkedWorkItem: card.linkedWorkItem ?? null, + recovery: { ...agentPick, note: card.note } + } +} + +/** + * Setup finished on its page: the composer submits with the dialog unseen. If the start can't run + * by itself in time (a form error, a revoked grant), the dialog appears with everything kept. + * Returns the modal data to render once visible (no second auto-start), or null while hidden. + */ +export function useCloudAutoStartReveal(modalData: ComposerModalData): ComposerModalData | null { + const [revealed, setRevealed] = useState(false) + useEffect(() => { + if (!modalData.cloudAutoStart) { + return + } + const timer = window.setTimeout(() => setRevealed(true), CLOUD_AUTO_START_REVEAL_MS) + return () => window.clearTimeout(timer) + }, [modalData.cloudAutoStart]) + if (!modalData.cloudAutoStart) { + return modalData + } + return revealed ? { ...modalData, cloudAutoStart: false } : null +} + +/** A closed Root still gives the title its context; nothing is portaled or shown. */ +export function HiddenComposer({ children }: { children: React.ReactNode }): React.JSX.Element { + return ( + +
+ {children} +
+
+ ) +} diff --git a/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts b/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts index b090d33479f..28cc960bfd6 100644 --- a/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts +++ b/src/renderer/src/components/new-workspace/run-on/use-cloud-start-composer.ts @@ -48,9 +48,13 @@ function showAgentNotStartedToast(agent: string | null): void { { action: { label: name - ? translate('components.newWorkspace.cloudStart.setUpAgentOnce', 'Set up {{agent}} once', { - agent: name - }) + ? translate( + 'components.newWorkspace.cloudStart.setUpAgentOnce', + 'Set up {{agent}} once', + { + agent: name + } + ) : translate('components.newWorkspace.cloudStart.setUpAgentOnceGeneric', 'Set up once'), onClick: openOrcaCloudAgentAccounts } diff --git a/src/renderer/src/components/new-workspace/run-on/use-composer-cloud-start.ts b/src/renderer/src/components/new-workspace/run-on/use-composer-cloud-start.ts index 4c14cbeb795..d275d5e4351 100644 --- a/src/renderer/src/components/new-workspace/run-on/use-composer-cloud-start.ts +++ b/src/renderer/src/components/new-workspace/run-on/use-composer-cloud-start.ts @@ -4,6 +4,8 @@ import { useCallback, useEffect, type MutableRefObject } from 'react' import type { ComposerModalData } from '../composer-modal-data' import type { NewWorkspaceComposerCardProps } from '../new-workspace-composer-card-props' import { useCloudStartComposer } from './use-cloud-start-composer' +import { buildComposerSnapshot } from '../composer-cloud-auto-start' +import type { TuiAgent } from '../../../../../shared/agent-launch/catalog/tui-agent' type ComposerCardState = Pick< NewWorkspaceComposerCardProps, @@ -12,7 +14,9 @@ type ComposerCardState = Pick< | 'onEphemeralVmRecipeChange' | 'repoId' | 'name' -> + | 'baseBranch' + | 'note' +> & { linkedWorkItem?: ComposerModalData['linkedWorkItem'] } export function useComposerCloudStart({ active, @@ -21,17 +25,18 @@ export function useComposerCloudStart({ quickAgent, handleCreate, createDisabled, - composerSnapshot, + quickAgentPick, recordCreatedRef, onClose }: { active: boolean modalData: ComposerModalData cardProps: ComposerCardState - quickAgent: string | null + quickAgent: TuiAgent | null handleCreate: (options?: { withoutAgent?: boolean }) => Promise createDisabled: boolean - composerSnapshot: () => ComposerModalData + /** The agent pick (surface, draft) as the composer keeps it, for the setup page's snapshot. */ + quickAgentPick: Omit, 'note'> /** The composer's onCreated calls this: only a start that happened is remembered. */ recordCreatedRef: MutableRefObject<(() => void) | null> onClose?: () => void @@ -43,6 +48,10 @@ export function useComposerCloudStart({ () => void handleCreate({ withoutAgent: true }), [handleCreate] ) + const composerSnapshot = useCallback( + () => buildComposerSnapshot(modalData, cardProps, { ...quickAgentPick, agent: quickAgent }), + [cardProps, modalData, quickAgent, quickAgentPick] + ) const cloudStart = useCloudStartComposer({ active, availability: cardProps.orcaCloudAvailability ?? 'unavailable', diff --git a/src/renderer/src/components/orca-cloud-setup/CloudSetupPage.tsx b/src/renderer/src/components/orca-cloud-setup/CloudSetupPage.tsx index 136b2899d67..21badae9365 100644 --- a/src/renderer/src/components/orca-cloud-setup/CloudSetupPage.tsx +++ b/src/renderer/src/components/orca-cloud-setup/CloudSetupPage.tsx @@ -77,7 +77,9 @@ function SetupStepper({ )} > {state === 'done' ? : null} - {state === 'current' ? : null} + {state === 'current' ? ( + + ) : null} -