4
4
* See License.AGPL.txt in the project root for license information.
5
5
*/
6
6
7
- import { ContextURL , GitpodServer , WorkspaceInfo } from "@gitpod/gitpod-protocol" ;
7
+ import { CommitContext , ContextURL , GitpodServer , WorkspaceInfo } from "@gitpod/gitpod-protocol" ;
8
8
import { SelectAccountPayload } from "@gitpod/gitpod-protocol/lib/auth" ;
9
9
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error" ;
10
10
import { Deferred } from "@gitpod/gitpod-protocol/lib/util/deferred" ;
11
- import { FunctionComponent , useCallback , useState } from "react" ;
11
+ import { FunctionComponent , useCallback , useEffect , useMemo , useState } from "react" ;
12
12
import { useHistory , useLocation } from "react-router" ;
13
13
import { Button } from "../components/Button" ;
14
14
import Modal , { ModalBody , ModalFooter , ModalHeader } from "../components/Modal" ;
@@ -19,7 +19,9 @@ import { Heading1 } from "../components/typography/headings";
19
19
import { UsageLimitReachedModal } from "../components/UsageLimitReachedModal" ;
20
20
import { useFeatureFlags } from "../contexts/FeatureFlagContext" ;
21
21
import { useCurrentOrg } from "../data/organizations/orgs-query" ;
22
+ import { useListProjectsQuery } from "../data/projects/list-projects-query" ;
22
23
import { useCreateWorkspaceMutation } from "../data/workspaces/create-workspace-mutation" ;
24
+ import { useWorkspaceContext } from "../data/workspaces/resolve-context-query" ;
23
25
import { openAuthorizeWindow } from "../provider-utils" ;
24
26
import { gitpodHostUrl } from "../service/service" ;
25
27
import { LimitReachedOutOfHours , LimitReachedParallelWorkspacesModal } from "../start/CreateWorkspace" ;
@@ -37,6 +39,7 @@ export const useNewCreateWorkspacePage = () => {
37
39
export function CreateWorkspacePage ( ) {
38
40
const user = useCurrentUser ( ) ;
39
41
const currentOrg = useCurrentOrg ( ) . data ;
42
+ const projects = useListProjectsQuery ( ) ;
40
43
const location = useLocation ( ) ;
41
44
const history = useHistory ( ) ;
42
45
const props = StartWorkspaceOptions . parseSearchParams ( location . search ) ;
@@ -55,6 +58,26 @@ export function CreateWorkspacePage() {
55
58
const [ selectedWsClass , setSelectedWsClass ] = useState < string | undefined > ( props . workspaceClass ) ;
56
59
const [ errorWsClass , setErrorWsClass ] = useState < string | undefined > ( undefined ) ;
57
60
const [ repo , setRepo ] = useState < string | undefined > ( location . hash . substring ( 1 ) ) ;
61
+ const workspaceContext = useWorkspaceContext ( repo ) ;
62
+ const isLoading = workspaceContext . isLoading || projects . isLoading ;
63
+ const project = useMemo ( ( ) => {
64
+ if ( ! workspaceContext . data || ! projects . data ) {
65
+ return undefined ;
66
+ }
67
+ const cloneUrl = ( workspaceContext . data as CommitContext ) . repository . cloneUrl ;
68
+ return projects . data . projects . find ( ( p ) => p . cloneUrl === cloneUrl ) ;
69
+ } , [ projects . data , workspaceContext . data ] ) ;
70
+
71
+ useEffect ( ( ) => {
72
+ if ( ! project || props . workspaceClass ) {
73
+ return ;
74
+ }
75
+ const wsClass = project . settings ?. workspaceClasses ;
76
+ if ( wsClass ?. regular ) {
77
+ setSelectedWsClass ( wsClass ?. regular ) ;
78
+ }
79
+ } , [ project , props . workspaceClass ] ) ;
80
+
58
81
const onSelectEditorChange = useCallback (
59
82
( ide : string , useLatest : boolean ) => {
60
83
setSelectedIde ( ide ) ;
@@ -151,10 +174,14 @@ export function CreateWorkspacePage() {
151
174
< div className = "w-full flex justify-end mt-6 space-x-2 px-6" >
152
175
< Button
153
176
onClick = { onClickCreate }
154
- loading = { createWorkspaceMutation . isLoading }
177
+ loading = { createWorkspaceMutation . isLoading || isLoading }
155
178
disabled = { ! repo || repo . length === 0 || ! ! errorIde || ! ! errorWsClass }
156
179
>
157
- { createWorkspaceMutation . isLoading ? "Creating Workspace ..." : "New Workspace" }
180
+ { isLoading
181
+ ? "Loading ..."
182
+ : createWorkspaceMutation . isLoading
183
+ ? "Creating Workspace ..."
184
+ : "New Workspace" }
158
185
</ Button >
159
186
</ div >
160
187
< div >
0 commit comments