import React, { useState } from "react"; import Button from "../../components/Button/Button"; import SimpleDialog from "../../components/Dialog/SimpleDialog"; import IconButton from "../../components/Icon/IconButton"; import HtmlContentBlock from "../../components/Typography/HtmlContentBlock"; 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; } /** 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(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 ( setDisplayFullscreen(!displayFullscreen)} /> } actions={[ , , ]} > {report} ); };