-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support downloading artifacts in the new emui (#1720)
## Description: This PR adds support for downloading artifacts as TGZ's from the new emui. Additionally this PR: * updates the copy on the files table to File Artifacts * Makes files non clickable * Fixing the scrolling behaviour over monaco editors. ## Is this change user facing? YES --------- Co-authored-by: Anders Schwartz <adschwartz@users.noreply.github.com> Co-authored-by: Anders Schwartz <anders.schwartz@kurtosistech.com>
- Loading branch information
1 parent
3d1e142
commit fbfeaa3
Showing
31 changed files
with
374 additions
and
233 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,55 @@ | ||
import { Button, ButtonProps } from "@chakra-ui/react"; | ||
import { Button, ButtonProps, IconButton, IconButtonProps } from "@chakra-ui/react"; | ||
import { FiDownload } from "react-icons/fi"; | ||
import { isDefined } from "../utils"; | ||
import { saveTextAsFile } from "../utils/download"; | ||
|
||
type DownloadButtonProps = ButtonProps & { | ||
type DownloadButtonProps<IsIconButton extends boolean> = (IsIconButton extends true ? IconButtonProps : ButtonProps) & { | ||
valueToDownload?: (() => string) | string | null; | ||
fileName: string; | ||
text?: string; | ||
text?: IsIconButton extends true ? string : never; | ||
isIconButton?: IsIconButton; | ||
}; | ||
|
||
export const DownloadButton = ({ valueToDownload, text, fileName, ...buttonProps }: DownloadButtonProps) => { | ||
export const DownloadButton = <IsIconButton extends boolean>({ | ||
valueToDownload, | ||
text, | ||
fileName, | ||
isIconButton, | ||
...buttonProps | ||
}: DownloadButtonProps<IsIconButton>) => { | ||
const handleDownloadClick = () => { | ||
if (isDefined(valueToDownload)) { | ||
const v = typeof valueToDownload === "string" ? valueToDownload : valueToDownload(); | ||
saveTextAsFile(v, fileName); | ||
} | ||
}; | ||
|
||
if (!isDefined(valueToDownload)) { | ||
if (!isDefined(valueToDownload) && !isDefined(buttonProps.onClick)) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Button | ||
leftIcon={<FiDownload />} | ||
size={"xs"} | ||
colorScheme={"darkBlue"} | ||
onClick={handleDownloadClick} | ||
{...buttonProps} | ||
> | ||
{text || "Download"} | ||
</Button> | ||
); | ||
if (isIconButton) { | ||
return ( | ||
<IconButton | ||
icon={<FiDownload />} | ||
size={"xs"} | ||
variant={"ghost"} | ||
colorScheme={"darkBlue"} | ||
onClick={handleDownloadClick} | ||
{...(buttonProps as IconButtonProps)} | ||
/> | ||
); | ||
} else { | ||
return ( | ||
<Button | ||
leftIcon={<FiDownload />} | ||
size={"xs"} | ||
colorScheme={"darkBlue"} | ||
onClick={handleDownloadClick} | ||
{...buttonProps} | ||
> | ||
{text || "Download"} | ||
</Button> | ||
); | ||
} | ||
}; |
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
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
Oops, something went wrong.