diff --git a/src/visits/helpers/MapModal.js b/src/visits/helpers/MapModal.js index 773bdadc..3f8407fa 100644 --- a/src/visits/helpers/MapModal.js +++ b/src/visits/helpers/MapModal.js @@ -9,7 +9,7 @@ const propTypes = { isOpen: PropTypes.bool, title: PropTypes.string, locations: PropTypes.arrayOf(PropTypes.shape({ - city: PropTypes.string.isRequired, + cityName: PropTypes.string.isRequired, latLong: PropTypes.arrayOf(PropTypes.number).isRequired, count: PropTypes.number.isRequired, })), @@ -31,9 +31,9 @@ const MapModal = ({ toggle, isOpen, title, locations }) => ( - {locations.map(({ city, latLong, count }, index) => ( + {locations.map(({ cityName, latLong, count }, index) => ( - {count} visit{count > 1 ? 's' : ''} from {city} + {count} visit{count > 1 ? 's' : ''} from {cityName} ))} diff --git a/src/visits/services/VisitsParser.js b/src/visits/services/VisitsParser.js index 6ff5662b..174291d1 100644 --- a/src/visits/services/VisitsParser.js +++ b/src/visits/services/VisitsParser.js @@ -100,17 +100,20 @@ export const processCitiesStats = buildLocationStatsProcessorByProperty('cityNam export const processCitiesStatsForMap = (visits) => reduce( (stats, { visitLocation }) => { - const hasCity = visitLocationHasProperty(visitLocation, 'cityName'); - const city = hasCity ? visitLocation.cityName : 'unknown'; - const currentCity = stats[city] || { - city, + if (!visitLocationHasProperty(visitLocation, 'cityName')) { + return stats; + } + + const { cityName, latitude, longitude } = visitLocation; + const currentCity = stats[cityName] || { + cityName, count: 0, - latLong: hasCity ? [ parseFloat(visitLocation.latitude), parseFloat(visitLocation.longitude) ] : [ 0, 0 ], + latLong: [ parseFloat(latitude), parseFloat(longitude) ], }; currentCity.count++; - return assoc(city, currentCity, stats); + return assoc(cityName, currentCity, stats); }, {}, visits,