Skip to content

Commit a2eece2

Browse files
committed
Fix issues on dref import and imminent risk map
- Update labels for severity control - Green -> 60 km/h - Orange -> 90 km/h - Red -> 120 km/h - Update how event details is shown - Previously, we had a navigation system - Now, we have exandable container - Fix issue related to richtext and excel - Filtered out empty text items - Fix issue with injecting client id - We were injecting clientId instead of client_id - We were not injecting clientId if keyFieldName was defined
1 parent 1b20b81 commit a2eece2

File tree

23 files changed

+294
-225
lines changed

23 files changed

+294
-225
lines changed

app/scripts/translatte/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ yargs(hideBin(process.argv))
112112
});
113113
},
114114
async (argv) => {
115-
console.warn(argv);
116115
await applyMigrations(
117116
currentDir,
118117
argv.SOURCE_FILE as string,

app/src/components/domain/RiskImminentEventMap/LayerOptions/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,22 @@ function LayerOptions(props: Props) {
5757
const setFieldValue = useSetFieldValue(onChange);
5858

5959
// FIXME: use strings
60+
// FIXME: These are hard-coded for Gdacs source.
61+
// Currently we are only showing severity control for Gdacs
6062
const severityLegendItems = useMemo<SeverityLegendItem[]>(() => ([
6163
{
6264
severity: 'green',
63-
label: 'Green',
65+
label: '60 km/h',
6466
color: COLOR_GREEN,
6567
},
6668
{
6769
severity: 'orange',
68-
label: 'Orange',
70+
label: '90 km/h',
6971
color: COLOR_ORANGE,
7072
},
7173
{
7274
severity: 'red',
73-
label: 'Red',
75+
label: '120 km/h',
7476
color: COLOR_RED,
7577
},
7678
{

app/src/components/domain/RiskImminentEventMap/i18n.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"namespace": "common",
33
"strings": {
44
"riskImminentEventsMap": "Risk Imminent Events Map",
5-
"backToEventsLabel": "Back to events",
65
"emptyImminentEventMessage": "No imminent event forecasted"
76
}
87
}

app/src/components/domain/RiskImminentEventMap/index.tsx

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import {
33
useMemo,
44
useState,
55
} from 'react';
6-
import { ChevronLeftLineIcon } from '@ifrc-go/icons';
76
import {
8-
Button,
97
Container,
108
List,
119
} from '@ifrc-go/ui';
@@ -86,8 +84,10 @@ export type EventPointFeature = GeoJSON.Feature<GeoJSON.Point, EventPointPropert
8684

8785
export interface RiskEventListItemProps<EVENT> {
8886
data: EVENT;
87+
expanded: boolean;
8988
onExpandClick: (eventId: number | string) => void;
9089
className?: string;
90+
children?: React.ReactNode;
9191
}
9292

9393
export interface RiskEventDetailProps<EVENT, EXPOSURE> {
@@ -243,10 +243,15 @@ function RiskImminentEventMap<
243243
(eventId: string | number | undefined) => {
244244
const eventIdSafe = eventId as KEY | undefined;
245245

246-
setActiveEventId(eventIdSafe);
247-
onActiveEventChange(eventIdSafe);
246+
if (activeEventId === eventIdSafe) {
247+
setActiveEventId(undefined);
248+
onActiveEventChange(undefined);
249+
} else {
250+
setActiveEventId(eventIdSafe);
251+
onActiveEventChange(eventIdSafe);
252+
}
248253
},
249-
[onActiveEventChange],
254+
[onActiveEventChange, activeEventId],
250255
);
251256

252257
const handlePointClick = useCallback(
@@ -258,17 +263,44 @@ function RiskImminentEventMap<
258263
[setActiveEventIdSafe],
259264
);
260265

266+
const DetailComponent = detailRenderer;
267+
261268
const eventListRendererParams = useCallback(
262269
(_: string | number, event: EVENT): RiskEventListItemProps<EVENT> => ({
263270
data: event,
264271
onExpandClick: setActiveEventIdSafe,
272+
expanded: activeEventId === keySelector(event),
265273
className: styles.riskEventListItem,
274+
children: activeEventId === keySelector(event) && (
275+
<DetailComponent
276+
data={event}
277+
exposure={activeEventExposure}
278+
pending={activeEventExposurePending}
279+
>
280+
{hazardTypeSelector(event) === 'TC' && (
281+
<LayerOptions
282+
value={layerOptions}
283+
// NOTE: Currently the information is only visible in gdacas
284+
exposureAreaControlHidden={source !== 'gdacs'}
285+
onChange={setLayerOptions}
286+
/>
287+
)}
288+
</DetailComponent>
289+
),
266290
}),
267-
[setActiveEventIdSafe],
291+
[
292+
setActiveEventIdSafe,
293+
activeEventExposure,
294+
activeEventExposurePending,
295+
layerOptions,
296+
hazardTypeSelector,
297+
DetailComponent,
298+
activeEventId,
299+
keySelector,
300+
source,
301+
],
268302
);
269303

270-
const DetailComponent = detailRenderer;
271-
272304
const [loadedIcons, setLoadedIcons] = useState<Record<string, boolean>>({});
273305

274306
const handleIconLoad = useCallback(
@@ -443,48 +475,18 @@ function RiskImminentEventMap<
443475
withInternalPadding
444476
childrenContainerClassName={styles.content}
445477
spacing="cozy"
446-
actions={isDefined(activeEventId) && (
447-
<Button
448-
name={undefined}
449-
onClick={setActiveEventIdSafe}
450-
variant="tertiary"
451-
icons={(
452-
<ChevronLeftLineIcon className={styles.icon} />
453-
)}
454-
>
455-
{strings.backToEventsLabel}
456-
</Button>
457-
)}
458478
>
459-
{isNotDefined(activeEventId) && (
460-
<List
461-
className={styles.eventList}
462-
filtered={false}
463-
pending={pending}
464-
errored={false}
465-
data={events}
466-
keySelector={keySelector}
467-
renderer={listItemRenderer}
468-
rendererParams={eventListRendererParams}
469-
emptyMessage={strings.emptyImminentEventMessage}
470-
/>
471-
)}
472-
{isDefined(activeEvent) && (
473-
<DetailComponent
474-
data={activeEvent}
475-
exposure={activeEventExposure}
476-
pending={activeEventExposurePending}
477-
>
478-
{hazardTypeSelector(activeEvent) === 'TC' && (
479-
<LayerOptions
480-
value={layerOptions}
481-
// NOTE: Currently the information is only visible in gdacas
482-
exposureAreaControlHidden={source !== 'gdacs'}
483-
onChange={setLayerOptions}
484-
/>
485-
)}
486-
</DetailComponent>
487-
)}
479+
<List
480+
className={styles.eventList}
481+
filtered={false}
482+
pending={pending}
483+
errored={false}
484+
data={events}
485+
keySelector={keySelector}
486+
renderer={listItemRenderer}
487+
rendererParams={eventListRendererParams}
488+
emptyMessage={strings.emptyImminentEventMessage}
489+
/>
488490
</Container>
489491
</div>
490492
);

app/src/components/domain/RiskImminentEvents/Gdacs/EventDetails/i18n.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"namespace": "common",
33
"strings": {
4-
"eventStartOnLabel": "Started on",
54
"eventMoreDetailsLink": "More Details",
65
"eventSourceLabel": "Forecast provider",
76
"eventDeathLabel": "Estimated deaths",

app/src/components/domain/RiskImminentEvents/Gdacs/EventDetails/index.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ type Props = RiskEventDetailProps<GdacsItem, GdacsExposure | undefined>;
7070
function EventDetails(props: Props) {
7171
const {
7272
data: {
73-
hazard_name,
74-
start_date,
7573
event_details,
7674
},
7775
exposure,
@@ -87,16 +85,7 @@ function EventDetails(props: Props) {
8785
return (
8886
<Container
8987
contentViewType="vertical"
90-
heading={hazard_name}
91-
headingLevel={5}
9288
spacing="cozy"
93-
headerDescription={(
94-
<TextOutput
95-
label={strings.eventStartOnLabel}
96-
value={start_date}
97-
valueType="date"
98-
/>
99-
)}
10089
withBorderAndHeaderBackground
10190
pending={pending}
10291
>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"namespace": "common",
33
"strings": {
4-
"gdacsEventViewDetails": "View Details",
4+
"gdacsEventViewDetails": "View / Hide Details",
55
"gdacsEventStartedOn": "Started On"
66
}
77
}

app/src/components/domain/RiskImminentEvents/Gdacs/EventListItem/index.tsx

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { ChevronRightLineIcon } from '@ifrc-go/icons';
1+
import {
2+
useEffect,
3+
useRef,
4+
} from 'react';
5+
import {
6+
ChevronDownLineIcon,
7+
ChevronUpLineIcon,
8+
} from '@ifrc-go/icons';
29
import {
310
Button,
411
Header,
@@ -25,35 +32,62 @@ function EventListItem(props: Props) {
2532
hazard_name,
2633
start_date,
2734
},
35+
expanded,
2836
onExpandClick,
2937
className,
38+
children,
3039
} = props;
3140

3241
const strings = useTranslation(i18n);
3342

43+
const elementRef = useRef<HTMLDivElement>(null);
44+
45+
useEffect(
46+
() => {
47+
if (expanded && elementRef.current) {
48+
const y = window.scrollY;
49+
const x = window.scrollX;
50+
elementRef.current.scrollIntoView({
51+
behavior: 'instant',
52+
block: 'start',
53+
});
54+
// NOTE: We need to scroll back because scrollIntoView also
55+
// scrolls the parent container
56+
window.scroll(x, y);
57+
}
58+
},
59+
[expanded],
60+
);
61+
3462
return (
35-
<Header
36-
className={_cs(styles.eventListItem, className)}
37-
heading={hazard_name ?? '--'}
38-
headingLevel={5}
39-
actions={(
40-
<Button
41-
name={id}
42-
onClick={onExpandClick}
43-
variant="tertiary"
44-
title={strings.gdacsEventViewDetails}
45-
>
46-
<ChevronRightLineIcon className={styles.icon} />
47-
</Button>
48-
)}
49-
spacing="cozy"
50-
>
51-
<TextOutput
52-
label={strings.gdacsEventStartedOn}
53-
value={start_date}
54-
valueType="date"
55-
/>
56-
</Header>
63+
<>
64+
<Header
65+
elementRef={elementRef}
66+
className={_cs(styles.eventListItem, className)}
67+
heading={hazard_name ?? '--'}
68+
headingLevel={5}
69+
actions={(
70+
<Button
71+
name={id}
72+
onClick={onExpandClick}
73+
variant="tertiary"
74+
title={strings.gdacsEventViewDetails}
75+
>
76+
{expanded
77+
? <ChevronUpLineIcon className={styles.icon} />
78+
: <ChevronDownLineIcon className={styles.icon} />}
79+
</Button>
80+
)}
81+
spacing="cozy"
82+
>
83+
<TextOutput
84+
label={strings.gdacsEventStartedOn}
85+
value={start_date}
86+
valueType="date"
87+
/>
88+
</Header>
89+
{children}
90+
</>
5791
);
5892
}
5993

app/src/components/domain/RiskImminentEvents/MeteoSwiss/EventDetails/i18n.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
"meteoSwissAuthoritativeMessage": "Please also consider {link} and classification of {classificationLink}.",
1010
"meteoSwissAuthoritativeLinkLabel": "authoritative information about the hazard",
1111
"meteoSwissTropicalStorm": "tropical storm",
12-
"meteoSwissEventDetailsStartedOnLabel": "Started on",
13-
"meteoSwissEventDetailsUpdatedAtLabel": "Updated at",
1412
"meteoSwissHazardName": "{hazardType} - {hazardName}",
1513
"meteoSwissImpactValue": "{value} ({fivePercent} - {ninetyFivePercent}) {unit}",
1614
"beta": "beta",

app/src/components/domain/RiskImminentEvents/MeteoSwiss/EventDetails/index.tsx

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ interface Props {
4141
function EventDetails(props: Props) {
4242
const {
4343
data: {
44-
// id,
45-
hazard_type_display,
4644
country_details,
4745
start_date,
4846
updated_at,
@@ -55,14 +53,6 @@ function EventDetails(props: Props) {
5553

5654
const strings = useTranslation(i18n);
5755

58-
const hazardName = resolveToString(
59-
strings.meteoSwissHazardName,
60-
{
61-
hazardType: hazard_type_display,
62-
hazardName: country_details?.name ?? hazard_name,
63-
},
64-
);
65-
6656
const getSaffirSimpsonScaleDescription = useCallback((windspeed: number) => {
6757
if (windspeed < 33) {
6858
return strings.tropicalStormDescription;
@@ -179,25 +169,6 @@ function EventDetails(props: Props) {
179169
<Container
180170
className={styles.eventDetails}
181171
childrenContainerClassName={styles.content}
182-
heading={hazardName}
183-
headingLevel={4}
184-
headerDescription={(
185-
<>
186-
<TextOutput
187-
label={strings.meteoSwissEventDetailsStartedOnLabel}
188-
value={start_date}
189-
valueType="date"
190-
strongValue
191-
/>
192-
<TextOutput
193-
label={strings.meteoSwissEventDetailsUpdatedAtLabel}
194-
value={updated_at}
195-
valueType="date"
196-
format={UPDATED_AT_FORMAT}
197-
strongValue
198-
/>
199-
</>
200-
)}
201172
contentViewType="vertical"
202173
>
203174
{pending && <BlockLoading />}

0 commit comments

Comments
 (0)