-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added download file button * added download file button * prettier * fix
- Loading branch information
Showing
16 changed files
with
667 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
frontend/src/components/jobs/result/visualizer/elements/download.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React from "react"; | ||
import { Button } from "reactstrap"; | ||
import PropTypes from "prop-types"; | ||
import { FaFileDownload } from "react-icons/fa"; | ||
import { fileDownload, humanReadbleSize } from "../../../../../utils/files"; | ||
import { VisualizerTooltip } from "../VisualizerTooltip"; | ||
|
||
export function DownloadVisualizer({ | ||
size, | ||
alignment, | ||
disable, | ||
id, | ||
value, | ||
mimetype, | ||
payload, | ||
isChild, | ||
copyText, | ||
description, | ||
addMetadataInDescription, | ||
link, | ||
}) { | ||
const blobFile = new Blob([payload], { type: mimetype }); | ||
let finalDescription = description; | ||
if (addMetadataInDescription) { | ||
finalDescription += `\n\n**Mimetype**: ${mimetype}. **Size**: ${humanReadbleSize( | ||
blobFile.size, | ||
)}`; | ||
} | ||
|
||
return ( | ||
<> | ||
<div | ||
className={`${size} ${ | ||
isChild ? "small" : "" | ||
} p-0 m-1 d-flex align-items-center text-${alignment} justify-content-${alignment} ${ | ||
disable ? "opacity-25" : "" | ||
}`} | ||
id={id} | ||
> | ||
<Button | ||
onClick={() => { | ||
const blob = blobFile; | ||
if (!blob) return; | ||
fileDownload(blob, value); | ||
}} | ||
id={`${id}-tooltip`} | ||
disabled={disable} | ||
> | ||
<FaFileDownload /> | ||
<span className={`${isChild ? "small" : ""}`}>{value}</span> | ||
</Button> | ||
</div> | ||
<VisualizerTooltip | ||
idElement={`${id}-tooltip`} | ||
copyText={copyText} | ||
link={link} | ||
disable={disable} | ||
description={finalDescription} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
DownloadVisualizer.propTypes = { | ||
size: PropTypes.string.isRequired, | ||
alignment: PropTypes.string, | ||
disable: PropTypes.bool, | ||
id: PropTypes.string.isRequired, | ||
value: PropTypes.string.isRequired, | ||
mimetype: PropTypes.string.isRequired, | ||
payload: PropTypes.string.isRequired, | ||
isChild: PropTypes.bool, | ||
copyText: PropTypes.string, | ||
description: PropTypes.string, | ||
addMetadataInDescription: PropTypes.bool, | ||
link: PropTypes.string, | ||
}; | ||
|
||
DownloadVisualizer.defaultProps = { | ||
alignment: "center", | ||
disable: false, | ||
isChild: false, | ||
copyText: "", | ||
description: "", | ||
addMetadataInDescription: true, | ||
link: "", | ||
}; |
Oops, something went wrong.