Skip to content

Commit

Permalink
feat: use molnix status to filter surge alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
samshara committed Aug 15, 2024
1 parent 57d6627 commit 47497be
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 43 deletions.
2 changes: 2 additions & 0 deletions app/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions app/src/views/AllSurgeAlerts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export function Component() {
country: countryFilter,

// FIXME: this should come from the useFilterState
ordering: 'status,-opens',
ordering: 'molnix_status,-opens',
},
});

Expand Down Expand Up @@ -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);
}

Expand All @@ -213,17 +213,17 @@ export function Component() {
{ cellRendererClassName: styles.startColumn },
),
createStringColumn<SurgeListItem, TableKey>(
'name',
'message',
strings.surgeAlertPosition,
(item) => getPositionString(item),
),
createStringColumn<SurgeListItem, TableKey>(
'keywords',
'molnix_tags',
strings.surgeAlertKeywords,
(item) => getMolnixKeywords(item.molnix_tags),
),
createLinkColumn<SurgeListItem, TableKey>(
'emergency',
'event',
strings.surgeAlertEmergency,
(item) => item.event?.name,
(item) => ({
Expand All @@ -243,9 +243,9 @@ export function Component() {
}),
),
createStringColumn<SurgeListItem, TableKey>(
'status',
'molnix_status',
strings.surgeAlertStatus,
(item) => item.status_display,
(item) => item.molnix_status_display,
),
]),
[
Expand Down
26 changes: 11 additions & 15 deletions app/src/views/EmergencySurge/SurgeTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}`],
},
});

Expand Down Expand Up @@ -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);
Expand All @@ -135,17 +131,17 @@ export default function SurgeTable(props: Props) {
{ cellRendererClassName: styles.startColumn },
),
createStringColumn<SurgeListItem, number>(
'name',
'message',
strings.surgeAlertPosition,
(item) => getPositionString(item),
),
createStringColumn<SurgeListItem, number>(
'keywords',
'molnix_tags',
strings.surgeAlertKeywords,
(item) => getMolnixKeywords(item.molnix_tags),
),
createLinkColumn<SurgeListItem, number>(
'emergency',
'event',
strings.surgeAlertEmergency,
(item) => item.event?.name,
(item) => ({
Expand All @@ -165,9 +161,9 @@ export default function SurgeTable(props: Props) {
}),
),
createStringColumn<SurgeListItem, number>(
'status',
'molnix_status',
strings.surgeAlertStatus,
(item) => item.status_display,
(item) => item.molnix_status_display,
),
]),
[
Expand Down
37 changes: 16 additions & 21 deletions app/src/views/SurgeOverview/SurgeAlertsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useTranslation } from '@ifrc-go/ui/hooks';
import {
createDateColumn,
createStringColumn,
DEFAULT_INVALID_TEXT,
formatDate,
getDuration,
} from '@ifrc-go/ui/utils';
Expand All @@ -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,
Expand Down Expand Up @@ -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}`],
},
});

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -133,41 +128,41 @@ function SurgeAlertsTable() {
{ cellRendererClassName: styles.startColumn },
),
createStringColumn<SurgeAlertListItem, number>(
'name',
'message',
strings.surgeAlertsTablePosition,
(surgeAlert) => getPositionString(surgeAlert),
),
createStringColumn<SurgeAlertListItem, number>(
'keywords',
'molnix_tags',
strings.surgeAlertsTableKeywords,
(surgeAlert) => getMolnixKeywords(surgeAlert.molnix_tags),
),
createLinkColumn<SurgeAlertListItem, number>(
'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<SurgeAlertListItem, number>(
'country',
strings.surgeAlertsTableCountry,
(surgeAlert) => surgeAlert.country.name,
(surgeAlert) => surgeAlert.country?.name,
(surgeAlert) => ({
to: 'countriesLayout',
urlParams: {
countryId: surgeAlert.country.id,
countryId: surgeAlert.country?.id,
},
}),
),
createStringColumn<SurgeAlertListItem, number>(
'status',
'molnix_status',
strings.surgeAlertsTableStatus,
(surgeAlert) => surgeAlert.status_display,
(surgeAlert) => surgeAlert.molnix_status_display,
),
]), [
strings.surgeAlertImmediately,
Expand Down

0 comments on commit 47497be

Please sign in to comment.