5
5
*/
6
6
7
7
import 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" ;
16
9
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error" ;
17
10
import Modal from "../components/Modal" ;
18
11
import { getGitpodService , gitpodHostUrl } from "../service/service" ;
@@ -22,14 +15,12 @@ import StartWorkspace, { parseProps } from "./StartWorkspace";
22
15
import { openAuthorizeWindow } from "../provider-utils" ;
23
16
import { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth" ;
24
17
import { SelectAccountModal } from "../settings/SelectAccountModal" ;
25
- import PrebuildLogs from "../components/PrebuildLogs" ;
26
18
import FeedbackComponent from "../feedback-form/FeedbackComponent" ;
27
19
import { isGitpodIo } from "../utils" ;
28
20
import { BillingAccountSelector } from "../components/BillingAccountSelector" ;
29
21
import { AttributionId } from "@gitpod/gitpod-protocol/lib/attribution" ;
30
22
import { TeamsContext } from "../teams/teams-context" ;
31
23
import Alert from "../components/Alert" ;
32
- import { FeatureFlagContext } from "../contexts/FeatureFlagContext" ;
33
24
34
25
export interface CreateWorkspaceProps {
35
26
contextUrl : string ;
@@ -48,22 +39,22 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
48
39
this . state = { stillParsing : true } ;
49
40
}
50
41
42
+ static contextType = UserContext ;
43
+
51
44
componentDidMount ( ) {
52
45
this . createWorkspace ( ) ;
53
46
}
54
47
55
- async createWorkspace ( mode = CreateWorkspaceMode . SelectIfRunning , forceDefaultConfig = false ) {
48
+ async createWorkspace ( opts ?: Omit < GitpodServer . CreateWorkspaceOptions , "contextUrl" > ) {
56
49
// Invalidate any previous result.
57
50
this . setState ( { result : undefined , stillParsing : true } ) ;
58
-
59
51
// We assume anything longer than 3 seconds is no longer just parsing the context URL (i.e. it's now creating a workspace).
60
52
let timeout = setTimeout ( ( ) => this . setState ( { stillParsing : false } ) , 3000 ) ;
61
-
62
53
try {
63
54
const result = await getGitpodService ( ) . server . createWorkspace ( {
64
55
contextUrl : this . props . contextUrl ,
65
- mode ,
66
- forceDefaultConfig ,
56
+ ignoreRunningWorkspaceOnSameCommit : false ,
57
+ ... opts ,
67
58
} ) ;
68
59
if ( result . workspaceURL ) {
69
60
window . location . href = result . workspaceURL ;
@@ -148,7 +139,7 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
148
139
< button
149
140
className = ""
150
141
onClick = { ( ) => {
151
- this . createWorkspace ( CreateWorkspaceMode . Default , true ) ;
142
+ this . createWorkspace ( { forceDefaultConfig : true } ) ;
152
143
} }
153
144
>
154
145
Continue with default configuration
@@ -262,21 +253,12 @@ export default class CreateWorkspace extends React.Component<CreateWorkspaceProp
262
253
</ >
263
254
</ div >
264
255
< 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 >
266
259
</ div >
267
260
</ Modal >
268
261
) ;
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
- ) ;
280
262
}
281
263
282
264
return (
@@ -526,64 +508,3 @@ function RepositoryNotFoundView(p: { error: StartWorkspaceError }) {
526
508
</ StartPage >
527
509
) ;
528
510
}
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