-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathActivityExecutionErrorReportModal.tsx
More file actions
72 lines (68 loc) · 2.56 KB
/
ActivityExecutionErrorReportModal.tsx
File metadata and controls
72 lines (68 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, { useState } from "react";
import { Button, HtmlContentBlock, IconButton, SimpleDialog } from "../../index";
interface ActivityExecutionErrorReportModalProps {
// Title of the modal
title?: string;
// Called when the close button is clicked
onDiscard: () => any;
// The error report
report: React.JSX.Element;
// Value of the download button
downloadButtonValue: string;
// Value of the close button
closeButtonValue: string;
// Function that fetches the Markdown error report
fetchErrorReport: () => Promise<string | undefined>;
}
/** Shows the execution error report to the user and offers to download the report. */
export const ActivityExecutionErrorReportModal = ({
title,
onDiscard,
report,
downloadButtonValue,
closeButtonValue,
fetchErrorReport,
}: ActivityExecutionErrorReportModalProps) => {
const [displayFullscreen, setDisplayFullscreen] = useState<boolean>(false);
const fileName =
"Activity execution report from " +
new Date().toISOString().replace(/T/, " ").replace(/:/g, "-").substr(0, 19) +
".md";
const handleDownload = async () => {
const markdown = await fetchErrorReport();
if (markdown) {
const element = document.createElement("a");
element.href = window.URL.createObjectURL(new Blob([markdown], { type: "text/markdown" }));
element.download = fileName;
//the above code is equivalent to
document.body.appendChild(element);
//onClick property
element.click();
document.body.removeChild(element);
}
};
return (
<SimpleDialog
title={title}
isOpen={true}
size={displayFullscreen ? "fullscreen" : "large"}
onClose={onDiscard}
headerOptions={
<IconButton
name={displayFullscreen ? "toggler-minimize" : "toggler-maximize"}
onClick={() => setDisplayFullscreen(!displayFullscreen)}
/>
}
actions={[
<Button data-test-id={"error-report-download-btn"} affirmative onClick={handleDownload} key="download">
{downloadButtonValue}
</Button>,
<Button data-test-id={"error-report-close-btn"} key="close" onClick={onDiscard}>
{closeButtonValue}
</Button>,
]}
>
<HtmlContentBlock noScrollbarsOnChildren>{report}</HtmlContentBlock>
</SimpleDialog>
);
};