Merge pull request #782 from Dokploy/733-project-env-ux-improvements

refactor: apply suggested changes
This commit is contained in:
Mauricio Siu
2024-11-28 22:56:58 -06:00
committed by GitHub
4 changed files with 55 additions and 52 deletions

View File

@@ -19,11 +19,9 @@ import {
FormLabel, FormLabel,
FormMessage, FormMessage,
} from "@/components/ui/form"; } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { api } from "@/utils/api"; import { api } from "@/utils/api";
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
import { AlertTriangle, FileIcon, SquarePen } from "lucide-react"; import { FileIcon } 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";
@@ -37,9 +35,10 @@ type UpdateProject = z.infer<typeof updateProjectSchema>;
interface Props { interface Props {
projectId: string; projectId: string;
children?: React.ReactNode;
} }
export const AddEnv = ({ projectId }: Props) => { export const ProjectEnviroment = ({ projectId, children }: Props) => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const utils = api.useUtils(); const utils = api.useUtils();
const { mutateAsync, error, isError, isLoading } = const { mutateAsync, error, isError, isLoading } =
@@ -53,7 +52,6 @@ export const AddEnv = ({ projectId }: Props) => {
}, },
); );
console.log(data);
const form = useForm<UpdateProject>({ const form = useForm<UpdateProject>({
defaultValues: { defaultValues: {
env: data?.env ?? "", env: data?.env ?? "",
@@ -86,34 +84,29 @@ export const AddEnv = ({ projectId }: Props) => {
return ( return (
<Dialog open={isOpen} onOpenChange={setIsOpen}> <Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild> <DialogTrigger asChild>
<DropdownMenuItem {children ?? (
className="w-full cursor-pointer space-x-3" <DropdownMenuItem
onSelect={(e) => e.preventDefault()} className="w-full cursor-pointer space-x-3"
> onSelect={(e) => e.preventDefault()}
<FileIcon className="size-4" /> >
<span>Add Env</span> <FileIcon className="size-4" />
</DropdownMenuItem> <span>Project Enviroment</span>
</DropdownMenuItem>
)}
</DialogTrigger> </DialogTrigger>
<DialogContent className="max-h-screen overflow-y-auto sm:max-w-6xl"> <DialogContent className="max-h-screen overflow-y-auto sm:max-w-6xl">
<DialogHeader> <DialogHeader>
<DialogTitle>Modify Shared Env</DialogTitle> <DialogTitle>Project Enviroment</DialogTitle>
<DialogDescription>Update the env variables</DialogDescription> <DialogDescription>
Update the env Environment variables that are accessible to all
services of this project. Use this syntax to reference project-level
variables in your service environments:
</DialogDescription>
</DialogHeader> </DialogHeader>
{isError && <AlertBlock type="error">{error?.message}</AlertBlock>} {isError && <AlertBlock type="error">{error?.message}</AlertBlock>}
<AlertBlock type="info"> <AlertBlock type="info">
To use a shared env, in one of your services, you need to use like Use this syntax to reference project-level variables in your service
this: Let's say you have a shared env ENVIROMENT="development" and you environments: <code>DATABASE_URL=${"{{project.DATABASE_URL}}"}</code>
want to use it in your service, you need to use like this:
<ul>
<li>
<code>ENVIRONMENT=${"{{project.ENVIRONMENT}}"}</code>
</li>
<li>
<code>DATABASE_URL=${"{{project.DATABASE_URL}}"}</code>
</li>
</ul>{" "}
This allows the service to inherit and use the shared variables from
the project level, ensuring consistency across services.
</AlertBlock> </AlertBlock>
<div className="grid gap-4"> <div className="grid gap-4">
<div className="grid items-center gap-4"> <div className="grid items-center gap-4">

View File

@@ -25,7 +25,6 @@ import { api } from "@/utils/api";
import { import {
AlertTriangle, AlertTriangle,
BookIcon, BookIcon,
CircuitBoard,
ExternalLink, ExternalLink,
ExternalLinkIcon, ExternalLinkIcon,
FolderInput, FolderInput,
@@ -35,7 +34,7 @@ import {
import Link from "next/link"; import Link from "next/link";
import { Fragment } from "react"; import { Fragment } from "react";
import { toast } from "sonner"; import { toast } from "sonner";
import { AddEnv } from "./add-env"; import { ProjectEnviroment } from "./project-enviroment";
import { UpdateProject } from "./update"; import { UpdateProject } from "./update";
export const ShowProjects = () => { export const ShowProjects = () => {
@@ -192,7 +191,9 @@ export const ShowProjects = () => {
Actions Actions
</DropdownMenuLabel> </DropdownMenuLabel>
<div onClick={(e) => e.stopPropagation()}> <div onClick={(e) => e.stopPropagation()}>
<AddEnv projectId={project.projectId} /> <ProjectEnviroment
projectId={project.projectId}
/>
</div> </div>
<div onClick={(e) => e.stopPropagation()}> <div onClick={(e) => e.stopPropagation()}>
<UpdateProject projectId={project.projectId} /> <UpdateProject projectId={project.projectId} />

View File

@@ -98,7 +98,7 @@ export const ShowServers = () => {
) )
)} )}
{data && data?.length > 0 && ( {data && data?.length > 0 && (
<div className="flex flex-col gap-6"> <div className="flex flex-col gap-6 overflow-auto">
<Table> <Table>
<TableCaption>See all servers</TableCaption> <TableCaption>See all servers</TableCaption>
<TableHeader> <TableHeader>

View File

@@ -2,6 +2,7 @@ import { AddApplication } from "@/components/dashboard/project/add-application";
import { AddCompose } from "@/components/dashboard/project/add-compose"; import { AddCompose } from "@/components/dashboard/project/add-compose";
import { AddDatabase } from "@/components/dashboard/project/add-database"; import { AddDatabase } from "@/components/dashboard/project/add-database";
import { AddTemplate } from "@/components/dashboard/project/add-template"; import { AddTemplate } from "@/components/dashboard/project/add-template";
import { ProjectEnviroment } from "@/components/dashboard/projects/project-enviroment";
import { import {
MariadbIcon, MariadbIcon,
MongodbIcon, MongodbIcon,
@@ -198,27 +199,35 @@ const Project = (
</div> </div>
{(auth?.rol === "admin" || user?.canCreateServices) && ( {(auth?.rol === "admin" || user?.canCreateServices) && (
<DropdownMenu> <div className="flex flex-row gap-4 flex-wrap">
<DropdownMenuTrigger asChild> <ProjectEnviroment projectId={projectId}>
<Button> <Button variant="outline">Project Enviroment</Button>
<PlusIcon className="h-4 w-4" /> </ProjectEnviroment>
Create Service <DropdownMenu>
</Button> <DropdownMenuTrigger asChild>
</DropdownMenuTrigger> <Button>
<DropdownMenuContent className="w-[200px] space-y-2" align="end"> <PlusIcon className="h-4 w-4" />
<DropdownMenuLabel className="text-sm font-normal "> Create Service
Actions </Button>
</DropdownMenuLabel> </DropdownMenuTrigger>
<DropdownMenuSeparator /> <DropdownMenuContent
<AddApplication className="w-[200px] space-y-2"
projectId={projectId} align="end"
projectName={data?.name} >
/> <DropdownMenuLabel className="text-sm font-normal ">
<AddDatabase projectId={projectId} projectName={data?.name} /> Actions
<AddCompose projectId={projectId} projectName={data?.name} /> </DropdownMenuLabel>
<AddTemplate projectId={projectId} /> <DropdownMenuSeparator />
</DropdownMenuContent> <AddApplication
</DropdownMenu> projectId={projectId}
projectName={data?.name}
/>
<AddDatabase projectId={projectId} projectName={data?.name} />
<AddCompose projectId={projectId} projectName={data?.name} />
<AddTemplate projectId={projectId} />
</DropdownMenuContent>
</DropdownMenu>
</div>
)} )}
</header> </header>
</div> </div>