Skip to content

Commit

Permalink
Zone Details: Header part 1 (#23)
Browse files Browse the repository at this point in the history
* add all the flags

* Add zoneFlag with hardcoded return

* Change leftpanel styling

* Add initial zoneHeader

* Works for countries

* Disable eslint
  • Loading branch information
Markus Killendahl authored Nov 10, 2022
1 parent 710437d commit 0485ce4
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 47 deletions.
42 changes: 42 additions & 0 deletions web/src/components/Flag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { resolvePath } from 'react-router-dom';

const DEFAULT_FLAG_SIZE = 48;

const getFlagFileName = (zoneId: string) => {
// Return (zonesConfig[zoneId.toUpperCase()] || {}).flag_file_name; TODO: enable when config setup
if (zoneId === 'DK-DK1') {
return 'dk.png';
}

if (zoneId === 'ES') {
return 'es.png';
}

return 'us.png';
};

const getFlagUri = function (zoneId: string, flagSize = DEFAULT_FLAG_SIZE) {
if (!zoneId) {
return;
}
const flagFile = getFlagFileName(zoneId);
return resolvePath(`flags_iso/${flagSize}/${flagFile}`).pathname;
};

export function CountryFlag({
zoneId,
flagSize = DEFAULT_FLAG_SIZE,
...props
}: {
zoneId: string;
flagSize?: number;
className?: string;
}) {
const flagUri = getFlagUri(zoneId, flagSize);

if (flagUri === undefined) {
return <div>No flag</div>;
}

return <img src={flagUri} alt={zoneId} {...props} />;
}
97 changes: 56 additions & 41 deletions web/src/features/panels/LeftPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ function OuterPanel({ children }: { children: React.ReactNode }) {

return (
<aside
className={`duration-400 absolute left-0 top-0 z-20 hidden h-full w-[calc(14vw_+_16rem)] bg-zinc-50 shadow-xl transition-all md:flex ${
className={`duration-400 absolute left-0 top-0 z-20 h-full w-full bg-zinc-50 shadow-xl transition-all md:flex md:w-[calc(14vw_+_16rem)] ${
isOpen && '-translate-x-full'
}`}
>
<section className="overflow-y-scroll p-2">{children}</section>
<section className="w-full overflow-y-scroll p-2">{children}</section>
<CollapseButton isCollapsed={isOpen} onCollapse={onCollapse} />
</aside>
);
Expand All @@ -55,45 +55,60 @@ export default function LeftPanel() {
path="/"
element={
<p className="bg-blue-200">
Ranking Panel Cillum aute occaecat in pariatur duis aliquip sint sunt excepteur Lorem. Incididunt quis id
sit consequat reprehenderit officia adipisicing ipsum. Esse anim excepteur do laboris do. Nulla magna sit
adipisicing incididunt proident tempor velit fugiat reprehenderit aute cillum est consectetur officia.
Culpa aliquip esse sint laborum minim reprehenderit enim proident commodo duis pariatur officia ut.
Laboris deserunt excepteur mollit elit amet quis cillum veniam ad laborum sit. Deserunt elit in nostrud
magna ipsum nulla sunt ea ut reprehenderit velit consequat do. Nulla consequat elit non amet aliqua sunt
aute nostrud magna dolor labore. Veniam eiusmod aliqua culpa id do incididunt incididunt in incididunt.
Esse incididunt ipsum et deserunt Lorem non aute ut culpa qui enim sit enim esse. Quis laboris nostrud
veniam duis tempor irure sint consequat reprehenderit excepteur ex ullamco. Do et cupidatat pariatur
nostrud occaecat laboris laborum ex. Cillum aliqua incididunt tempor officia adipisicing excepteur
reprehenderit magna quis cupidatat. Voluptate occaecat laboris ad ad ad irure quis est duis id adipisicing
et laboris. Dolor non aliqua laborum enim cillum eu consequat est anim est magna velit voluptate. Sint
dolor pariatur dolore ut in sint anim ipsum. Et ullamco veniam Lorem incididunt fugiat eiusmod aute aliqua
elit. Magna Lorem eu ad do enim excepteur eiusmod dolor dolore adipisicing laborum ad. Duis sunt pariatur
eu sit esse tempor pariatur consectetur anim aliqua laborum mollit culpa aliqua. Qui aliqua voluptate
fugiat incididunt excepteur consequat ea adipisicing est deserunt incididunt. Cupidatat sit sint sunt
voluptate minim. Culpa aliquip officia voluptate ad nostrud. Ut qui ipsum ipsum eiusmod nostrud fugiat in
incididunt mollit ea. Non veniam sunt in minim ea. Id dolor nisi excepteur culpa pariatur cillum ullamco
proident incididunt. Tempor irure aute deserunt nisi. Consequat aute Lorem ea et quis cupidatat aliqua
officia laborum ad est quis ex sunt. Reprehenderit proident mollit aliqua ea magna elit. Officia sint
consectetur duis sint non consectetur ad reprehenderit ullamco do enim. Nisi incididunt eiusmod enim enim
est. Nisi non commodo qui fugiat exercitation sunt incididunt sit et. Nulla aliquip reprehenderit sint
duis occaecat ipsum quis dolore aliqua aute ea quis Lorem deserunt. Pariatur ex aliquip velit dolore
cillum. Commodo minim deserunt id deserunt anim aliquip. Sint fugiat duis laboris culpa voluptate officia
sint pariatur consequat proident culpa. Veniam aliquip ut occaecat ad ut sint et fugiat aliquip sunt sit
enim dolor minim. Sunt excepteur cillum ut minim in laboris occaecat eu voluptate sint et est. Ad anim
irure dolore et incididunt enim ut nulla quis consequat culpa esse cillum in. Magna amet occaecat aute
sunt adipisicing mollit sunt velit aliqua duis magna ad. Irure velit proident velit excepteur et elit
officia ut consequat ut. Cupidatat labore id nisi elit commodo minim ut labore Lorem cupidatat nisi amet
do. Voluptate ipsum incididunt quis qui dolore voluptate aliqua. Ut mollit fugiat qui nulla nulla amet est
enim et laboris enim duis esse. Qui minim Lorem adipisicing eu cillum. Velit laboris dolore excepteur
voluptate deserunt excepteur do. Aliquip ipsum enim veniam deserunt veniam ut nisi occaecat. Cupidatat
magna pariatur pariatur laborum eu elit incididunt magna ea cupidatat velit sit enim officia. Ex labore
nulla do excepteur consequat duis exercitation voluptate cillum incididunt deserunt. Elit excepteur
voluptate pariatur ut tempor id veniam commodo sint laborum deserunt est irure. Officia fugiat ea qui
nisi. Laboris sunt in qui labore voluptate ea consequat aliquip sit exercitation ipsum. Quis magna cillum
ex adipisicing. Anim eiusmod amet consectetur eiusmod do pariatur excepteur eu pariatur ullamco nostrud
irure sit. Eiusmod pariatur labore voluptate excepteur commodo occaecat officia anim et magna id culpa
reprehenderit.
Ranking Panel Cillum aute occaecat in pariatur duis aliquip sint sunt
excepteur Lorem. Incididunt quis id sit consequat reprehenderit officia
adipisicing ipsum. Esse anim excepteur do laboris do. Nulla magna sit
adipisicing incididunt proident tempor velit fugiat reprehenderit aute
cillum est consectetur officia. Culpa aliquip esse sint laborum minim
reprehenderit enim proident commodo duis pariatur officia ut. Laboris
deserunt excepteur mollit elit amet quis cillum veniam ad laborum sit.
Deserunt elit in nostrud magna ipsum nulla sunt ea ut reprehenderit velit
consequat do. Nulla consequat elit non amet aliqua sunt aute nostrud magna
dolor labore. Veniam eiusmod aliqua culpa id do incididunt incididunt in
incididunt. Esse incididunt ipsum et deserunt Lorem non aute ut culpa qui
enim sit enim esse. Quis laboris nostrud veniam duis tempor irure sint
consequat reprehenderit excepteur ex ullamco. Do et cupidatat pariatur
nostrud occaecat laboris laborum ex. Cillum aliqua incididunt tempor officia
adipisicing excepteur reprehenderit magna quis cupidatat. Voluptate occaecat
laboris ad ad ad irure quis est duis id adipisicing et laboris. Dolor non
aliqua laborum enim cillum eu consequat est anim est magna velit voluptate.
Sint dolor pariatur dolore ut in sint anim ipsum. Et ullamco veniam Lorem
incididunt fugiat eiusmod aute aliqua elit. Magna Lorem eu ad do enim
excepteur eiusmod dolor dolore adipisicing laborum ad. Duis sunt pariatur eu
sit esse tempor pariatur consectetur anim aliqua laborum mollit culpa
aliqua. Qui aliqua voluptate fugiat incididunt excepteur consequat ea
adipisicing est deserunt incididunt. Cupidatat sit sint sunt voluptate
minim. Culpa aliquip officia voluptate ad nostrud. Ut qui ipsum ipsum
eiusmod nostrud fugiat in incididunt mollit ea. Non veniam sunt in minim ea.
Id dolor nisi excepteur culpa pariatur cillum ullamco proident incididunt.
Tempor irure aute deserunt nisi. Consequat aute Lorem ea et quis cupidatat
aliqua officia laborum ad est quis ex sunt. Reprehenderit proident mollit
aliqua ea magna elit. Officia sint consectetur duis sint non consectetur ad
reprehenderit ullamco do enim. Nisi incididunt eiusmod enim enim est. Nisi
non commodo qui fugiat exercitation sunt incididunt sit et. Nulla aliquip
reprehenderit sint duis occaecat ipsum quis dolore aliqua aute ea quis Lorem
deserunt. Pariatur ex aliquip velit dolore cillum. Commodo minim deserunt id
deserunt anim aliquip. Sint fugiat duis laboris culpa voluptate officia sint
pariatur consequat proident culpa. Veniam aliquip ut occaecat ad ut sint et
fugiat aliquip sunt sit enim dolor minim. Sunt excepteur cillum ut minim in
laboris occaecat eu voluptate sint et est. Ad anim irure dolore et
incididunt enim ut nulla quis consequat culpa esse cillum in. Magna amet
occaecat aute sunt adipisicing mollit sunt velit aliqua duis magna ad. Irure
velit proident velit excepteur et elit officia ut consequat ut. Cupidatat
labore id nisi elit commodo minim ut labore Lorem cupidatat nisi amet do.
Voluptate ipsum incididunt quis qui dolore voluptate aliqua. Ut mollit
fugiat qui nulla nulla amet est enim et laboris enim duis esse. Qui minim
Lorem adipisicing eu cillum. Velit laboris dolore excepteur voluptate
deserunt excepteur do. Aliquip ipsum enim veniam deserunt veniam ut nisi
occaecat. Cupidatat magna pariatur pariatur laborum eu elit incididunt magna
ea cupidatat velit sit enim officia. Ex labore nulla do excepteur consequat
duis exercitation voluptate cillum incididunt deserunt. Elit excepteur
voluptate pariatur ut tempor id veniam commodo sint laborum deserunt est
irure. Officia fugiat ea qui nisi. Laboris sunt in qui labore voluptate ea
consequat aliquip sit exercitation ipsum. Quis magna cillum ex adipisicing.
Anim eiusmod amet consectetur eiusmod do pariatur excepteur eu pariatur
ullamco nostrud irure sit. Eiusmod pariatur labore voluptate excepteur
commodo occaecat officia anim et magna id culpa reprehenderit.
</p>
}
/>
Expand Down
29 changes: 29 additions & 0 deletions web/src/features/panels/Zone/CountryTag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { CountryFlag } from 'components/Flag';

// TODO: move to translations when config is added
const getCountryName = (zoneId: string) => {
if (zoneId === 'DK-DK1') {
return 'Denmark';
}
if (zoneId === 'ES') {
return 'Spain';
}
return 'USA';
};

export function CountryTag({ zoneId }: { zoneId: string }) {
const countryName = getCountryName(zoneId);
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
const isACountry = zoneId.length === 2; // TODO: set up proper method to check if zoneId is a country

if (isACountry) {
return <CountryFlag zoneId={zoneId} flagSize={16} className="inline-flex" />;
}

return (
<span className="inline-flex items-center gap-1 rounded-full bg-gray-200 px-2 py-0 text-xs">
<CountryFlag zoneId={zoneId} flagSize={16} />
<span>{countryName}</span>
</span>
);
}
9 changes: 4 additions & 5 deletions web/src/features/panels/Zone/ZoneDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import LoadingOrError from 'components/LoadingOrError';
import { useAtom } from 'jotai';
import { Navigate, useParams } from 'react-router-dom';
import { timeAverageAtom } from 'utils/state';
import { ZoneHeader } from './ZoneHeader';

export default function ZoneDetails(): JSX.Element {
const { zoneId } = useParams();
Expand All @@ -19,13 +20,11 @@ export default function ZoneDetails(): JSX.Element {
return <LoadingOrError error={error as Error} />;
}

console.log('I should do something with all this data', data);

return (
<div>
{data.zoneStates.map((x) => (
<div key={x.stateDatetime}>
{x.stateDatetime} : {x.co2intensity}
</div>
))}{' '}
<ZoneHeader zoneId={zoneId} />
</div>
);
}
56 changes: 56 additions & 0 deletions web/src/features/panels/Zone/ZoneHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { CountryTag } from './CountryTag';
import ZoneHeaderTitle from './ZoneHeaderTitle';

interface ZoneHeaderProps {
zoneId: string;
}

export function ZoneHeader(props: ZoneHeaderProps) {
const { zoneId } = props;
// TODO: use correct zoneId

return (
<div className="mt-1 grid w-full gap-20 pr-4">
<ZoneHeaderTitle
title="Western Area Power Administration Rocky Mountain Region "
formattedDate="November 9, 2022 at 8:00"
goBackPath="/"
labels={[
<div
key="estimated"
className="w-18 rounded-full bg-yellow-400 px-2 text-center text-xs"
>
Estimated
</div>,
<div
key="estimated"
className="w-20 rounded-full bg-gray-400 px-2 text-center text-xs text-white"
>
Aggregated
</div>,
]}
countryTag={<CountryTag zoneId={'US-NW-WACM'} />}
/>
<ZoneHeaderTitle
title="West Denmark"
formattedDate="November 9, 2022 at 8:00"
goBackPath="/"
labels={[
<div
key="estimated"
className="w-18 rounded-full bg-yellow-400 px-2 text-center text-xs"
>
Estimated
</div>,
]}
countryTag={<CountryTag zoneId={'DK-DK1'} />}
/>
<ZoneHeaderTitle
title="Spain "
formattedDate="November 9, 2022 at 8:00"
goBackPath="/"
countryTag={<CountryTag zoneId={'ES'} />}
/>
</div>
);
}
36 changes: 36 additions & 0 deletions web/src/features/panels/Zone/ZoneHeaderTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Link } from 'react-router-dom';

interface ZoneHeaderTitleProps {
title: string;
goBackPath: string;
labels?: React.ReactElement[];
countryTag?: React.ReactElement;
formattedDate: string;
}

export default function ZoneHeaderTitle({
title,
goBackPath,
labels,
formattedDate,
countryTag,
}: ZoneHeaderTitleProps) {
// TODO: add correct icon
return (
<div className="flex flex-row pl-2">
<Link className="mr-4 self-center text-3xl text-gray-400" to={goBackPath}>
{'❮'}
</Link>
<div>
<h2 className="text-md mb-1 text-base font-medium">
<span>{title}</span>
<span> {countryTag}</span>
</h2>
<div className="flex flex-wrap items-center gap-1 text-center">
{labels}
<p className="whitespace-nowrap text-xs">{formattedDate}</p>
</div>
</div>
</div>
);
}
2 changes: 1 addition & 1 deletion web/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if (container) {
<BrowserRouter>
<App />
</BrowserRouter>
<ReactQueryDevtools position='top-right' initialIsOpen={false} />
<ReactQueryDevtools position="bottom-right" initialIsOpen={false} />
</QueryClientProvider>
</StrictMode>
);
Expand Down

0 comments on commit 0485ce4

Please sign in to comment.