get all of the process identifiers that the diagram knows about so we can display the correct task info

This commit is contained in:
jasquat 2022-12-15 14:55:06 -05:00
parent 5d692cff46
commit 5ecc775d29
3 changed files with 42 additions and 11 deletions

View File

@ -58,7 +58,7 @@ import { Can } from '@casl/react';
import HttpService from '../services/HttpService'; import HttpService from '../services/HttpService';
import ButtonWithConfirmation from './ButtonWithConfirmation'; import ButtonWithConfirmation from './ButtonWithConfirmation';
import { makeid } from '../helpers'; import { getBpmnProcessIdentifiers, makeid } from '../helpers';
import { useUriListForPermissions } from '../hooks/UriListForPermissions'; import { useUriListForPermissions } from '../hooks/UriListForPermissions';
import { PermissionsToCheck, ProcessInstanceTask } from '../interfaces'; import { PermissionsToCheck, ProcessInstanceTask } from '../interfaces';
import { usePermissionFetcher } from '../hooks/PermissionService'; import { usePermissionFetcher } from '../hooks/PermissionService';
@ -231,8 +231,10 @@ export default function ReactDiagramEditor({
function handleElementClick(event: any) { function handleElementClick(event: any) {
if (onElementClick) { if (onElementClick) {
const canvas = diagramModeler.get('canvas'); const canvas = diagramModeler.get('canvas');
const rootElement = canvas.getRootElement(); const bpmnProcessIdentifiers = getBpmnProcessIdentifiers(
onElementClick(event.element, rootElement); canvas.getRootElement()
);
onElementClick(event.element, bpmnProcessIdentifiers);
} }
} }
@ -357,11 +359,15 @@ export default function ReactDiagramEditor({
canvas: any, canvas: any,
processInstanceTask: ProcessInstanceTask, processInstanceTask: ProcessInstanceTask,
bpmnIoClassName: string, bpmnIoClassName: string,
bpmnRootElementId: string bpmnProcessIdentifiers: string[]
) { ) {
if (checkTaskCanBeHighlighted(processInstanceTask.name)) { if (checkTaskCanBeHighlighted(processInstanceTask.name)) {
try { try {
if (bpmnRootElementId === processInstanceTask.process_identifier) { if (
bpmnProcessIdentifiers.includes(
processInstanceTask.process_identifier
)
) {
canvas.addMarker(processInstanceTask.name, bpmnIoClassName); canvas.addMarker(processInstanceTask.name, bpmnIoClassName);
} }
} catch (bpmnIoError: any) { } catch (bpmnIoError: any) {
@ -403,24 +409,28 @@ export default function ReactDiagramEditor({
// Option 3 at: // Option 3 at:
// https://github.com/bpmn-io/bpmn-js-examples/tree/master/colors // https://github.com/bpmn-io/bpmn-js-examples/tree/master/colors
if (readyOrWaitingProcessInstanceTasks) { if (readyOrWaitingProcessInstanceTasks) {
const rootElement = canvas.getRootElement(); const bpmnProcessIdentifiers = getBpmnProcessIdentifiers(
canvas.getRootElement()
);
readyOrWaitingProcessInstanceTasks.forEach((readyOrWaitingBpmnTask) => { readyOrWaitingProcessInstanceTasks.forEach((readyOrWaitingBpmnTask) => {
highlightBpmnIoElement( highlightBpmnIoElement(
canvas, canvas,
readyOrWaitingBpmnTask, readyOrWaitingBpmnTask,
'active-task-highlight', 'active-task-highlight',
rootElement.id bpmnProcessIdentifiers
); );
}); });
} }
if (completedProcessInstanceTasks) { if (completedProcessInstanceTasks) {
const rootElement = canvas.getRootElement(); const bpmnProcessIdentifiers = getBpmnProcessIdentifiers(
canvas.getRootElement()
);
completedProcessInstanceTasks.forEach((completedTask) => { completedProcessInstanceTasks.forEach((completedTask) => {
highlightBpmnIoElement( highlightBpmnIoElement(
canvas, canvas,
completedTask, completedTask,
'completed-task-highlight', 'completed-task-highlight',
rootElement.id bpmnProcessIdentifiers
); );
}); });
} }

View File

@ -213,3 +213,24 @@ export const refreshAtInterval = (
clearTimeout(timeoutRef); clearTimeout(timeoutRef);
}; };
}; };
const getChildProcesses = (bpmnElement: any) => {
let elements: string[] = [];
bpmnElement.children.forEach((c: any) => {
if (c.type === 'bpmn:Participant') {
if (c.businessObject.processRef) {
elements.push(c.businessObject.processRef.id);
}
elements = [...elements, ...getChildProcesses(c)];
} else if (c.type === 'bpmn:SubProcess') {
elements.push(c.id);
}
});
return elements;
};
export const getBpmnProcessIdentifiers = (rootBpmnElement: any) => {
const childProcesses = getChildProcesses(rootBpmnElement);
childProcesses.push(rootBpmnElement.businessObject.id);
return childProcesses;
};

View File

@ -392,13 +392,13 @@ export default function ProcessInstanceShow() {
const handleClickedDiagramTask = ( const handleClickedDiagramTask = (
shapeElement: any, shapeElement: any,
bpmnRootElement: any bpmnProcessIdentifiers: any
) => { ) => {
if (tasks) { if (tasks) {
const matchingTask: any = tasks.find( const matchingTask: any = tasks.find(
(task: any) => (task: any) =>
task.name === shapeElement.id && task.name === shapeElement.id &&
task.process_identifier === bpmnRootElement.id bpmnProcessIdentifiers.includes(task.process_identifier)
); );
if (matchingTask) { if (matchingTask) {
setTaskToDisplay(matchingTask); setTaskToDisplay(matchingTask);