Skip to content

Commit

Permalink
feat(web): better search with full zone name (#7318)
Browse files Browse the repository at this point in the history
* feat(web): better search with full zone name

* feat(web): empty state and leave according at bottom on search
  • Loading branch information
tonypls authored Oct 14, 2024
1 parent 8289815 commit 5e480d5
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 16 deletions.
37 changes: 23 additions & 14 deletions web/src/features/panels/ranking-panel/RankingPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useAtomValue } from 'jotai';
import { ReactElement, useCallback, useState } from 'react';
import { Helmet } from 'react-helmet-async';
import { useTranslation } from 'react-i18next';
import { metaTitleSuffix, Mode } from 'utils/constants';
import { metaTitleSuffix } from 'utils/constants';
import {
isConsumptionAtom,
selectedDatetimeStringAtom,
Expand Down Expand Up @@ -50,28 +50,37 @@ export default function RankingPanel(): ReactElement {
(zone) =>
zone.countryName?.toLowerCase().includes(searchTerm) ||
zone.zoneName?.toLowerCase().includes(searchTerm) ||
zone.zoneId.toLowerCase().includes(searchTerm)
zone.zoneId.toLowerCase().includes(searchTerm) ||
zone.fullZoneName?.toLowerCase().includes(searchTerm)
);

return (
<div className="flex max-h-[calc(100vh-236px)] flex-col py-3 pl-4 pr-1 ">
<div className="flex h-[calc(100vh-236px)] w-full flex-col py-3 pl-4 pr-1">
<Helmet prioritizeSeoTags>
<title>{t('misc.maintitle') + metaTitleSuffix}</title>
<link rel="canonical" href={canonicalUrl} />
</Helmet>
<div className="pb-5">
<h1>{t('ranking-panel.title')}</h1>
<h2 className="text-sm">{t('ranking-panel.subtitle')}</h2>

<div className="flex flex-grow flex-col overflow-hidden ">
<div className="pb-5">
<h1>{t('ranking-panel.title')}</h1>
<h2 className="text-sm">{t('ranking-panel.subtitle')}</h2>
</div>

<SearchBar
placeholder={t('ranking-panel.search')}
searchHandler={inputHandler}
value={searchTerm}
/>

<div className="flex-grow overflow-y-auto">
{filteredList.length === 0 && <div>{t('ranking-panel.no-results')}</div>}
<VirtualizedZoneList data={filteredList} />
{/* TODO: Revise the margin here once the scrollbars are fixed */}
</div>
</div>

<SearchBar
placeholder={t('ranking-panel.search')}
searchHandler={inputHandler}
value={searchTerm}
/>
<VirtualizedZoneList data={filteredList} />
{/* TODO: Revise the margin here once the scrollbars are fixed */}
<div className="my-2 pr-3">
<div className="mt-auto py-2 pr-3">
<RankingPanelAccordion />
<HorizontalDivider />
<SocialIconRow />
Expand Down
1 change: 1 addition & 0 deletions web/src/features/panels/ranking-panel/ZoneList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ZoneRowType {
co2intensity?: number | null;
countryName?: string;
zoneName?: string;
fullZoneName?: string;
}

function ZoneRow({ zoneId, color, ranking, countryName, zoneName }: ZoneRowType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports[`getRankedState > sorts the zones by carbon intensity in ascending order
"co2intensity": 5,
"color": "color",
"countryName": "",
"fullZoneName": "",
"ranking": 1,
"zoneId": "zone2",
"zoneName": "",
Expand All @@ -14,6 +15,7 @@ exports[`getRankedState > sorts the zones by carbon intensity in ascending order
"co2intensity": 10,
"color": "color",
"countryName": "",
"fullZoneName": "",
"ranking": 2,
"zoneId": "zone1",
"zoneName": "",
Expand All @@ -22,6 +24,7 @@ exports[`getRankedState > sorts the zones by carbon intensity in ascending order
"co2intensity": 15,
"color": "color",
"countryName": "",
"fullZoneName": "",
"ranking": 3,
"zoneId": "zone4",
"zoneName": "",
Expand All @@ -30,6 +33,7 @@ exports[`getRankedState > sorts the zones by carbon intensity in ascending order
"co2intensity": 25,
"color": "color",
"countryName": "",
"fullZoneName": "",
"ranking": 4,
"zoneId": "zone6",
"zoneName": "",
Expand All @@ -38,6 +42,7 @@ exports[`getRankedState > sorts the zones by carbon intensity in ascending order
"co2intensity": 25,
"color": "color",
"countryName": "",
"fullZoneName": "",
"ranking": 5,
"zoneId": "zone8",
"zoneName": "",
Expand All @@ -51,6 +56,7 @@ exports[`getRankedState > sorts the zones by carbon intensity in descending orde
"co2intensity": 25,
"color": "color",
"countryName": "",
"fullZoneName": "",
"ranking": 1,
"zoneId": "zone6",
"zoneName": "",
Expand All @@ -59,6 +65,7 @@ exports[`getRankedState > sorts the zones by carbon intensity in descending orde
"co2intensity": 25,
"color": "color",
"countryName": "",
"fullZoneName": "",
"ranking": 2,
"zoneId": "zone8",
"zoneName": "",
Expand All @@ -67,6 +74,7 @@ exports[`getRankedState > sorts the zones by carbon intensity in descending orde
"co2intensity": 15,
"color": "color",
"countryName": "",
"fullZoneName": "",
"ranking": 3,
"zoneId": "zone4",
"zoneName": "",
Expand All @@ -75,6 +83,7 @@ exports[`getRankedState > sorts the zones by carbon intensity in descending orde
"co2intensity": 10,
"color": "color",
"countryName": "",
"fullZoneName": "",
"ranking": 4,
"zoneId": "zone1",
"zoneName": "",
Expand All @@ -83,6 +92,7 @@ exports[`getRankedState > sorts the zones by carbon intensity in descending orde
"co2intensity": 5,
"color": "color",
"countryName": "",
"fullZoneName": "",
"ranking": 5,
"zoneId": "zone2",
"zoneName": "",
Expand Down
3 changes: 2 additions & 1 deletion web/src/features/panels/ranking-panel/getRankingPanelData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCountryName, getZoneName } from 'translation/translation';
import { getCountryName, getFullZoneName, getZoneName } from 'translation/translation';
import type { GridState, StateZoneData, ZoneKey } from 'types';
import { SpatialAggregate } from 'utils/constants';
import { getCarbonIntensity } from 'utils/helpers';
Expand Down Expand Up @@ -76,6 +76,7 @@ export const getRankedState = (
co2intensity,
countryName: getCountryName(key),
zoneName: getZoneName(key),
fullZoneName: getFullZoneName(key),
ranking: ranking,
});
ranking++; // Increment the ranking for the next zone.
Expand Down
3 changes: 2 additions & 1 deletion web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"ranking-panel": {
"title": "Climate Impact by Area",
"subtitle": "Ranked by carbon intensity of electricity consumed (gCO₂eq/kWh)",
"search": "Search areas"
"search": "Search areas",
"no-results": "No results found for this search 🌍"
},
"button": {
"reddit": "Join r/electricitymaps",
Expand Down

0 comments on commit 5e480d5

Please sign in to comment.