Skip to content

Commit

Permalink
add catches and more localized error message
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinBeczak committed Nov 12, 2024
1 parent 235cf3c commit c6367e6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 27 deletions.
36 changes: 20 additions & 16 deletions src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import _get from 'lodash/get'
import _isFinite from 'lodash/isFinite'
import {
bundleTasks,
deleteTaskBundle,
removeTaskFromBundle,
deleteTaskBundle,
fetchTaskBundle,
updateTaskBundle,
releaseTask,
Expand All @@ -29,7 +28,8 @@ export function WithTaskBundle(WrappedComponent) {
taskBundle: null,
completingTask: null,
selectedTasks: [],
resetSelectedTasks: null
resetSelectedTasks: null,
errorMessage: null
}

async componentDidMount() {
Expand Down Expand Up @@ -71,12 +71,14 @@ export function WithTaskBundle(WrappedComponent) {

updateBundlingConditions = () => {
const { task, taskReadOnly, workspace, user, name } = this.props
const isCompletionWorkspace = ["taskCompletion"].includes(workspace?.name || name)
const isReviewWorkspace = ["taskReview"].includes(workspace?.name || name)
const workspaceName = workspace?.name || name
const isCompletionWorkspace = ["taskCompletion"].includes(workspaceName)
const isReviewWorkspace = ["taskReview"].includes(workspaceName)

const completionStatus = isCompletionWorkspace && ([2].includes(task?.reviewStatus) || [0, 3, 6].includes(task?.status))
const enableMapperEdits = (!task?.completedBy || user.id === task.completedBy) && completionStatus && !isReviewWorkspace
const enableMapperEdits = !task?.completedBy || user.id === task.completedBy
const enableSuperUserEdits = user.isSuperUser && (completionStatus || isReviewWorkspace)
const bundleEditsDisabled = taskReadOnly || (!enableMapperEdits && !enableSuperUserEdits)
const bundleEditsDisabled = taskReadOnly || !(enableMapperEdits && completionStatus) && !enableSuperUserEdits

this.setState({ bundleEditsDisabled })
}
Expand Down Expand Up @@ -113,15 +115,17 @@ export function WithTaskBundle(WrappedComponent) {
}

lockTask = async (taskId) => {
this.setState({ loading: true });
try {
const task = await this.props.startTask(taskId)
setTimeout(() => localStorage.removeItem(`lock-${taskId}`), 1500)
return task.entities.tasks[taskId]
const task = await this.props.startTask(taskId, true);
setTimeout(() => localStorage.removeItem(`lock-${taskId}`), 1500);
return task.entities.tasks[taskId];
} catch (error) {
console.error(`Failed to lock task ${taskId}:`, error)
dispatch(addError(`Failed to lock task ${taskId}:`, error))
dispatch(addError(AppErrors.challenge.rebuildFailure));
throw error
console.error(`Failed to lock task ${taskId}:`, error);
this.setState({ errorMessage: `Failed to lock task ${taskId}. Please try again.` });
throw error;
} finally {
this.setState({ loading: false });
}
}

Expand Down Expand Up @@ -215,6 +219,7 @@ export function WithTaskBundle(WrappedComponent) {
bundleEditsDisabled={this.state.bundleEditsDisabled}
setResetSelectedTasksAccessor={(f) => this.setState({ resetSelectedTasks: f })}
resetSelectedTasks={this.resetSelectedTasks}
errorMessage={this.state.errorMessage}
/>
)
}
Expand All @@ -224,12 +229,11 @@ export function WithTaskBundle(WrappedComponent) {
export const mapDispatchToProps = dispatch => bindActionCreators({
fetchTaskBundle,
bundleTasks,
removeTaskFromBundle,
deleteTaskBundle,
updateTaskBundle,
releaseTask,
startTask
}, dispatch)

export default WrappedComponent =>
connect(null, mapDispatchToProps)(WithTaskBundle(WrappedComponent))
connect(null, mapDispatchToProps)(WithTaskBundle(WrappedComponent))
16 changes: 9 additions & 7 deletions src/components/TaskAnalysisTable/TaskAnalysisTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,17 @@ const setupColumnTypes = (props, taskBaseRoute, manager, data, openComments) =>
accessor: 'remove',
minWidth: 110,
Cell: ({ row }) => {
const bundlePrimary = props.taskBundle?.tasks.find(task => task.isBundlePrimary)
const isTaskSelected = row._original.id === (bundlePrimary?.id || props.task?.id)
const alreadyBundled = row._original.bundleId && props.taskBundle?.bundleId !== row._original.bundleId
const enableBundleEdits = props.initialBundle?.taskIds?.includes(row._original.id) ||
[0, 3, 6].includes(row._original.status)
const isInActiveBundle = props.taskBundle?.taskIds?.includes(row._original.id)
const { taskBundle, task, initialBundle } = props;
const { id: taskId, bundleId, status } = row._original;

const isTaskSelected = taskId === task?.id
const isInActiveBundle = taskBundle?.taskIds?.includes(taskId);
const alreadyBundled = bundleId && taskBundle?.bundleId !== bundleId;
const enableBundleEdits = initialBundle?.taskIds?.includes(taskId) || [0, 3, 6].includes(status) && !alreadyBundled

return (
<div>
{!isTaskSelected && enableBundleEdits && !alreadyBundled && isInActiveBundle && (
{!isTaskSelected && enableBundleEdits && isInActiveBundle && (
<button
disabled={props.bundleEditsDisabled}
className="mr-text-red-light"
Expand Down
24 changes: 20 additions & 4 deletions src/components/Widgets/TaskBundleWidget/TaskBundleWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const shortcutGroup = 'taskEditing'
export default class TaskBundleWidget extends Component {
state = {
shortcutActive: false,
bundleButtonDisabled: false,
}

handleKeyboardShortcuts = (event) => {
Expand Down Expand Up @@ -114,7 +115,7 @@ export default class TaskBundleWidget extends Component {

bundleTasks = () => {
if (this.props.taskBundle || this.props.bundleEditsDisabled) {
return
return;
}

const selectedArray = Array.from(this.props.selectedTasks.selected.values());
Expand All @@ -126,7 +127,12 @@ export default class TaskBundleWidget extends Component {
}
});

this.setState({ bundleButtonDisabled: true });
this.props.createTaskBundle([...this.props.selectedTasks.selected.keys()]);

setTimeout(() => {
this.setState({ bundleButtonDisabled: false });
}, 5000);
}

unbundleTask = (task) => {
Expand Down Expand Up @@ -221,6 +227,10 @@ export default class TaskBundleWidget extends Component {
this.setBoundsToNearbyTask()
}
}

if (this.props.selectedTasks.selected.size !== prevProps.selectedTasks.selected.size) {
this.setState({ bundleButtonDisabled: false });
}
}

componentWillUnmount() {
Expand All @@ -234,7 +244,7 @@ export default class TaskBundleWidget extends Component {
}

render() {
const WidgetContent = this.props.taskBundle ? ActiveBundle : BuildBundle
const WidgetContent = this.props.taskBundle ? ActiveBundle : BuildBundle;
return (
<QuickWidget
{...this.props}
Expand All @@ -246,6 +256,7 @@ export default class TaskBundleWidget extends Component {
>
<WidgetContent
{...this.props}
errorMessage={this.props.errorMessage}
saveFilters={this.saveFilters}
revertFilters={this.revertFilters}
bundleTasks={this.bundleTasks}
Expand Down Expand Up @@ -334,7 +345,7 @@ const ActiveBundle = props => {
defaultPageSize={5}
/>
)
console.log(props)

return (
<div className="mr-h-full mr-rounded">
<div className="mr-h-3/4 mr-min-h-80 mr-max-h-screen-80" style={{ maxHeight: `${props.widgetLayout.w * 80}px` }}>
Expand All @@ -343,6 +354,9 @@ console.log(props)
) : (
<MapPane>{map}</MapPane>
)}
{props.errorMessage && (
<div className="mr-text-red">{props.errorMessage}</div>
)}
<h3 className="mr-text-lg mr-text-center mr-text-pink-light mr-mt-4">
<FormattedMessage
{...messages.simultaneousTasks}
Expand Down Expand Up @@ -507,7 +521,9 @@ const BuildBundle = props => {
<MapPane showLasso>{map}</MapPane>
}
</div>

{props.errorMessage && (
<div className="mr-text-red">{props.errorMessage}</div>
)}
<div className={props.widgetLayout && props.widgetLayout?.w === 4 ? "mr-my-4 mr-px-4 mr-space-y-3" : "mr-my-4 mr-px-4 xl:mr-flex xl:mr-justify-between mr-items-center"}>
{props.initialBundle && (
<button
Expand Down

0 comments on commit c6367e6

Please sign in to comment.