Skip to content

Commit

Permalink
Fix missing parameter in administrative layer style function
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Oct 7, 2021
1 parent 70eea1e commit 84510e7
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 58 deletions.
2 changes: 1 addition & 1 deletion frontend/cypress/integration/layers_sidebar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ context('LayersSidebar', () => {
cy.wait(500)

// Then
cy.get('.ol-layer').eq(0).toMatchImageSnapshot({
cy.get('.administrative').eq(0).toMatchImageSnapshot({
clip: { x: 400, y: 0, width: 200, height: 200 }
})

Expand Down
36 changes: 0 additions & 36 deletions frontend/src/domain/entities/layers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { getAdministrativeSubZonesFromAPI } from '../../api/fetch'

export const layersGroups = {
TWELVE_FORTY_ONE: {
code: 'twelve_forty_one',
Expand Down Expand Up @@ -382,40 +380,6 @@ export const baseLayers = {
}
}

export const getZonesAndSubZonesPromises = () => {
return Object.keys(Layers)
.map(layer => Layers[layer])
.filter(layer => layer.type === layersType.ADMINISTRATIVE)
.filter(layer => layer.isIntersectable)
.map(zone => {
if (zone.containsMultipleZones) {
return getAdministrativeSubZonesFromAPI(zone.code).then(subZonesFeatures => {
return subZonesFeatures.features.map(subZone => {
return {
group: zone.name,
groupCode: zone.code,
label: subZone.properties[zone.subZoneFieldKey] ? subZone.properties[zone.subZoneFieldKey]?.replace(/[_]/g, ' ') : 'Aucun nom',
name: subZone.properties[zone.subZoneFieldKey] ? subZone.properties[zone.subZoneFieldKey]?.replace(/[_]/g, ' ') : 'Aucun nom',
code: subZone.id,
value: subZone.id,
isSubZone: true
}
})
}).catch(error => {
console.warn(error)
})
}

const nextZone = { ...zone }

nextZone.label = zone.name
nextZone.value = zone.code
nextZone.group = zone.group ? zone.group.name : 'Administratives'

return nextZone
})
}

function removeMiscellaneousGears (layerGearsArray) {
return layerGearsArray
.filter(gearCode => gearCode !== 'MIS')
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/domain/use_cases/getZonesAndSubZonesPromises.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { getAdministrativeSubZonesFromAPI } from '../../api/fetch'
import Layers, { layersType } from '../entities/layers'

export const getZonesAndSubZonesPromises = () => {
return Object.keys(Layers)
.map(layer => Layers[layer])
.filter(layer => layer.type === layersType.ADMINISTRATIVE)
.filter(layer => layer.isIntersectable)
.map(zone => {
if (zone.containsMultipleZones) {
return getAdministrativeSubZonesFromAPI(zone.code).then(subZonesFeatures => {
return subZonesFeatures.features.map(subZone => {
return {
group: zone.name,
groupCode: zone.code,
label: subZone.properties[zone.subZoneFieldKey] ? subZone.properties[zone.subZoneFieldKey]?.replace(/[_]/g, ' ') : 'Aucun nom',
name: subZone.properties[zone.subZoneFieldKey] ? subZone.properties[zone.subZoneFieldKey]?.replace(/[_]/g, ' ') : 'Aucun nom',
code: subZone.id,
value: subZone.id,
isSubZone: true
}
})
}).catch(error => {
console.warn(error)
})
}

const nextZone = { ...zone }

nextZone.label = zone.name
nextZone.value = zone.code
nextZone.group = zone.group ? zone.group.name : 'Administratives'

return nextZone
})
}
4 changes: 2 additions & 2 deletions frontend/src/domain/use_cases/showAdministrativeLayer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import layer from '../shared_slices/Layer'
import { getVectorLayerStyle } from '../../layers/styles/vectorLayer.style'
import { getAdministrativeAndRegulatoryLayersStyle } from '../../layers/styles/administrativeAndRegulatoryLayers.style'
import VectorSource from 'ol/source/Vector'
import GeoJSON from 'ol/format/GeoJSON'
import { OPENLAYERS_PROJECTION, WSG84_PROJECTION } from '../entities/map'
Expand Down Expand Up @@ -46,7 +46,7 @@ const getVectorLayer = (type, zone) => {
updateWhileAnimating: true,
updateWhileInteracting: true,
style: feature => {
return [getVectorLayerStyle(type)(feature)]
return [getAdministrativeAndRegulatoryLayersStyle(type)(feature)]
},
declutter: true
})
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/domain/use_cases/showRegulatoryLayer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Layers, { getGearCategory } from '../entities/layers'
import layer from '../shared_slices/Layer'
import { getVectorLayerStyle } from '../../layers/styles/vectorLayer.style'
import { getAdministrativeAndRegulatoryLayersStyle } from '../../layers/styles/administrativeAndRegulatoryLayers.style'
import VectorSource from 'ol/source/Vector'
import GeoJSON from 'ol/format/GeoJSON'
import { OPENLAYERS_PROJECTION, WSG84_PROJECTION } from '../entities/map'
Expand Down Expand Up @@ -58,7 +58,7 @@ const getVectorLayer = (dispatch, getState) => (layerToShow, hash, gearCategory)
source: getRegulatoryVectorSource(dispatch, getState)(layerToShow),
className: 'regulatory',
style: feature => {
return [getVectorLayerStyle(Layers.REGULATORY.code)(feature, hash, gearCategory)]
return [getAdministrativeAndRegulatoryLayersStyle(Layers.REGULATORY.code)(feature, hash, gearCategory)]
}
})
layer.name = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ const AdministrativeLayers = props => {
}
}, [hideLayersListWhenSearching])

const callShowAdministrativeZone = namespace => (type, zone) => {
const callShowAdministrativeLayer = namespace => (type, zone) => {
dispatch(showAdministrativeLayer({
type: type,
zone: zone,
namespace
}))
}

const callHideAdministrativeZone = namespace => (type, zone) => {
const callHideAdministrativeLayer = namespace => (type, zone) => {
dispatch(hideLayer({
type: type,
zone: zone,
Expand Down Expand Up @@ -98,8 +98,8 @@ const AdministrativeLayers = props => {
key={layers[0].code}
isShownOnInit={showedLayers.some(layer_ => layer_.type === layers[0].code)}
layer={layers[0]}
callShowAdministrativeZone={callShowAdministrativeZone(namespace)}
callHideAdministrativeZone={callHideAdministrativeZone(namespace)}
callShowAdministrativeZone={callShowAdministrativeLayer(namespace)}
callHideAdministrativeZone={callHideAdministrativeLayer(namespace)}
/>
</ListItem>
} else {
Expand All @@ -108,8 +108,8 @@ const AdministrativeLayers = props => {
isLastItem={zones.length === index + 1}
layers={layers}
showedLayers={showedLayers}
callShowAdministrativeZone={callShowAdministrativeZone(namespace)}
callHideAdministrativeZone={callHideAdministrativeZone(namespace)}
callShowAdministrativeZone={callShowAdministrativeLayer(namespace)}
callHideAdministrativeZone={callHideAdministrativeLayer(namespace)}
/>
</ListItem>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useState } from 'react'
import styled from 'styled-components'
import RegulatoryLayerZone from './RegulatoryLayerZone'
import { getHash } from '../../../utils'
import { getVectorLayerStyle } from '../../../layers/styles/vectorLayer.style'
import { getAdministrativeAndRegulatoryLayersStyle } from '../../../layers/styles/administrativeAndRegulatoryLayers.style'
import Layers, { getGearCategory } from '../../../domain/entities/layers'
import { COLORS } from '../../../constants/constants'
import { useSelector } from 'react-redux'
Expand Down Expand Up @@ -79,7 +79,7 @@ const RegulatoryLayerTopic = props => {
if (regulatoryZone.zone && regulatoryZone.topic && regulatoryZone.gears && gears) {
const hash = getHash(`${regulatoryZone.topic}:${regulatoryZone.zone}`)
const gearCategory = getGearCategory(regulatoryZone.gears, gears)
vectorLayerStyle = getVectorLayerStyle(Layers.REGULATORY.code)(null, hash, gearCategory)
vectorLayerStyle = getAdministrativeAndRegulatoryLayersStyle(Layers.REGULATORY.code)(null, hash, gearCategory)
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'
import styled, { css } from 'styled-components'
import { COLORS } from '../../../../constants/constants'
import { getHash } from '../../../../utils'
import { getVectorLayerStyle } from '../../../../layers/styles/vectorLayer.style'
import { getAdministrativeAndRegulatoryLayersStyle } from '../../../../layers/styles/administrativeAndRegulatoryLayers.style'
import Layers, { getGearCategory } from '../../../../domain/entities/layers'
import { useDispatch, useSelector } from 'react-redux'
import Checkbox from 'rsuite/lib/Checkbox'
Expand Down Expand Up @@ -85,7 +85,7 @@ const RegulatoryLayerSearchResultZone = props => {
const hash = getHash(`${regulatoryZone.topic}:${regulatoryZone.zone}`)
const gearCategory = getGearCategory(regulatoryZone.gears, gears)

setZoneStyle(getVectorLayerStyle(Layers.REGULATORY.code)(null, hash, gearCategory))
setZoneStyle(getAdministrativeAndRegulatoryLayersStyle(Layers.REGULATORY.code)(null, hash, gearCategory))
}
}, [regulatoryZone, isOpen])

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/features/map/controls/LayerDetailsBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect, useState } from 'react'
import styled from 'styled-components'
import { COLORS } from '../../../constants/constants'
import { getHash } from '../../../utils'
import { getVectorLayerStyle } from '../../../layers/styles/vectorLayer.style'
import { getAdministrativeAndRegulatoryLayersStyle } from '../../../layers/styles/administrativeAndRegulatoryLayers.style'
import Layers, { getGearCategory } from '../../../domain/entities/layers'

const LayerDetailsBox = props => {
Expand Down Expand Up @@ -34,7 +34,7 @@ const LayerDetailsBox = props => {
if (zones && layer_name && engins && gears) {
const hash = getHash(`${layer_name}:${zones}`)
const gearCategory = getGearCategory(engins, props.gears)
setVectorLayerStyle(getVectorLayerStyle(Layers.REGULATORY.code)(null, hash, gearCategory))
setVectorLayerStyle(getAdministrativeAndRegulatoryLayersStyle(Layers.REGULATORY.code)(null, hash, gearCategory))
}
}
}, [regulatoryFeatureToShowOnCard, gears, setVectorLayerStyle])
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/features/vessel_list/VesselList.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useDispatch, useSelector } from 'react-redux'
import Modal from 'rsuite/lib/Modal'

import { COLORS } from '../../constants/constants'
import { getZonesAndSubZonesPromises, layersType } from '../../domain/entities/layers'
import { layersType } from '../../domain/entities/layers'
import { removeZoneSelected, resetZonesSelected, setInteraction, setZonesSelected } from '../../domain/shared_slices/Map'
import { InteractionTypes } from '../../domain/entities/map'
import VesselListTable from './VesselListTable'
Expand All @@ -20,6 +20,7 @@ import { addFilter } from '../../domain/shared_slices/Filter'
import { MapComponentStyle } from '../commonStyles/MapComponent.style'
import { MapButtonStyle } from '../commonStyles/MapButton.style'
import { VesselListSVG } from '../commonStyles/icons/VesselListSVG'
import { getZonesAndSubZonesPromises } from '../../domain/use_cases/getZonesAndSubZonesPromises'

const VesselList = ({ namespace }) => {
const dispatch = useDispatch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { getColorWithAlpha } from '../../utils'
import { COLORS } from '../../constants/constants'
import { metadataIsShowedPropertyName } from '../RegulatoryLayers'

export const getVectorLayerStyle = type => {
export const getAdministrativeAndRegulatoryLayersStyle = type => {
switch (type) {
case Layers.EEZ.code:
return feature => new Style({
Expand Down Expand Up @@ -102,21 +102,21 @@ export const getVectorLayerStyle = type => {
})
})
case Layers.THREE_MILES.code:
return new Style({
return _ => new Style({
stroke: new Stroke({
color: 'rgba(5, 5, 94, 0.5)',
width: 2
})
})
case Layers.SIX_MILES.code:
return new Style({
return _ => new Style({
stroke: new Stroke({
color: 'rgba(5, 5, 94, 0.5)',
width: 2
})
})
case Layers.TWELVE_MILES.code:
return new Style({
return _ => new Style({
stroke: new Stroke({
color: 'rgba(5, 5, 94, 0.5)',
width: 2
Expand Down

0 comments on commit 84510e7

Please sign in to comment.