feat(preview-deployments): new UI

This commit is contained in:
Nicholas Penree
2024-12-23 16:40:36 -05:00
parent 96cdffb5b9
commit 8410d94283
3 changed files with 144 additions and 132 deletions

View File

@@ -18,17 +18,26 @@ import { ShowDeployment } from "../deployments/show-deployment";
interface Props { interface Props {
deployments: RouterOutputs["deployment"]["all"]; deployments: RouterOutputs["deployment"]["all"];
serverId?: string; serverId?: string;
trigger?: React.ReactNode;
} }
export const ShowPreviewBuilds = ({ deployments, serverId }: Props) => { export const ShowPreviewBuilds = ({
deployments,
serverId,
trigger,
}: Props) => {
const [activeLog, setActiveLog] = useState<string | null>(null); const [activeLog, setActiveLog] = useState<string | null>(null);
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
return ( return (
<Dialog open={isOpen} onOpenChange={setIsOpen}> <Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild> <DialogTrigger asChild>
{trigger ? (
trigger
) : (
<Button className="sm:w-auto w-full" size="sm" variant="outline"> <Button className="sm:w-auto w-full" size="sm" variant="outline">
View Builds View Builds
</Button> </Button>
)}
</DialogTrigger> </DialogTrigger>
<DialogContent className="max-h-screen overflow-y-auto sm:max-w-5xl"> <DialogContent className="max-h-screen overflow-y-auto sm:max-w-5xl">
<DialogHeader> <DialogHeader>

View File

@@ -1,3 +1,4 @@
import { GithubIcon } from "@/components/icons/data-tools-icons";
import { DateTooltip } from "@/components/shared/date-tooltip"; import { DateTooltip } from "@/components/shared/date-tooltip";
import { DialogAction } from "@/components/shared/dialog-action"; import { DialogAction } from "@/components/shared/dialog-action";
import { StatusTooltip } from "@/components/shared/status-tooltip"; import { StatusTooltip } from "@/components/shared/status-tooltip";
@@ -10,16 +11,17 @@ import {
CardHeader, CardHeader,
CardTitle, CardTitle,
} from "@/components/ui/card"; } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator"; import { Input } from "@/components/ui/input";
import { api } from "@/utils/api"; import { api } from "@/utils/api";
import { import {
Clock, ExternalLink,
GitBranch, FileText,
GitPullRequest, GitPullRequest,
Pencil, Layers,
PenSquare,
RocketIcon, RocketIcon,
Trash2,
} from "lucide-react"; } from "lucide-react";
import Link from "next/link";
import React from "react"; import React from "react";
import { toast } from "sonner"; import { toast } from "sonner";
import { ShowModalLogs } from "../../settings/web-server/show-modal-logs"; import { ShowModalLogs } from "../../settings/web-server/show-modal-logs";
@@ -88,136 +90,133 @@ export const ShowPreviewDeployments = ({ applicationId }: Props) => {
</div> </div>
) : ( ) : (
<div className="flex flex-col gap-4"> <div className="flex flex-col gap-4">
{previewDeployments.map((previewDeployment) => ( {previewDeployments?.map((deployment) => {
const deploymentUrl = `${deployment.domain?.https ? "https" : "http"}://${deployment.domain?.host}${deployment.domain?.path || "/"}`;
return (
<div <div
key={previewDeployment.previewDeploymentId} key={deployment.previewDeploymentId}
className="w-full border rounded-xl" className="group relative overflow-hidden border rounded-lg transition-colors"
> >
<div className="md:p-6 p-2 md:pb-3 flex flex-row items-center justify-between"> <div
<span className="text-lg font-bold"> className={`absolute left-0 top-0 w-1 h-full ${
{previewDeployment.pullRequestTitle} deployment.previewStatus === "running"
</span> ? "bg-green-500"
<Badge : "bg-red-500"
variant="outline" }`}
className="text-sm font-medium gap-x-2"
>
<StatusTooltip
status={previewDeployment.previewStatus}
className="size-2.5"
/> />
{previewDeployment.previewStatus
?.replace("running", "Running") <div className="p-4">
.replace("done", "Done") <div className="flex items-start justify-between mb-3">
.replace("error", "Error") <div className="flex items-start gap-3">
.replace("idle", "Idle") || "Idle"} <GitPullRequest className="size-5 text-muted-foreground mt-1 flex-shrink-0" />
<div>
<div className="font-medium text-sm">
{deployment.pullRequestTitle}
</div>
<div className="text-sm text-muted-foreground mt-1">
{deployment.branch}
</div>
</div>
</div>
<Badge variant="outline" className="gap-2">
<StatusTooltip
status={deployment.previewStatus}
className="size-2"
/>
<DateTooltip date={deployment.createdAt} />
</Badge> </Badge>
</div> </div>
<div className="md:p-6 p-2 md:pt-0 space-y-4"> <div className="pl-8 space-y-3">
<div className="flex sm:flex-row flex-col items-center gap-2"> <div className="relative flex-grow">
<Link <Input
href={`http://${previewDeployment.domain?.host}`} value={deploymentUrl}
target="_blank" readOnly
className="text-sm text-blue-500/95 hover:underline gap-2 flex w-full sm:flex-row flex-col items-center justify-between rounded-lg border p-2" className="pr-8 text-sm text-blue-500 hover:text-blue-600 cursor-pointer"
> onClick={() =>
{previewDeployment.domain?.host} window.open(deploymentUrl, "_blank")
</Link>
<AddPreviewDomain
previewDeploymentId={
previewDeployment.previewDeploymentId
} }
domainId={previewDeployment.domain?.domainId} />
> <ExternalLink className="absolute right-3 top-1/2 -translate-y-1/2 size-4 text-gray-400" />
</div>
<div className="flex gap-2 opacity-80 group-hover:opacity-100 transition-opacity">
<Button <Button
className="sm:w-auto w-full"
size="sm"
variant="outline" variant="outline"
size="sm"
className="gap-2"
onClick={() =>
window.open(deployment.pullRequestURL, "_blank")
}
> >
<Pencil className="size-4" /> <GithubIcon className="size-4" />
Edit
</Button>
</AddPreviewDomain>
</div>
<div className="flex sm:flex-row text-sm flex-col items-center justify-between">
<div className="flex items-center space-x-2">
<GitBranch className="size-5 text-gray-400" />
<span>Branch:</span>
<Badge className="p-2" variant="blank">
{previewDeployment.branch}
</Badge>
</div>
<div className="flex items-center space-x-2">
<Clock className="size-5 text-gray-400" />
<span>Deployed:</span>
<Badge className="p-2" variant="blank">
<DateTooltip date={previewDeployment.createdAt} />
</Badge>
</div>
</div>
<Separator />
<div className="rounded-lg bg-muted p-4">
<h3 className="mb-2 text-sm font-medium">
Pull Request Pull Request
</h3> </Button>
<div className="flex items-center space-x-2 text-sm text-muted-foreground">
<GitPullRequest className="size-5 text-gray-400" />
<Link
className="hover:text-blue-500/95 hover:underline"
target="_blank"
href={previewDeployment.pullRequestURL}
>
{previewDeployment.pullRequestTitle}
</Link>
</div>
</div>
</div>
<div className="justify-center flex-wrap md:p-6 p-2 md:pt-0">
<div className="flex flex-wrap justify-end gap-2">
<ShowModalLogs <ShowModalLogs
appName={previewDeployment.appName} appName={deployment.appName}
serverId={data?.serverId || ""} serverId={data?.serverId || ""}
> >
<Button <Button
className="sm:w-auto w-full"
variant="outline" variant="outline"
size="sm" size="sm"
className="gap-2"
> >
View Logs <FileText className="size-4" />
Logs
</Button> </Button>
</ShowModalLogs> </ShowModalLogs>
<ShowPreviewBuilds <ShowPreviewBuilds
deployments={previewDeployment.deployments || []} deployments={deployment.deployments || []}
serverId={data?.serverId || ""} serverId={data?.serverId || ""}
trigger={
<Button
variant="outline"
size="sm"
className="gap-2"
>
<Layers className="size-4" />
Builds
</Button>
}
/> />
<AddPreviewDomain
previewDeploymentId={`${deployment.previewDeploymentId}`}
domainId={deployment.domain?.domainId}
>
<Button
variant="ghost"
size="sm"
className="gap-2"
>
<PenSquare className="size-4" />
</Button>
</AddPreviewDomain>
<DialogAction <DialogAction
title="Delete Preview" title="Delete Preview"
description="Are you sure you want to delete this preview?" description="Are you sure you want to delete this preview?"
onClick={() => onClick={() =>
handleDeletePreviewDeployment( handleDeletePreviewDeployment(
previewDeployment.previewDeploymentId, deployment.previewDeploymentId,
) )
} }
> >
<Button <Button
className="sm:w-auto w-full" variant="ghost"
variant="destructive"
isLoading={isLoading}
size="sm" size="sm"
isLoading={isLoading}
className="text-red-600 hover:text-red-700 hover:bg-red-50"
> >
Delete Preview <Trash2 className="size-4" />
</Button> </Button>
</DialogAction> </DialogAction>
</div> </div>
</div> </div>
</div> </div>
))} </div>
);
})}
</div> </div>
)} )}
</> </>

View File

@@ -29,6 +29,7 @@ import {
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
import { api } from "@/utils/api"; import { api } from "@/utils/api";
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
import { Settings2 } from "lucide-react";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { toast } from "sonner"; import { toast } from "sonner";
@@ -116,7 +117,10 @@ export const ShowPreviewSettings = ({ applicationId }: Props) => {
<div> <div>
<Dialog open={isOpen} onOpenChange={setIsOpen}> <Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild> <DialogTrigger asChild>
<Button variant="outline">View Settings</Button> <Button variant="outline">
<Settings2 className="size-4" />
Configure
</Button>
</DialogTrigger> </DialogTrigger>
<DialogContent className="max-h-screen overflow-y-auto sm:max-w-5xl w-full"> <DialogContent className="max-h-screen overflow-y-auto sm:max-w-5xl w-full">
<DialogHeader> <DialogHeader>