-
Notifications
You must be signed in to change notification settings - Fork 6
Complete Allow the user to delete the rules file from the downloads #1219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7d24e3f
Complete Allow the user to delete the rules file from the downloads
brian-kim31 665e652
Fix File Formatting
brian-kim31 6523768
Fix File Formatting
brian-kim31 c440c12
Improve Rules download delete Feature
brian-kim31 19739d9
Fix code formatting
brian-kim31 b3e0d70
Fix code formatting
brian-kim31 8ce55f2
Rename RETENTION_DAYS to OLD_FILE_THRESHOLD
brian-kim31 f20ff17
Format and move FileDownloadsTable.tsx to files
brian-kim31 67f17fb
Update Documentation
brian-kim31 cdd8229
Update Dialog text to use efault foreground color
brian-kim31 16686a0
Fix Delete Dialog
brian-kim31 924432e
Completed delete mapping rules feature
brian-kim31 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
app/api/files/migrations/0002_add_deleted_at_to_filedownload.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Generated by Django 5.2.1 on 2025-10-08 16:13 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("files", "0001_initial"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="filedownload", | ||
| name="deleted_at", | ||
| field=models.DateTimeField(blank=True, null=True), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name="filedownload", | ||
| name="id", | ||
| field=models.BigAutoField( | ||
| auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
| ), | ||
| ), | ||
| migrations.AlterField( | ||
| model_name="filetype", | ||
| name="id", | ||
| field=models.BigAutoField( | ||
| auto_created=True, primary_key=True, serialize=False, verbose_name="ID" | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| "use client"; | ||
|
|
||
| import { | ||
| Dialog, | ||
| DialogClose, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| DialogTrigger | ||
| } from "../ui/dialog"; | ||
| import { toast } from "sonner"; | ||
| import { Button } from "../ui/button"; | ||
| import { deleteFile } from "@/api/files"; | ||
| import { useRouter } from "next/navigation"; | ||
| import { Trash2 } from "lucide-react"; | ||
|
|
||
| interface DeleteFileDialogProps { | ||
| fileId: number; | ||
| scanReportId: number; | ||
| fileName: string; | ||
| isOpen?: boolean; | ||
| setOpen?: (isOpen: boolean) => void; | ||
| needTrigger?: boolean; | ||
| } | ||
|
|
||
| const DeleteFileDialog = ({ | ||
| fileId, | ||
| scanReportId, | ||
| fileName, | ||
| isOpen, | ||
| setOpen = () => {}, | ||
| needTrigger = false | ||
| }: DeleteFileDialogProps) => { | ||
| const router = useRouter(); | ||
|
|
||
| const handleDelete = async () => { | ||
| const response = await deleteFile(scanReportId, fileId); | ||
| if (response.success) { | ||
| toast.success(`File "${fileName}" deleted successfully`); | ||
| router.refresh(); | ||
| } else { | ||
| toast.error( | ||
| `Failed to delete file: ${response.errorMessage || "Unknown error"}` | ||
| ); | ||
| } | ||
| setOpen(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog open={isOpen} onOpenChange={() => setOpen(false)}> | ||
| {needTrigger && ( | ||
| <DialogTrigger asChild> | ||
| <Button variant="destructive" size="sm"> | ||
| <Trash2 className="h-4 w-4" /> | ||
| </Button> | ||
| </DialogTrigger> | ||
| )} | ||
| <DialogContent> | ||
| <DialogHeader className="text-start"> | ||
| <DialogTitle>Delete File</DialogTitle> | ||
| <DialogDescription> | ||
|
AndrewThien marked this conversation as resolved.
Outdated
|
||
| Are you sure you want to delete "{fileName}"? This action cannot be | ||
| undone and will permanently remove the file from storage. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| <DialogFooter className="flex-col space-y-2 sm:space-y-0 sm:space-x-2"> | ||
| <Button variant="destructive" onClick={handleDelete}> | ||
| Delete | ||
| </Button> | ||
| <DialogClose asChild> | ||
| <Button variant="outline">Cancel</Button> | ||
| </DialogClose> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| }; | ||
|
|
||
| export default DeleteFileDialog; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.