Skip to content

Commit 6b4d367

Browse files
authored
Merge pull request #820 from l3montree-dev/feat/file-naming-for-downloads
feat: added assetNames to downloads of sbom and vex
2 parents 5b89a52 + 703f3ae commit 6b4d367

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/components/common/DelayedDownloadButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface DelayedDownloadButtonProps {
88
label: string;
99
className?: string;
1010
"data-testid"?: string;
11+
downloadFileName?: string;
1112
}
1213

1314
export function DelayedDownloadButton({
@@ -16,6 +17,7 @@ export function DelayedDownloadButton({
1617
label,
1718
className = "",
1819
"data-testid": dataTestId,
20+
downloadFileName,
1921
}: DelayedDownloadButtonProps) {
2022
const [loading, setLoading] = useState(false);
2123

@@ -29,7 +31,7 @@ export function DelayedDownloadButton({
2931
const parts = href.split("/");
3032
const filename = parts[parts.length - 1].split("?")[0];
3133

32-
link.download = filename;
34+
link.download = downloadFileName ?? filename;
3335
document.body.appendChild(link);
3436
link.click();
3537
document.body.removeChild(link);

src/components/dependencies/SbomDownloadModal.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export default function SbomDownloadModal({
6060
(artifacts ?? []).map((a) => a.artifactName),
6161
);
6262

63+
const jsonFileName = `${assetName}_sbom.json`
64+
const xmlFileName = `${assetName}_sbom.xml`
65+
6366
return (
6467
<Dialog open={showSBOMModal}>
6568
<DialogContent setOpen={setShowSBOMModal}>
@@ -116,6 +119,7 @@ export default function SbomDownloadModal({
116119
/>
117120
}
118121
label={"Download in JSON-Format"}
122+
downloadFileName={jsonFileName}
119123
/>
120124
<DelayedDownloadButton
121125
href={
@@ -126,6 +130,7 @@ export default function SbomDownloadModal({
126130
}
127131
icon={<FileCode className="h-5 w-auto inline-block text-success" />}
128132
label={"Download in XML-Format"}
133+
downloadFileName={xmlFileName}
129134
/>
130135
</div>
131136
<hr className="mt-6" />

src/components/dependencies/VexDownloadModal.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export default function VexDownloadModal({
6060
(artifacts ?? []).map((a) => a.artifactName),
6161
);
6262

63+
const jsonFileName = `${assetName}_vex.json`
64+
const xmlFileName = `${assetName}_vex.xml`
65+
6366
return (
6467
<Dialog open={showVexModal}>
6568
<DialogContent setOpen={setShowVexModal}>
@@ -123,6 +126,7 @@ export default function VexDownloadModal({
123126
/>
124127
}
125128
label={"Download in JSON-Format"}
129+
downloadFileName={jsonFileName}
126130
/>
127131
<DelayedDownloadButton
128132
href={
@@ -133,6 +137,7 @@ export default function VexDownloadModal({
133137
}
134138
icon={<FileCode className="h-5 w-auto inline-block text-success" />}
135139
label={"Download in XML-Format"}
140+
downloadFileName={xmlFileName}
136141
/>
137142
</div>
138143
<hr className="mt-6" />

0 commit comments

Comments
 (0)