From ec0d9c11484828d0f12781427201ffff67984a7c Mon Sep 17 00:00:00 2001 From: Rodrigo Fuentes Date: Thu, 9 Sep 2021 08:54:23 -0300 Subject: [PATCH] Api event regions updates --- .../activity/vessels-activity.selectors.ts | 24 ++++++--- .../activity/vessels-activity.utils.ts | 50 ------------------- .../activity/vessels-highlight.worker.ts | 4 +- .../vessel-history/src/types/activity.ts | 13 +---- .../src/utils/region-name-transform.ts | 6 +-- 5 files changed, 21 insertions(+), 76 deletions(-) diff --git a/applications/vessel-history/src/features/vessels/activity/vessels-activity.selectors.ts b/applications/vessel-history/src/features/vessels/activity/vessels-activity.selectors.ts index 1c37b43f93..0554b4c11c 100644 --- a/applications/vessel-history/src/features/vessels/activity/vessels-activity.selectors.ts +++ b/applications/vessel-history/src/features/vessels/activity/vessels-activity.selectors.ts @@ -11,7 +11,7 @@ import { Filters, initialState, selectFilters } from 'features/event-filters/fil import { t } from 'features/i18n/i18n' import { selectActiveTrackDataviews } from 'features/dataviews/dataviews.selectors' import { ActivityEvent, Regions } from 'types/activity' -import { selectEEZs, selectRFMOs } from 'features/regions/regions.selectors' +import { selectEEZs, selectMPAs, selectRFMOs } from 'features/regions/regions.selectors' import { getEEZName } from 'utils/region-name-transform' import { Region } from 'features/regions/regions.slice' import { selectSettings } from 'features/settings/settings.slice' @@ -90,13 +90,13 @@ export const selectEventsForTracks = createSelector( ) export const selectEventsWithRenderingInfo = createSelector( - [selectEventsForTracks, selectEEZs, selectRFMOs], - (eventsForTrack, eezs = [], rfmos = []) => { + [selectEventsForTracks, selectEEZs, selectRFMOs, selectMPAs], + (eventsForTrack, eezs = [], rfmos = [], mpas = []) => { const eventsWithRenderingInfo: RenderedEvent[][] = eventsForTrack.map(({ dataview, data }) => { return (data || []).map((event: ActivityEvent, index) => { // const vesselName = event.vessel.name || event.vessel.id - const regionDescription = getEventRegionDescription(event, eezs, rfmos) + const regionDescription = getEventRegionDescription(event, eezs, rfmos, mpas) let description = '' let descriptionGeneric = '' @@ -194,7 +194,12 @@ export const selectFilteredActivityHighlightEvents = createSelector( } ) -const getEventRegionDescription = (event: ActivityEvent, eezs: Region[], rfmos: Region[]) => { +const getEventRegionDescription = ( + event: ActivityEvent, + eezs: Region[], + rfmos: Region[], + mpas: Region[] +) => { const getRegionNamesByType = (regionType: string, values: string[]) => { switch (regionType) { case 'eez': @@ -211,14 +216,17 @@ const getEventRegionDescription = (event: ActivityEvent, eezs: Region[], rfmos: .filter((value) => value.length > 0) .join(', ') ) - case 'ocean': - return t('event.internationalWaters', 'International Waters') //values.map((ocean) => ocean).join(', ') + case 'mpa': + return values + .map((mpaId) => mpas.find((eez) => eez.id.toString() === mpaId)?.label ?? '') + .filter((value) => value.length > 0) + .join(', ') default: return values.join(', ') } } - const regionsDescription = (['eez', 'rfmo', 'ocean'] as (keyof Regions)[]) + const regionsDescription = (['eez', 'rfmo', 'mpa'] as (keyof Regions)[]) // use only regions with values .filter((regionType) => event?.regions && event?.regions[regionType].length > 0) // take only the first found diff --git a/applications/vessel-history/src/features/vessels/activity/vessels-activity.utils.ts b/applications/vessel-history/src/features/vessels/activity/vessels-activity.utils.ts index 3483f27018..c37ca47220 100644 --- a/applications/vessel-history/src/features/vessels/activity/vessels-activity.utils.ts +++ b/applications/vessel-history/src/features/vessels/activity/vessels-activity.utils.ts @@ -7,53 +7,3 @@ export const groupEvents = (events: ActivityEvent[]) => { export const getEncounterStatus = (event: ActivityEvent): string => { return event.encounter?.authorizationStatus || '' } - - -// const equals = (a: GroupRegions[], b: GroupRegions[]) => -// a.length === b.length && a.every((v, i) => v.type === b[i].type && v.id === b[i].id) - -// export const groupEvents = (events: ActivityEvent[]) => { -// const groups: ActivityEventGroup[] = [] -// events.forEach((event) => { -// const places: GroupRegions[] = [] -// if (event.regions.eez[0]) { -// const place: GroupRegions = { -// id: event.regions.eez[0], -// type: MarineRegionType.eez, -// } -// places.push(place) -// } -// if (event.regions.rfmo[0]) { -// const place: GroupRegions = { -// id: event.regions.rfmo[0], -// type: MarineRegionType.rfmo, -// } -// places.push(place) -// } - -// if ( -// !groups.length || -// groups[groups.length - 1].event_type !== event.type || -// !equals(groups[groups.length - 1].event_places, places) -// ) { -// const newGroup = { -// event_type: event.type, -// event_places: places, -// ocean: event.regions.ocean[0], -// start: event.start, -// end: event.end, -// open: true, -// entries: [event], -// } -// groups.push(newGroup) -// } else if ( -// groups[groups.length - 1].event_type === event.type && -// equals(groups[groups.length - 1].event_places, places) -// ) { -// groups[groups.length - 1].entries.push(event) -// groups[groups.length - 1].end = event.end -// groups[groups.length - 1].open = false -// } -// }) -// return groups -// } diff --git a/applications/vessel-history/src/features/vessels/activity/vessels-highlight.worker.ts b/applications/vessel-history/src/features/vessels/activity/vessels-highlight.worker.ts index 65287822a4..0aa440d73d 100644 --- a/applications/vessel-history/src/features/vessels/activity/vessels-highlight.worker.ts +++ b/applications/vessel-history/src/features/vessels/activity/vessels-highlight.worker.ts @@ -42,9 +42,7 @@ const filterActivityEvent = (event: RenderedEvent, filter: SettingsEvents) => // any rfmo is matched matchAnyRegion(event.regions.rfmo, filter.rfmos) || // any mpa is matched (VERIFY/CONFIRM IF THIS IS CORRECT) - matchAnyRegion(event.regions.mpant, filter.mpas) || - matchAnyRegion(event.regions.mparu, filter.mpas) || - matchAnyRegion(event.regions.mregion, filter.mpas)))) && + matchAnyRegion(event.regions.mpa, filter.mpas)))) && matchAnyValueLonger([event.duration], filter.duration) && matchAnyValueLonger( [ diff --git a/applications/vessel-history/src/types/activity.ts b/applications/vessel-history/src/types/activity.ts index 30bc41d2b2..d535fb48d1 100644 --- a/applications/vessel-history/src/types/activity.ts +++ b/applications/vessel-history/src/types/activity.ts @@ -13,20 +13,9 @@ export interface Position { } export interface Regions { - arg: any[] eez: string[] - fao: string[] - hsp: any[] - kkp: any[] - vme: string[] - ames: string[] rfmo: string[] - mpant: any[] - mparu: any[] - ocean: string[] - other: any[] - mregion: string[] - majorFao: string[] + mpa: any[] } export interface Distances { diff --git a/applications/vessel-history/src/utils/region-name-transform.ts b/applications/vessel-history/src/utils/region-name-transform.ts index fc2add56f1..409fdba562 100644 --- a/applications/vessel-history/src/utils/region-name-transform.ts +++ b/applications/vessel-history/src/utils/region-name-transform.ts @@ -1,5 +1,5 @@ -import { Region } from "features/regions/regions.slice" +import { Region } from 'features/regions/regions.slice' -export const getEEZName = (region: Region | null | undefined, ocean?: string): string => { - return region?.label?.replace('Exclusive Economic Zone', 'EEZ') || ocean || 'unknown' +export const getEEZName = (region: Region | null | undefined): string => { + return region?.label?.replace('Exclusive Economic Zone', 'EEZ') || 'unknown' }