Skip to content

Commit 0a562cb

Browse files
sjd78sshveta
authored andcommitted
🐛 Fix some applications query issues (konveyor#2606)
Resolves some issues noticed while updating the application form: - `useDeleteApplicationMutation()` was not sending the correct application id to `onSuccess()` - `downloadStaticReport()` was not testing for mime type properly when setting the accept headers for yaml types - `DownloadButton` changed: - Using `mutateAsync` instead of `mutate` - Use `isPending` instead of `isLoading` as per the deprecation comment Signed-off-by: Scott J Dickerson <[email protected]>
1 parent 2e87799 commit 0a562cb

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

client/src/app/pages/applications/application-detail-drawer/components/download-button.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import React from "react";
22
import { Button } from "@patternfly/react-core";
3+
import { Alert, Spinner } from "@patternfly/react-core";
34
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";
4-
import { useDownloadStaticReport } from "@app/queries/applications";
5-
import { Application } from "@app/api/models";
6-
import { Spinner, Alert } from "@patternfly/react-core";
75

8-
import { MimeType } from "@app/api/models";
6+
import { Application, MimeType } from "@app/api/models";
7+
import { useDownloadStaticReport } from "@app/queries/applications";
98

109
interface IDownloadButtonProps {
1110
application: Application;
@@ -20,8 +19,8 @@ export const DownloadButton: React.FC<IDownloadButtonProps> = ({
2019
isDownloadEnabled,
2120
}) => {
2221
const {
23-
mutate: downloadFile,
24-
isLoading,
22+
mutateAsync: downloadFile,
23+
isPending,
2524
isError,
2625
} = useDownloadStaticReport();
2726

@@ -34,7 +33,7 @@ export const DownloadButton: React.FC<IDownloadButtonProps> = ({
3433

3534
return (
3635
<>
37-
{isLoading ? (
36+
{isPending ? (
3837
<Spinner size="sm" />
3938
) : isError ? (
4039
<Alert variant="warning" isInline title={"Error downloading report"}>

client/src/app/queries/applications.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "@app/api/models";
1212
import {
1313
APPLICATIONS,
14+
HEADERS,
1415
createApplication,
1516
createApplicationDependency,
1617
deleteApplication,
@@ -207,9 +208,9 @@ export const useDeleteApplicationMutation = (
207208
const queryClient = useQueryClient();
208209
return useMutation({
209210
mutationFn: ({ id }: { id: number }) => deleteApplication(id),
210-
onSuccess: (_res) => {
211+
onSuccess: (_res, vars) => {
211212
queryClient.invalidateQueries({ queryKey: [ApplicationsQueryKey] });
212-
onSuccess(1);
213+
onSuccess(vars.id);
213214
},
214215
onError: onError,
215216
});
@@ -230,11 +231,10 @@ export const useBulkDeleteApplicationMutation = (
230231
});
231232
};
232233

233-
export const downloadStaticReport = async ({
234+
const downloadStaticReport = async ({
234235
application,
235236
mimeType,
236237
}: DownloadOptions): Promise<void> => {
237-
const yamlAcceptHeader = "application/x-yaml";
238238
let url = `${APPLICATIONS}/${application.id}/analysis/report`;
239239

240240
switch (mimeType) {
@@ -249,11 +249,7 @@ export const downloadStaticReport = async ({
249249
try {
250250
const response = await axios.get(url, {
251251
responseType: "blob",
252-
...(MimeType.YAML && {
253-
headers: {
254-
Accept: yamlAcceptHeader,
255-
},
256-
}),
252+
...(mimeType === MimeType.YAML && { headers: HEADERS.yaml }),
257253
});
258254

259255
if (response.status !== 200) {

0 commit comments

Comments
 (0)