-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate WorkspaceService.CreateAndStartWorkspace
- Loading branch information
1 parent
b9189bf
commit bbe8ef2
Showing
34 changed files
with
2,607 additions
and
509 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
components/dashboard/src/data/workspaces/start-workspace-mutation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useMutation } from "@tanstack/react-query"; | ||
import { useState } from "react"; | ||
import { workspaceClient } from "../../service/public-api"; | ||
import { StartWorkspaceRequest, StartWorkspaceResponse } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb"; | ||
import { PartialMessage } from "@bufbuild/protobuf"; | ||
import { ConnectError } from "@connectrpc/connect"; | ||
import { useUpdateWorkspaceInCache } from "./list-workspaces-query"; | ||
|
||
export const useStartWorkspaceMutation = () => { | ||
const updateWorkspace = useUpdateWorkspaceInCache(); | ||
const [isStarting, setIsStarting] = useState(false); | ||
const mutation = useMutation<StartWorkspaceResponse, ConnectError, PartialMessage<StartWorkspaceRequest>>({ | ||
mutationFn: async (options) => { | ||
return await workspaceClient.createAndStartWorkspace(options); | ||
}, | ||
onMutate: async (options: PartialMessage<StartWorkspaceRequest>) => { | ||
setIsStarting(true); | ||
}, | ||
onError: (error) => { | ||
setIsStarting(false); | ||
}, | ||
onSuccess: (result) => { | ||
if (result.workspace?.id) { | ||
// successfully started a workspace, wait a bit before we allow to start another one | ||
setTimeout(() => { | ||
setIsStarting(false); | ||
}, 4000); | ||
} else { | ||
setIsStarting(false); | ||
} | ||
|
||
if (!result.workspace) { | ||
return; | ||
} | ||
updateWorkspace(result.workspace, false); | ||
}, | ||
}); | ||
return { | ||
startWorkspace: (options: PartialMessage<StartWorkspaceRequest>) => { | ||
return mutation.mutateAsync(options); | ||
}, | ||
// Can we use mutation.isLoading here instead? | ||
isStarting, | ||
error: mutation.error, | ||
reset: mutation.reset, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.