@@ -12,7 +12,6 @@ import {
1212 getNewProjectPublishTarget ,
1313 getNewProjectPublishTargets ,
1414 getNewProjectRepository ,
15- type NewProjectPublishTarget ,
1615 normalizePastedCloneUrl ,
1716 addProjectRemoteSourceLabel ,
1817 addProjectRemoteSourcePathHint ,
@@ -196,18 +195,24 @@ import {
196195 buildNewThreadInProjectItems ,
197196 buildProjectSearchItems ,
198197} from "./CommandPaletteProjectItems" ;
198+ import {
199+ CommandPaletteSubmitButton ,
200+ NewProjectPublishHostPicker ,
201+ NewProjectSummary ,
202+ RemoteRepositorySummary ,
203+ remoteProjectSourceIcon ,
204+ sourceControlHostIcon ,
205+ } from "./CommandPaletteAddProject" ;
199206import { useCommandPaletteThreadItems } from "./CommandPaletteThreadItems" ;
200207import {
201208 APPEARANCE_OPTIONS ,
202209 notifyThemeSaveFailure ,
203210 useCommandPaletteThemeItems ,
204211} from "./CommandPaletteThemeItems" ;
205212import {
206- CommandPaletteTitleIcon ,
207213 CommandPaletteVirtualizedResults ,
208214 scrollCommandPaletteRowIntoView ,
209215} from "./CommandPaletteResults" ;
210- import { sourceControlIcon } from "~/sourceControlPresentation" ;
211216import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon" ;
212217import { Checkbox } from "./ui/checkbox" ;
213218import { ProjectFilePicker } from "./files/ProjectFilePicker" ;
@@ -219,8 +224,6 @@ import { primaryServerKeybindingsAtom } from "../state/server";
219224import { resolveShortcutCommand , threadJumpIndexFromCommand } from "../keybindings" ;
220225import { CommandDialog , CommandDialogPopup , CommandFooterAction } from "./ui/command" ;
221226import { Button } from "./ui/button" ;
222- import { Kbd , KbdGroup } from "./ui/kbd" ;
223- import { Select , SelectItem , SelectPopup , SelectTrigger , SelectValue } from "./ui/select" ;
224227import { stackedThreadToast , toastManager } from "./ui/toast" ;
225228import { Tooltip , TooltipPopup , TooltipTrigger } from "./ui/tooltip" ;
226229import { ComposerHandleContext , useComposerHandleContext } from "../composerHandleContext" ;
@@ -232,20 +235,6 @@ import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
232235
233236const EMPTY_BROWSE_ENTRIES : FilesystemBrowseResult [ "entries" ] = [ ] ;
234237
235- function remoteProjectSourceIcon ( source : AddProjectRemoteSource , className : string ) : ReactNode {
236- if ( source === "url" ) return < LinkIcon className = { className } /> ;
237- const Icon = sourceControlIcon ( sourceControlClients . get ( source ) ) ;
238- return < Icon className = { className } /> ;
239- }
240-
241- function sourceControlHostIcon (
242- definition : NewProjectPublishTarget [ "definition" ] ,
243- className : string ,
244- ) : ReactNode {
245- const Icon = sourceControlIcon ( definition ) ;
246- return < Icon className = { className } /> ;
247- }
248-
249238export function CommandPalette ( { children } : { children : ReactNode } ) {
250239 const navigate = useNavigate ( ) ;
251240 const [ state , dispatch ] = useReducer ( reduceCommandPaletteUiState , {
@@ -599,7 +588,6 @@ function OpenCommandPaletteDialog(props: {
599588 const [ newProjectPublishes , setNewProjectPublishes ] = useState ( false ) ;
600589 const [ newProjectPublishKind , setNewProjectPublishKind ] =
601590 useState < SourceControlProviderKind | null > ( null ) ;
602- const [ newProjectHostPickerOpen , setNewProjectHostPickerOpen ] = useState ( false ) ;
603591 const [ isCreatingNewProject , setIsCreatingNewProject ] = useState ( false ) ;
604592 // State lags a render behind, so a repeated Enter could start a second create.
605593 const newProjectSubmittingRef = useRef ( false ) ;
@@ -2091,18 +2079,6 @@ function OpenCommandPaletteDialog(props: {
20912079 group . value === "directories" ? { ...group , label : "Select where to clone" } : group ,
20922080 ) ;
20932081
2094- const remoteProjectContext = ( ( ) => {
2095- if ( addProjectCloneFlow ?. step !== "confirm" ) {
2096- return null ;
2097- }
2098-
2099- return {
2100- title : addProjectCloneFlow . repository ?. nameWithOwner ?? addProjectCloneFlow . repositoryInput ,
2101- description : addProjectCloneFlow . repository ?. url ?? addProjectCloneFlow . remoteUrl ,
2102- icon : remoteProjectSourceIcon ( addProjectCloneFlow . source , ITEM_ICON_CLASS ) ,
2103- } ;
2104- } ) ( ) ;
2105-
21062082 const newProjectsRoot = newProjectFlow ? newProjectsRootFor ( newProjectFlow . environmentId ) : null ;
21072083 const newProjectPathPreview =
21082084 newProjectsRoot === null ? null : getNewProjectPathPreview ( newProjectsRoot , newProjectName ) ;
@@ -2209,55 +2185,12 @@ function OpenCommandPaletteDialog(props: {
22092185 titleTrailingContent : (
22102186 < span className = "ms-auto flex items-center gap-2" >
22112187 { newProjectPublishTargets . length > 1 ? (
2212- // The row toggles on click, so the picker keeps its clicks to itself. The
2213- // row also cancels pointerdown to keep focus in the input, which drops the
2214- // mousedown Select opens on, so the picker opens on click instead.
2215- < span
2216- className = "flex"
2217- onClick = { ( event ) => {
2218- event . stopPropagation ( ) ;
2219- // React bubbles the popup's clicks here through its portal; only the
2220- // trigger opens the picker.
2221- if ( ! event . currentTarget . contains ( event . target as Node ) ) return ;
2222- if ( ! isCreatingNewProject ) setNewProjectHostPickerOpen ( true ) ;
2223- } }
2224- >
2225- < Select
2226- disabled = { isCreatingNewProject }
2227- open = { newProjectHostPickerOpen }
2228- onOpenChange = { setNewProjectHostPickerOpen }
2229- value = { newProjectPublishTarget . definition . kind }
2230- onValueChange = { ( kind ) => {
2231- if ( kind !== null ) setNewProjectPublishKind ( kind ) ;
2232- } }
2233- >
2234- < SelectTrigger
2235- size = "xs"
2236- variant = "ghost"
2237- aria-label = "Host for the new repository"
2238- >
2239- < SelectValue >
2240- { ( kind : SourceControlProviderKind ) =>
2241- sourceControlClients . get ( kind ) . label
2242- }
2243- </ SelectValue >
2244- </ SelectTrigger >
2245- < SelectPopup align = "end" alignItemWithTrigger = { false } >
2246- { newProjectPublishTargets . map ( ( target ) => (
2247- < SelectItem
2248- key = { target . definition . kind }
2249- hideIndicator
2250- value = { target . definition . kind }
2251- >
2252- < span className = "inline-flex items-center gap-1.5" >
2253- { sourceControlHostIcon ( target . definition , "size-3.5" ) }
2254- { target . definition . label }
2255- </ span >
2256- </ SelectItem >
2257- ) ) }
2258- </ SelectPopup >
2259- </ Select >
2260- </ span >
2188+ < NewProjectPublishHostPicker
2189+ disabled = { isCreatingNewProject }
2190+ targets = { newProjectPublishTargets }
2191+ value = { newProjectPublishTarget . definition . kind }
2192+ onValueChange = { setNewProjectPublishKind }
2193+ />
22612194 ) : null }
22622195 < span className = "pointer-events-none flex" >
22632196 < Checkbox checked = { newProjectPublishes } tabIndex = { - 1 } aria-hidden />
@@ -2622,106 +2555,56 @@ function OpenCommandPaletteDialog(props: {
26222555
26232556 const inputAccessory =
26242557 newProjectFlow !== null ? (
2625- < Tooltip >
2626- < TooltipTrigger
2627- render = {
2628- < Button
2629- variant = "outline"
2630- size = "xs"
2631- tabIndex = { - 1 }
2632- className = "absolute inset-e-2.5 top-1/2 -translate-y-1/2"
2633- aria-label = { `Create (${ createShortcutLabel } )` }
2634- disabled = { ! canSubmitNewProject }
2635- onMouseDown = { ( event ) => {
2636- event . preventDefault ( ) ;
2637- } }
2638- onClick = { ( ) => {
2639- void submitNewProject ( ) ;
2640- } }
2641- />
2642- }
2643- >
2644- < span > { isCreatingNewProject ? "Creating" : "Create" } </ span >
2645- < KbdGroup className = "pointer-events-none -me-0.5" >
2646- < Kbd > { createShortcutLabel } </ Kbd >
2647- </ KbdGroup >
2648- </ TooltipTrigger >
2649- < TooltipPopup side = "top" > { `Create (${ createShortcutLabel } )` } </ TooltipPopup >
2650- </ Tooltip >
2558+ < CommandPaletteSubmitButton
2559+ label = { isCreatingNewProject ? "Creating" : "Create" }
2560+ shortcutLabel = { createShortcutLabel }
2561+ ariaLabel = { `Create (${ createShortcutLabel } )` }
2562+ tooltip = { `Create (${ createShortcutLabel } )` }
2563+ disabled = { ! canSubmitNewProject }
2564+ onSubmit = { ( ) => {
2565+ void submitNewProject ( ) ;
2566+ } }
2567+ />
26512568 ) : addProjectCloneFlow ?. step === "repository" ? (
2652- < Tooltip >
2653- < TooltipTrigger
2654- render = {
2655- < Button
2656- variant = "outline"
2657- size = "xs"
2658- tabIndex = { - 1 }
2659- className = "absolute inset-e-2.5 top-1/2 -translate-y-1/2"
2660- aria-label = { `${ remoteProjectButtonLabel ?? "Continue" } (Enter)` }
2661- disabled = { ! canSubmitRemoteProjectFlow }
2662- onMouseDown = { ( event ) => {
2663- event . preventDefault ( ) ;
2664- } }
2665- onClick = { ( ) => {
2666- void submitAddProjectCloneFlow ( ) ;
2667- } }
2668- />
2669- }
2670- >
2671- < span > { isRemoteProjectPending ? "Working" : remoteProjectButtonLabel } </ span >
2672- < KbdGroup className = "pointer-events-none -me-0.5" >
2673- < Kbd > Enter</ Kbd >
2674- </ KbdGroup >
2675- </ TooltipTrigger >
2676- < TooltipPopup side = "top" > { remoteProjectButtonLabel ?? "Continue" } (Enter)</ TooltipPopup >
2677- </ Tooltip >
2569+ < CommandPaletteSubmitButton
2570+ label = { isRemoteProjectPending ? "Working" : remoteProjectButtonLabel }
2571+ shortcutLabel = "Enter"
2572+ ariaLabel = { `${ remoteProjectButtonLabel ?? "Continue" } (Enter)` }
2573+ tooltip = { `${ remoteProjectButtonLabel ?? "Continue" } (Enter)` }
2574+ disabled = { ! canSubmitRemoteProjectFlow }
2575+ onSubmit = { ( ) => {
2576+ void submitAddProjectCloneFlow ( ) ;
2577+ } }
2578+ />
26782579 ) : isBrowsing ? (
2679- < Tooltip >
2680- < TooltipTrigger
2681- render = {
2682- < Button
2683- variant = "outline"
2684- size = "xs"
2685- tabIndex = { - 1 }
2686- className = "absolute inset-e-2.5 top-1/2 -translate-y-1/2"
2687- aria-label = { `${ submitActionLabel } (${ addShortcutLabel } )` }
2688- disabled = {
2689- ! canCreateProject ||
2690- ! canCreateProjectInEnvironment ( browseEnvironment ?. connection . phase ) ||
2691- relativePathNeedsActiveProject ||
2692- ( isCloneDestinationStep && ( ! canCloneProject || isRemoteProjectPending ) )
2693- }
2694- onMouseDown = { ( event ) => {
2695- event . preventDefault ( ) ;
2696- } }
2697- onClick = { ( ) => {
2698- if ( relativePathNeedsActiveProject ) {
2699- return ;
2700- }
2701- if ( isCloneDestinationStep ) {
2702- void submitAddProjectCloneFlow ( resolvedAddProjectPath ) ;
2703- } else {
2704- void handleAddProject ( resolvedAddProjectPath ) ;
2705- }
2706- } }
2707- />
2708- }
2709- >
2710- < span >
2711- { isCloneDestinationStep && isRemoteProjectPending ? "Cloning" : submitActionLabel }
2712- </ span >
2713- < KbdGroup className = "pointer-events-none -me-0.5" >
2714- < Kbd > { hasHighlightedBrowseItem ? `${ submitModifierLabel } Enter` : "Enter" } </ Kbd >
2715- </ KbdGroup >
2716- </ TooltipTrigger >
2717- < TooltipPopup side = "top" >
2718- { isCloneDestinationStep && ! canCloneProject
2580+ < CommandPaletteSubmitButton
2581+ label = { isCloneDestinationStep && isRemoteProjectPending ? "Cloning" : submitActionLabel }
2582+ shortcutLabel = { addShortcutLabel }
2583+ ariaLabel = { `${ submitActionLabel } (${ addShortcutLabel } )` }
2584+ tooltip = {
2585+ isCloneDestinationStep && ! canCloneProject
27192586 ? "This connection needs permission to write source control and add projects."
27202587 : canCreateProject
27212588 ? `${ submitActionLabel } (${ addShortcutLabel } )`
2722- : "This connection cannot add projects." }
2723- </ TooltipPopup >
2724- </ Tooltip >
2589+ : "This connection cannot add projects."
2590+ }
2591+ disabled = {
2592+ ! canCreateProject ||
2593+ ! canCreateProjectInEnvironment ( browseEnvironment ?. connection . phase ) ||
2594+ relativePathNeedsActiveProject ||
2595+ ( isCloneDestinationStep && ( ! canCloneProject || isRemoteProjectPending ) )
2596+ }
2597+ onSubmit = { ( ) => {
2598+ if ( relativePathNeedsActiveProject ) {
2599+ return ;
2600+ }
2601+ if ( isCloneDestinationStep ) {
2602+ void submitAddProjectCloneFlow ( resolvedAddProjectPath ) ;
2603+ } else {
2604+ void handleAddProject ( resolvedAddProjectPath ) ;
2605+ }
2606+ } }
2607+ />
27252608 ) : null ;
27262609
27272610 const footerActionLabel =
@@ -2803,38 +2686,21 @@ function OpenCommandPaletteDialog(props: {
28032686 value = { query }
28042687 >
28052688 { newProjectPathPreview !== null ? (
2806- < div className = "p-2 pb-0" >
2807- < div className = "flex min-h-8 items-center gap-2 rounded-sm px-2 py-1.5" >
2808- < CommandPaletteTitleIcon >
2809- < FolderGit2Icon className = { ITEM_ICON_CLASS } />
2810- </ CommandPaletteTitleIcon >
2811- < span className = "flex min-w-0 flex-1 flex-col" >
2812- < span className = "truncate text-foreground text-sm" >
2813- { newProjectName . length > 0 ? newProjectName : "New project" }
2814- </ span >
2815- < span className = "truncate text-muted-foreground/85 text-xs" >
2816- { newProjectName . length > 0
2817- ? `Creates ${ newProjectPathPreview } `
2818- : `Goes in ${ newProjectsRoot } ` }
2819- { newProjectEnvironmentLabel === null ? null : ` on ${ newProjectEnvironmentLabel } ` }
2820- </ span >
2821- </ span >
2822- </ div >
2823- </ div >
2689+ < NewProjectSummary
2690+ name = { newProjectName }
2691+ pathPreview = { newProjectPathPreview }
2692+ projectsRoot = { newProjectsRoot }
2693+ environmentLabel = { newProjectEnvironmentLabel }
2694+ />
28242695 ) : null }
2825- { remoteProjectContext ? (
2826- < div className = "shrink-0 p-2 pb-0" >
2827- < div className = "px-2 py-1.5 font-medium text-muted-foreground text-xs" > Repository</ div >
2828- < div className = "flex min-h-8 items-center gap-2 rounded-sm px-2 py-1.5" >
2829- < CommandPaletteTitleIcon > { remoteProjectContext . icon } </ CommandPaletteTitleIcon >
2830- < span className = "flex min-w-0 flex-1 flex-col" >
2831- < span className = "truncate text-foreground text-sm" > { remoteProjectContext . title } </ span >
2832- < span className = "truncate text-muted-foreground/85 text-xs" >
2833- { remoteProjectContext . description }
2834- </ span >
2835- </ span >
2836- </ div >
2837- </ div >
2696+ { addProjectCloneFlow ?. step === "confirm" ? (
2697+ < RemoteRepositorySummary
2698+ source = { addProjectCloneFlow . source }
2699+ title = {
2700+ addProjectCloneFlow . repository ?. nameWithOwner ?? addProjectCloneFlow . repositoryInput
2701+ }
2702+ description = { addProjectCloneFlow . repository ?. url ?? addProjectCloneFlow . remoteUrl }
2703+ />
28382704 ) : null }
28392705 { browseAccessError ? (
28402706 < div role = "alert" className = "px-4 py-3 text-sm text-muted-foreground" >
0 commit comments