refactor: simplify database colums

This commit is contained in:
Mauricio Siu
2024-09-01 00:48:47 -06:00
parent 73efe0d0ed
commit 766b166bf2
10 changed files with 70 additions and 76 deletions
@@ -47,7 +47,7 @@ const BitbucketProviderSchema = z.object({
})
.required(),
branch: z.string().min(1, "Branch is required"),
bitbucketProviderId: z.string().min(1, "Bitbucket Provider is required"),
bitbucketId: z.string().min(1, "Bitbucket Provider is required"),
});
type BitbucketProvider = z.infer<typeof BitbucketProviderSchema>;
@@ -71,14 +71,14 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
owner: "",
repo: "",
},
bitbucketProviderId: "",
bitbucketId: "",
branch: "",
},
resolver: zodResolver(BitbucketProviderSchema),
});
const repository = form.watch("repository");
const bitbucketProviderId = form.watch("bitbucketProviderId");
const bitbucketId = form.watch("bitbucketId");
const {
data: repositories,
@@ -86,7 +86,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
error,
isError,
} = api.gitProvider.getBitbucketRepositories.useQuery({
bitbucketProviderId,
bitbucketId,
});
const {
@@ -97,11 +97,10 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
{
owner: repository?.owner,
repo: repository?.repo,
bitbucketProviderId,
bitbucketId,
},
{
enabled:
!!repository?.owner && !!repository?.repo && !!bitbucketProviderId,
enabled: !!repository?.owner && !!repository?.repo && !!bitbucketId,
},
);
@@ -114,7 +113,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
owner: data.bitbucketOwner || "",
},
buildPath: data.bitbucketBuildPath || "/",
bitbucketProviderId: data.bitbucketProviderId || "",
bitbucketId: data.bitbucketId || "",
});
}
}, [form.reset, data, form]);
@@ -125,7 +124,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
bitbucketRepository: data.repository.repo,
bitbucketOwner: data.repository.owner,
bitbucketBuildPath: data.buildPath,
bitbucketProviderId: data.bitbucketProviderId,
bitbucketId: data.bitbucketId,
applicationId,
})
.then(async () => {
@@ -150,7 +149,7 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
<div className="grid md:grid-cols-2 gap-4">
<FormField
control={form.control}
name="bitbucketProviderId"
name="bitbucketId"
render={({ field }) => (
<FormItem className="md:col-span-2 flex flex-col">
<FormLabel>Bitbucket Account</FormLabel>
@@ -174,8 +173,8 @@ export const SaveBitbucketProvider = ({ applicationId }: Props) => {
<SelectContent>
{bitbucketProviders?.map((bitbucketProvider) => (
<SelectItem
key={bitbucketProvider.bitbucketProviderId}
value={bitbucketProvider.bitbucketProviderId}
key={bitbucketProvider.bitbucketId}
value={bitbucketProvider.bitbucketId}
>
{bitbucketProvider.gitProvider.name}
</SelectItem>
@@ -46,7 +46,7 @@ const GithubProviderSchema = z.object({
})
.required(),
branch: z.string().min(1, "Branch is required"),
githubProviderId: z.string().min(1, "Github Provider is required"),
githubId: z.string().min(1, "Github Provider is required"),
});
type GithubProvider = z.infer<typeof GithubProviderSchema>;
@@ -69,18 +69,18 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
owner: "",
repo: "",
},
githubProviderId: "",
githubId: "",
branch: "",
},
resolver: zodResolver(GithubProviderSchema),
});
const repository = form.watch("repository");
const githubProviderId = form.watch("githubProviderId");
const githubId = form.watch("githubId");
const { data: repositories, isLoading: isLoadingRepositories } =
api.gitProvider.getRepositories.useQuery({
githubProviderId,
githubId,
});
const {
@@ -91,10 +91,10 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
{
owner: repository?.owner,
repo: repository?.repo,
githubProviderId,
githubId,
},
{
enabled: !!repository?.owner && !!repository?.repo && !!githubProviderId,
enabled: !!repository?.owner && !!repository?.repo && !!githubId,
},
);
@@ -107,7 +107,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
owner: data.owner || "",
},
buildPath: data.buildPath || "/",
githubProviderId: data.githubProviderId || "",
githubId: data.githubId || "",
});
}
}, [form.reset, data, form]);
@@ -119,7 +119,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
applicationId,
owner: data.repository.owner,
buildPath: data.buildPath,
githubProviderId: data.githubProviderId,
githubId: data.githubId,
})
.then(async () => {
toast.success("Service Provided Saved");
@@ -140,7 +140,7 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
<div className="grid md:grid-cols-2 gap-4">
<FormField
control={form.control}
name="githubProviderId"
name="githubId"
render={({ field }) => (
<FormItem className="md:col-span-2 flex flex-col">
<FormLabel>Github Account</FormLabel>
@@ -164,8 +164,8 @@ export const SaveGithubProvider = ({ applicationId }: Props) => {
<SelectContent>
{githubProviders?.map((githubProvider) => (
<SelectItem
key={githubProvider.githubProviderId}
value={githubProvider.githubProviderId}
key={githubProvider.githubId}
value={githubProvider.githubId}
>
{githubProvider.gitProvider.name}
</SelectItem>
@@ -47,7 +47,7 @@ const GitlabProviderSchema = z.object({
})
.required(),
branch: z.string().min(1, "Branch is required"),
gitlabProviderId: z.string().min(1, "Gitlab Provider is required"),
gitlabId: z.string().min(1, "Gitlab Provider is required"),
});
type GitlabProvider = z.infer<typeof GitlabProviderSchema>;
@@ -70,21 +70,21 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
owner: "",
repo: "",
},
gitlabProviderId: "",
gitlabId: "",
branch: "",
},
resolver: zodResolver(GitlabProviderSchema),
});
const repository = form.watch("repository");
const gitlabProviderId = form.watch("gitlabProviderId");
const gitlabId = form.watch("gitlabId");
const {
data: repositories,
isLoading: isLoadingRepositories,
error,
} = api.gitProvider.getGitlabRepositories.useQuery({
gitlabProviderId,
gitlabId,
});
const {
@@ -95,10 +95,10 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
{
owner: repository?.owner,
repo: repository?.repo,
gitlabProviderId: gitlabProviderId,
gitlabId: gitlabId,
},
{
enabled: !!repository?.owner && !!repository?.repo && !!gitlabProviderId,
enabled: !!repository?.owner && !!repository?.repo && !!gitlabId,
},
);
@@ -111,7 +111,7 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
owner: data.gitlabOwner || "",
},
buildPath: data.gitlabBuildPath || "/",
gitlabProviderId: data.gitlabProviderId || "",
gitlabId: data.gitlabId || "",
});
}
}, [form.reset, data, form]);
@@ -122,7 +122,7 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
gitlabRepository: data.repository.repo,
gitlabOwner: data.repository.owner,
gitlabBuildPath: data.buildPath,
gitlabProviderId: data.gitlabProviderId,
gitlabId: data.gitlabId,
applicationId,
})
.then(async () => {
@@ -145,7 +145,7 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
<div className="grid md:grid-cols-2 gap-4">
<FormField
control={form.control}
name="gitlabProviderId"
name="gitlabId"
render={({ field }) => (
<FormItem className="md:col-span-2 flex flex-col">
<FormLabel>Gitlab Account</FormLabel>
@@ -169,8 +169,8 @@ export const SaveGitlabProvider = ({ applicationId }: Props) => {
<SelectContent>
{gitlabProviders?.map((gitlabProvider) => (
<SelectItem
key={gitlabProvider.gitlabProviderId}
value={gitlabProvider.gitlabProviderId}
key={gitlabProvider.gitlabId}
value={gitlabProvider.gitlabId}
>
{gitlabProvider.gitProvider.name}
</SelectItem>
@@ -1,5 +1,5 @@
import { buttonVariants } from "@/components/ui/button";
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
import { Card, CardContent } from "@/components/ui/card";
import { AddGitlabProvider } from "./add-gitlab-provider";
import {
BitbucketIcon,
@@ -49,13 +49,12 @@ export const ShowGitProviders = () => {
const isGitlab = gitProvider.providerType === "gitlab";
const haveGithubRequirements =
gitProvider.providerType === "github" &&
gitProvider.githubProvider?.githubPrivateKey &&
gitProvider.githubProvider?.githubAppId &&
gitProvider.githubProvider?.githubInstallationId;
gitProvider.github?.githubPrivateKey &&
gitProvider.github?.githubAppId &&
gitProvider.github?.githubInstallationId;
const haveGitlabRequirements =
gitProvider.gitlabProvider?.accessToken &&
gitProvider.gitlabProvider?.refreshToken;
gitProvider.gitlab?.accessToken && gitProvider.gitlab?.refreshToken;
return (
<div
className="space-y-4"
@@ -89,7 +88,7 @@ export const ShowGitProviders = () => {
{!haveGithubRequirements && isGithub && (
<div className="flex flex-col gap-1">
<Link
href={`${gitProvider?.githubProvider?.githubAppName}/installations/new?state=gh_setup:${gitProvider?.githubProvider.githubProviderId}`}
href={`${gitProvider?.github?.githubAppName}/installations/new?state=gh_setup:${gitProvider?.github.githubId}`}
className={buttonVariants({ className: "w-fit" })}
>
Install Github App
@@ -100,7 +99,7 @@ export const ShowGitProviders = () => {
{haveGithubRequirements && isGithub && (
<div className="flex flex-col gap-1">
<Link
href={`${gitProvider?.githubProvider?.githubAppName}`}
href={`${gitProvider?.github?.githubAppName}`}
target="_blank"
className={buttonVariants({
className: "w-fit",
@@ -116,8 +115,8 @@ export const ShowGitProviders = () => {
<div className="flex flex-col gap-1">
<Link
href={getGitlabUrl(
gitProvider.gitlabProvider?.applicationId || "",
gitProvider.gitlabProvider?.gitlabProviderId || "",
gitProvider.gitlab?.applicationId || "",
gitProvider.gitlab?.gitlabId || "",
)}
target="_blank"
className={buttonVariants({