Skip to content
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

🪟 🎉 Show error notification when download logs request fails #15655

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useIntl } from "react-intl";
import { Button } from "components";

import { JobDebugInfoRead } from "core/request/AirbyteClient";
import { downloadFile } from "utils/file";

interface DownloadButtonProps {
jobDebugInfo: JobDebugInfoRead;
Expand All @@ -16,15 +17,10 @@ const DownloadButton: React.FC<DownloadButtonProps> = ({ jobDebugInfo, fileName
const { formatMessage } = useIntl();

const downloadFileWithLogs = () => {
const element = document.createElement("a");
const file = new Blob([jobDebugInfo.attempts.flatMap((info) => info.logs.logLines).join("\n")], {
type: "text/plain;charset=utf-8",
});
element.href = URL.createObjectURL(file);
element.download = `${fileName}.txt`;
document.body.appendChild(element); // Required for this to work in FireFox
element.click();
document.body.removeChild(element);
downloadFile(file, `${fileName}.txt`);
};

return (
Expand Down
1 change: 1 addition & 0 deletions airbyte-webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@
"admin.dropZoneTitle": "Drag 'n' drop file here, or click to select file",
"admin.dropZoneSubtitle": "Only *.tar and *.gz files will be accepted",
"admin.logs": "Logs",
"admin.logs.error": "Unable to download logs at this time.",
"admin.downloadServerLogs": "Download Server Logs",
"admin.downloadSchedulerLogs": "Download Scheduler Logs",
"admin.upgradeAll": "Upgrade all",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import React from "react";
import { FormattedMessage } from "react-intl";
import { FormattedMessage, useIntl } from "react-intl";
import { useAsyncFn } from "react-use";
import styled from "styled-components";

import { LoadingButton } from "components";

import { LogType } from "core/domain/logs/types";
import { useNotificationService } from "hooks/services/Notification";
import { useGetLogs } from "services/logs/LogsService";

import { LogType } from "../../../../../core/domain/logs/types";
import { downloadFile } from "utils/file";

const Content = styled.div`
padding: 29px 0 27px;
Expand All @@ -18,22 +19,26 @@ const LogsButton = styled(LoadingButton)`
margin: 0 15px;
`;

const downloadFile = (file: Blob, name: string) => {
const element = document.createElement("a");
element.href = URL.createObjectURL(file);
element.download = name;
document.body.appendChild(element); // Required for this to work in FireFox
element.click();
document.body.removeChild(element);
};

const LogsContent: React.FC = () => {
const { registerNotification } = useNotificationService();
const { formatMessage } = useIntl();

const fetchLogs = useGetLogs();

const downloadLogs = async (logType: LogType) => {
const file = await fetchLogs({ logType });
const name = `${logType}-logs.txt`;
downloadFile(file, name);
try {
const file = await fetchLogs({ logType });
const name = `${logType}-logs.txt`;
downloadFile(file, name);
} catch (e) {
console.error(e);

registerNotification({
id: "admin.logs.error",
title: formatMessage({ id: "admin.logs.error" }),
isError: true,
});
}
};

// TODO: get rid of useAsyncFn and use react-query
Expand Down
8 changes: 8 additions & 0 deletions airbyte-webapp/src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const downloadFile = (blob: Blob, name: string) => {
const element = document.createElement("a");
element.href = URL.createObjectURL(blob);
element.download = name;
document.body.appendChild(element); // Required for this to work in FireFox
element.click();
document.body.removeChild(element);
};