From 29034082cbaaf70b43b34ff9167a14473f77e079 Mon Sep 17 00:00:00 2001 From: jasquat Date: Thu, 26 Jan 2023 09:45:09 -0500 Subject: [PATCH] use the ProcessInstanceTask interface where we can and move some stuff around better for useEffect --- spiffworkflow-frontend/src/interfaces.ts | 26 ++++-- .../src/routes/ProcessInstanceShow.tsx | 4 +- .../src/routes/TaskShow.tsx | 89 ++++++++++--------- 3 files changed, 67 insertions(+), 52 deletions(-) diff --git a/spiffworkflow-frontend/src/interfaces.ts b/spiffworkflow-frontend/src/interfaces.ts index a6f0f985f..7b0aba38b 100644 --- a/spiffworkflow-frontend/src/interfaces.ts +++ b/spiffworkflow-frontend/src/interfaces.ts @@ -24,20 +24,28 @@ export interface RecentProcessModel { export interface ProcessInstanceTask { id: number; task_id: string; + + calling_subprocess_task_id: string; + created_at_in_seconds: number; + current_user_is_potential_owner: number; + data: any; + form_schema: any; + form_ui_schema: any; + lane_assignment_id: string; + name: string; + process_identifier: string; + process_initiator_username: string; process_instance_id: number; + process_instance_status: string; process_model_display_name: string; process_model_identifier: string; - task_title: string; - lane_assignment_id: string; - process_instance_status: string; + properties: any; state: string; - process_identifier: string; - name: string; - process_initiator_username: string; - created_at_in_seconds: number; + task_title: string; + title: string; + type: string; updated_at_in_seconds: number; - current_user_is_potential_owner: number; - calling_subprocess_task_id: string; + potential_owner_usernames?: string; assigned_user_group_identifier?: string; } diff --git a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx index c706007b7..5b8bb2855 100644 --- a/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx +++ b/spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx @@ -154,8 +154,8 @@ export default function ProcessInstanceShow({ variant }: OwnProps) { } } }, [ - // targetUris, - // params, + targetUris, + params, modifiedProcessModelId, permissionsLoaded, ability, diff --git a/spiffworkflow-frontend/src/routes/TaskShow.tsx b/spiffworkflow-frontend/src/routes/TaskShow.tsx index 3437db71c..f7506c44e 100644 --- a/spiffworkflow-frontend/src/routes/TaskShow.tsx +++ b/spiffworkflow-frontend/src/routes/TaskShow.tsx @@ -20,11 +20,11 @@ import HttpService from '../services/HttpService'; import useAPIError from '../hooks/UseApiError'; import { modifyProcessIdentifierForPathParam } from '../helpers'; import { useUriListForPermissions } from '../hooks/UriListForPermissions'; -import { PermissionsToCheck } from '../interfaces'; +import { PermissionsToCheck, ProcessInstanceTask } from '../interfaces'; import { usePermissionFetcher } from '../hooks/PermissionService'; export default function TaskShow() { - const [task, setTask] = useState(null); + const [task, setTask] = useState(null); const [userTasks, setUserTasks] = useState(null); const params = useParams(); const navigate = useNavigate(); @@ -39,35 +39,37 @@ export default function TaskShow() { permissionRequestData ); - const processResult = (result: any) => { - setTask(result); - const url = `/task-data/${modifyProcessIdentifierForPathParam( - result.process_model_identifier - )}/${params.process_instance_id}`; - if ( - result.process_model_identifier && - ability.can('GET', url) - // Assure we get a valid process model identifier back - ) { - HttpService.makeCallToBackend({ - path: url, - successCallback: setUserTasks, - failureCallback: (error: any) => { - addError(error); - }, - }); - } - }; - useEffect(() => { if (permissionsLoaded) { + const processResult = (result: ProcessInstanceTask) => { + // Assure we get a valid process model identifier back + if (!result.process_model_identifier) { + return null; + } + setTask(result); + const url = `/task-data/${modifyProcessIdentifierForPathParam( + result.process_model_identifier + )}/${params.process_instance_id}`; + if (ability.can('GET', url)) { + HttpService.makeCallToBackend({ + path: url, + successCallback: setUserTasks, + failureCallback: (error: any) => { + addError(error); + }, + }); + } + return null; + }; HttpService.makeCallToBackend({ path: `/tasks/${params.process_instance_id}/${params.task_id}`, successCallback: processResult, failureCallback: addError, }); } - }, [permissionsLoaded, ability]); // params and targetUris (which deps on params) cause this to re-fire in an infinite loop on error. + // FIXME: not sure what to do about addError. adding it to this array causes the page to endlessly reload + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [permissionsLoaded, ability, params, targetUris]); const processSubmitResult = (result: any) => { removeError(); @@ -173,12 +175,16 @@ export default function TaskShow() { return errors; }; - const formElement = (taskToUse: any) => { + const formElement = () => { + if (!task) { + return null; + } + let formUiSchema; - let taskData = taskToUse.data; - let jsonSchema = taskToUse.form_schema; + let taskData = task.data; + let jsonSchema = task.form_schema; let reactFragmentToHideSubmitButton = null; - if (taskToUse.type === 'Manual Task') { + if (task.type === 'Manual Task') { taskData = {}; jsonSchema = { type: 'object', @@ -196,10 +202,10 @@ export default function TaskShow() { 'ui:widget': 'hidden', }, }; - } else if (taskToUse.form_ui_schema) { - formUiSchema = JSON.parse(taskToUse.form_ui_schema); + } else if (task.form_ui_schema) { + formUiSchema = JSON.parse(task.form_ui_schema); } - if (taskToUse.state !== 'READY') { + if (task.state !== 'READY') { formUiSchema = Object.assign(formUiSchema || {}, { 'ui:readonly': true, }); @@ -211,7 +217,7 @@ export default function TaskShow() { reactFragmentToHideSubmitButton =
; } - if (taskToUse.type === 'Manual Task' && taskToUse.state === 'READY') { + if (task.type === 'Manual Task' && task.state === 'READY') { reactFragmentToHideSubmitButton = (
@@ -241,10 +247,13 @@ export default function TaskShow() { ); }; - const instructionsElement = (taskToUse: any) => { + const instructionsElement = () => { + if (!task) { + return null; + } let instructions = ''; - if (taskToUse.properties.instructionsForEndUser) { - instructions = taskToUse.properties.instructionsForEndUser; + if (task.properties.instructionsForEndUser) { + instructions = task.properties.instructionsForEndUser; } return (
@@ -256,21 +265,19 @@ export default function TaskShow() { }; if (task) { - const taskToUse = task as any; let statusString = ''; - if (taskToUse.state !== 'READY') { - statusString = ` ${taskToUse.state}`; + if (task.state !== 'READY') { + statusString = ` ${task.state}`; } return (
{buildTaskNavigation()}

- Task: {taskToUse.title} ({taskToUse.process_model_display_name}) - {statusString} + Task: {task.title} ({task.process_model_display_name}){statusString}

- {instructionsElement(taskToUse)} - {formElement(taskToUse)} + {instructionsElement()} + {formElement()}
); }