From c6367e6faf1f36d5b25bc519cfa4101116bed3e6 Mon Sep 17 00:00:00 2001 From: CollinBeczak Date: Tue, 12 Nov 2024 12:11:58 -0600 Subject: [PATCH] add catches and more localized error message --- .../HOCs/WithTaskBundle/WithTaskBundle.jsx | 36 ++++++++++--------- .../TaskAnalysisTable/TaskAnalysisTable.jsx | 16 +++++---- .../TaskBundleWidget/TaskBundleWidget.jsx | 24 ++++++++++--- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx b/src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx index bd9ba7831..d920103c0 100644 --- a/src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx +++ b/src/components/HOCs/WithTaskBundle/WithTaskBundle.jsx @@ -6,8 +6,7 @@ import _get from 'lodash/get' import _isFinite from 'lodash/isFinite' import { bundleTasks, - deleteTaskBundle, - removeTaskFromBundle, + deleteTaskBundle, fetchTaskBundle, updateTaskBundle, releaseTask, @@ -29,7 +28,8 @@ export function WithTaskBundle(WrappedComponent) { taskBundle: null, completingTask: null, selectedTasks: [], - resetSelectedTasks: null + resetSelectedTasks: null, + errorMessage: null } async componentDidMount() { @@ -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 }) } @@ -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 }); } } @@ -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} /> ) } @@ -224,7 +229,6 @@ export function WithTaskBundle(WrappedComponent) { export const mapDispatchToProps = dispatch => bindActionCreators({ fetchTaskBundle, bundleTasks, - removeTaskFromBundle, deleteTaskBundle, updateTaskBundle, releaseTask, @@ -232,4 +236,4 @@ export const mapDispatchToProps = dispatch => bindActionCreators({ }, dispatch) export default WrappedComponent => - connect(null, mapDispatchToProps)(WithTaskBundle(WrappedComponent)) \ No newline at end of file + connect(null, mapDispatchToProps)(WithTaskBundle(WrappedComponent)) diff --git a/src/components/TaskAnalysisTable/TaskAnalysisTable.jsx b/src/components/TaskAnalysisTable/TaskAnalysisTable.jsx index 712d7d6c7..80cbec9c3 100644 --- a/src/components/TaskAnalysisTable/TaskAnalysisTable.jsx +++ b/src/components/TaskAnalysisTable/TaskAnalysisTable.jsx @@ -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 (
- {!isTaskSelected && enableBundleEdits && !alreadyBundled && isInActiveBundle && ( + {!isTaskSelected && enableBundleEdits && isInActiveBundle && (