Skip to content

Commit

Permalink
Add highligted operations and country key figures
Browse files Browse the repository at this point in the history
  • Loading branch information
barshathakuri authored and frozenhelium committed Dec 14, 2023
1 parent 8adafa4 commit de043b2
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 135 deletions.
20 changes: 7 additions & 13 deletions src/components/domain/ActiveOperationMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import LegendItem from '#components/LegendItem';
import Link from '#components/Link';
import MapContainerWithDisclaimer from '#components/MapContainerWithDisclaimer';
import MapPopup from '#components/MapPopup';
import MultiSelectInput from '#components/MultiSelectInput';
import RadioInput from '#components/RadioInput';
import SelectInput from '#components/SelectInput';
import TextOutput from '#components/TextOutput';
Expand All @@ -36,10 +35,6 @@ import useGlobalEnums from '#hooks/domain/useGlobalEnums';
import useInputState from '#hooks/useInputState';
import { useRequest } from '#utils/restRequest';
import type { GoApiUrlQuery, GoApiResponse } from '#utils/restRequest';
import {
numericIdSelector,
stringNameSelector,
} from '#utils/selectors';
import {
adminFillLayerOptions,
} from '#utils/map';
Expand Down Expand Up @@ -68,6 +63,7 @@ import {
APPEAL_TYPE_MULTIPLE,
} from './utils';
import styles from './styles.module.css';
import DistrictSearchMultiSelectInput, { DistrictItem } from '../DistrictSearchMultiSelectInput';

type AppealQueryParams = GoApiUrlQuery<'/api/v2/appeal/'>;
type GlobalEnumsResponse = GoApiResponse<'/api/v2/global-enums/'>;
Expand Down Expand Up @@ -102,8 +98,6 @@ interface ClickedPoint {
lngLat: mapboxgl.LngLatLike;
}

type DistrictListItem = NonNullable<GoApiResponse<'/api/v2/district/'>['results']>[number];

type BaseProps = {
className?: string;
onPresentationModeButtonClick?: () => void;
Expand All @@ -114,7 +108,6 @@ type BaseProps = {
type CountryProps = {
variant: 'country';
countryId: number;
districtList: DistrictListItem[];
}
type RegionProps = {
variant: 'region';
Expand Down Expand Up @@ -159,7 +152,6 @@ function ActiveOperationMap(props: Props) {
// eslint-disable-next-line react/destructuring-assignment
const countryId = variant === 'country' ? props.countryId : undefined;
// eslint-disable-next-line react/destructuring-assignment
const districtList = variant === 'country' ? props.districtList : undefined;

const query = useMemo<AppealQueryParams>(
() => {
Expand Down Expand Up @@ -372,6 +364,8 @@ function ActiveOperationMap(props: Props) {
? countryGroupedAppeal[clickedPointProperties.feature.properties.iso3]
: undefined;

const [districtOptions, setDistrictOptions] = useState<DistrictItem[] | null | undefined>();

return (
<Container
className={_cs(styles.activeOperationMap, className)}
Expand All @@ -394,15 +388,15 @@ function ActiveOperationMap(props: Props) {
value={rawFilter.startDateBefore}
/>
{variant === 'country' && (
<MultiSelectInput
<DistrictSearchMultiSelectInput
name="district"
placeholder={strings.operationFilterDistrictPlaceholder}
label={strings.operationMapProvinces}
options={districtList}
value={rawFilter.district}
keySelector={numericIdSelector}
labelSelector={stringNameSelector}
options={districtOptions}
onOptionsChange={setDistrictOptions}
onChange={setFilterField}
countryId={countryId}
/>
)}
<SelectInput
Expand Down
2 changes: 2 additions & 0 deletions src/components/domain/HighlightedOperations/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"namespace": "common",
"strings": {
"highlightedOperationsTitle": "Highlighted Operations",
"highlightedOperationsCountryTitle": "Emergencies in last 30 days",
"highlightedOperationsViewAllInRegion":"View all Emergencies in this Region",
"highlightedOperationsViewAllInCountry":"View all Emergencies in this Country",
"highlightedOperationsViewAll":"View all Emergencies"
}
}
62 changes: 55 additions & 7 deletions src/components/domain/HighlightedOperations/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ type BaseProps = {
className?: string;
}

type CountryProps = {
variant: 'country';
countryId: number;
}

type RegionProps = {
variant: 'region';
regionId: number;
Expand All @@ -36,7 +41,7 @@ type GlobalProps = {
variant: 'global';
}

type Props = BaseProps & (RegionProps | GlobalProps);
type Props = BaseProps & (CountryProps | RegionProps | GlobalProps);

function HighlightedOperations(props: Props) {
const {
Expand All @@ -49,18 +54,33 @@ function HighlightedOperations(props: Props) {
// eslint-disable-next-line react/destructuring-assignment
const regionId = variant === 'region' ? props.regionId : undefined;

// eslint-disable-next-line react/destructuring-assignment
const countryId = variant === 'country' ? props.countryId : undefined;

const query = useMemo<EventQueryParams>(
() => {
if (variant === 'global') {
return { is_featured: true };
}

if (variant === 'country') {
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
thirtyDaysAgo.setHours(0, 0, 0, 0);

return {
countries__in: countryId,
disaster_start_date__gte: thirtyDaysAgo.toISOString(),
ordering: '-disaster_start_date',
};
}

return {
is_featured_region: true,
regions__in: regionId,
};
},
[variant, regionId],
[variant, regionId, countryId],
);

const {
Expand Down Expand Up @@ -97,21 +117,49 @@ function HighlightedOperations(props: Props) {

const featuredEmergencies = featuredEmergencyResponse?.results;

const urlSearch = useMemo(
() => {
if (variant === 'country') {
return `countryId=${countryId}`;
}

if (variant === 'region') {
return `regionId=${regionId}`;
}

return undefined;
},
[regionId, countryId, variant],
);

const viewAllLabel = useMemo(
() => {
if (variant === 'country') {
return strings.highlightedOperationsViewAllInCountry;
}

if (variant === 'region') {
return strings.highlightedOperationsViewAllInRegion;
}

return strings.highlightedOperationsViewAll;
},
[variant, strings],
);

return (
<Container
className={className}
withHeaderBorder
heading={strings.highlightedOperationsTitle}
heading={variant === 'country' ? strings.highlightedOperationsCountryTitle : strings.highlightedOperationsTitle}
actions={(
<Link
to="allEmergencies"
urlSearch={variant === 'region' ? `region=${regionId}` : undefined}
urlSearch={urlSearch}
withLinkIcon
withUnderline
>
{variant === 'region'
? strings.highlightedOperationsViewAllInRegion
: strings.highlightedOperationsViewAll}
{viewAllLabel}
</Link>
)}
>
Expand Down
2 changes: 1 addition & 1 deletion src/views/CountryOngoingActivities/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import styles from './styles.module.css';
// eslint-disable-next-line import/prefer-default-export
export function Component() {
const outletContext = useOutletContext<CountryOutletContext>();
const strings = useTranslation(i18n);
const { countryId } = outletContext;
const strings = useTranslation(i18n);

return (
<div className={styles.countryOngoingActivities}>
Expand Down
3 changes: 3 additions & 0 deletions src/views/CountryOngoingActivities/styles.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.country-ongoing-activities {
display: flex;
flex-direction: column;
gap: var(--go-ui-spacing-2xl);
padding: var(--go-ui-spacing-2xl) 0;
}
17 changes: 15 additions & 2 deletions src/views/CountryOngoingActivitiesEmergencies/i18n.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
{
"namespace": "countryOngoingActivitiesEmergencies",
"strings": {
"pageTitle": "Country Ongoing Emergencies",
"fullScreenHeading": "IFRC Disaster Response and Preparedness",
"countryCloseButton": "Close"
"countryCloseButton": "Close",
"countryOngoingActivitiesDREFOperations": "Active DREF Operations",
"countryOngoingActivitiesKeyFiguresDrefTitle": "DREF",
"countryOngoingActivitiesKeyFiguresDref": "These are small to medium scale emergency operations funded through the Disaster Relief Emergency Fund (DREF).The DREF provides immediate financial support to National Red Cross and Red Crescent Societies, enabling them to carry out their unique role as first responders after a disaster.",
"countryOngoingActivitiesKeyFiguresAppealsTitle": "Emergency Appeal",
"countryOngoingActivitiesFigureAppealDescription": "These are medium to large scale emergency operations funded through a public appeal for funds.",
"countryOngoingActivitiesKeyFiguresActiveAppeals": "Active Emergency Appeals",
"countryOngoingActivitiesKeyFiguresTargetPop": "Targeted Population",
"countryOngoingActivitiesKeyFiguresBudget": "Funding Requirements (CHF)",
"countryOngoingActivitiesKeyFiguresAppealsFunding": "Funding Coverage",
"countryOngoingActivitiesEditCountryLink": "Edit Country",
"countryOngoingActivitiesEmergenciesDescription": "The following data displays the current and ongoing emergencies within the country that are reported by the National Societies and partners. The displayed data is based on reporting and may not be fully indicative of all the activities.",
"countryOngoingActivitiesTitle": "Active Emergencies",
"countryOngoingActivitiesViewAll":"View all Emergencies in this Country",
"countryOngoingActivitiesViewAllInRegion": "View all Emergencies in this Region"
}
}
Loading

0 comments on commit de043b2

Please sign in to comment.