Skip to content

Commit

Permalink
Api event regions updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rdgfuentes committed Sep 9, 2021
1 parent 91df3aa commit ec0d9c1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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':
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
// }
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand Down
13 changes: 1 addition & 12 deletions applications/vessel-history/src/types/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
}

0 comments on commit ec0d9c1

Please sign in to comment.