Skip to content

Commit 865c22a

Browse files
frozenheliumtnagorra
authored andcommitted
Use current month as default value in country seasonal risk month selector
1 parent c323bdf commit 865c22a

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

app/src/utils/constants.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { listToMap } from '@togglecorp/fujs';
2+
13
import { type components } from '#generated/types';
24

35
export const defaultChartMargin = {
@@ -199,3 +201,10 @@ type SupportedByOrganizationType = components<'read'>['schemas']['PerSupportedBy
199201
export const NATIONAL_SOCIETY = 3 satisfies SupportedByOrganizationType;
200202

201203
export const MAX_PAGE_LIMIT = 9999;
204+
205+
export const monthKeyList = Array.from(Array(12).keys());
206+
export const multiMonthSelectDefaultValue = listToMap(
207+
monthKeyList,
208+
(key) => key,
209+
() => false,
210+
);

app/src/views/CountryProfileRiskWatch/CountryRiskSourcesOutput/index.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import { useMemo } from 'react';
1+
import {
2+
Fragment,
3+
useMemo,
4+
} from 'react';
25
import { TextOutput } from '@ifrc-go/ui';
36
import { useTranslation } from '@ifrc-go/ui/hooks';
47
import { resolveToComponent } from '@ifrc-go/ui/utils';
@@ -13,21 +16,25 @@ function CountryRiskSourcesOutput() {
1316
const riskByMonthSources = useMemo(
1417
() => [
1518
{
19+
key: 'inform',
1620
link: 'https://drmkc.jrc.ec.europa.eu/inform-index/INFORM-Risk',
1721
label: strings.inform,
1822
description: strings.sourceINFORM,
1923
},
2024
{
25+
key: 'undrr',
2126
link: 'https://www.undrr.org/',
2227
label: strings.undrr,
2328
description: strings.sourceUNDRR,
2429
},
2530
{
31+
key: 'idmc',
2632
link: 'https://www.internal-displacement.org/',
2733
label: strings.idmc,
2834
description: strings.sourceIDMC,
2935
},
3036
{
37+
key: 'ipc',
3138
link: 'https://www.ipcinfo.org/',
3239
label: strings.ipc,
3340
description: strings.sourceIPC,
@@ -40,8 +47,8 @@ function CountryRiskSourcesOutput() {
4047
<TextOutput
4148
label={strings.source}
4249
value={
43-
riskByMonthSources.map((source) => (
44-
<>
50+
riskByMonthSources.map((source, i) => (
51+
<Fragment key={source.key}>
4552
{resolveToComponent(
4653
source.description,
4754
{
@@ -57,8 +64,8 @@ function CountryRiskSourcesOutput() {
5764
),
5865
},
5966
)}
60-
<br />
61-
</>
67+
{i < (riskByMonthSources.length - 1) && <br />}
68+
</Fragment>
6269
))
6370
}
6471
/>

app/src/views/CountryProfileRiskWatch/MultiMonthSelectInput/index.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ import {
1212
} from '@togglecorp/fujs';
1313
import type { SetValueArg } from '@togglecorp/toggle-form';
1414

15+
import {
16+
monthKeyList,
17+
multiMonthSelectDefaultValue,
18+
} from '#utils/constants';
19+
1520
import i18n from './i18n.json';
1621
import styles from './styles.module.css';
1722

18-
const keyList = Array.from(Array(12).keys());
19-
const defaultValue = listToMap(
20-
keyList,
21-
(key) => key,
22-
() => false,
23-
);
24-
2523
interface Props<NAME> {
2624
className?: string;
2725
value: Record<number, boolean> | undefined;
@@ -87,7 +85,7 @@ function MultiMonthSelectInput<NAME>(props: Props<NAME>) {
8785
) {
8886
// Selecting only single value
8987
return {
90-
...defaultValue,
88+
...multiMonthSelectDefaultValue,
9189
[month]: true,
9290
};
9391
}
@@ -127,7 +125,7 @@ function MultiMonthSelectInput<NAME>(props: Props<NAME>) {
127125
return (
128126
<div className={_cs(styles.multiMonthSelectInput, className)}>
129127
<div className={styles.monthList}>
130-
{keyList.map(
128+
{monthKeyList.map(
131129
(key) => {
132130
const date = new Date();
133131
date.setDate(1);

app/src/views/CountryProfileRiskWatch/index.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import RiskImminentEvents, { type ImminentEventSource } from '#components/domain
1616
import Link from '#components/Link';
1717
import WikiLink from '#components/WikiLink';
1818
import useInputState from '#hooks/useInputState';
19+
import { multiMonthSelectDefaultValue } from '#utils/constants';
1920
import type { CountryOutletContext } from '#utils/outletContext';
2021
import { useRiskRequest } from '#utils/restRequest';
2122

@@ -29,6 +30,10 @@ import RiskTable from './RiskTable';
2930
import i18n from './i18n.json';
3031
import styles from './styles.module.css';
3132

33+
function getCurrentMonth() {
34+
return new Date().getMonth();
35+
}
36+
3237
/** @knipignore */
3338
// eslint-disable-next-line import/prefer-default-export
3439
export function Component() {
@@ -38,7 +43,10 @@ export function Component() {
3843
const [
3944
selectedMonths,
4045
setSelectedMonths,
41-
] = useInputState<Record<number, boolean> | undefined>({ 0: true });
46+
] = useInputState<(typeof multiMonthSelectDefaultValue) | undefined>({
47+
...multiMonthSelectDefaultValue,
48+
[getCurrentMonth()]: true,
49+
});
4250

4351
const {
4452
pending: pendingCountryRiskResponse,

0 commit comments

Comments
 (0)