Skip to content

Commit

Permalink
add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nichhk committed Jul 5, 2022
1 parent 4ad35da commit a9df8a8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 7 additions & 1 deletion client/components/Map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
30 changes: 28 additions & 2 deletions client/components/Map/layers/RequestsLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand All @@ -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']];
Expand Down Expand Up @@ -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)];
};
Expand Down

0 comments on commit a9df8a8

Please sign in to comment.