From 47b21ed2af3c9829c41ddaf8c5f050178150a8b7 Mon Sep 17 00:00:00 2001 From: tonypls Date: Wed, 8 Jan 2025 18:12:05 +1300 Subject: [PATCH 1/3] feat(web): link data portal from app --- web/src/components/buttons/DownloadCsv.tsx | 36 +++++++++++++++++++++ web/src/features/panels/zone/ZoneHeader.tsx | 2 ++ 2 files changed, 38 insertions(+) create mode 100644 web/src/components/buttons/DownloadCsv.tsx diff --git a/web/src/components/buttons/DownloadCsv.tsx b/web/src/components/buttons/DownloadCsv.tsx new file mode 100644 index 0000000000..af1be77d18 --- /dev/null +++ b/web/src/components/buttons/DownloadCsv.tsx @@ -0,0 +1,36 @@ +import { Button } from 'components/Button'; +import { Download } from 'lucide-react'; +import { useParams } from 'react-router-dom'; +import { DEFAULT_ICON_SIZE } from 'utils/constants'; + +import { getCountryName, getZoneName } from '../../translation/translation'; + +function getCountryToDownload(zoneId?: string) { + if (!zoneId) { + return ''; + } + + const zoneName = getZoneName(zoneId); + const zoneCountryName = + zoneId && zoneId.includes('-') && getCountryName(zoneId)?.toLowerCase(); + return zoneCountryName || zoneName; +} + +export function DownloadCsv() { + const { zoneId } = useParams(); + const countryToDownload = getCountryToDownload(zoneId); + + const url = `https://www.electricitymaps.com/data-portal/${countryToDownload.toLowerCase()}?utm_source=app&utm_medium=download_button&utm_campaign=csv_download`; + + return ( +