From c681aa2e9f915cc7cb8b5163ebd56300ab95fba1 Mon Sep 17 00:00:00 2001 From: Lorenzo Migliorero Date: Thu, 25 Jul 2024 22:10:35 +0200 Subject: [PATCH] feat: compose app --- .../general/generic/save-git-provider.tsx | 9 - .../generic/save-git-provider-compose.tsx | 215 +- drizzle/0027_fantastic_squadron_sinister.sql | 8 + drizzle/meta/0027_snapshot.json | 3010 +++++++++++++++++ drizzle/meta/_journal.json | 7 + server/api/routers/application.ts | 32 - server/api/routers/compose.ts | 32 - server/db/schema/compose.ts | 13 +- server/db/schema/ssh-key.ts | 2 + server/utils/providers/git.ts | 2 +- 10 files changed, 3122 insertions(+), 208 deletions(-) create mode 100644 drizzle/0027_fantastic_squadron_sinister.sql create mode 100644 drizzle/meta/0027_snapshot.json diff --git a/components/dashboard/application/general/generic/save-git-provider.tsx b/components/dashboard/application/general/generic/save-git-provider.tsx index baafa20a..58fd1973 100644 --- a/components/dashboard/application/general/generic/save-git-provider.tsx +++ b/components/dashboard/application/general/generic/save-git-provider.tsx @@ -1,4 +1,3 @@ -import { AddSSHKey } from "@/components/dashboard/settings/ssh-keys/add-ssh-key"; import { Button } from "@/components/ui/button"; import { Form, @@ -20,13 +19,10 @@ import { } from "@/components/ui/select"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; -import { SelectSeparator } from "@radix-ui/react-select"; import { KeyRoundIcon, LockIcon } from "lucide-react"; -import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect } from "react"; -import { flushSync } from "react-dom"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; @@ -53,11 +49,7 @@ export const SaveGitProvider = ({ applicationId }: Props) => { const { mutateAsync, isLoading } = api.application.saveGitProdiver.useMutation(); - // const { mutateAsync: generateSSHKey, isLoading: isGeneratingSSHKey } = - // api.application.generateSSHKey.useMutation(); - // const { mutateAsync: removeSSHKey, isLoading: isRemovingSSHKey } = - // api.application.removeSSHKey.useMutation(); const form = useForm({ defaultValues: { branch: "", @@ -152,7 +144,6 @@ export const SaveGitProvider = ({ applicationId }: Props) => { None Keys ({sshKeys?.length}) - diff --git a/components/dashboard/compose/general/generic/save-git-provider-compose.tsx b/components/dashboard/compose/general/generic/save-git-provider-compose.tsx index 129d97dc..c05dc7ed 100644 --- a/components/dashboard/compose/general/generic/save-git-provider-compose.tsx +++ b/components/dashboard/compose/general/generic/save-git-provider-compose.tsx @@ -1,13 +1,4 @@ import { Button } from "@/components/ui/button"; -import { - Dialog, - DialogContent, - DialogDescription, - DialogFooter, - DialogHeader, - DialogTitle, - DialogTrigger, -} from "@/components/ui/dialog"; import { Form, FormControl, @@ -17,11 +8,19 @@ import { FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; -import { Textarea } from "@/components/ui/textarea"; +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; import { api } from "@/utils/api"; import { zodResolver } from "@hookform/resolvers/zod"; -import copy from "copy-to-clipboard"; -import { CopyIcon, LockIcon } from "lucide-react"; +import { KeyRoundIcon, LockIcon } from "lucide-react"; +import { useRouter } from "next/router"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; @@ -33,6 +32,7 @@ const GitProviderSchema = z.object({ message: "Repository URL is required", }), branch: z.string().min(1, "Branch required"), + sshKey: z.string().optional(), }); type GitProvider = z.infer; @@ -43,19 +43,17 @@ interface Props { export const SaveGitProviderCompose = ({ composeId }: Props) => { const { data, refetch } = api.compose.one.useQuery({ composeId }); + const { data: sshKeys } = api.sshKey.all.useQuery(); + const router = useRouter(); const { mutateAsync, isLoading } = api.compose.update.useMutation(); - const { mutateAsync: generateSSHKey, isLoading: isGeneratingSSHKey } = - api.compose.generateSSHKey.useMutation(); - - const { mutateAsync: removeSSHKey, isLoading: isRemovingSSHKey } = - api.compose.removeSSHKey.useMutation(); const form = useForm({ defaultValues: { branch: "", repositoryURL: "", composePath: "./docker-compose.yml", + sshKey: undefined, }, resolver: zodResolver(GitProviderSchema), }); @@ -63,6 +61,7 @@ export const SaveGitProviderCompose = ({ composeId }: Props) => { useEffect(() => { if (data) { form.reset({ + sshKey: data.customGitSSHKeyId || undefined, branch: data.customGitBranch || "", repositoryURL: data.customGitUrl || "", composePath: data.composePath, @@ -74,6 +73,7 @@ export const SaveGitProviderCompose = ({ composeId }: Props) => { await mutateAsync({ customGitBranch: values.branch, customGitUrl: values.repositoryURL, + customGitSSHKeyId: values.sshKey === "none" ? null : values.sshKey, composeId, sourceType: "git", composePath: values.composePath, @@ -94,123 +94,72 @@ export const SaveGitProviderCompose = ({ composeId }: Props) => { className="flex flex-col gap-4" >
-
- ( - - - Repository URL -
- - - ? - - - - Private Repository - - If your repository is private is necessary to - generate SSH Keys to add to your git provider. - - -
-
-