diff --git a/client/components/Map/index.js b/client/components/Map/index.js index 1f8b48864..1131937dc 100644 --- a/client/components/Map/index.js +++ b/client/components/Map/index.js @@ -54,7 +54,13 @@ class MapContainer extends React.Component { componentWillUnmount() { this.isSubscribed = false; } - + /** + * Gets all requests over the time range specified in the Redux store. + * + * Since the server is slow to retrieve all the requests at once, we need to + * make multiple API calls, using `skip` and `limit` to retrieve consecutive + * chunks of data. + */ getAllRequests = async () => { const { startDate, endDate } = this.props; const url = new URL(`${process.env.API_URL}/requests`); diff --git a/client/components/Map/layers/RequestsLayer.js b/client/components/Map/layers/RequestsLayer.js index 4a4287620..0d3e52cd1 100644 --- a/client/components/Map/layers/RequestsLayer.js +++ b/client/components/Map/layers/RequestsLayer.js @@ -30,8 +30,15 @@ function circleColors(requestTypes) { ]; } +/** + * Gets a MapBox GL JS filter specification to filter request types. + * + * @param {Object} selectedTypes A mapping of k:v, where k is an str request + * type, and v is a boolean indicating whether the request type is selected. + * @return {Array} A Mapbox GL JS filter specification that filters out the + * unselected types. + */ function typeFilter(selectedTypes) { - // selectedTypes maps ints (in string form) to booleans, indicating whether the type is selected. // Get an array of int typeIds corresponding value in selectedTypes is true. var trueTypes = Object.keys(selectedTypes).map((type) => parseInt(type)).filter((type) => selectedTypes[type]); return [ @@ -41,8 +48,16 @@ function typeFilter(selectedTypes) { ]; } +/** + * Gets a MapBox GL JS filter specification to filter request statuses. + * + * @param {Object} requestStatus A mapping of k:v, where k is a request status + * (either open or closed), and v is a boolean indicating whether the request + * status is selected. + * @return {Array} A Mapbox GL JS filter specification that filters out the + * unselected statuses. + */ function statusFilter(requestStatus) { - // requestStatus is an object with keys "open" and "closed", and boolean values. if (requestStatus.open && requestStatus.closed) { // Hack to allow ALL requests. return ['==', [LITERAL, 'a'], [LITERAL, 'a']]; @@ -167,6 +182,17 @@ class RequestsLayer extends React.Component { } }; + /** + * Gets a MapBox GL JS filter specification. + * + * @param {Object} selectedTypes A mapping of k:v, where k is an int request + * type, and v is a boolean indicating whether the request type is selected. + * @param {Object} requestStatus A mapping of k:v, where k is a request status + * (either open or closed), and v is a boolean indicating whether the request + * status is selected. + * @return {Array} A Mapbox GL JS filter specification that filters out the + * unselected types and statuses. + */ getFilterSpec = (selectedTypes, requestStatus) => { return ['all', typeFilter(selectedTypes), statusFilter(requestStatus)]; };