-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(client): Isolate dataset card buttons
- Loading branch information
1 parent
ddabe47
commit 679183b
Showing
5 changed files
with
222 additions
and
157 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
48 changes: 48 additions & 0 deletions
48
client/src/components/dataset-card/download-chart-button.tsx
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,48 @@ | ||
import { useCallback } from "react"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; | ||
import GraphIcon from "@/svgs/graph.svg"; | ||
|
||
interface DownloadChartButtonProps { | ||
data: unknown; | ||
fileName: string; | ||
disabled: boolean; | ||
} | ||
|
||
const DownloadChartButton = ({ data, fileName, disabled }: DownloadChartButtonProps) => { | ||
const onClickSaveChartData = useCallback(() => { | ||
const blob = new Blob([JSON.stringify(data)], { type: "application/json" }); | ||
|
||
const link = document.createElement("a"); | ||
link.download = fileName; | ||
link.href = URL.createObjectURL(blob); | ||
link.click(); | ||
link.remove(); | ||
}, [data, fileName]); | ||
|
||
return ( | ||
<TooltipProvider> | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<Button | ||
variant="ghost" | ||
size="icon-sm" | ||
className="group/chart" | ||
disabled={disabled} | ||
onClick={onClickSaveChartData} | ||
> | ||
<span className="sr-only">Save chart data</span> | ||
<GraphIcon | ||
className="!size-4 transition-colors group-hover/chart:text-casper-blue-300" | ||
aria-hidden | ||
/> | ||
</Button> | ||
</TooltipTrigger> | ||
<TooltipContent>Save chart data</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
); | ||
}; | ||
|
||
export default DownloadChartButton; |
33 changes: 33 additions & 0 deletions
33
client/src/components/dataset-card/download-layer-button.tsx
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,33 @@ | ||
import Link from "next/link"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; | ||
import DownloadIcon from "@/svgs/download.svg"; | ||
|
||
interface DownloadLayerButtonProps { | ||
link: string; | ||
fileName: string; | ||
} | ||
|
||
const DownloadLayerButton = ({ link, fileName }: DownloadLayerButtonProps) => { | ||
return ( | ||
<TooltipProvider> | ||
<Tooltip> | ||
<TooltipTrigger asChild> | ||
<Button variant="ghost" size="icon-sm" className="group/download" asChild> | ||
<Link href={link} rel="noopener noreferrer" download={fileName}> | ||
<span className="sr-only">Download</span> | ||
<DownloadIcon | ||
className="!size-4 transition-colors group-hover/download:text-casper-blue-300" | ||
aria-hidden | ||
/> | ||
</Link> | ||
</Button> | ||
</TooltipTrigger> | ||
<TooltipContent>Download dataset</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
); | ||
}; | ||
|
||
export default DownloadLayerButton; |
Oops, something went wrong.