@@ -10,36 +10,33 @@ import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
10
10
import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred" ;
11
11
import { FC , FunctionComponent , useCallback , useContext , useEffect , useMemo , useState } from "react" ;
12
12
import { useHistory , useLocation } from "react-router" ;
13
- import { Link } from "react-router-dom" ;
13
+ import Alert from "../components/Alert" ;
14
+ import { AuthorizeGit , useNeedsGitAuthorization } from "../components/AuthorizeGit" ;
14
15
import { Button } from "../components/Button" ;
16
+ import { LinkButton } from "../components/LinkButton" ;
15
17
import Modal from "../components/Modal" ;
16
18
import RepositoryFinder from "../components/RepositoryFinder" ;
17
19
import SelectIDEComponent from "../components/SelectIDEComponent" ;
18
20
import SelectWorkspaceClassComponent from "../components/SelectWorkspaceClassComponent" ;
19
21
import { UsageLimitReachedModal } from "../components/UsageLimitReachedModal" ;
20
- import { CheckboxInputField } from "../components/forms/CheckboxInputField " ;
22
+ import { InputField } from "../components/forms/InputField " ;
21
23
import { Heading1 } from "../components/typography/headings" ;
22
24
import { useAuthProviders } from "../data/auth-providers/auth-provider-query" ;
23
25
import { useCurrentOrg } from "../data/organizations/orgs-query" ;
24
26
import { useListProjectsQuery } from "../data/projects/list-projects-query" ;
25
27
import { useCreateWorkspaceMutation } from "../data/workspaces/create-workspace-mutation" ;
26
28
import { useListWorkspacesQuery } from "../data/workspaces/list-workspaces-query" ;
27
29
import { useWorkspaceContext } from "../data/workspaces/resolve-context-query" ;
30
+ import { useDirtyState } from "../hooks/use-dirty-state" ;
28
31
import { openAuthorizeWindow } from "../provider-utils" ;
29
32
import { getGitpodService , gitpodHostUrl } from "../service/service" ;
30
33
import { StartWorkspaceError } from "../start/StartPage" ;
31
34
import { VerifyModal } from "../start/VerifyModal" ;
32
35
import { StartWorkspaceOptions } from "../start/start-workspace-options" ;
33
36
import { UserContext , useCurrentUser } from "../user-context" ;
34
37
import { SelectAccountModal } from "../user-settings/SelectAccountModal" ;
35
- import { settingsPathPreferences } from "../user-settings/settings.routes" ;
36
- import { WorkspaceEntry } from "./WorkspaceEntry" ;
37
- import { AuthorizeGit , useNeedsGitAuthorization } from "../components/AuthorizeGit" ;
38
38
import { settingsPathIntegrations } from "../user-settings/settings.routes" ;
39
- import { useDirtyState } from "../hooks/use-dirty-state" ;
40
- import { LinkButton } from "../components/LinkButton" ;
41
- import { InputField } from "../components/forms/InputField" ;
42
- import Alert from "../components/Alert" ;
39
+ import { WorkspaceEntry } from "./WorkspaceEntry" ;
43
40
44
41
export function CreateWorkspacePage ( ) {
45
42
const { user, setUser } = useContext ( UserContext ) ;
@@ -48,8 +45,14 @@ export function CreateWorkspacePage() {
48
45
const workspaces = useListWorkspacesQuery ( { limit : 50 } ) ;
49
46
const location = useLocation ( ) ;
50
47
const history = useHistory ( ) ;
48
+ const [ contextURL , setContextURL ] = useState < string | undefined > (
49
+ StartWorkspaceOptions . parseContextUrl ( location . hash ) ,
50
+ ) ;
51
51
const props = StartWorkspaceOptions . parseSearchParams ( location . search ) ;
52
- const [ autostart , setAutostart ] = useState < boolean | undefined > ( props . autostart ) ;
52
+ // we autostart when a contextURL is provided via the URL hash and autostart is not explicitly set to false
53
+ const [ autostart , setAutostart ] = useState < boolean | undefined > (
54
+ contextURL !== undefined && props . autostart !== false ,
55
+ ) ;
53
56
const createWorkspaceMutation = useCreateWorkspaceMutation ( ) ;
54
57
55
58
const defaultLatestIde =
@@ -65,11 +68,7 @@ export function CreateWorkspacePage() {
65
68
const defaultWorkspaceClass = props . workspaceClass ;
66
69
const [ selectedWsClass , setSelectedWsClass , selectedWsClassIsDirty ] = useDirtyState ( defaultWorkspaceClass ) ;
67
70
const [ errorWsClass , setErrorWsClass ] = useState < string | undefined > ( undefined ) ;
68
- const [ contextURL , setContextURL ] = useState < string | undefined > (
69
- StartWorkspaceOptions . parseContextUrl ( location . hash ) ,
70
- ) ;
71
71
const workspaceContext = useWorkspaceContext ( contextURL ) ;
72
- const [ rememberOptions , setRememberOptions ] = useState ( false ) ;
73
72
const needsGitAuthorization = useNeedsGitAuthorization ( ) ;
74
73
75
74
const storeAutoStartOptions = useCallback ( async ( ) => {
@@ -87,24 +86,22 @@ export function CreateWorkspacePage() {
87
86
// we only keep the last 20 options
88
87
workspaceAutoStartOptions = workspaceAutoStartOptions . slice ( - 40 ) ;
89
88
90
- if ( rememberOptions ) {
91
- workspaceAutoStartOptions . push ( {
92
- cloneURL,
93
- organizationId : currentOrg . id ,
94
- ideSettings : {
95
- defaultIde : selectedIde ,
96
- useLatestVersion : useLatestIde ,
97
- } ,
98
- workspaceClass : selectedWsClass ,
99
- } ) ;
100
- }
89
+ workspaceAutoStartOptions . push ( {
90
+ cloneURL,
91
+ organizationId : currentOrg . id ,
92
+ ideSettings : {
93
+ defaultIde : selectedIde ,
94
+ useLatestVersion : useLatestIde ,
95
+ } ,
96
+ workspaceClass : selectedWsClass ,
97
+ } ) ;
101
98
AdditionalUserData . set ( user , {
102
99
workspaceAutostartOptions : workspaceAutoStartOptions ,
103
100
} ) ;
104
101
setUser ( user ) ;
105
102
await getGitpodService ( ) . server . updateLoggedInUser ( user ) ;
106
103
console . log ( "Stored autostart options" , workspaceAutoStartOptions ) ;
107
- } , [ currentOrg , rememberOptions , selectedIde , selectedWsClass , setUser , useLatestIde , user , workspaceContext . data ] ) ;
104
+ } , [ currentOrg , selectedIde , selectedWsClass , setUser , useLatestIde , user , workspaceContext . data ] ) ;
108
105
109
106
// see if we have a matching project based on context url and project's repo url
110
107
const project = useMemo ( ( ) => {
@@ -274,7 +271,6 @@ export function CreateWorkspacePage() {
274
271
( e ) => e . cloneURL === cloneURL && e . organizationId === currentOrg ?. id ,
275
272
) ;
276
273
if ( rememberedOptions ) {
277
- setRememberOptions ( true ) ;
278
274
if ( ! selectedIdeIsDirty ) {
279
275
setSelectedIde ( rememberedOptions . ideSettings ?. defaultIde , false ) ;
280
276
setUseLatestIde ( ! ! rememberedOptions . ideSettings ?. useLatestVersion ) ;
@@ -287,12 +283,15 @@ export function CreateWorkspacePage() {
287
283
setAutostart ( true ) ;
288
284
}
289
285
} else {
290
- setRememberOptions ( false ) ;
291
286
// reset the ide settings to the user's default IF they haven't changed it manually
292
287
if ( ! selectedIdeIsDirty ) {
293
288
setSelectedIde ( defaultIde , false ) ;
294
289
setUseLatestIde ( defaultLatestIde ) ;
295
290
}
291
+
292
+ if ( ! selectedWsClassIsDirty ) {
293
+ setSelectedWsClass ( defaultWorkspaceClass , false ) ;
294
+ }
296
295
}
297
296
// we only update the remembered options when the workspaceContext changes
298
297
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -313,7 +312,14 @@ export function CreateWorkspacePage() {
313
312
314
313
// Derive if the continue button is disabled based on current state
315
314
const continueButtonDisabled = useMemo ( ( ) => {
316
- if ( workspaceContext . isLoading || ! contextURL || contextURL . length === 0 || ! ! errorIde || ! ! errorWsClass ) {
315
+ if (
316
+ createWorkspaceMutation . isStarting ||
317
+ workspaceContext . isLoading ||
318
+ ! contextURL ||
319
+ contextURL . length === 0 ||
320
+ ! ! errorIde ||
321
+ ! ! errorWsClass
322
+ ) {
317
323
return true ;
318
324
}
319
325
if ( workspaceContext . error ) {
@@ -326,7 +332,14 @@ export function CreateWorkspacePage() {
326
332
}
327
333
328
334
return false ;
329
- } , [ contextURL , errorIde , errorWsClass , workspaceContext . error , workspaceContext . isLoading ] ) ;
335
+ } , [
336
+ contextURL ,
337
+ createWorkspaceMutation . isStarting ,
338
+ errorIde ,
339
+ errorWsClass ,
340
+ workspaceContext . error ,
341
+ workspaceContext . isLoading ,
342
+ ] ) ;
330
343
331
344
if ( SelectAccountPayload . is ( selectAccountError ) ) {
332
345
return (
@@ -418,13 +431,6 @@ export function CreateWorkspacePage() {
418
431
</ Button >
419
432
</ div >
420
433
421
- { workspaceContext . data && (
422
- < RememberOptions
423
- disabled = { workspaceContext . isLoading || createWorkspaceMutation . isStarting }
424
- checked = { rememberOptions }
425
- onChange = { setRememberOptions }
426
- />
427
- ) }
428
434
{ existingWorkspaces . length > 0 && ! createWorkspaceMutation . isStarting && (
429
435
< div className = "w-full flex flex-col justify-end px-6" >
430
436
< p className = "mt-6 text-center text-base" > Running workspaces on this revision</ p >
@@ -446,33 +452,6 @@ export function CreateWorkspacePage() {
446
452
) ;
447
453
}
448
454
449
- function RememberOptions ( params : { disabled ?: boolean ; checked : boolean ; onChange : ( checked : boolean ) => void } ) {
450
- const { disabled, checked, onChange } = params ;
451
-
452
- return (
453
- < >
454
- < div className = { "w-full flex justify-center mt-3 px-8 mx-2" } >
455
- < CheckboxInputField
456
- label = "Autostart with these options for this repository."
457
- checked = { checked }
458
- disabled = { disabled }
459
- topMargin = { false }
460
- onChange = { onChange }
461
- />
462
- </ div >
463
- < div className = { "w-full flex justify-center px-8 mx-2" } >
464
- < p className = "text-gray-400 dark:text-gray-500 text-sm" >
465
- Don't worry, you can reset this anytime in your{ " " }
466
- < Link to = { settingsPathPreferences } className = "gp-link" >
467
- preferences
468
- </ Link >
469
- .
470
- </ p >
471
- </ div >
472
- </ >
473
- ) ;
474
- }
475
-
476
455
function tryAuthorize ( host : string , scopes ?: string [ ] ) : Promise < SelectAccountPayload | undefined > {
477
456
const result = new Deferred < SelectAccountPayload | undefined > ( ) ;
478
457
openAuthorizeWindow ( {
0 commit comments