Skip to content

Commit 89cf22c

Browse files
committed
Completed Removing Duplicate actions button #1076
1 parent a39f0fe commit 89cf22c

3 files changed

Lines changed: 49 additions & 65 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use client";
2+
3+
import { Button } from "@/components/ui/button";
4+
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
5+
import { FileJson, FileSpreadsheet } from "lucide-react";
6+
import { useRouter } from "next/navigation";
7+
import { toast } from "sonner";
8+
import { requestFile } from "@/api/files";
9+
10+
type Props = { scanreportId: string };
11+
12+
export function ActionsDownloadMenu({ scanreportId }: Props) {
13+
const router = useRouter();
14+
15+
const handleDownload = async (fileType: FileTypeFormat) => {
16+
const resp = await requestFile(Number(scanreportId), fileType);
17+
if (resp.success) {
18+
router.push(`downloads`);
19+
toast.success("File requested.");
20+
} else {
21+
toast.error(
22+
`Error downloading file: ${(resp.errorMessage as any).message}`
23+
);
24+
}
25+
};
26+
27+
return (
28+
<>
29+
<DropdownMenuItem onSelect={() => handleDownload("application/json")}>
30+
<FileJson className="mr-2 size-4" />
31+
Mapping JSON
32+
</DropdownMenuItem>
33+
<DropdownMenuItem onSelect={() => handleDownload("text/csv")}>
34+
<FileSpreadsheet className="mr-2 size-4" />
35+
Mapping CSV
36+
</DropdownMenuItem>
37+
</>
38+
);
39+
}

app/next-client-app/app/(protected)/scanreports/[id]/layout.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
DropdownMenu,
1010
DropdownMenuContent,
1111
DropdownMenuItem,
12-
DropdownMenuTrigger,
12+
DropdownMenuTrigger
1313
} from "@/components/ui/dropdown-menu";
1414
import { Suspense } from "react";
1515
import { Skeleton } from "@/components/ui/skeleton";
@@ -21,6 +21,7 @@ import { MappingStatus } from "@/components/scanreports/MappingStatus";
2121
import { StatusIcon } from "@/components/core/StatusIcon";
2222
import { UploadStatusOptions } from "@/constants/scanReportStatus";
2323
import ExportScanReport from "@/components/scanreports/ExportScanReport";
24+
import { ActionsDownloadMenu } from "./actions-download-menu";
2425

2526
export default async function ScanReportLayout(
2627
props: Readonly<{
@@ -41,11 +42,11 @@ export default async function ScanReportLayout(
4142
const items = [
4243
{
4344
name: "Tables",
44-
iconName: "TableProperties",
45+
iconName: "TableProperties"
4546
},
4647
{ name: "Rules", slug: "mapping_rules", iconName: "Waypoints" },
4748
{ name: "Review Rules", slug: "review_rules", iconName: "SearchCheck" },
48-
{ name: "Downloads", slug: "downloads", iconName: "Download" },
49+
{ name: "Downloads", slug: "downloads", iconName: "Download" }
4950
];
5051

5152
{
@@ -55,7 +56,7 @@ export default async function ScanReportLayout(
5556
items.push({
5657
name: "Edit Details",
5758
slug: "details",
58-
iconName: "Edit",
59+
iconName: "Edit"
5960
});
6061
}
6162

@@ -138,8 +139,8 @@ export default async function ScanReportLayout(
138139
...items.map((x) => ({
139140
text: x.name,
140141
slug: x.slug,
141-
iconName: x.iconName,
142-
})),
142+
iconName: x.iconName
143+
}))
143144
]}
144145
/>
145146
</div>
@@ -158,6 +159,7 @@ export default async function ScanReportLayout(
158159
scanReportName={scanreport.dataset}
159160
/>
160161
<DeleteDialog id={Number(params.id)} redirect needTrigger />
162+
<ActionsDownloadMenu scanreportId={params.id} />
161163
</DropdownMenuContent>
162164
</DropdownMenu>
163165
</div>

app/next-client-app/app/(protected)/scanreports/[id]/mapping_rules/rules-buttons.tsx

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,9 @@
22

33
import { Button } from "@/components/ui/button";
44
import { Dialog, DialogContent, DialogTrigger } from "@/components/ui/dialog";
5-
import {
6-
BarChartHorizontalBig,
7-
ChevronDown,
8-
FileJson,
9-
FileSpreadsheet,
10-
} from "lucide-react";
5+
import { BarChartHorizontalBig } from "lucide-react";
116
import { ScrollArea } from "@/components/ui/scroll-area";
127
import { GetFile } from "@/app/(protected)/scanreports/[id]/mapping_rules/get-file";
13-
import {
14-
DropdownMenu,
15-
DropdownMenuContent,
16-
DropdownMenuItem,
17-
DropdownMenuTrigger,
18-
} from "@/components/ui/dropdown-menu";
19-
import { requestFile } from "@/api/files";
20-
import { toast } from "sonner";
21-
import { useRouter } from "next/navigation";
228

239
export function RulesButton({
2410
scanreportId,
@@ -29,19 +15,7 @@ export function RulesButton({
2915
query: string;
3016
filename: string;
3117
}) {
32-
const router = useRouter();
33-
34-
const handleDownload = async (fileType: FileTypeFormat) => {
35-
const resp = await requestFile(Number(scanreportId), fileType);
36-
if (resp.success) {
37-
router.push(`downloads`);
38-
toast.success("File requested.");
39-
} else {
40-
toast.error(
41-
`Error downloading file: ${(resp.errorMessage as any).message}`
42-
);
43-
}
44-
};
18+
4519
return (
4620
<div className="hidden md:flex gap-2 justify-end w-full mr-2">
4721
<div>
@@ -66,37 +40,6 @@ export function RulesButton({
6640
</DialogContent>
6741
</Dialog>
6842
</div>
69-
<div>
70-
<DropdownMenu>
71-
<DropdownMenuTrigger asChild>
72-
<Button variant="outline">
73-
Request Download <ChevronDown className="ml-2 size-4" />
74-
</Button>
75-
</DropdownMenuTrigger>
76-
<DropdownMenuContent className="w-[180px]">
77-
<DropdownMenuItem>
78-
<Button
79-
onClick={() => handleDownload("application/json")}
80-
variant={"ghost"}
81-
size={"sm"}
82-
>
83-
Mapping JSON
84-
<FileJson className="ml-2 size-4" />
85-
</Button>
86-
</DropdownMenuItem>
87-
<DropdownMenuItem>
88-
<Button
89-
onClick={() => handleDownload("text/csv")}
90-
variant={"ghost"}
91-
size={"sm"}
92-
>
93-
Mapping CSV
94-
<FileSpreadsheet className="ml-2 size-4" />
95-
</Button>
96-
</DropdownMenuItem>
97-
</DropdownMenuContent>
98-
</DropdownMenu>
99-
</div>
10043
</div>
10144
);
10245
}

0 commit comments

Comments
 (0)