Skip to content

Commit

Permalink
add "bundle" button
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Nov 27, 2024
1 parent 258941b commit f156a3d
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 40 deletions.
12 changes: 12 additions & 0 deletions src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,17 @@ export function WithTaskBundle(WrappedComponent) {
this.setState({ taskBundle: updatedTaskBundle })
}

addTaskToBundle = async (taskId) => {
const { taskBundle } = this.state
const task = await this.lockTask(taskId)
const updatedTaskBundle = {
...taskBundle,
taskIds: [...taskBundle.taskIds, taskId],
tasks: [...taskBundle.tasks, task]
}
this.setState({ taskBundle: updatedTaskBundle })
}

updateTaskBundle = async () => {
const { taskBundle, initialBundle } = this.state
if (taskBundle || initialBundle) {
Expand Down Expand Up @@ -272,6 +283,7 @@ export function WithTaskBundle(WrappedComponent) {
updateTaskBundle={this.updateTaskBundle}
resetTaskBundle={this.resetTaskBundle}

Check warning on line 284 in src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx#L283-L284

Added lines #L283 - L284 were not covered by tests
removeTaskFromBundle={this.removeTaskFromBundle}
addTaskToBundle={this.addTaskToBundle}

Check warning on line 286 in src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx#L286

Added line #L286 was not covered by tests
clearActiveTaskBundle={this.clearActiveTaskBundle}
setSelectedTasks={(selectedTasks) => this.setState({ selectedTasks })}

Check warning on line 288 in src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx#L288

Added line #L288 was not covered by tests
selectedTasks={this.state.selectedTasks}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ export const WithTaskClusterMarkers = function(WrappedComponent) {
*/
updateMapMarkers() {
const markers = _map(this.props.taskClusters, cluster => {
const cluserStatus = cluster.status ?? cluster.taskStatus
const clusterStatus = cluster.status ?? cluster.taskStatus

Check warning on line 36 in src/components/HOCs/WithTaskClusterMarkers/WithTaskClusterMarkers.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/HOCs/WithTaskClusterMarkers/WithTaskClusterMarkers.jsx#L36

Added line #L36 was not covered by tests
const clusterId = cluster.id ?? cluster.taskId
const alreadyBundled = cluster.bundleId && !this.props.taskBundle?.bundleId !== cluster.bundleId
const alreadyBundled = cluster.bundleId && this.props.initialBundle?.bundleId !== cluster.bundleId

Check warning on line 38 in src/components/HOCs/WithTaskClusterMarkers/WithTaskClusterMarkers.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/HOCs/WithTaskClusterMarkers/WithTaskClusterMarkers.jsx#L38

Added line #L38 was not covered by tests

const bundleConflict = Boolean(
(clusterId &&
this.props.task &&
![0, 3, 6].includes(cluserStatus) &&
![0, 3, 6].includes(clusterStatus) &&

Check warning on line 43 in src/components/HOCs/WithTaskClusterMarkers/WithTaskClusterMarkers.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/HOCs/WithTaskClusterMarkers/WithTaskClusterMarkers.jsx#L43

Added line #L43 was not covered by tests
!this.props.taskBundle?.taskIds?.includes(clusterId) &&
!this.props.initialBundle?.taskIds?.includes(clusterId)) ||
alreadyBundled
Expand Down
18 changes: 18 additions & 0 deletions src/components/TaskAnalysisTable/TaskAnalysisTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export class TaskAnalysisTableInternal extends Component {
<ViewTaskSubComponent taskId={props.original.id} />
}
unbundleTask={this.props.unbundleTask}
bundleTask={this.props.bundleTask}
collapseOnDataChange={false}
minRows={1}
manual
Expand Down Expand Up @@ -444,6 +445,23 @@ const setupColumnTypes = (props, taskBaseRoute, manager, data, openComments) =>
<FormattedMessage {...messages.unbundle} />
</button>
)}


{!isActiveTask && validBundlingStatus && !isInActiveBundle && !alreadyBundled && (
<button
disabled={props.bundleEditsDisabled}
className="mr-text-green-lighter"
style={{
cursor: props.bundleEditsDisabled ? 'default' : 'pointer',
opacity: props.bundleEditsDisabled ? 0.3 : 1,
pointerEvents: props.bundleEditsDisabled ? 'none' : 'auto'
}}
onClick={() => props.bundleTask(row._original)}

Check warning on line 459 in src/components/TaskAnalysisTable/TaskAnalysisTable.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/TaskAnalysisTable/TaskAnalysisTable.jsx#L450-L459

Added lines #L450 - L459 were not covered by tests
>
<FormattedMessage {...messages.bundle} />

Check warning on line 461 in src/components/TaskAnalysisTable/TaskAnalysisTable.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/TaskAnalysisTable/TaskAnalysisTable.jsx#L461

Added line #L461 was not covered by tests
</button>
)}


{isActiveTask && <div className="mr-text-yellow">Primary Task</div>}

Check warning on line 466 in src/components/TaskAnalysisTable/TaskAnalysisTable.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/TaskAnalysisTable/TaskAnalysisTable.jsx#L466

Added line #L466 was not covered by tests
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/TaskClusterMap/TaskClusterMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const TaskClusterMap = (props) => {

useEffect(() => {
// Check condition for toggling showAsClusters
if (!props.showAsClusters && props.totalTaskCount > UNCLUSTER_THRESHOLD) {
if (!props.showAsClusters && props.totalTaskCount > UNCLUSTER_THRESHOLD && !props.createTaskBundle) {
props.toggleShowAsClusters();
}

Expand Down Expand Up @@ -250,7 +250,7 @@ export const TaskClusterMap = (props) => {
<ResizeMap />
<AttributionControl position="bottomleft" prefix={false} />
{(Boolean(props.loading) || Boolean(props.loadingChallenge)) && <BusySpinner mapMode xlarge />}
{props.totalTaskCount && props.totalTaskCount <= UNCLUSTER_THRESHOLD && !searchOpen && !props.loading &&
{props.totalTaskCount && props.totalTaskCount <= UNCLUSTER_THRESHOLD && !searchOpen && !props.loading && !props.createTaskBundle &&
<label htmlFor="show-clusters-input" className="mr-absolute mr-z-10 mr-top-0 mr-left-0 mr-mt-2 mr-ml-2 mr-shadow mr-rounded-sm mr-bg-black-50 mr-px-2 mr-py-1 mr-text-white mr-text-xs mr-flex mr-items-center">
<input
id="show-clusters-input"
Expand Down
5 changes: 5 additions & 0 deletions src/components/Widgets/TaskBundleWidget/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ export default defineMessages({
id: "Widgets.TaskBundleWidget.removeFromBundle",
defaultMessage: "Remove from bundle",
},

addToBundle: {
id: "Widgets.TaskBundleWidget.addToBundle",
defaultMessage: "Add to bundle",
},

unbundleTasksLabel: {
id: "Widgets.TaskBundleWidget.controls.stopBundlinsg.label",
Expand Down
17 changes: 12 additions & 5 deletions src/components/Widgets/TaskBundleWidget/TaskBundleWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const descriptor = {
const ClusterMap = WithChallengeTaskClusters(
WithTaskClusterMarkers(TaskClusterMap('taskBundling')),
true,
true,
false,
false,
false
)
Expand Down Expand Up @@ -92,7 +92,7 @@ export default class TaskBundleWidget extends Component {

const shortcuts = keyboardShortcutGroups.taskEditing;
if (event.key === shortcuts.completeTogether.key) {
this.bundleTasks()
this.createBundle()
}
}

Expand All @@ -116,7 +116,7 @@ export default class TaskBundleWidget extends Component {
}
}

bundleTasks = () => {
createBundle = () => {
if (this.props.taskBundle || this.props.bundleEditsDisabled) {
return;
}
Expand Down Expand Up @@ -144,6 +144,12 @@ export default class TaskBundleWidget extends Component {
this.props.toggleTaskSelection(task)
}

bundleTask = (task) => {
const taskId = task.id ?? task.taskId
this.props.addTaskToBundle(taskId)
this.props.toggleTaskSelection(task)
}

setBoundsToNearbyTask = () => {
const taskList = _get(this.props, 'nearbyTasks.tasks')

Expand Down Expand Up @@ -258,8 +264,9 @@ export default class TaskBundleWidget extends Component {
{...this.props}
saveFilters={this.saveFilters}
revertFilters={this.revertFilters}
bundleTasks={this.bundleTasks}
createBundle={this.createBundle}

Check warning on line 267 in src/components/Widgets/TaskBundleWidget/TaskBundleWidget.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Widgets/TaskBundleWidget/TaskBundleWidget.jsx#L267

Added line #L267 was not covered by tests
unbundleTask={this.unbundleTask}
bundleTask={this.bundleTask}

Check warning on line 269 in src/components/Widgets/TaskBundleWidget/TaskBundleWidget.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Widgets/TaskBundleWidget/TaskBundleWidget.jsx#L269

Added line #L269 was not covered by tests
loading={this.props.loading}
/>
{this.props.errorMessage && (
Expand Down Expand Up @@ -486,7 +493,7 @@ const BuildBundle = props => {
const bundleButton = !props.taskReadOnly && props.selectedTaskCount(totalTaskCount) > 1 && !props.bundleEditsDisabled ? (
<button
className="mr-button mr-button--green-lighter mr-button--small"
onClick={props.bundleTasks}
onClick={props.createBundle}

Check warning on line 496 in src/components/Widgets/TaskBundleWidget/TaskBundleWidget.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Widgets/TaskBundleWidget/TaskBundleWidget.jsx#L496

Added line #L496 was not covered by tests
>
<FormattedMessage {...messages.bundleTasksLabel} />
</button>
Expand Down
16 changes: 15 additions & 1 deletion src/components/Widgets/TaskBundleWidget/TaskMarkerContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,21 @@ class TaskMarkerContent extends Component {
>
<FormattedMessage {...messages.removeFromBundle} />
</button>
) : null}
) : (
!alreadyBundled && (
<button
disabled={this.props.bundleEditsDisabled}
onClick={() => this.props.bundleTask(this.props.marker.options)}
className="mr-text-green mr-border-solid mr-border mr-border-green mr-px-2 mr-mb-1"
style={{
cursor: this.props.bundleEditsDisabled ? 'default' : 'pointer',
opacity: this.props.bundleEditsDisabled ? 0.3 : 1,
}}

Check warning on line 131 in src/components/Widgets/TaskBundleWidget/TaskMarkerContent.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Widgets/TaskBundleWidget/TaskMarkerContent.jsx#L123-L131

Added lines #L123 - L131 were not covered by tests
>
<FormattedMessage {...messages.addToBundle} />

Check warning on line 133 in src/components/Widgets/TaskBundleWidget/TaskMarkerContent.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Widgets/TaskBundleWidget/TaskMarkerContent.jsx#L133

Added line #L133 was not covered by tests
</button>
)
)}
</div>
) : null}
</label>
Expand Down
1 change: 0 additions & 1 deletion src/services/Error/AppErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default {
locked: messages.taskLocked,
lockRefreshFailure: messages.taskLockRefreshFailure,
bundleFailure: messages.taskBundleFailure,
removeTaskFromBundleFailure: messages.removeTaskFromBundleFailure,
bundleCooperative: messages.taskBundleCooperative,
addCommentFailure: messages.addCommentFailure,
bundleNotCooperative: messages.taskBundleNotCooperative,
Expand Down
4 changes: 0 additions & 4 deletions src/services/Error/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ export default defineMessages({
id: "Errors.task.bundleFailure",
defaultMessage: "Unable to bundle tasks together",
},
removeTaskFromBundleFailure: {
id: "Errors.task.removeTaskFromBundleFailure",
defaultMessage: "Unable to remove task from bundle",
},
taskBundleCooperative: {
id: "Errors.task.bundleCooperative",
defaultMessage: "The main task is Cooperative. All selected tasks must be Cooperative.",
Expand Down
1 change: 0 additions & 1 deletion src/services/Server/APIRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ const apiRoutes = (factory) => {
bundle: factory.post("/taskBundle"),
updateBundle: factory.post("/taskBundle/:bundleId/update"),
deleteBundle: factory.delete("/taskBundle/:bundleId"),
removeTaskFromBundle: factory.post("/taskBundle/:id/unbundle"),
fetchBundle: factory.post("/taskBundle/:bundleId"),
bundled: {
updateStatus: factory.put("/taskBundle/:bundleId/:status"),
Expand Down
23 changes: 0 additions & 23 deletions src/services/Task/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -997,29 +997,6 @@ export const deleteTaskBundle = function(bundleId) {
}
}

export const removeTaskFromBundle = function (initialBundleTaskIds, bundleId, taskIds) {
return function (dispatch) {
return new Endpoint(api.tasks.removeTaskFromBundle, {
variables: { id: bundleId },
params: { id: bundleId, taskIds: taskIds, preventTaskIdUnlocks: initialBundleTaskIds || [] },
})
.execute()
.then((results) => {
return results;
})
.catch((error) => {
if (isSecurityError(error)) {
dispatch(ensureUserLoggedIn()).then(() =>
dispatch(addError(AppErrors.user.unauthorized))
);
} else {
dispatch(addError(AppErrors.task.removeTaskFromBundleFailure));
console.log(error.response || error);
}
});
};
};

/**
* Retrieve and process a single task retrieval from the given endpoint (next
* task, previous task, random task, etc).
Expand Down

0 comments on commit f156a3d

Please sign in to comment.