From 478ee59bb05959ecbd858ba544d63e999e8e33cb Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 10 Mar 2019 10:56:36 +0100 Subject: [PATCH] Updated cities chart so that map shows locations from current page when result set is paginated --- src/visits/ShortUrlVisits.js | 12 +++++++++--- src/visits/SortableBarGraph.js | 13 +++++++++++-- src/visits/helpers/OpenMapModalBtn.js | 8 +++++--- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/visits/ShortUrlVisits.js b/src/visits/ShortUrlVisits.js index 820956d3..9c74356f 100644 --- a/src/visits/ShortUrlVisits.js +++ b/src/visits/ShortUrlVisits.js @@ -116,9 +116,15 @@ const ShortUrlVisits = ({ processStatsFromVisits }) => class ShortUrlVisits exte 0 && - )} + extraHeaderContent={(filterLocations) => + mapLocations.length > 0 && ( + + ) + } sortingItems={{ name: 'City name', amount: 'Visits amount', diff --git a/src/visits/SortableBarGraph.js b/src/visits/SortableBarGraph.js index 70b309e5..2d0d5e60 100644 --- a/src/visits/SortableBarGraph.js +++ b/src/visits/SortableBarGraph.js @@ -16,7 +16,7 @@ export default class SortableBarGraph extends React.Component { stats: PropTypes.object.isRequired, title: PropTypes.string.isRequired, sortingItems: PropTypes.object.isRequired, - extraHeaderContent: PropTypes.node, + extraHeaderContent: PropTypes.func, withPagination: PropTypes.bool, }; @@ -96,6 +96,11 @@ export default class SortableBarGraph extends React.Component { render() { const { stats, sortingItems, title, extraHeaderContent, withPagination = true } = this.props; const { currentPageStats, pagination, max } = this.determineStats(stats, sortingItems); + const filterLocations = (locations) => { + const validCities = keys(currentPageStats); + + return locations.filter(({ cityName }) => validCities.includes(cityName)); + }; const computedTitle = ( {title} @@ -122,7 +127,11 @@ export default class SortableBarGraph extends React.Component { /> )} - {extraHeaderContent &&
{extraHeaderContent}
} + {extraHeaderContent && ( +
+ {extraHeaderContent(pagination ? filterLocations : undefined)} +
+ )}
); diff --git a/src/visits/helpers/OpenMapModalBtn.js b/src/visits/helpers/OpenMapModalBtn.js index afe00d1c..18a88f4f 100644 --- a/src/visits/helpers/OpenMapModalBtn.js +++ b/src/visits/helpers/OpenMapModalBtn.js @@ -10,22 +10,24 @@ export default class OpenMapModalBtn extends React.Component { static propTypes = { modalTitle: PropTypes.string.isRequired, locations: PropTypes.arrayOf(PropTypes.object), + filterLocations: PropTypes.func, }; state = { mapIsOpened: false }; render() { - const { modalTitle, locations = [] } = this.props; + const { modalTitle, locations = [], filterLocations } = this.props; const toggleMap = () => this.setState(({ mapIsOpened }) => ({ mapIsOpened: !mapIsOpened })); const buttonRef = React.createRef(); + const filteredLocations = filterLocations ? filterLocations(locations) : locations; return ( - buttonRef.current}>Show in map - + buttonRef.current}>Show in map + ); }