Skip to content

Commit

Permalink
Add app name to download file name
Browse files Browse the repository at this point in the history
Signed-off-by: ibolton336 <[email protected]>
  • Loading branch information
ibolton336 committed Sep 27, 2023
1 parent a7cb60c commit 033af7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const ApplicationDetailDrawerAnalysis: React.FC<
position="top"
>
<DownloadButton
id={application.id}
application={application}
mimeType={MimeType.TAR}
/>
</Tooltip>
Expand All @@ -149,7 +149,7 @@ export const ApplicationDetailDrawerAnalysis: React.FC<
position="top"
>
<DownloadButton
id={application.id}
application={application}
mimeType={MimeType.YAML}
/>
</Tooltip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import { Alert, Button } from "@patternfly/react-core";
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";
import { Spinner } from "@patternfly/react-core";
import { useDownloadStaticReport } from "@app/queries/applications";
import { Application } from "@app/api/models";

export enum MimeType {
TAR = "tar",
YAML = "yaml",
}
interface IDownloadButtonProps {
id: number;
application: Application;
mimeType: MimeType;
}
export const DownloadButton: React.FC<IDownloadButtonProps> = ({
id,
application,
mimeType,
}) => {
const {
Expand All @@ -24,7 +25,7 @@ export const DownloadButton: React.FC<IDownloadButtonProps> = ({

const handleDownload = () => {
downloadFile({
applicationId: id,
application: application,
mimeType: mimeType,
});
};
Expand Down
14 changes: 7 additions & 7 deletions client/src/app/queries/applications.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import axios, { AxiosError } from "axios";

import { MimeType } from "@app/api/models";
import { Application, MimeType } from "@app/api/models";
import {
APPLICATIONS,
createApplication,
Expand All @@ -21,7 +21,7 @@ export const ApplicationsQueryKey = "applications";
export const ReportQueryKey = "report";

interface DownloadOptions {
applicationId: number;
application: Application;
mimeType: MimeType;
}

Expand Down Expand Up @@ -141,19 +141,19 @@ export const useBulkDeleteApplicationMutation = (
};

export const downloadStaticReport = async ({
applicationId,
application,
mimeType,
}: DownloadOptions): Promise<void> => {
const yamlAcceptHeader = "application/x-yaml";
let url = `${APPLICATIONS}/${applicationId}/analysis/report`;
let url = `${APPLICATIONS}/${application.id}/analysis/report`;

Check warning on line 148 in client/src/app/queries/applications.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/queries/applications.ts#L146-L148

Added lines #L146 - L148 were not covered by tests

switch (mimeType) {
case MimeType.YAML:
url = `${APPLICATIONS}/${applicationId}/analysis`;
url = `${APPLICATIONS}/${application.id}/analysis`;
break;
case MimeType.TAR:
default:
url = `${APPLICATIONS}/${applicationId}/analysis/report`;
url = `${APPLICATIONS}/${application.id}/analysis/report`;

Check warning on line 156 in client/src/app/queries/applications.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/queries/applications.ts#L151-L156

Added lines #L151 - L156 were not covered by tests
}

try {
Expand All @@ -171,7 +171,7 @@ export const downloadStaticReport = async ({
}

const blob = new Blob([response.data]);
saveAs(blob, `analysis-report-app-${applicationId}.${mimeType}`);
saveAs(blob, `analysis-report-app-${application.name}.${mimeType}`);

Check warning on line 174 in client/src/app/queries/applications.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/queries/applications.ts#L173-L174

Added lines #L173 - L174 were not covered by tests
} catch (error) {
console.error("There was an error downloading the file:", error);
throw error;

Check warning on line 177 in client/src/app/queries/applications.ts

View check run for this annotation

Codecov / codecov/patch

client/src/app/queries/applications.ts#L176-L177

Added lines #L176 - L177 were not covered by tests
Expand Down

0 comments on commit 033af7e

Please sign in to comment.