Skip to content

Commit

Permalink
feat(web): link data portal from app
Browse files Browse the repository at this point in the history
  • Loading branch information
tonypls committed Jan 8, 2025
1 parent 0a29884 commit c875228
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
36 changes: 36 additions & 0 deletions web/src/components/buttons/DownloadCsv.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Button
href={url}
icon={<Download size={DEFAULT_ICON_SIZE} />}
type="tertiary"
size="md"
aria-label="Download CSV Data"
/>
);
}

export default DownloadCsv;
2 changes: 2 additions & 0 deletions web/src/features/panels/zone/ZoneHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DownloadCsv } from 'components/buttons/DownloadCsv';
import { MoreOptionsDropdown, useShowMoreOptions } from 'components/MoreOptionsDropdown';
import { TimeDisplay } from 'components/TimeDisplay';
import { useFeatureFlag } from 'features/feature-flags/api';
Expand Down Expand Up @@ -45,6 +46,7 @@ export default function ZoneHeader({ zoneId, isEstimated }: ZoneHeaderTitleProps
<ZoneHeaderTitle zoneId={zoneId} zoneNameFull={zoneNameFull} />
<TimeDisplay className="whitespace-nowrap text-sm" />
</div>
<DownloadCsv />
{isShareButtonEnabled &&
isConsumption &&
(showMoreOptions ? (
Expand Down

0 comments on commit c875228

Please sign in to comment.