Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix risk issues #347

Merged
merged 8 commits into from
Dec 13, 2023
2 changes: 1 addition & 1 deletion src/components/MapPopup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function MapPopup(props: Props) {
// eslint-disable-next-line react/jsx-props-no-spreading
{...containerProps}
className={styles.container}
ellipsizeHeading
withoutWrapInHeading
childrenContainerClassName={_cs(styles.content, childrenContainerClassName)}
withHeaderBorder
withInternalPadding
Expand Down
1 change: 1 addition & 0 deletions src/components/Table/HeaderCell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function HeaderCell(props: HeaderCellProps) {
</div>
{infoTitle && infoDescription && (
<InfoPopup
className={styles.infoPopupIcon}
title={infoTitle}
description={infoDescription}
/>
Expand Down
5 changes: 5 additions & 0 deletions src/components/Table/HeaderCell/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
}

.icon {
flex-shrink: 0;
font-size: var(--go-ui-height-icon-multiplier);
}

.info-popup-icon {
flex-shrink: 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"namespace": "common",
"strings": {
"eventStartOnLabel": "Started on",
"usefulLinksHeading": "Useful links:",
"eventMoreDetailsLink": "More Details",
"eventGeometryLink": "Geometry",
"eventReportLink": "Report",
"eventSourceLabel": "Source",
"eventDeathLabel": "Estimated deaths",
"eventDisplacedLabel": "Estimated number of people displaced",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,42 +103,6 @@ function EventDetails(props: Props) {
)}
>
{pending && <BlockLoading />}
{isDefined(eventDetails?.url) && (
<Container
heading={strings.usefulLinksHeading}
headingLevel={5}
childrenContainerClassName={styles.usefulLinksContent}
spacing="compact"
>
{isDefined(eventDetails?.url.details) && (
<Link
href={eventDetails?.url.details}
external
withLinkIcon
>
{strings.eventMoreDetailsLink}
</Link>
)}
{isDefined(eventDetails?.url.geometry) && (
<Link
href={eventDetails?.url.geometry}
external
withLinkIcon
>
{strings.eventGeometryLink}
</Link>
)}
{isDefined(eventDetails?.url.report) && (
<Link
href={eventDetails?.url.report}
external
withLinkIcon
>
{strings.eventReportLink}
</Link>
)}
</Container>
)}
<div className={styles.eventDetails}>
{isDefined(eventDetails?.source) && (
<TextOutput
Expand Down Expand Up @@ -190,6 +154,18 @@ function EventDetails(props: Props) {
/>
)}
</div>
{isDefined(eventDetails)
&& isDefined(eventDetails.url)
&& isDefined(eventDetails.url.report)
&& (
<Link
href={eventDetails?.url.report}
external
withLinkIcon
>
{strings.eventMoreDetailsLink}
</Link>
)}
</Container>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"wfpExposed90": "Exposed (90km/h)",
"wfpExposed120": "Exposed (120km/h)",
"wfpFloodArea": "Flood Area",
"wfpFloodCropland": "Flood Cropland"
"wfpFloodCropland": "Flood Cropland",
"wfpChartLabel": "Windspeed over time"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import Link from '#components/Link';
import BlockLoading from '#components/BlockLoading';
import Container from '#components/Container';
import TextOutput from '#components/TextOutput';
import Tooltip from '#components/Tooltip';
import useTranslation from '#hooks/useTranslation';
import { getPercentage, maxSafe, roundSafe } from '#utils/common';
import { type RiskApiResponse } from '#utils/restRequest';
import useTranslation from '#hooks/useTranslation';
import { isValidFeatureCollection, isValidPointFeature } from '#utils/domain/risk';
import { resolveToString } from '#utils/translation';

Expand Down Expand Up @@ -167,23 +168,33 @@ function EventDetails(props: Props) {
{stormPoints && stormPoints.length > 0 && isDefined(maxWindSpeed) && (
/* TODO: use proper svg charts */
<div className={styles.windSpeedChart}>
{stormPoints.map(
(point) => (
<div
key={point.id}
className={styles.bar}
// FIXME: Use percent function
style={{ height: `${getPercentage(point.windSpeed, maxWindSpeed)}%` }}
title={resolveToString(
strings.wfpEventDetailsKm,
{
point: point.windSpeed,
pontDate: point.date.toLocaleString(),
},
)}
/>
),
)}
<div className={styles.barListContainer}>
{stormPoints.map(
(point) => (
<div
key={point.id}
className={styles.barContainer}
>
<Tooltip
description={resolveToString(
strings.wfpEventDetailsKm,
{
point: point.windSpeed ?? '--',
pointDate: point.date.toLocaleString() ?? '--',
},
)}
/>
<div
style={{ height: `${getPercentage(point.windSpeed, maxWindSpeed)}%` }}
className={styles.bar}
/>
</div>
),
)}
</div>
<div className={styles.chartLabel}>
{strings.wfpChartLabel}
</div>
</div>
)}
{isDefined(eventDetails)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,42 @@

.wind-speed-chart {
display: flex;
align-items: flex-end;
justify-content: space-around;
height: 10rem;
flex-direction: column;
gap: var(--go-ui-spacing-xs);

.bar {
border-top-left-radius: 2pt;
border-top-right-radius: 2pt;
background-color: var(--go-ui-color-primary-red);
width: 4pt;
.bar-list-container {
display: flex;
align-items: stretch;
height: 10rem;

.bar-container {
display: flex;
align-items: flex-end;
flex-basis: 0;
flex-grow: 1;
justify-content: center;
transition: var(--go-ui-duration-transition-medium) background-color ease-in-out;
border-top-left-radius: 2pt;
border-top-right-radius: 2pt;
background-color: transparent;

.bar {
background-color: var(--go-ui-color-primary-red);
width: 4pt;
height: 100%;
}

&:hover {
background-color: var(--go-ui-color-background-hover);
}
}
}

.chart-label {
text-align: center;
color: var(--go-ui-color-text-light);
font-size: var(--go-ui-font-size-sm);
font-weight: var(--go-ui-font-weight-medium);
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/components/domain/RiskImminentEvents/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import MeteoSwiss from './MeteoSwiss';
import i18n from './i18n.json';
import styles from './styles.module.css';

type ActiveView = 'pdc' | 'wfpAdam' | 'gdacs' | 'meteoSwiss';
export type ImminentEventSource = 'pdc' | 'wfpAdam' | 'gdacs' | 'meteoSwiss';
type HazardType = components<'read'>['schemas']['HazardTypeEnum'];

type BaseProps = {
className?: string;
title: React.ReactNode;
bbox: LngLatBoundsLike | undefined;
defaultSource?: ImminentEventSource;
}

type Props = BaseProps & ({
Expand All @@ -47,8 +48,12 @@ type Props = BaseProps & ({
})

function RiskImminentEvents(props: Props) {
const [activeView, setActiveView] = useState<ActiveView>('pdc');
const { className, ...otherProps } = props;
const {
className,
defaultSource = 'pdc',
...otherProps
} = props;
const [activeView, setActiveView] = useState<ImminentEventSource>(defaultSource);

const strings = useTranslation(i18n);

Expand All @@ -75,7 +80,7 @@ function RiskImminentEvents(props: Props) {
[activeView],
);

const handleRadioClick = useCallback((key: ActiveView) => {
const handleRadioClick = useCallback((key: ImminentEventSource) => {
setActiveView(key);
}, []);

Expand Down
Loading