diff --git a/.changeset/slimy-laws-fry.md b/.changeset/slimy-laws-fry.md new file mode 100644 index 000000000..5577ed8ed --- /dev/null +++ b/.changeset/slimy-laws-fry.md @@ -0,0 +1,5 @@ +--- +"go-web-app": patch +--- + +Use `molnix status` to filter surge alerts in [#2208](https://github.com/IFRCGo/go-api/issues/2208) diff --git a/app/src/utils/constants.ts b/app/src/utils/constants.ts index 2ae0fe6f7..8337906c4 100644 --- a/app/src/utils/constants.ts +++ b/app/src/utils/constants.ts @@ -175,6 +175,8 @@ export const COUNTRY_RECORD_TYPE_COUNTRY_OFFICE = 4 satisfies CountryRecordTypeE export const COUNTRY_RECORD_TYPE_REPRESENTATIVE_OFFICE = 5 satisfies CountryRecordTypeEnum; type SurgeAlertTypeEnum = components<'read'>['schemas']['NotificationsSurgeAlertStatusEnumKey']; +export const SURGE_ALERT_STATUS_OPEN = 0 satisfies SurgeAlertTypeEnum; +export const SURGE_ALERT_STATUS_STOOD_DOWN = 1 satisfies SurgeAlertTypeEnum; export const SURGE_ALERT_STATUS_CLOSED = 2 satisfies SurgeAlertTypeEnum; export const NUM_X_AXIS_TICKS_MIN = 3; diff --git a/app/src/views/AllSurgeAlerts/index.tsx b/app/src/views/AllSurgeAlerts/index.tsx index 9b328c098..49824a79e 100644 --- a/app/src/views/AllSurgeAlerts/index.tsx +++ b/app/src/views/AllSurgeAlerts/index.tsx @@ -163,7 +163,7 @@ export function Component() { country: countryFilter, // FIXME: this should come from the useFilterState - ordering: 'status,-opens', + ordering: 'molnix_status,-opens', }, }); @@ -198,7 +198,7 @@ export function Component() { const startDate = isDefined(item.start) ? new Date(item.start) : undefined; if (isDefined(startDate)) { - if (item.status === SURGE_ALERT_STATUS_CLOSED) { + if (item.molnix_status === SURGE_ALERT_STATUS_CLOSED) { return formatDate(startDate); } @@ -213,17 +213,17 @@ export function Component() { { cellRendererClassName: styles.startColumn }, ), createStringColumn( - 'name', + 'message', strings.surgeAlertPosition, (item) => getPositionString(item), ), createStringColumn( - 'keywords', + 'molnix_tags', strings.surgeAlertKeywords, (item) => getMolnixKeywords(item.molnix_tags), ), createLinkColumn( - 'emergency', + 'event', strings.surgeAlertEmergency, (item) => item.event?.name, (item) => ({ @@ -243,9 +243,9 @@ export function Component() { }), ), createStringColumn( - 'status', + 'molnix_status', strings.surgeAlertStatus, - (item) => item.status_display, + (item) => item.molnix_status_display, ), ]), [ diff --git a/app/src/views/EmergencySurge/SurgeTable/index.tsx b/app/src/views/EmergencySurge/SurgeTable/index.tsx index 2d8c234e7..aae75e660 100644 --- a/app/src/views/EmergencySurge/SurgeTable/index.tsx +++ b/app/src/views/EmergencySurge/SurgeTable/index.tsx @@ -19,7 +19,10 @@ import { import Link from '#components/Link'; import useFilterState from '#hooks/useFilterState'; -import { SURGE_ALERT_STATUS_CLOSED } from '#utils/constants'; +import { + SURGE_ALERT_STATUS_OPEN, + SURGE_ALERT_STATUS_STOOD_DOWN, +} from '#utils/constants'; import { createLinkColumn } from '#utils/domain/tableHelpers'; import { type GoApiResponse, @@ -78,11 +81,8 @@ export default function SurgeTable(props: Props) { offset, // FIXME: this should come from the useFilterState - ordering: 'status,-opens', - - // NOTE: following filters are required - is_active: true, - end__gte: now.toISOString(), + ordering: 'molnix_status,-opens', + molnix_status: [`${SURGE_ALERT_STATUS_OPEN}`, `${SURGE_ALERT_STATUS_STOOD_DOWN}`], }, }); @@ -120,10 +120,6 @@ export default function SurgeTable(props: Props) { const startDate = isDefined(item.start) ? new Date(item.start) : undefined; if (isDefined(startDate)) { - if (item.status === SURGE_ALERT_STATUS_CLOSED) { - return formatDate(startDate); - } - const dateStarted = startDate.getTime() < nowTimestamp ? strings.emergencySurgeImmediately : formatDate(startDate); @@ -135,17 +131,17 @@ export default function SurgeTable(props: Props) { { cellRendererClassName: styles.startColumn }, ), createStringColumn( - 'name', + 'message', strings.surgeAlertPosition, (item) => getPositionString(item), ), createStringColumn( - 'keywords', + 'molnix_tags', strings.surgeAlertKeywords, (item) => getMolnixKeywords(item.molnix_tags), ), createLinkColumn( - 'emergency', + 'event', strings.surgeAlertEmergency, (item) => item.event?.name, (item) => ({ @@ -165,9 +161,9 @@ export default function SurgeTable(props: Props) { }), ), createStringColumn( - 'status', + 'molnix_status', strings.surgeAlertStatus, - (item) => item.status_display, + (item) => item.molnix_status_display, ), ]), [ diff --git a/app/src/views/SurgeOverview/SurgeAlertsTable/index.tsx b/app/src/views/SurgeOverview/SurgeAlertsTable/index.tsx index 402e26bc1..0dda27604 100644 --- a/app/src/views/SurgeOverview/SurgeAlertsTable/index.tsx +++ b/app/src/views/SurgeOverview/SurgeAlertsTable/index.tsx @@ -9,7 +9,6 @@ import { useTranslation } from '@ifrc-go/ui/hooks'; import { createDateColumn, createStringColumn, - DEFAULT_INVALID_TEXT, formatDate, getDuration, } from '@ifrc-go/ui/utils'; @@ -20,7 +19,10 @@ import { import Link from '#components/Link'; import useFilterState from '#hooks/useFilterState'; -import { SURGE_ALERT_STATUS_CLOSED } from '#utils/constants'; +import { + SURGE_ALERT_STATUS_OPEN, + SURGE_ALERT_STATUS_STOOD_DOWN, +} from '#utils/constants'; import { createLinkColumn } from '#utils/domain/tableHelpers'; import { type GoApiResponse, @@ -80,11 +82,8 @@ function SurgeAlertsTable() { offset, // FIXME: this should come from the useFilterState - ordering: 'status,-opens', - - // NOTE: following filters are required - is_active: true, - end__gte: today.toISOString(), + ordering: 'molnix_status,-opens', + molnix_status: [`${SURGE_ALERT_STATUS_OPEN}`, `${SURGE_ALERT_STATUS_STOOD_DOWN}`], }, }); @@ -100,7 +99,7 @@ function SurgeAlertsTable() { strings.surgeAlertsTableDuration, (surgeAlert) => { if (isNotDefined(surgeAlert.start) || isNotDefined(surgeAlert.end)) { - return DEFAULT_INVALID_TEXT; + return undefined; } const startDate = new Date(surgeAlert.start); @@ -118,10 +117,6 @@ function SurgeAlertsTable() { ? new Date(surgeAlert.start) : undefined; if (isDefined(startDate)) { - if (surgeAlert.status === SURGE_ALERT_STATUS_CLOSED) { - return formatDate(startDate); - } - const dateStarted = startDate.getTime() < todayTimestamp ? strings.surgeAlertImmediately : formatDate(startDate); @@ -133,41 +128,41 @@ function SurgeAlertsTable() { { cellRendererClassName: styles.startColumn }, ), createStringColumn( - 'name', + 'message', strings.surgeAlertsTablePosition, (surgeAlert) => getPositionString(surgeAlert), ), createStringColumn( - 'keywords', + 'molnix_tags', strings.surgeAlertsTableKeywords, (surgeAlert) => getMolnixKeywords(surgeAlert.molnix_tags), ), createLinkColumn( - 'emergency', + 'event', strings.surgeAlertsTableEmergency, - (surgeAlert) => surgeAlert.event.name, + (surgeAlert) => surgeAlert.event?.name, (surgeAlert) => ({ to: 'emergenciesLayout', urlParams: { - emergencyId: surgeAlert.event.id, + emergencyId: surgeAlert.event?.id, }, }), ), createLinkColumn( 'country', strings.surgeAlertsTableCountry, - (surgeAlert) => surgeAlert.country.name, + (surgeAlert) => surgeAlert.country?.name, (surgeAlert) => ({ to: 'countriesLayout', urlParams: { - countryId: surgeAlert.country.id, + countryId: surgeAlert.country?.id, }, }), ), createStringColumn( - 'status', + 'molnix_status', strings.surgeAlertsTableStatus, - (surgeAlert) => surgeAlert.status_display, + (surgeAlert) => surgeAlert.molnix_status_display, ), ]), [ strings.surgeAlertImmediately,