Skip to content

Commit

Permalink
connect to new endpoint for fetching specifically task markers
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Jun 3, 2024
1 parent 584b53b commit c85d03d
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { fromLatLngBounds, boundsWithinAllowedMaxDegrees }
from '../../../services/MapBounds/MapBounds'
import { fetchTaskClusters, clearTaskClusters }
from '../../../services/Task/TaskClusters'
import { fetchBoundedTasks, clearBoundedTasks }
import { fetchBoundedTaskMarkers, fetchBoundedTasks, clearBoundedTasks }
from '../../../services/Task/BoundedTask'
import { MAX_ZOOM, UNCLUSTER_THRESHOLD } from '../../TaskClusterMap/TaskClusterMap'

Expand Down Expand Up @@ -107,7 +107,7 @@ export const WithChallengeTaskClusters = function(WrappedComponent, storeTasks=f
searchCriteria.page = 0

// Fetch up to threshold+1 individual tasks (eg. 1001 tasks)
this.props.fetchBoundedTasks(searchCriteria, UNCLUSTER_THRESHOLD + 1, !storeTasks, ignoreLocked, true).then(results => {
this.props.fetchBoundedTaskMarkers(searchCriteria, UNCLUSTER_THRESHOLD + 1, !storeTasks, ignoreLocked).then(results => {
if (currentFetchId >= this.state.fetchId) {
// If we retrieved 1001 tasks then there might be more tasks and
// they should be clustered. So fetch as clusters
Expand Down Expand Up @@ -246,7 +246,7 @@ export const WithChallengeTaskClusters = function(WrappedComponent, storeTasks=f

export const mapDispatchToProps = dispatch => Object.assign(
{},
bindActionCreators({ fetchTaskClusters, fetchBoundedTasks }, dispatch),
bindActionCreators({ fetchTaskClusters, fetchBoundedTaskMarkers, fetchBoundedTasks }, dispatch),
{
clearTasksAndClusters: () => {
dispatch(clearBoundedTasks())
Expand Down
2 changes: 1 addition & 1 deletion src/components/TaskClusterMap/TaskClusterMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const MIN_ZOOM = 2
* An uncluster option will be offered if no more than this number of tasks
* will be shown.
*/
export const UNCLUSTER_THRESHOLD = 1000 // max number of tasks
export const UNCLUSTER_THRESHOLD = 500 // max number of tasks

/**
* The number of clusters to show.
Expand Down
1 change: 1 addition & 0 deletions src/services/Server/APIRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const apiRoutes = (factory) => {
tasks: {
random: factory.get("/tasks/random", { noCache: true }),
withinBounds: factory.put("/tasks/box/:left/:bottom/:right/:top"),
markersWithinBounds: factory.put("/markers/box/:left/:bottom/:right/:top"),
bulkUpdate: factory.put("/tasks"),
bulkStatusChange: factory.put("/tasks/changeStatus"),
review: factory.get("/tasks/review"),
Expand Down
104 changes: 103 additions & 1 deletion src/services/Task/BoundedTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,109 @@ export const receiveBoundedTasks = function(tasks,
}
}

// async action creators
/**
* Retrieve all task markers (up to the given limit) matching the given search
* criteria, which should at least include a boundingBox field, and may
* optionally include a filters field with additional constraints
*/
export const fetchBoundedTaskMarkers = function(criteria, limit = 50, skipDispatch = false, ignoreLocked = true, withGeometries) {
return function(dispatch) {
if (!skipDispatch) {
// The map is either showing task clusters or bounded tasks so we shouldn't
// have both in redux.
// (ChallengeLocation needs to know which challenge tasks pass the location)
dispatch(clearTaskClusters())
}

const normalizedBounds = toLatLngBounds(criteria.boundingBox)
if (!normalizedBounds) {
return null
}

const filters = _get(criteria, 'filters', {})
const searchParameters = generateSearchParametersString(
filters,
null,
_get(criteria, 'savedChallengesOnly'),
null,
null,
_get(criteria, 'invertFields')
)

if (!filters.challengeId) {
const onlyEnabled = _isUndefined(criteria.onlyEnabled) ?
true :
criteria.onlyEnabled
const challengeStatus = criteria.challengeStatus
if (challengeStatus) {
searchParameters.cStatus = challengeStatus.join(',')
}

// ce: limit to enabled challenges
// pe: limit to enabled projects
searchParameters.ce = onlyEnabled ? 'true' : 'false'
searchParameters.pe = onlyEnabled ? 'true' : 'false'

// if we are restricting to onlyEnabled challenges then let's
// not show 'local' challenges either.
searchParameters.cLocal = onlyEnabled ? CHALLENGE_EXCLUDE_LOCAL :
CHALLENGE_INCLUDE_LOCAL
}

// If we are searching within map bounds we need to ensure the parent
// challenge is also within those bounds
if (filters.location === CHALLENGE_LOCATION_WITHIN_MAPBOUNDS) {
if (_isArray(criteria.boundingBox)) {
searchParameters.bb = criteria.boundingBox.join(',')
} else {
searchParameters.bb = criteria.boundingBox
}
}

const fetchId = uuidv1()
!skipDispatch && dispatch(receiveBoundedTasks(null, RequestStatus.inProgress, fetchId))

return new Endpoint(
api.tasks.markersWithinBounds, {
schema: {
tasks: [taskSchema()]
},
variables: {
left: normalizedBounds.getWest(),
bottom: normalizedBounds.getSouth(),
right: normalizedBounds.getEast(),
top: normalizedBounds.getNorth(),
},
params: {
limit,
excludeLocked: ignoreLocked,
...searchParameters,
},
json: filters.taskPropertySearch ? {
taskPropertySearch: filters.taskPropertySearch
} : null,
}
).execute().then(normalizedResults => {
const totalCount = normalizedResults.result.total

let tasks = _values(_get(normalizedResults, 'entities.tasks', {}))
tasks = _map(tasks, task =>
Object.assign(task, {}, task.pointReview)
)

!skipDispatch && dispatch(receiveBoundedTasks(tasks, RequestStatus.success, fetchId, totalCount))

return {
tasks,
totalCount
}
}).catch(error => {
dispatch(receiveBoundedTasks([], RequestStatus.error, fetchId))
dispatch(addError(AppErrors.boundedTask.fetchFailure))
console.log(error.response || error)
})
}
}

/**
* Retrieve all tasks (up to the given limit) matching the given search
Expand Down

0 comments on commit c85d03d

Please sign in to comment.