-
Notifications
You must be signed in to change notification settings - Fork 605
feat: a user can rollback to a previous stable version #3952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
181badf
feat: implement rollback functionality for
mcstepp 21a2d41
fmt
mcstepp d35c8e0
go fmt
mcstepp 7f5cefb
include deployments as a dependency for the memoization
mcstepp 81e7fcf
use protojson instead of proto
mcstepp 7c3745a
[autofix.ci] apply automated fixes
autofix-ci[bot] 96618de
fix import
mcstepp 6334d93
update makefile for slqc 1.29 and regen
mcstepp 363dc3d
rabbit + include previous openapi/keyauthid for gateway configuration
mcstepp f92051d
rabbit
mcstepp 440cd4c
[autofix.ci] apply automated fixes
autofix-ci[bot] e002603
chore: clean up a little
chronark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
164 changes: 164 additions & 0 deletions
164
apps/dashboard/app/(app)/projects/[projectId]/deployments/components/rollback-dialog.tsx
This file contains hidden or 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,164 @@ | ||
| "use client"; | ||
|
|
||
| import { type Deployment, collection } from "@/lib/collections"; | ||
| import { trpc } from "@/lib/trpc/client"; | ||
| import { CircleInfo, Cloud, CodeBranch, CodeCommit } from "@unkey/icons"; | ||
| import { Badge, Button, DialogContainer, toast } from "@unkey/ui"; | ||
|
|
||
| type RollbackDialogProps = { | ||
| isOpen: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| deployment: Deployment; | ||
| currentDeployment: Deployment; | ||
| hostname?: string; | ||
| }; | ||
|
|
||
| export const RollbackDialog = ({ | ||
| isOpen, | ||
| onOpenChange, | ||
| deployment, | ||
| currentDeployment, | ||
| hostname, | ||
| }: RollbackDialogProps) => { | ||
| const utils = trpc.useUtils(); | ||
| const rollback = trpc.deploy.rollback.useMutation({ | ||
| onSuccess: () => { | ||
| utils.invalidate(); | ||
| toast.success("Rollback completed", { | ||
| description: `Successfully rolled back to deployment ${deployment.id}`, | ||
| }); | ||
| // hack to revalidate | ||
| try { | ||
| // @ts-expect-error Their docs say it's here | ||
| collection.projects.utils.refetch(); | ||
| } catch (error) { | ||
| console.error("Refetch error:", error); | ||
| } | ||
|
|
||
| onOpenChange(false); | ||
| }, | ||
| onError: (error) => { | ||
| toast.error("Rollback failed", { | ||
| description: error.message, | ||
| }); | ||
| }, | ||
| }); | ||
|
|
||
| const handleRollback = async () => { | ||
| if (!hostname) { | ||
| toast.error("Missing hostname", { | ||
| description: "Cannot perform rollback without hostname information", | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await rollback.mutateAsync({ | ||
| hostname, | ||
| targetDeploymentId: deployment.id, | ||
| }); | ||
| } catch (error) { | ||
| console.error("Rollback error:", error); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <DialogContainer | ||
| isOpen={isOpen} | ||
| onOpenChange={onOpenChange} | ||
| title="Rollback to version" | ||
| subTitle="Switch the active deployment to a target stable version" | ||
| footer={ | ||
| <div className="flex flex-col items-center w-full gap-2"> | ||
| <Button | ||
| variant="primary" | ||
| size="xlg" | ||
| onClick={handleRollback} | ||
| disabled={rollback.isLoading} | ||
| loading={rollback.isLoading} | ||
| className="w-full rounded-lg" | ||
| > | ||
| Rollback to target version | ||
| </Button> | ||
| <div className="text-xs text-gray-9">Rollbacks usually complete within seconds</div> | ||
| </div> | ||
| } | ||
| > | ||
| <div className="space-y-6"> | ||
| {/* Current active deployment */} | ||
| <div className="space-y-2"> | ||
| <div className="flex items-center gap-2"> | ||
| <h3 className="text-sm font-medium text-gray-12">Current active deployment</h3> | ||
| <CircleInfo size="sm-regular" className="text-gray-9" /> | ||
| </div> | ||
|
|
||
| <div className="bg-gray-2 border border-gray-6 rounded-lg p-4"> | ||
| <div className="flex items-center justify-between"> | ||
| <div className="flex items-center gap-3"> | ||
| <Cloud size="md-regular" className="text-gray-11 bg-gray-3 rounded" /> | ||
| <div> | ||
| <div className="flex items-center gap-2"> | ||
| <span className="text-sm font-medium text-gray-12">{currentDeployment.id}</span> | ||
| <Badge variant="success" className="text-successA-11 font-medium"> | ||
| <div className="flex items-center gap-2">Active</div> | ||
| </Badge> | ||
| </div> | ||
| <div className="text-xs text-gray-11"> | ||
| {currentDeployment?.gitCommitMessage || "Current active deployment"} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div className="flex flex-col gap-1.5"> | ||
| <div className="flex items-center gap-1.5 px-2 py-1 bg-gray-3 rounded text-xs text-gray-11"> | ||
| <CodeBranch size="sm-regular" /> | ||
| <span>{currentDeployment.gitBranch}</span> | ||
| </div> | ||
| <div className="flex items-center gap-1.5 px-2 py-1 bg-gray-3 rounded text-xs text-gray-11"> | ||
| <CodeCommit size="sm-regular" /> | ||
| <span>{currentDeployment.gitCommitSha}</span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Target version */} | ||
| <div className="space-y-2"> | ||
| <div className="flex items-center gap-2"> | ||
| <h3 className="text-sm font-medium text-gray-12">Target version</h3> | ||
| <CircleInfo size="sm-regular" className="text-gray-9" /> | ||
| </div> | ||
|
|
||
| <div className="bg-gray-2 border border-gray-6 rounded-lg p-4"> | ||
| <div className="flex items-center justify-between"> | ||
| <div className="flex items-center gap-3"> | ||
| <Cloud size="md-regular" className="text-gray-11 bg-gray-3 rounded" /> | ||
| <div> | ||
| <div className="flex items-center gap-2"> | ||
| <span className="text-sm font-medium text-gray-12">{deployment.id}</span> | ||
| <Badge variant="primary" className="text-primaryA-11 font-medium"> | ||
| <div className="flex items-center gap-1">Inactive</div> | ||
| </Badge> | ||
| </div> | ||
| <div className="text-xs text-gray-11"> | ||
| {deployment.gitCommitMessage || "Target deployment"} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div className="flex flex-col gap-1.5"> | ||
| <div className="flex items-center gap-1.5 px-2 py-1 bg-gray-3 rounded text-xs text-gray-11"> | ||
| <CodeBranch size="sm-regular" /> | ||
| <span>{deployment.gitBranch}</span> | ||
| </div> | ||
| <div className="flex items-center gap-1.5 px-2 py-1 bg-gray-3 rounded text-xs text-gray-11"> | ||
| <CodeCommit size="sm-regular" /> | ||
| <span>{deployment.gitCommitSha}</span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </DialogContainer> | ||
| ); | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.