Skip to content
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

fix: Init redeploy #25

Merged
merged 10 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use client";

import { useRouter } from "next/navigation";

import { cn } from "@ctrlplane/ui";
import { Button } from "@ctrlplane/ui/button";

import { api } from "~/trpc/react";

export const DeployButton: React.FC<{
releaseId: string;
environmentId: string;
}> = ({ releaseId, environmentId }) => {
const deploy = api.release.deploy.toEnvironment.useMutation();
const router = useRouter();

return (
<Button
className={cn(
"w-full border-dashed border-neutral-800/50 bg-transparent text-center text-neutral-800 hover:border-blue-400 hover:bg-transparent hover:text-blue-400",
)}
variant="outline"
size="sm"
onClick={() =>
deploy
.mutateAsync({
environmentId,
releaseId,
})
.then(() => router.refresh())
}
disabled={deploy.isPending}
>
Deploy
</Button>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use client";

import { capitalCase } from "change-case";
import {
Bar,
BarChart,
Cell,
ResponsiveContainer,
XAxis,
YAxis,
} from "recharts";

import { getStatusColor } from "./status-color";

export const DeploymentBarChart: React.FC<{
data: { name: string; count: number }[];
}> = ({ data }) => (
<ResponsiveContainer width="100%" height={250}>
<BarChart data={data} margin={{ top: 10, left: -25, bottom: -10 }}>
<XAxis
dataKey="name"
type="category"
interval={0}
height={100}
style={{ fontSize: "0.75rem" }}
angle={-45}
textAnchor="end"
tickFormatter={(value) => capitalCase(value as string)}
/>
<YAxis style={{ fontSize: "0.75rem" }} />
<Bar dataKey="count" fill="#8884d8">
{data.map(({ name }) => (
<Cell key={name} fill={getStatusColor(name)} />
))}
</Bar>
</BarChart>
</ResponsiveContainer>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
"use client";

import { useRouter } from "next/navigation";
import { TbAlertTriangle, TbDotsVertical, TbReload } from "react-icons/tb";

import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@ctrlplane/ui/alert-dialog";
import { Badge } from "@ctrlplane/ui/badge";
import { Button, buttonVariants } from "@ctrlplane/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@ctrlplane/ui/dialog";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@ctrlplane/ui/dropdown-menu";

import { api } from "~/trpc/react";

const RedeployReleaseDialog: React.FC<{
release: {
id: string;
name: string;
};
environment: {
id: string;
name: string;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
release: {
id: string;
name: string;
};
environment: {
id: string;
name: string;
};
release: {
id: string;
name: string;
};
environment: {
id: string;
name: string;
};

I think you can one liner this :)

children: React.ReactNode;
}> = ({ release, environment, children }) => {
const router = useRouter();
const redeploy = api.release.deploy.toEnvironment.useMutation();

return (
<Dialog>
<DialogTrigger asChild>{children}</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>
Redeploy{" "}
<Badge variant="secondary" className="h-7 text-lg">
{release.name}
</Badge>{" "}
to {environment.name}?
</DialogTitle>
<DialogDescription>
This will redeploy the release to all targets in the environment.
</DialogDescription>
</DialogHeader>

<DialogFooter>
<Button
onClick={() =>
redeploy
.mutateAsync({
environmentId: environment.id,
releaseId: release.id,
})
.then(() => router.refresh())
}
>
Redeploy
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
};

const ForceReleaseDialog: React.FC<{
release: {
id: string;
name: string;
};
environment: {
id: string;
name: string;
};
children: React.ReactNode;
}> = ({ release, environment, children }) => {
const forceDeploy = api.release.deploy.toEnvironment.useMutation();
const router = useRouter();
return (
<AlertDialog>
<AlertDialogTrigger asChild>{children}</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
Force release {release.name} to {environment.name}?
</AlertDialogTitle>
<AlertDialogDescription>
This will force the release to be deployed to all targets in the
environment regardless of any policies set on the environment.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter className="flex">
<AlertDialogCancel>Cancel</AlertDialogCancel>
<div className="flex-grow" />
<AlertDialogAction
className={buttonVariants({ variant: "destructive" })}
onClick={() =>
forceDeploy
.mutateAsync({
environmentId: environment.id,
releaseId: release.id,
isForcedRelease: true,
})
.then(() => router.refresh())
}
>
Force deploy
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
};

export const ReleaseDropdownMenu: React.FC<{
release: {
id: string;
name: string;
};
environment: {
id: string;
name: string;
};
isReleaseCompleted: boolean;
}> = ({ release, environment, isReleaseCompleted }) => (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" size="icon">
<TbDotsVertical />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<RedeployReleaseDialog release={release} environment={environment}>
<DropdownMenuItem
disabled={!isReleaseCompleted}
onSelect={(e) => e.preventDefault()}
className="space-x-2"
>
<TbReload />
<span>Redeploy</span>
</DropdownMenuItem>
</RedeployReleaseDialog>
<ForceReleaseDialog release={release} environment={environment}>
<DropdownMenuItem
onSelect={(e) => e.preventDefault()}
className="space-x-2"
>
<TbAlertTriangle />
<span>Force deploy</span>
</DropdownMenuItem>
</ForceReleaseDialog>
</DropdownMenuContent>
</DropdownMenu>
);
Loading
Loading