Skip to content

Commit 708d516

Browse files
committed
feat: add onTaskExecutionError andonTaskExecutionCancelled props
Related to camunda/camunda-modeler#5597
1 parent 34f6769 commit 708d516

File tree

4 files changed

+383
-1
lines changed

4 files changed

+383
-1
lines changed

demo/App.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ function App() {
162162
onConfigChanged={ onConfigChanged }
163163
operateBaseUrl={ operateURL }
164164
documentationUrl="https://docs.camunda.io/"
165+
onTaskExecutionStarted={ (element) => {
166+
console.log('Task execution started:', element.id);
167+
} }
168+
onTaskExecutionFinished={ (element, output) => {
169+
console.log('Task execution finished:', element.id, output);
170+
} }
171+
onTaskExecutionError={ (element, error) => {
172+
console.log('Task execution error:', element.id, error);
173+
} }
174+
onTaskExecutionInterrupted={ () => {
175+
console.log('Task execution interrupted');
176+
} }
177+
onTaskExecutionCanceled={ () => {
178+
console.log('Task execution canceled');
179+
} }
165180
/>
166181
</div>
167182
</>

lib/TaskExecution.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const SCOPES = {
4141
* - `taskExecution.finished` with {@link TaskExecutionResult}
4242
* - `taskExecution.error` with {@link TaskExecutionError}
4343
* - `taskExecution.interrupted` when execution is interrupted by switching focus
44+
* - `taskExecution.canceled` when execution is manually canceled by the user
4445
*/
4546
export default class TaskExecution extends EventEmitter {
4647

@@ -243,11 +244,17 @@ export default class TaskExecution extends EventEmitter {
243244
// - delete process definition
244245
// - cancel deploy and start instance if they are in progress
245246

247+
const wasCanceled = this._status !== 'idle';
248+
246249
if (this._interval) {
247250
clearInterval(this._interval);
248251
}
249252

250253
this._changeStatus('idle');
254+
255+
if (wasCanceled) {
256+
this.emit('taskExecution.canceled');
257+
}
251258
}
252259

253260
/**

lib/components/TaskTesting/TaskTesting.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ import { OutputTab } from '../Output/OutputVariables';
5353
* @param {string} [props.documentationUrl]
5454
* @param {Function} [props.onTaskExecutionStarted=() => {}]
5555
* @param {Function} [props.onTaskExecutionFinished=() => {}]
56+
* @param {Function} [props.onTaskExecutionError=() => {}]
5657
* @param {Function} [props.onTaskExecutionInterrupted=() => {}]
58+
* @param {Function} [props.onTaskExecutionCanceled=() => {}]
5759
* @param {React.ReactNode[]} [props.children=[]]
5860
*/
5961
export default function TaskTesting({
@@ -71,6 +73,8 @@ export default function TaskTesting({
7173
documentationUrl,
7274
onTaskExecutionStarted = () => {},
7375
onTaskExecutionFinished = () => {},
76+
onTaskExecutionError = () => {},
77+
onTaskExecutionCanceled = () => {},
7478
onTaskExecutionInterrupted = () => {},
7579
children = []
7680
}) {
@@ -210,6 +214,7 @@ export default function TaskTesting({
210214
success: false,
211215
error
212216
});
217+
onTaskExecutionError(element, error);
213218
};
214219

215220
/**
@@ -242,17 +247,23 @@ export default function TaskTesting({
242247
onTaskExecutionInterrupted();
243248
};
244249

250+
const handleCanceled = () => {
251+
onTaskExecutionCanceled();
252+
};
253+
245254
taskExecutionRef?.current?.on('taskExecution.finished', handleFinished);
246255
taskExecutionRef?.current?.on('taskExecution.status.changed', handleStatusChange);
247256
taskExecutionRef?.current?.on('taskExecution.error', handleError);
248257
taskExecutionRef?.current?.on('taskExecution.interrupted', handleInterrupted);
258+
taskExecutionRef?.current?.on('taskExecution.canceled', handleCanceled);
249259

250260
return () => {
251261
if (taskExecutionRef.current) {
252262
taskExecutionRef.current.off('taskExecution.finished', handleFinished);
253263
taskExecutionRef.current.off('taskExecution.status.changed', handleStatusChange);
254264
taskExecutionRef.current.off('taskExecution.error', handleError);
255265
taskExecutionRef.current.off('taskExecution.interrupted', handleInterrupted);
266+
taskExecutionRef.current.off('taskExecution.canceled', handleCanceled);
256267
}
257268
};
258269
}, [ element, operateBaseUrl, currentOperateUrl ]);

0 commit comments

Comments
 (0)