|
1 | 1 | import { useState, useEffect } from 'react'; |
2 | 2 |
|
3 | 3 | import { |
4 | | - getBusinessObject, |
5 | | - is, |
6 | 4 | isAny |
7 | 5 | } from 'bpmn-js/lib/util/ModelUtil'; |
8 | 6 |
|
9 | | -const SUPPORTED_ELEMENT_TYPES = [ 'bpmn:Task' ]; |
| 7 | +import { isInsideAdHocSubProcess } from '../utils/element'; |
10 | 8 |
|
11 | | -export const SINGLE_TASK_SELECTION_REQUIRED_MESSAGE = 'Select a task to start testing.'; |
12 | | -export const TASK_SELECTION_REQUIRED_MESSAGE = 'Task testing is only supported for tasks. Select a task to start testing.'; |
13 | | -export const AD_HOC_SUBPROCESS_TASK_UNSUPPORTED_MESSAGE = 'Task testing is not supported for tasks inside an ad-hoc subprocess. Select a different task to start testing.'; |
| 9 | +const SUPPORTED_ELEMENT_TYPES = [ 'bpmn:Task', 'bpmn:SubProcess' ]; |
| 10 | + |
| 11 | +export const SINGLE_TASK_SELECTION_REQUIRED_MESSAGE = 'Select a task or subprocess to start testing.'; |
| 12 | +export const TASK_SELECTION_REQUIRED_MESSAGE = 'Task testing is only supported for tasks and subprocesses. Select one to start testing.'; |
| 13 | +export const AD_HOC_SUBPROCESS_MESSAGE = 'Task testing is not supported for tasks inside ad-hoc subprocesses.'; |
14 | 14 |
|
15 | 15 | /** |
16 | | - * Get currently selected BPMN element, if it is a single `bpmn:Task`. If not, |
17 | | - * return null and a message indicating what to do. |
| 16 | + * Get currently selected BPMN element, if it is a single supported element |
| 17 | + * (`bpmn:Task` or `bpmn:SubProcess`). If not, return null and a message |
| 18 | + * indicating what to do. |
18 | 19 | * |
19 | 20 | * @param {Object} injector |
20 | 21 | * @return {[ Object|null, string|null ]} |
@@ -74,27 +75,11 @@ function validateSelection(selection) { |
74 | 75 | return TASK_SELECTION_REQUIRED_MESSAGE; |
75 | 76 | } |
76 | 77 |
|
77 | | - if (isInAdHocSubprocess(selection[0])) { |
78 | | - return AD_HOC_SUBPROCESS_TASK_UNSUPPORTED_MESSAGE; |
| 78 | + if (isInsideAdHocSubProcess(selection[0])) { |
| 79 | + return AD_HOC_SUBPROCESS_MESSAGE; |
79 | 80 | } |
80 | 81 |
|
81 | 82 | return null; |
82 | 83 | } |
83 | 84 |
|
84 | | -function isInAdHocSubprocess(element) { |
85 | | - const bo = getBusinessObject(element); |
86 | | - let parent = getParent(bo); |
87 | | - |
88 | | - while (parent) { |
89 | | - if (is(parent, 'bpmn:AdHocSubProcess')) { |
90 | | - return true; |
91 | | - } |
92 | | - parent = getParent(parent); |
93 | | - } |
94 | 85 |
|
95 | | - return false; |
96 | | -} |
97 | | - |
98 | | -function getParent(bo) { |
99 | | - return bo.$parent; |
100 | | -} |
0 commit comments