mirror of
https://github.com/biersoeckli/QuickStack.git
synced 2026-02-10 21:49:19 -06:00
feat: add deleteBackup function and integrate it into BackupDetailDialog
This commit is contained in:
@@ -25,4 +25,20 @@ export const downloadBackup = async (s3TargetId: string, s3Key: string) =>
|
||||
|
||||
const fileNameOfDownloadedFile = await backupService.downloadBackupForS3TargetAndKey(validatetData.s3TargetId, validatetData.s3Key);
|
||||
return new SuccessActionResult(fileNameOfDownloadedFile, 'Starting download...'); // returns the download path on the server
|
||||
}) as Promise<ServerActionResult<any, string>>;
|
||||
|
||||
export const deleteBackup = async (s3TargetId: string, s3Key: string) =>
|
||||
simpleAction(async () => {
|
||||
await getAuthUserSession();
|
||||
|
||||
const validatetData = z.object({
|
||||
s3TargetId: z.string(),
|
||||
s3Key: z.string()
|
||||
}).parse({
|
||||
s3TargetId,
|
||||
s3Key
|
||||
});
|
||||
|
||||
await backupService.deleteBackupFromS3(validatetData.s3TargetId, validatetData.s3Key);
|
||||
return new SuccessActionResult(undefined, 'Backup will be deleted. Refresh the page to see the changes.');
|
||||
}) as Promise<ServerActionResult<any, string>>;
|
||||
@@ -12,10 +12,11 @@ import { ScrollArea } from "@radix-ui/react-scroll-area";
|
||||
import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { KubeSizeConverter } from "@/shared/utils/kubernetes-size-converter.utils";
|
||||
import { formatDateTime } from "@/frontend/utils/format.utils";
|
||||
import { downloadBackup } from "./actions";
|
||||
import { deleteBackup, downloadBackup } from "./actions";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Download } from "lucide-react";
|
||||
import { Download, Trash2 } from "lucide-react";
|
||||
import { Toast } from "@/frontend/utils/toast.utils";
|
||||
import { useConfirmDialog } from "@/frontend/states/zustand.states";
|
||||
|
||||
export function BackupDetailDialog({
|
||||
backupInfo,
|
||||
@@ -25,6 +26,7 @@ export function BackupDetailDialog({
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
|
||||
const { openConfirmDialog } = useConfirmDialog();
|
||||
const [isOpen, setIsOpen] = React.useState(false);
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
|
||||
@@ -41,6 +43,16 @@ export function BackupDetailDialog({
|
||||
}
|
||||
}
|
||||
|
||||
const asyncDeleteBackup = async (s3Key: string) => {
|
||||
if (await openConfirmDialog({
|
||||
title: 'Delete Backup',
|
||||
description: 'This action deletes the backup from the storage. This action cannot be undone.',
|
||||
okButton: 'Delete'
|
||||
})) {
|
||||
await Toast.fromAction(() => deleteBackup(backupInfo.s3TargetId, s3Key));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={(isO) => {
|
||||
setIsOpen(isO);
|
||||
@@ -72,10 +84,13 @@ export function BackupDetailDialog({
|
||||
<TableRow key={index}>
|
||||
<TableCell>{formatDateTime(item.backupDate, true)}</TableCell>
|
||||
<TableCell>{item.sizeBytes ? KubeSizeConverter.convertBytesToReadableSize(item.sizeBytes) : 'unknown'}</TableCell>
|
||||
<TableCell className="flex justify-end">
|
||||
<TableCell className="flex justify-end gap-2">
|
||||
<Button variant="ghost" size="sm" onClick={() => asyncDownloadPvcData(item.key)} disabled={isLoading}>
|
||||
<Download />
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" onClick={() => asyncDeleteBackup(item.key)} disabled={isLoading}>
|
||||
<Trash2 />
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
|
||||
@@ -250,6 +250,15 @@ class BackupService {
|
||||
await FsUtils.deleteFileIfExists(downloadPath);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteBackupFromS3(s3TargetId: string, key: string) {
|
||||
const target = await dataAccess.client.s3Target.findFirstOrThrow({
|
||||
where: {
|
||||
id: s3TargetId
|
||||
}
|
||||
});
|
||||
return s3Service.deleteFile(target, key);
|
||||
}
|
||||
}
|
||||
|
||||
const backupService = new BackupService();
|
||||
|
||||
Reference in New Issue
Block a user