[autofix.ci] apply automated fixes

This commit is contained in:
autofix-ci[bot]
2025-12-08 02:30:23 +00:00
committed by Marc Fernandez
parent 33fb21bfe1
commit 95dd9ddeb6
4 changed files with 80 additions and 73 deletions

View File

@@ -1,78 +1,81 @@
import { Paintbrush } from "lucide-react";
import { toast } from "sonner";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import { api } from "@/utils/api";
interface Props {
id: string;
type: "application" | "compose";
id: string;
type: "application" | "compose";
}
export const ClearDeployments = ({ id, type }: Props) => {
const utils = api.useUtils();
const { mutateAsync, isLoading } =
type === "application"
? api.application.clearDeployments.useMutation()
: api.compose.clearDeployments.useMutation();
const { data: isCloud } = api.settings.isCloud.useQuery();
const utils = api.useUtils();
const { mutateAsync, isLoading } =
type === "application"
? api.application.clearDeployments.useMutation()
: api.compose.clearDeployments.useMutation();
const { data: isCloud } = api.settings.isCloud.useQuery();
if (isCloud) {
return null;
}
if (isCloud) {
return null;
}
return (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="outline" className="w-fit" isLoading={isLoading}>
Clear deployments
<Paintbrush className="size-4" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
Are you sure you want to clear old deployments?
</AlertDialogTitle>
<AlertDialogDescription>
This will delete all old deployment records and logs, keeping only the active deployment (the most recent successful one).
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={async () => {
await mutateAsync({
applicationId: id || "",
composeId: id || "",
})
.then(async (result) => {
toast.success(`${result.deletedCount} old deployments cleared successfully`);
// Invalidate deployment queries to refresh the list
await utils.deployment.allByType.invalidate({
id,
type,
});
})
.catch((err) => {
toast.error(err.message);
});
}}
>
Confirm
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
return (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant="outline" className="w-fit" isLoading={isLoading}>
Clear deployments
<Paintbrush className="size-4" />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
Are you sure you want to clear old deployments?
</AlertDialogTitle>
<AlertDialogDescription>
This will delete all old deployment records and logs, keeping only
the active deployment (the most recent successful one).
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={async () => {
await mutateAsync({
applicationId: id || "",
composeId: id || "",
})
.then(async (result) => {
toast.success(
`${result.deletedCount} old deployments cleared successfully`,
);
// Invalidate deployment queries to refresh the list
await utils.deployment.allByType.invalidate({
id,
type,
});
})
.catch((err) => {
toast.error(err.message);
});
}}
>
Confirm
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
};

View File

@@ -745,10 +745,13 @@ export const applicationRouter = createTRPCRouter({
) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You are not authorized to clear deployments for this application",
message:
"You are not authorized to clear deployments for this application",
});
}
const result = await clearOldDeploymentsByApplicationId(input.applicationId);
const result = await clearOldDeploymentsByApplicationId(
input.applicationId,
);
return {
success: true,
message: `${result.deletedCount} old deployments cleared successfully`,

View File

@@ -263,7 +263,8 @@ export const composeRouter = createTRPCRouter({
) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You are not authorized to clear deployments for this compose",
message:
"You are not authorized to clear deployments for this compose",
});
}
const result = await clearOldDeploymentsByComposeId(input.composeId);

View File

@@ -849,7 +849,7 @@ export const clearOldDeploymentsByApplicationId = async (
// If there's an active deployment, keep it and remove all others
// If there's no active deployment, keep the most recent one and remove the rest
let deploymentsToKeep: string[] = [];
if (activeDeployment) {
deploymentsToKeep.push(activeDeployment.deploymentId);
} else if (deploymentsList.length > 0) {
@@ -866,7 +866,7 @@ export const clearOldDeploymentsByApplicationId = async (
if (deployment.rollbackId) {
await removeRollbackById(deployment.rollbackId);
}
// Remove log file if it exists
const logPath = deployment.logPath;
if (logPath && logPath !== "." && existsSync(logPath)) {
@@ -876,7 +876,7 @@ export const clearOldDeploymentsByApplicationId = async (
console.error(`Error removing log file ${logPath}:`, error);
}
}
// Delete deployment from database
await removeDeployment(deployment.deploymentId);
}
@@ -902,7 +902,7 @@ export const clearOldDeploymentsByComposeId = async (composeId: string) => {
// If there's an active deployment, keep it and remove all others
// If there's no active deployment, keep the most recent one and remove the rest
let deploymentsToKeep: string[] = [];
if (activeDeployment) {
deploymentsToKeep.push(activeDeployment.deploymentId);
} else if (deploymentsList.length > 0) {
@@ -919,7 +919,7 @@ export const clearOldDeploymentsByComposeId = async (composeId: string) => {
if (deployment.rollbackId) {
await removeRollbackById(deployment.rollbackId);
}
// Remove log file if it exists
const logPath = deployment.logPath;
if (logPath && logPath !== "." && existsSync(logPath)) {
@@ -929,7 +929,7 @@ export const clearOldDeploymentsByComposeId = async (composeId: string) => {
console.error(`Error removing log file ${logPath}:`, error);
}
}
// Delete deployment from database
await removeDeployment(deployment.deploymentId);
}