Skip to content

Commit

Permalink
Fix issues on dref import and imminent risk map
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tnagorra committed Nov 12, 2024
1 parent 1b20b81 commit 577b252
Show file tree
Hide file tree
Showing 23 changed files with 282 additions and 223 deletions.
1 change: 0 additions & 1 deletion app/scripts/translatte/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ yargs(hideBin(process.argv))
});
},
async (argv) => {
console.warn(argv);
await applyMigrations(
currentDir,
argv.SOURCE_FILE as string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,22 @@ function LayerOptions(props: Props) {
const setFieldValue = useSetFieldValue(onChange);

// FIXME: use strings
// FIXME: These are hard-coded for Gdacs source.
// Currently we are only showing severity control for Gdacs
const severityLegendItems = useMemo<SeverityLegendItem[]>(() => ([
{
severity: 'green',
label: 'Green',
label: '60 km/h',
color: COLOR_GREEN,
},
{
severity: 'orange',
label: 'Orange',
label: '90 km/h',
color: COLOR_ORANGE,
},
{
severity: 'red',
label: 'Red',
label: '120 km/h',
color: COLOR_RED,
},
{
Expand Down
1 change: 0 additions & 1 deletion app/src/components/domain/RiskImminentEventMap/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"namespace": "common",
"strings": {
"riskImminentEventsMap": "Risk Imminent Events Map",
"backToEventsLabel": "Back to events",
"emptyImminentEventMessage": "No imminent event forecasted"
}
}
98 changes: 51 additions & 47 deletions app/src/components/domain/RiskImminentEventMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ export type EventPointFeature = GeoJSON.Feature<GeoJSON.Point, EventPointPropert

export interface RiskEventListItemProps<EVENT> {
data: EVENT;
expanded: boolean;
onExpandClick: (eventId: number | string) => void;
className?: string;
children?: React.ReactNode;
}

export interface RiskEventDetailProps<EVENT, EXPOSURE> {
Expand Down Expand Up @@ -243,10 +245,15 @@ function RiskImminentEventMap<
(eventId: string | number | undefined) => {
const eventIdSafe = eventId as KEY | undefined;

setActiveEventId(eventIdSafe);
onActiveEventChange(eventIdSafe);
if (activeEventId === eventIdSafe) {
setActiveEventId(undefined);
onActiveEventChange(undefined);
} else {
setActiveEventId(eventIdSafe);
onActiveEventChange(eventIdSafe);
}
},
[onActiveEventChange],
[onActiveEventChange, activeEventId],
);

const handlePointClick = useCallback(
Expand All @@ -258,17 +265,44 @@ function RiskImminentEventMap<
[setActiveEventIdSafe],
);

const DetailComponent = detailRenderer;

const eventListRendererParams = useCallback(
(_: string | number, event: EVENT): RiskEventListItemProps<EVENT> => ({
data: event,
onExpandClick: setActiveEventIdSafe,
expanded: activeEventId === keySelector(event),
className: styles.riskEventListItem,
children: activeEventId === keySelector(event) && (
<DetailComponent
data={event}
exposure={activeEventExposure}
pending={activeEventExposurePending}
>
{hazardTypeSelector(event) === 'TC' && (
<LayerOptions
value={layerOptions}
// NOTE: Currently the information is only visible in gdacas
exposureAreaControlHidden={source !== 'gdacs'}
onChange={setLayerOptions}
/>
)}
</DetailComponent>
),
}),
[setActiveEventIdSafe],
[
setActiveEventIdSafe,
activeEventExposure,
activeEventExposurePending,
layerOptions,
hazardTypeSelector,
DetailComponent,
activeEventId,
keySelector,
source,
],
);

const DetailComponent = detailRenderer;

const [loadedIcons, setLoadedIcons] = useState<Record<string, boolean>>({});

const handleIconLoad = useCallback(
Expand Down Expand Up @@ -443,48 +477,18 @@ function RiskImminentEventMap<
withInternalPadding
childrenContainerClassName={styles.content}
spacing="cozy"
actions={isDefined(activeEventId) && (
<Button
name={undefined}
onClick={setActiveEventIdSafe}
variant="tertiary"
icons={(
<ChevronLeftLineIcon className={styles.icon} />
)}
>
{strings.backToEventsLabel}
</Button>
)}
>
{isNotDefined(activeEventId) && (
<List
className={styles.eventList}
filtered={false}
pending={pending}
errored={false}
data={events}
keySelector={keySelector}
renderer={listItemRenderer}
rendererParams={eventListRendererParams}
emptyMessage={strings.emptyImminentEventMessage}
/>
)}
{isDefined(activeEvent) && (
<DetailComponent
data={activeEvent}
exposure={activeEventExposure}
pending={activeEventExposurePending}
>
{hazardTypeSelector(activeEvent) === 'TC' && (
<LayerOptions
value={layerOptions}
// NOTE: Currently the information is only visible in gdacas
exposureAreaControlHidden={source !== 'gdacs'}
onChange={setLayerOptions}
/>
)}
</DetailComponent>
)}
<List
className={styles.eventList}
filtered={false}
pending={pending}
errored={false}
data={events}
keySelector={keySelector}
renderer={listItemRenderer}
rendererParams={eventListRendererParams}
emptyMessage={strings.emptyImminentEventMessage}
/>
</Container>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"namespace": "common",
"strings": {
"eventStartOnLabel": "Started on",
"eventMoreDetailsLink": "More Details",
"eventSourceLabel": "Forecast provider",
"eventDeathLabel": "Estimated deaths",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ type Props = RiskEventDetailProps<GdacsItem, GdacsExposure | undefined>;
function EventDetails(props: Props) {
const {
data: {
hazard_name,
start_date,
event_details,
},
exposure,
Expand All @@ -87,16 +85,7 @@ function EventDetails(props: Props) {
return (
<Container
contentViewType="vertical"
heading={hazard_name}
headingLevel={5}
spacing="cozy"
headerDescription={(
<TextOutput
label={strings.eventStartOnLabel}
value={start_date}
valueType="date"
/>
)}
withBorderAndHeaderBackground
pending={pending}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"namespace": "common",
"strings": {
"gdacsEventViewDetails": "View Details",
"gdacsEventViewDetails": "View / Hide Details",
"gdacsEventStartedOn": "Started On"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ChevronRightLineIcon } from '@ifrc-go/icons';
import { useRef, useEffect } from 'react';

Check warning on line 1 in app/src/components/domain/RiskImminentEvents/Gdacs/EventListItem/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

Imports must be broken into multiple lines if there are more than 1 elements

Check failure on line 1 in app/src/components/domain/RiskImminentEvents/Gdacs/EventListItem/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

Run autofix to sort these imports!

Check warning on line 1 in app/src/components/domain/RiskImminentEvents/Gdacs/EventListItem/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

Imports must be broken into multiple lines if there are more than 1 elements

Check failure on line 1 in app/src/components/domain/RiskImminentEvents/Gdacs/EventListItem/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

Run autofix to sort these imports!
import {
ChevronDownLineIcon,
ChevronUpLineIcon

Check failure on line 4 in app/src/components/domain/RiskImminentEvents/Gdacs/EventListItem/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

Missing trailing comma

Check failure on line 4 in app/src/components/domain/RiskImminentEvents/Gdacs/EventListItem/index.tsx

View workflow job for this annotation

GitHub Actions / Lint JS

Missing trailing comma
} from '@ifrc-go/icons';
import {
Button,
Header,
Expand All @@ -25,35 +29,62 @@ function EventListItem(props: Props) {
hazard_name,
start_date,
},
expanded,
onExpandClick,
className,
children,
} = props;

const strings = useTranslation(i18n);

const elementRef = useRef<HTMLDivElement>(null);

useEffect(
() => {
if (expanded && elementRef.current) {
const y = window.scrollY;
const x = window.scrollX;
elementRef.current.scrollIntoView({
behavior: 'instant',
block: 'start',
});
// NOTE: We need to scroll back because scrollIntoView also
// scrolls the parent container
window.scroll(x, y);
}
},
[expanded],
);

return (
<Header
className={_cs(styles.eventListItem, className)}
heading={hazard_name ?? '--'}
headingLevel={5}
actions={(
<Button
name={id}
onClick={onExpandClick}
variant="tertiary"
title={strings.gdacsEventViewDetails}
>
<ChevronRightLineIcon className={styles.icon} />
</Button>
)}
spacing="cozy"
>
<TextOutput
label={strings.gdacsEventStartedOn}
value={start_date}
valueType="date"
/>
</Header>
<>
<Header
elementRef={elementRef}
className={_cs(styles.eventListItem, className)}
heading={hazard_name ?? '--'}
headingLevel={5}
actions={(
<Button
name={id}
onClick={onExpandClick}
variant="tertiary"
title={strings.gdacsEventViewDetails}
>
{expanded
? <ChevronUpLineIcon className={styles.icon} />
: <ChevronDownLineIcon className={styles.icon} />}
</Button>
)}
spacing="cozy"
>
<TextOutput
label={strings.gdacsEventStartedOn}
value={start_date}
valueType="date"
/>
</Header>
{children}
</>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
"meteoSwissAuthoritativeMessage": "Please also consider {link} and classification of {classificationLink}.",
"meteoSwissAuthoritativeLinkLabel": "authoritative information about the hazard",
"meteoSwissTropicalStorm": "tropical storm",
"meteoSwissEventDetailsStartedOnLabel": "Started on",
"meteoSwissEventDetailsUpdatedAtLabel": "Updated at",
"meteoSwissHazardName": "{hazardType} - {hazardName}",
"meteoSwissImpactValue": "{value} ({fivePercent} - {ninetyFivePercent}) {unit}",
"beta": "beta",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ interface Props {
function EventDetails(props: Props) {
const {
data: {
// id,
hazard_type_display,
country_details,
start_date,
updated_at,
Expand All @@ -55,14 +53,6 @@ function EventDetails(props: Props) {

const strings = useTranslation(i18n);

const hazardName = resolveToString(
strings.meteoSwissHazardName,
{
hazardType: hazard_type_display,
hazardName: country_details?.name ?? hazard_name,
},
);

const getSaffirSimpsonScaleDescription = useCallback((windspeed: number) => {
if (windspeed < 33) {
return strings.tropicalStormDescription;
Expand Down Expand Up @@ -179,25 +169,6 @@ function EventDetails(props: Props) {
<Container
className={styles.eventDetails}
childrenContainerClassName={styles.content}
heading={hazardName}
headingLevel={4}
headerDescription={(
<>
<TextOutput
label={strings.meteoSwissEventDetailsStartedOnLabel}
value={start_date}
valueType="date"
strongValue
/>
<TextOutput
label={strings.meteoSwissEventDetailsUpdatedAtLabel}
value={updated_at}
valueType="date"
format={UPDATED_AT_FORMAT}
strongValue
/>
</>
)}
contentViewType="vertical"
>
{pending && <BlockLoading />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"namespace": "common",
"strings": {
"meteoSwissEventListViewDetails": "View Details",
"meteoSwissEventListViewDetails": "View / Hide Details",
"meteoSwissEventListStartedOn": "Started On"
}
}
Loading

0 comments on commit 577b252

Please sign in to comment.