use the ProcessInstanceTask interface where we can and move some stuff around better for useEffect
This commit is contained in:
parent
5f7dac332f
commit
29034082cb
|
@ -24,20 +24,28 @@ export interface RecentProcessModel {
|
||||||
export interface ProcessInstanceTask {
|
export interface ProcessInstanceTask {
|
||||||
id: number;
|
id: number;
|
||||||
task_id: string;
|
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_id: number;
|
||||||
|
process_instance_status: string;
|
||||||
process_model_display_name: string;
|
process_model_display_name: string;
|
||||||
process_model_identifier: string;
|
process_model_identifier: string;
|
||||||
task_title: string;
|
properties: any;
|
||||||
lane_assignment_id: string;
|
|
||||||
process_instance_status: string;
|
|
||||||
state: string;
|
state: string;
|
||||||
process_identifier: string;
|
task_title: string;
|
||||||
name: string;
|
title: string;
|
||||||
process_initiator_username: string;
|
type: string;
|
||||||
created_at_in_seconds: number;
|
|
||||||
updated_at_in_seconds: number;
|
updated_at_in_seconds: number;
|
||||||
current_user_is_potential_owner: number;
|
|
||||||
calling_subprocess_task_id: string;
|
|
||||||
potential_owner_usernames?: string;
|
potential_owner_usernames?: string;
|
||||||
assigned_user_group_identifier?: string;
|
assigned_user_group_identifier?: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,8 +154,8 @@ export default function ProcessInstanceShow({ variant }: OwnProps) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
// targetUris,
|
targetUris,
|
||||||
// params,
|
params,
|
||||||
modifiedProcessModelId,
|
modifiedProcessModelId,
|
||||||
permissionsLoaded,
|
permissionsLoaded,
|
||||||
ability,
|
ability,
|
||||||
|
|
|
@ -20,11 +20,11 @@ import HttpService from '../services/HttpService';
|
||||||
import useAPIError from '../hooks/UseApiError';
|
import useAPIError from '../hooks/UseApiError';
|
||||||
import { modifyProcessIdentifierForPathParam } from '../helpers';
|
import { modifyProcessIdentifierForPathParam } from '../helpers';
|
||||||
import { useUriListForPermissions } from '../hooks/UriListForPermissions';
|
import { useUriListForPermissions } from '../hooks/UriListForPermissions';
|
||||||
import { PermissionsToCheck } from '../interfaces';
|
import { PermissionsToCheck, ProcessInstanceTask } from '../interfaces';
|
||||||
import { usePermissionFetcher } from '../hooks/PermissionService';
|
import { usePermissionFetcher } from '../hooks/PermissionService';
|
||||||
|
|
||||||
export default function TaskShow() {
|
export default function TaskShow() {
|
||||||
const [task, setTask] = useState(null);
|
const [task, setTask] = useState<ProcessInstanceTask | null>(null);
|
||||||
const [userTasks, setUserTasks] = useState(null);
|
const [userTasks, setUserTasks] = useState(null);
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
@ -39,16 +39,18 @@ export default function TaskShow() {
|
||||||
permissionRequestData
|
permissionRequestData
|
||||||
);
|
);
|
||||||
|
|
||||||
const processResult = (result: any) => {
|
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);
|
setTask(result);
|
||||||
const url = `/task-data/${modifyProcessIdentifierForPathParam(
|
const url = `/task-data/${modifyProcessIdentifierForPathParam(
|
||||||
result.process_model_identifier
|
result.process_model_identifier
|
||||||
)}/${params.process_instance_id}`;
|
)}/${params.process_instance_id}`;
|
||||||
if (
|
if (ability.can('GET', url)) {
|
||||||
result.process_model_identifier &&
|
|
||||||
ability.can('GET', url)
|
|
||||||
// Assure we get a valid process model identifier back
|
|
||||||
) {
|
|
||||||
HttpService.makeCallToBackend({
|
HttpService.makeCallToBackend({
|
||||||
path: url,
|
path: url,
|
||||||
successCallback: setUserTasks,
|
successCallback: setUserTasks,
|
||||||
|
@ -57,17 +59,17 @@ export default function TaskShow() {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (permissionsLoaded) {
|
|
||||||
HttpService.makeCallToBackend({
|
HttpService.makeCallToBackend({
|
||||||
path: `/tasks/${params.process_instance_id}/${params.task_id}`,
|
path: `/tasks/${params.process_instance_id}/${params.task_id}`,
|
||||||
successCallback: processResult,
|
successCallback: processResult,
|
||||||
failureCallback: addError,
|
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) => {
|
const processSubmitResult = (result: any) => {
|
||||||
removeError();
|
removeError();
|
||||||
|
@ -173,12 +175,16 @@ export default function TaskShow() {
|
||||||
return errors;
|
return errors;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formElement = (taskToUse: any) => {
|
const formElement = () => {
|
||||||
|
if (!task) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
let formUiSchema;
|
let formUiSchema;
|
||||||
let taskData = taskToUse.data;
|
let taskData = task.data;
|
||||||
let jsonSchema = taskToUse.form_schema;
|
let jsonSchema = task.form_schema;
|
||||||
let reactFragmentToHideSubmitButton = null;
|
let reactFragmentToHideSubmitButton = null;
|
||||||
if (taskToUse.type === 'Manual Task') {
|
if (task.type === 'Manual Task') {
|
||||||
taskData = {};
|
taskData = {};
|
||||||
jsonSchema = {
|
jsonSchema = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -196,10 +202,10 @@ export default function TaskShow() {
|
||||||
'ui:widget': 'hidden',
|
'ui:widget': 'hidden',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else if (taskToUse.form_ui_schema) {
|
} else if (task.form_ui_schema) {
|
||||||
formUiSchema = JSON.parse(taskToUse.form_ui_schema);
|
formUiSchema = JSON.parse(task.form_ui_schema);
|
||||||
}
|
}
|
||||||
if (taskToUse.state !== 'READY') {
|
if (task.state !== 'READY') {
|
||||||
formUiSchema = Object.assign(formUiSchema || {}, {
|
formUiSchema = Object.assign(formUiSchema || {}, {
|
||||||
'ui:readonly': true,
|
'ui:readonly': true,
|
||||||
});
|
});
|
||||||
|
@ -211,7 +217,7 @@ export default function TaskShow() {
|
||||||
reactFragmentToHideSubmitButton = <div />;
|
reactFragmentToHideSubmitButton = <div />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taskToUse.type === 'Manual Task' && taskToUse.state === 'READY') {
|
if (task.type === 'Manual Task' && task.state === 'READY') {
|
||||||
reactFragmentToHideSubmitButton = (
|
reactFragmentToHideSubmitButton = (
|
||||||
<div>
|
<div>
|
||||||
<Button type="submit">Continue</Button>
|
<Button type="submit">Continue</Button>
|
||||||
|
@ -241,10 +247,13 @@ export default function TaskShow() {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const instructionsElement = (taskToUse: any) => {
|
const instructionsElement = () => {
|
||||||
|
if (!task) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
let instructions = '';
|
let instructions = '';
|
||||||
if (taskToUse.properties.instructionsForEndUser) {
|
if (task.properties.instructionsForEndUser) {
|
||||||
instructions = taskToUse.properties.instructionsForEndUser;
|
instructions = task.properties.instructionsForEndUser;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="markdown">
|
<div className="markdown">
|
||||||
|
@ -256,21 +265,19 @@ export default function TaskShow() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (task) {
|
if (task) {
|
||||||
const taskToUse = task as any;
|
|
||||||
let statusString = '';
|
let statusString = '';
|
||||||
if (taskToUse.state !== 'READY') {
|
if (task.state !== 'READY') {
|
||||||
statusString = ` ${taskToUse.state}`;
|
statusString = ` ${task.state}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<div>{buildTaskNavigation()}</div>
|
<div>{buildTaskNavigation()}</div>
|
||||||
<h3>
|
<h3>
|
||||||
Task: {taskToUse.title} ({taskToUse.process_model_display_name})
|
Task: {task.title} ({task.process_model_display_name}){statusString}
|
||||||
{statusString}
|
|
||||||
</h3>
|
</h3>
|
||||||
{instructionsElement(taskToUse)}
|
{instructionsElement()}
|
||||||
{formElement(taskToUse)}
|
{formElement()}
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue