55 */
66
77import React , { useEffect , useContext , useState } from "react" ;
8- import {
9- CreateWorkspaceMode ,
10- WorkspaceCreationResult ,
11- RunningWorkspacePrebuildStarting ,
12- ContextURL ,
13- DisposableCollection ,
14- Team ,
15- } from "@gitpod/gitpod-protocol" ;
8+ import { WorkspaceCreationResult , ContextURL , Team , GitpodServer } from "@gitpod/gitpod-protocol" ;
169import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error" ;
1710import Modal from "../components/Modal" ;
1811import { getGitpodService , gitpodHostUrl } from "../service/service" ;
@@ -22,14 +15,12 @@ import StartWorkspace, { parseProps } from "./StartWorkspace";
2215import { openAuthorizeWindow } from "../provider-utils" ;
2316import { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth" ;
2417import { SelectAccountModal } from "../settings/SelectAccountModal" ;
25- import PrebuildLogs from "../components/PrebuildLogs" ;
2618import FeedbackComponent from "../feedback-form/FeedbackComponent" ;
2719import { isGitpodIo } from "../utils" ;
2820import { BillingAccountSelector } from "../components/BillingAccountSelector" ;
2921import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution" ;
3022import { TeamsContext } from "../teams/teams-context" ;
3123import Alert from "../components/Alert" ;
32- import { FeatureFlagContext } from "../contexts/FeatureFlagContext" ;
3324
3425export interface CreateWorkspaceProps {
3526 contextUrl : string ;
@@ -48,22 +39,22 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
4839 this . state = { stillParsing : true } ;
4940 }
5041
42+ static contextType = UserContext ;
43+
5144 componentDidMount ( ) {
5245 this . createWorkspace ( ) ;
5346 }
5447
55- async createWorkspace ( mode = CreateWorkspaceMode . SelectIfRunning , forceDefaultConfig = false ) {
48+ async createWorkspace ( opts ?: Omit < GitpodServer . CreateWorkspaceOptions , "contextUrl" > ) {
5649 // Invalidate any previous result.
5750 this . setState ( { result : undefined , stillParsing : true } ) ;
58-
5951 // We assume anything longer than 3 seconds is no longer just parsing the context URL (i.e. it's now creating a workspace).
6052 let timeout = setTimeout ( ( ) => this . setState ( { stillParsing : false } ) , 3000 ) ;
61-
6253 try {
6354 const result = await getGitpodService ( ) . server . createWorkspace ( {
6455 contextUrl : this . props . contextUrl ,
65- mode ,
66- forceDefaultConfig ,
56+ ignoreRunningWorkspaceOnSameCommit : false ,
57+ ... opts ,
6758 } ) ;
6859 if ( result . workspaceURL ) {
6960 window . location . href = result . workspaceURL ;
@@ -148,7 +139,7 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
148139 < button
149140 className = ""
150141 onClick = { ( ) => {
151- this . createWorkspace ( CreateWorkspaceMode . Default , true ) ;
142+ this . createWorkspace ( { forceDefaultConfig : true } ) ;
152143 } }
153144 >
154145 Continue with default configuration
@@ -262,21 +253,12 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
262253 </ >
263254 </ div >
264255 < div className = "flex justify-end mt-6" >
265- < button onClick = { ( ) => this . createWorkspace ( CreateWorkspaceMode . Default ) } > New Workspace</ button >
256+ < button onClick = { ( ) => this . createWorkspace ( { ignoreRunningWorkspaceOnSameCommit : true } ) } >
257+ New Workspace
258+ </ button >
266259 </ div >
267260 </ Modal >
268261 ) ;
269- } else if ( result ?. runningWorkspacePrebuild ) {
270- return (
271- < RunningPrebuildView
272- runningPrebuild = { result . runningWorkspacePrebuild }
273- onUseLastSuccessfulPrebuild = { ( ) =>
274- this . createWorkspace ( CreateWorkspaceMode . UseLastSuccessfulPrebuild )
275- }
276- onIgnorePrebuild = { ( ) => this . createWorkspace ( CreateWorkspaceMode . ForceNew ) }
277- onPrebuildSucceeded = { ( ) => this . createWorkspace ( CreateWorkspaceMode . UsePrebuild ) }
278- />
279- ) ;
280262 }
281263
282264 return (
@@ -526,64 +508,3 @@ function RepositoryNotFoundView(p: { error: StartWorkspaceError }) {
526508 </ StartPage >
527509 ) ;
528510}
529-
530- interface RunningPrebuildViewProps {
531- runningPrebuild : {
532- prebuildID : string ;
533- workspaceID : string ;
534- instanceID : string ;
535- starting : RunningWorkspacePrebuildStarting ;
536- sameCluster : boolean ;
537- } ;
538- onUseLastSuccessfulPrebuild : ( ) => void ;
539- onIgnorePrebuild : ( ) => void ;
540- onPrebuildSucceeded : ( ) => void ;
541- }
542-
543- function RunningPrebuildView ( props : RunningPrebuildViewProps ) {
544- const workspaceId = props . runningPrebuild . workspaceID ;
545- const { showUseLastSuccessfulPrebuild } = useContext ( FeatureFlagContext ) ;
546-
547- useEffect ( ( ) => {
548- const disposables = new DisposableCollection ( ) ;
549-
550- disposables . push (
551- getGitpodService ( ) . registerClient ( {
552- onInstanceUpdate : ( update ) => {
553- if ( update . workspaceId !== workspaceId ) {
554- return ;
555- }
556- if ( update . status . phase === "stopped" ) {
557- props . onPrebuildSucceeded ( ) ;
558- }
559- } ,
560- } ) ,
561- ) ;
562-
563- return function cleanup ( ) {
564- disposables . dispose ( ) ;
565- } ;
566- // eslint-disable-next-line
567- } , [ workspaceId ] ) ;
568-
569- return (
570- < StartPage title = "Prebuild in Progress" >
571- { /* TODO(gpl) Copied around in Start-/CreateWorkspace. This should properly go somewhere central. */ }
572- < div className = "h-full mt-6 w-11/12 lg:w-3/5" >
573- < PrebuildLogs workspaceId = { workspaceId } onIgnorePrebuild = { props . onIgnorePrebuild } >
574- { showUseLastSuccessfulPrebuild && (
575- < button
576- className = "secondary"
577- onClick = { ( ) => props . onUseLastSuccessfulPrebuild && props . onUseLastSuccessfulPrebuild ( ) }
578- >
579- Use Last Successful Prebuild
580- </ button >
581- ) }
582- < button className = "secondary" onClick = { ( ) => props . onIgnorePrebuild && props . onIgnorePrebuild ( ) } >
583- Skip Prebuild
584- </ button >
585- </ PrebuildLogs >
586- </ div >
587- </ StartPage >
588- ) ;
589- }
0 commit comments