From f3ab18829f5aafcdeb19dd9d89640c23ef4b6d35 Mon Sep 17 00:00:00 2001 From: ericboucher Date: Wed, 11 Sep 2024 16:50:52 +0200 Subject: [PATCH 01/11] Update utils.ts --- .../AnticipatoryActionPanel/Timeline/utils.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts index d4be1c1f0..b41eef4c9 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts @@ -69,18 +69,24 @@ export function timelineTransform({ filtered.forEach(x => { const key = getColumnKey(x); const val = categoriesMap.get(key); - categoriesMap.set( - key, - val - ? { status: val.status, data: [...val.data, x] } - : { - status: { - category: x.category, - phase: x.phase, - }, - data: [x], - }, - ); + if (val) { + // Prioritize valid elements when multiple indicators overlap on the same date + const existingValidItem = val.data.find( + item => item.isValid && item.date === x.date, + ); + if (!existingValidItem || x.isValid) { + // eslint-disable-next-line fp/no-mutation + val.data = [...val.data.filter(item => item.date !== x.date), x]; + } + } else { + categoriesMap.set(key, { + status: { + category: x.category, + phase: x.phase, + }, + data: [x], + }); + } }); return [win, { months, rows: Object.fromEntries(categoriesMap) }]; }) as [ From ad495ccbf369daf18d2b4033446d0fa74aa8cec2 Mon Sep 17 00:00:00 2001 From: ericboucher Date: Thu, 12 Sep 2024 23:16:56 +0200 Subject: [PATCH 02/11] Prioritize trigger that are valid as ready and set --- .../AnticipatoryActionPanel/HomeTable/index.tsx | 2 +- .../AnticipatoryActionPanel/Timeline/utils.ts | 10 ++++++++-- .../src/context/anticipatoryActionStateSlice/types.ts | 1 + .../src/context/anticipatoryActionStateSlice/utils.ts | 2 ++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.tsx b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.tsx index ab3e32e6e..4f2222f40 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.tsx +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.tsx @@ -214,7 +214,7 @@ function HomeTable({ dialogs }: HomeTableProps) { startIcon: , text: 'Assets', component: 'a', - href: appConfig.anticipatoryActionUrl, + href: `${appConfig.anticipatoryActionUrl}?date=${new Date().toISOString().split('T')[0]}`, download: `${window2Range?.end}-${filename}`, }, { diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts index b41eef4c9..f498c27ae 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts @@ -72,9 +72,15 @@ export function timelineTransform({ if (val) { // Prioritize valid elements when multiple indicators overlap on the same date const existingValidItem = val.data.find( - item => item.isValid && item.date === x.date, + item => + item.isValid && + item.date === x.date && + (item.phase !== 'Ready' || item.willSetBeValid), ); - if (!existingValidItem || x.isValid) { + if ( + !existingValidItem || + (x.isValid && (x.phase !== 'Ready' || x.willSetBeValid)) + ) { // eslint-disable-next-line fp/no-mutation val.data = [...val.data.filter(item => item.date !== x.date), x]; } diff --git a/frontend/src/context/anticipatoryActionStateSlice/types.ts b/frontend/src/context/anticipatoryActionStateSlice/types.ts index ec905f635..73fd702b2 100644 --- a/frontend/src/context/anticipatoryActionStateSlice/types.ts +++ b/frontend/src/context/anticipatoryActionStateSlice/types.ts @@ -32,6 +32,7 @@ export interface AnticipatoryActionDataRow { new: boolean; isValid?: boolean; wasReadyValid?: boolean; + willSetBeValid?: boolean; computedRow?: boolean; // district vulnerability level vulnerability?: Vulnerability; diff --git a/frontend/src/context/anticipatoryActionStateSlice/utils.ts b/frontend/src/context/anticipatoryActionStateSlice/utils.ts index 0a0b8d721..6e6bb3424 100644 --- a/frontend/src/context/anticipatoryActionStateSlice/utils.ts +++ b/frontend/src/context/anticipatoryActionStateSlice/utils.ts @@ -77,6 +77,8 @@ export function parseAndTransformAA(data: any[]) { trigger: Number(x.trigger_ready), date: x.date_ready, isValid: isReadyValid, + willSetBeValid: + isReadyValid && Number(x.prob_set) > Number(x.trigger_set), }; const set = { From 980b7d0b41281384f0209e315825d1cca69e39cd Mon Sep 17 00:00:00 2001 From: ericboucher Date: Thu, 12 Sep 2024 23:54:19 +0200 Subject: [PATCH 03/11] Use isOtherPhaseValid --- .../AnticipatoryActionPanel/Timeline/utils.ts | 44 +++++++++++++------ .../anticipatoryActionStateSlice/types.ts | 3 +- .../anticipatoryActionStateSlice/utils.ts | 4 +- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts index f498c27ae..0f35b3d28 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/utils.ts @@ -70,20 +70,36 @@ export function timelineTransform({ const key = getColumnKey(x); const val = categoriesMap.get(key); if (val) { - // Prioritize valid elements when multiple indicators overlap on the same date - const existingValidItem = val.data.find( - item => - item.isValid && - item.date === x.date && - (item.phase !== 'Ready' || item.willSetBeValid), - ); - if ( - !existingValidItem || - (x.isValid && (x.phase !== 'Ready' || x.willSetBeValid)) - ) { - // eslint-disable-next-line fp/no-mutation - val.data = [...val.data.filter(item => item.date !== x.date), x]; - } + // Sort the new data based on validity + // eslint-disable-next-line fp/no-mutating-methods + const sortedData = [ + x, + ...val.data.filter(item => item.date === x.date), + ].sort((a, b) => { + if (a.isValid && a.isOtherPhaseValid) { + return -1; + } + if (b.isValid && b.isOtherPhaseValid) { + return 1; + } + if (a.isValid) { + return -1; + } + if (b.isValid) { + return 1; + } + return 0; + }); + + // Keep only the highest priority item for this date + const highestPriorityItem = sortedData[0]; + + // Update the data array + // eslint-disable-next-line fp/no-mutation + val.data = [ + ...val.data.filter(item => item.date !== x.date), + highestPriorityItem, + ]; } else { categoriesMap.set(key, { status: { diff --git a/frontend/src/context/anticipatoryActionStateSlice/types.ts b/frontend/src/context/anticipatoryActionStateSlice/types.ts index 73fd702b2..f69413035 100644 --- a/frontend/src/context/anticipatoryActionStateSlice/types.ts +++ b/frontend/src/context/anticipatoryActionStateSlice/types.ts @@ -31,8 +31,7 @@ export interface AnticipatoryActionDataRow { season: string; new: boolean; isValid?: boolean; - wasReadyValid?: boolean; - willSetBeValid?: boolean; + isOtherPhaseValid?: boolean; computedRow?: boolean; // district vulnerability level vulnerability?: Vulnerability; diff --git a/frontend/src/context/anticipatoryActionStateSlice/utils.ts b/frontend/src/context/anticipatoryActionStateSlice/utils.ts index 6e6bb3424..3954eda4f 100644 --- a/frontend/src/context/anticipatoryActionStateSlice/utils.ts +++ b/frontend/src/context/anticipatoryActionStateSlice/utils.ts @@ -77,7 +77,7 @@ export function parseAndTransformAA(data: any[]) { trigger: Number(x.trigger_ready), date: x.date_ready, isValid: isReadyValid, - willSetBeValid: + isOtherPhaseValid: isReadyValid && Number(x.prob_set) > Number(x.trigger_set), }; @@ -87,7 +87,7 @@ export function parseAndTransformAA(data: any[]) { trigger: Number(x.trigger_set), date: x.date_set, isValid: ready.isValid && Number(x.prob_set) > Number(x.trigger_set), - wasReadyValid: isReadyValid, + isOtherPhaseValid: isReadyValid, }; const result = []; From d9568f0690f7a3858dea98c52b1581b282b032bb Mon Sep 17 00:00:00 2001 From: ericboucher Date: Thu, 12 Sep 2024 23:54:47 +0200 Subject: [PATCH 04/11] Adjust index font size based on character count --- .../Timeline/index.tsx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.tsx b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.tsx index ad2ffc0d8..d09244b8f 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.tsx +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.tsx @@ -33,6 +33,16 @@ function TimelineItem({ item }: TimelineItemProps) { const color = getAAColor(item.category, item.isValid ? item.phase : 'na'); + // Calculate font size based on character count + const calculateFontSize = (text: string) => { + const baseSize = 0.8; // rem + const minSize = 0.2; // rem + const charCount = text.length; + return Math.max(baseSize - (charCount - 6) * 0.05, minSize); + }; + + const fontSize = calculateFontSize(item.index); + return (
{item.probability} @@ -52,7 +62,14 @@ function TimelineItem({ item }: TimelineItemProps) { width: `${item.trigger * 100}%`, }} /> - {item.index} + + {item.index} +
); } @@ -78,6 +95,10 @@ const useTimelineItemStyles = makeStyles(() => backgroundColor: 'black', borderRadius: '0 2px 2px 0', }, + indexText: { + whiteSpace: 'nowrap', + lineHeight: '1.2rem', + }, }), ); From 45e3a524cf2a7ab057f726b9fcaa11f83bd2fd1d Mon Sep 17 00:00:00 2001 From: ericboucher Date: Thu, 12 Sep 2024 23:56:15 +0200 Subject: [PATCH 05/11] Update tests for isOtherPhaseValid --- .../DistrictView/index.test.tsx | 6 +++--- .../Timeline/index.test.tsx | 10 +++++----- .../AnticipatoryActionPanel/test.utils.ts | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/DistrictView/index.test.tsx b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/DistrictView/index.test.tsx index c376475b9..87c1e4f82 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/DistrictView/index.test.tsx +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/DistrictView/index.test.tsx @@ -112,7 +112,7 @@ const out = { probability: 0.12, trigger: 0.3, type: 'SPI', - wasReadyValid: false, + isOtherPhaseValid: false, window: 'Window 1', }, { @@ -142,7 +142,7 @@ const out = { date: '2023-11-01', season: '2023-24', isValid: true, - wasReadyValid: true, + isOtherPhaseValid: true, }, ], '40': [ @@ -187,7 +187,7 @@ const out = { date: '2023-11-01', season: '2023-24', isValid: false, - wasReadyValid: true, + isOtherPhaseValid: true, }, ], }, diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.test.tsx b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.test.tsx index 8171618e5..4cd2b6a56 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.test.tsx +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.test.tsx @@ -146,7 +146,7 @@ const out = { date: '2023-09-01', season: '2023-24', isValid: false, - wasReadyValid: false, + isOtherPhaseValid: false, }, { category: 'Mild', @@ -161,7 +161,7 @@ const out = { date: '2023-10-01', season: '2023-24', isValid: false, - wasReadyValid: false, + isOtherPhaseValid: false, }, { category: 'Mild', @@ -176,7 +176,7 @@ const out = { date: '2023-11-01', season: '2023-24', isValid: true, - wasReadyValid: true, + isOtherPhaseValid: true, }, ], }, @@ -235,7 +235,7 @@ const out = { date: '2023-10-01', season: '2023-24', isValid: false, - wasReadyValid: true, + isOtherPhaseValid: true, }, { category: 'Moderate', @@ -250,7 +250,7 @@ const out = { date: '2023-11-01', season: '2023-24', isValid: false, - wasReadyValid: true, + isOtherPhaseValid: true, }, ], }, diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/test.utils.ts b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/test.utils.ts index cdc0c8022..6d72646e2 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/test.utils.ts +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/test.utils.ts @@ -155,7 +155,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-12-01', season: '2023-24', isValid: false, - wasReadyValid: false, + isOtherPhaseValid: false, }, ], Changara: [ @@ -214,7 +214,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-09-01', season: '2023-24', isValid: false, - wasReadyValid: false, + isOtherPhaseValid: false, }, { category: 'Mild', @@ -257,7 +257,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-10-01', season: '2023-24', isValid: false, - wasReadyValid: false, + isOtherPhaseValid: false, }, { category: 'Moderate', @@ -272,7 +272,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-10-01', season: '2023-24', isValid: false, - wasReadyValid: true, + isOtherPhaseValid: true, }, { category: 'Mild', @@ -287,7 +287,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-11-01', season: '2023-24', isValid: true, - wasReadyValid: true, + isOtherPhaseValid: true, }, { category: 'Moderate', @@ -302,7 +302,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-11-01', season: '2023-24', isValid: false, - wasReadyValid: true, + isOtherPhaseValid: true, }, { category: 'Mild', @@ -318,7 +318,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { season: '2023-24', isValid: true, computedRow: true, - wasReadyValid: true, + isOtherPhaseValid: true, }, ], }, From f3341a18ce14df2a23f752a621c9e4668bce452a Mon Sep 17 00:00:00 2001 From: ericboucher Date: Fri, 13 Sep 2024 11:29:15 +0200 Subject: [PATCH 06/11] Fix tests --- .../DistrictView/index.test.tsx | 7 ++++- .../__snapshots__/index.test.tsx.snap | 2 +- .../__snapshots__/index.test.tsx.snap | 30 ++++++++++++------- .../Timeline/index.test.tsx | 5 ++++ .../AnticipatoryActionPanel/test.utils.ts | 6 ++++ .../MapView/__snapshots__/index.test.tsx.snap | 2 +- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/DistrictView/index.test.tsx b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/DistrictView/index.test.tsx index 87c1e4f82..a5bb092fb 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/DistrictView/index.test.tsx +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/DistrictView/index.test.tsx @@ -79,6 +79,7 @@ const out = { district: 'Changara', index: 'SPI DJF', isValid: false, + isOtherPhaseValid: false, new: false, phase: 'na', probability: 0.16, @@ -93,6 +94,7 @@ const out = { district: 'Changara', index: 'SPI DJF', isValid: false, + isOtherPhaseValid: false, new: false, phase: 'na', probability: 0.22, @@ -107,12 +109,12 @@ const out = { district: 'Changara', index: 'SPI DJF', isValid: false, + isOtherPhaseValid: false, new: false, phase: 'na', probability: 0.12, trigger: 0.3, type: 'SPI', - isOtherPhaseValid: false, window: 'Window 1', }, { @@ -128,6 +130,7 @@ const out = { date: '2023-10-01', season: '2023-24', isValid: true, + isOtherPhaseValid: true, }, { category: 'Mild', @@ -159,6 +162,7 @@ const out = { date: '2023-09-01', season: '2023-24', isValid: true, + isOtherPhaseValid: false, }, { category: 'Moderate', @@ -173,6 +177,7 @@ const out = { date: '2023-10-01', season: '2023-24', isValid: true, + isOtherPhaseValid: false, }, { category: 'Moderate', diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap index 7e708892b..d1b5c06c6 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap @@ -331,7 +331,7 @@ exports[`renders as expected 1`] = ` component="a" download="2023-12-01-aa_probabilities_triggers_moz.csv" fullwidth="true" - href="https://data.earthobservation.vam.wfp.org/public-share/aa/aa_probabilities_triggers_moz.csv" + href="https://data.earthobservation.vam.wfp.org/public-share/aa/aa_probabilities_triggers_moz.csv?date=2024-09-13" starticon="[object Object]" variant="outlined" > diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/__snapshots__/index.test.tsx.snap b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/__snapshots__/index.test.tsx.snap index f5e968ab6..b405089a7 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/__snapshots__/index.test.tsx.snap +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/__snapshots__/index.test.tsx.snap @@ -121,7 +121,8 @@ exports[`renders as expected 1`] = ` style="width: 26%;" /> SPI DJF @@ -153,7 +154,8 @@ exports[`renders as expected 1`] = ` style="width: 30%;" /> SPI DJF @@ -218,7 +220,8 @@ exports[`renders as expected 1`] = ` style="width: 10%;" /> SPI DJF @@ -250,7 +253,8 @@ exports[`renders as expected 1`] = ` style="width: 20%;" /> SPI DJF @@ -318,7 +322,8 @@ exports[`renders as expected 1`] = ` style="width: 30%;" /> SPI DJF @@ -350,7 +355,8 @@ exports[`renders as expected 1`] = ` style="width: 33%;" /> SPI DJF @@ -382,7 +388,8 @@ exports[`renders as expected 1`] = ` style="width: 25%;" /> SPI DJF @@ -444,7 +451,8 @@ exports[`renders as expected 1`] = ` style="width: 17%;" /> SPI DJF @@ -476,7 +484,8 @@ exports[`renders as expected 1`] = ` style="width: 30%;" /> SPI DJF @@ -508,7 +517,8 @@ exports[`renders as expected 1`] = ` style="width: 20%;" /> SPI DJF diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.test.tsx b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.test.tsx index 4cd2b6a56..a95f67598 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.test.tsx +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/Timeline/index.test.tsx @@ -96,6 +96,7 @@ const out = { date: '2023-08-01', season: '2023-24', isValid: false, + isOtherPhaseValid: false, }, { category: 'Mild', @@ -110,6 +111,7 @@ const out = { date: '2023-09-01', season: '2023-24', isValid: false, + isOtherPhaseValid: false, }, { category: 'Mild', @@ -124,6 +126,7 @@ const out = { date: '2023-10-01', season: '2023-24', isValid: true, + isOtherPhaseValid: true, }, ], }, @@ -199,6 +202,7 @@ const out = { date: '2023-09-01', season: '2023-24', isValid: true, + isOtherPhaseValid: false, }, { category: 'Moderate', @@ -213,6 +217,7 @@ const out = { date: '2023-10-01', season: '2023-24', isValid: true, + isOtherPhaseValid: false, }, ], }, diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/test.utils.ts b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/test.utils.ts index 6d72646e2..0439df03c 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/test.utils.ts +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/test.utils.ts @@ -141,6 +141,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-11-01', season: '2023-24', isValid: false, + isOtherPhaseValid: false, }, { category: 'Moderate', @@ -172,6 +173,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-08-01', season: '2023-24', isValid: false, + isOtherPhaseValid: false, }, { category: 'Mild', @@ -186,6 +188,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-09-01', season: '2023-24', isValid: false, + isOtherPhaseValid: false, }, { category: 'Moderate', @@ -200,6 +203,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-09-01', season: '2023-24', isValid: true, + isOtherPhaseValid: false, }, { category: 'Mild', @@ -229,6 +233,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-10-01', season: '2023-24', isValid: true, + isOtherPhaseValid: true, }, { category: 'Moderate', @@ -243,6 +248,7 @@ export const mockAAData: AnticipatoryActionState['data'] = { date: '2023-10-01', season: '2023-24', isValid: true, + isOtherPhaseValid: false, }, { category: 'Mild', diff --git a/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap b/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap index 945ea39ae..9b9242e96 100644 --- a/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap +++ b/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap @@ -1312,7 +1312,7 @@ exports[`renders as expected 1`] = ` component="a" download="undefined-aa_probabilities_triggers_moz.csv" fullwidth="true" - href="https://data.earthobservation.vam.wfp.org/public-share/aa/aa_probabilities_triggers_moz.csv" + href="https://data.earthobservation.vam.wfp.org/public-share/aa/aa_probabilities_triggers_moz.csv?date=2024-09-13" starticon="[object Object]" variant="outlined" > From 5f5312c5b22df6356343edf7bd80c718144fa785 Mon Sep 17 00:00:00 2001 From: ericboucher Date: Fri, 20 Sep 2024 16:20:14 +0200 Subject: [PATCH 07/11] Fix moving date snapshots --- .../__snapshots__/index.test.tsx.snap | 4 +-- .../HomeTable/index.test.tsx | 31 +++++++++++++------ .../MapView/__snapshots__/index.test.tsx.snap | 4 +-- .../src/components/MapView/index.test.tsx | 27 +++++++++++----- 4 files changed, 46 insertions(+), 20 deletions(-) diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap index d1b5c06c6..e8ca113b1 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`renders as expected 1`] = ` +exports[`HomeTable renders as expected 1`] = `
diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.test.tsx b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.test.tsx index 95b269998..788b0e429 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.test.tsx +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.test.tsx @@ -37,13 +37,26 @@ const store = mockStore({ }, }); -test('renders as expected', () => { - const { container } = render( - - - - - , - ); - expect(container).toMatchSnapshot(); +describe('HomeTable', () => { + beforeAll(() => { + // Mock the date to a specific value + jest.useFakeTimers(); + jest.setSystemTime(new Date('2024-12-01')); + }); + + afterAll(() => { + // Restore the real timer + jest.useRealTimers(); + }); + + test('renders as expected', () => { + const { container } = render( + + + + + , + ); + expect(container).toMatchSnapshot(); + }); }); diff --git a/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap b/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap index 9b9242e96..f19186867 100644 --- a/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap +++ b/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`renders as expected 1`] = ` +exports[`MapView renders as expected 1`] = `
diff --git a/frontend/src/components/MapView/index.test.tsx b/frontend/src/components/MapView/index.test.tsx index 68e6fea8b..044013613 100644 --- a/frontend/src/components/MapView/index.test.tsx +++ b/frontend/src/components/MapView/index.test.tsx @@ -21,11 +21,24 @@ jest.mock('react-router-dom', () => ({ }), })); -test('renders as expected', () => { - const { container } = render( - - {}} /> - , - ); - expect(container).toMatchSnapshot(); +describe('MapView', () => { + beforeAll(() => { + // Mock the date to a specific value + jest.useFakeTimers(); + jest.setSystemTime(new Date('2024-12-01')); + }); + + afterAll(() => { + // Restore the real timer + jest.useRealTimers(); + }); + + test('renders as expected', () => { + const { container } = render( + + {}} /> + , + ); + expect(container).toMatchSnapshot(); + }); }); From f813253247fa94551a40c358b4e20ed3307ac50f Mon Sep 17 00:00:00 2001 From: ericboucher Date: Fri, 20 Sep 2024 16:58:48 +0200 Subject: [PATCH 08/11] Filter empty date --- frontend/src/context/anticipatoryActionStateSlice/index.ts | 2 +- frontend/src/context/anticipatoryActionStateSlice/utils.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frontend/src/context/anticipatoryActionStateSlice/index.ts b/frontend/src/context/anticipatoryActionStateSlice/index.ts index d46d1b038..3b9561fe8 100644 --- a/frontend/src/context/anticipatoryActionStateSlice/index.ts +++ b/frontend/src/context/anticipatoryActionStateSlice/index.ts @@ -57,7 +57,7 @@ export const loadAAData = createAsyncThunk< undefined, CreateAsyncThunkTypes >('anticipatoryActionState/loadAAData', async () => { - const url = `${appConfig.anticipatoryActionUrl}?_=${new Date().toDateString()}`; + const url = `${appConfig.anticipatoryActionUrl}?date=${new Date().toDateString()}`; return new Promise((resolve, reject) => { Papa.parse(url, { diff --git a/frontend/src/context/anticipatoryActionStateSlice/utils.ts b/frontend/src/context/anticipatoryActionStateSlice/utils.ts index 3954eda4f..38d8daa6f 100644 --- a/frontend/src/context/anticipatoryActionStateSlice/utils.ts +++ b/frontend/src/context/anticipatoryActionStateSlice/utils.ts @@ -116,7 +116,9 @@ export function parseAndTransformAA(data: any[]) { ); const windowData = AAWindowKeys.map(windowKey => { - const filtered = parsed.filter(x => x.window === windowKey); + const filtered = parsed.filter(x => x.window === windowKey && x.date); + + console.log({ filtered }); // eslint-disable-next-line fp/no-mutating-methods const dates = [ From 4f87411d4272ae1ae9b7a30eed76be74c206adf5 Mon Sep 17 00:00:00 2001 From: ericboucher Date: Fri, 20 Sep 2024 17:07:01 +0200 Subject: [PATCH 09/11] Update utils.ts --- frontend/src/context/anticipatoryActionStateSlice/utils.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/src/context/anticipatoryActionStateSlice/utils.ts b/frontend/src/context/anticipatoryActionStateSlice/utils.ts index 38d8daa6f..8b4e0db02 100644 --- a/frontend/src/context/anticipatoryActionStateSlice/utils.ts +++ b/frontend/src/context/anticipatoryActionStateSlice/utils.ts @@ -118,8 +118,6 @@ export function parseAndTransformAA(data: any[]) { const windowData = AAWindowKeys.map(windowKey => { const filtered = parsed.filter(x => x.window === windowKey && x.date); - console.log({ filtered }); - // eslint-disable-next-line fp/no-mutating-methods const dates = [ ...new Set(filtered.map(x => new Date(x.date).getTime())), From 1e4b44c5f7071d8e08516ff24a4c4c6121dceab7 Mon Sep 17 00:00:00 2001 From: ericboucher Date: Fri, 20 Sep 2024 17:15:38 +0200 Subject: [PATCH 10/11] Reset aa URL every minute --- .../LeftPanel/AnticipatoryActionPanel/HomeTable/index.tsx | 3 ++- frontend/src/context/anticipatoryActionStateSlice/index.ts | 3 ++- frontend/src/utils/date-utils.ts | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.tsx b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.tsx index 4f2222f40..06d0b173c 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.tsx +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/index.tsx @@ -25,6 +25,7 @@ import { import { GetApp, BarChartOutlined } from '@material-ui/icons'; import { appConfig, safeCountry } from 'config'; import { PanelSize } from 'config/types'; +import { getCurrentDateTimeForUrl } from 'utils/date-utils'; import { AADataSeverityOrder, getAAIcon, useAACommonStyles } from '../utils'; interface AreaTagProps { @@ -214,7 +215,7 @@ function HomeTable({ dialogs }: HomeTableProps) { startIcon: , text: 'Assets', component: 'a', - href: `${appConfig.anticipatoryActionUrl}?date=${new Date().toISOString().split('T')[0]}`, + href: `${appConfig.anticipatoryActionUrl}?date=${getCurrentDateTimeForUrl()}`, download: `${window2Range?.end}-${filename}`, }, { diff --git a/frontend/src/context/anticipatoryActionStateSlice/index.ts b/frontend/src/context/anticipatoryActionStateSlice/index.ts index 3b9561fe8..7e160c34c 100644 --- a/frontend/src/context/anticipatoryActionStateSlice/index.ts +++ b/frontend/src/context/anticipatoryActionStateSlice/index.ts @@ -3,6 +3,7 @@ import Papa from 'papaparse'; import { DateItem } from 'config/types'; import { appConfig } from 'config'; import { AAWindowKeys } from 'config/utils'; +import { getCurrentDateTimeForUrl } from 'utils/date-utils'; import type { CreateAsyncThunkTypes, RootState } from '../store'; import { AACategoryType, @@ -57,7 +58,7 @@ export const loadAAData = createAsyncThunk< undefined, CreateAsyncThunkTypes >('anticipatoryActionState/loadAAData', async () => { - const url = `${appConfig.anticipatoryActionUrl}?date=${new Date().toDateString()}`; + const url = `${appConfig.anticipatoryActionUrl}?date=${getCurrentDateTimeForUrl()}`; return new Promise((resolve, reject) => { Papa.parse(url, { diff --git a/frontend/src/utils/date-utils.ts b/frontend/src/utils/date-utils.ts index 8f5055ac5..95d9229c8 100644 --- a/frontend/src/utils/date-utils.ts +++ b/frontend/src/utils/date-utils.ts @@ -8,6 +8,9 @@ export interface StartEndDate { const millisecondsInADay = 24 * 60 * 60 * 1000; +export const getCurrentDateTimeForUrl = (): string => + new Date().toISOString().slice(0, 16).replace(/[T:]/g, '-'); + export const dateWithoutTime = (date: number | Date): number => { const cleanDate = date instanceof Date ? date.getTime() : date; return cleanDate - (cleanDate % millisecondsInADay); From 44eb45def359574f96e0c44926bbb7cfd46b004d Mon Sep 17 00:00:00 2001 From: ericboucher Date: Mon, 23 Sep 2024 19:22:45 +0200 Subject: [PATCH 11/11] Update snapshots --- .../HomeTable/__snapshots__/index.test.tsx.snap | 2 +- .../src/components/MapView/__snapshots__/index.test.tsx.snap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap index e8ca113b1..5a594c7ad 100644 --- a/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap +++ b/frontend/src/components/MapView/LeftPanel/AnticipatoryActionPanel/HomeTable/__snapshots__/index.test.tsx.snap @@ -331,7 +331,7 @@ exports[`HomeTable renders as expected 1`] = ` component="a" download="2023-12-01-aa_probabilities_triggers_moz.csv" fullwidth="true" - href="https://data.earthobservation.vam.wfp.org/public-share/aa/aa_probabilities_triggers_moz.csv?date=2024-12-01" + href="https://data.earthobservation.vam.wfp.org/public-share/aa/aa_probabilities_triggers_moz.csv?date=2024-12-01-00-00" starticon="[object Object]" variant="outlined" > diff --git a/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap b/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap index f19186867..21a04fe6b 100644 --- a/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap +++ b/frontend/src/components/MapView/__snapshots__/index.test.tsx.snap @@ -1312,7 +1312,7 @@ exports[`MapView renders as expected 1`] = ` component="a" download="undefined-aa_probabilities_triggers_moz.csv" fullwidth="true" - href="https://data.earthobservation.vam.wfp.org/public-share/aa/aa_probabilities_triggers_moz.csv?date=2024-12-01" + href="https://data.earthobservation.vam.wfp.org/public-share/aa/aa_probabilities_triggers_moz.csv?date=2024-12-01-00-00" starticon="[object Object]" variant="outlined" >