Skip to content

Commit c5d3955

Browse files
committed
Add explanation for resolveImmediatelyOnCancel for progress dialogs
1 parent 37954c2 commit c5d3955

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

  • content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/web-extensions-howtos/dialog-api.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ To show a progress dialog, call the method `studioPro.ui.dialogs.showProgressDia
230230
* `title`The title of the step, which is highlighted when the step runs.
231231
* `description`The description of the step, which shows at the bottom of the dialog next to the progress bar.
232232
* `action`The action the step performs that returns `Promise<true | string>`, where `string` indicates the reason for failure if the step fails, and `true` is returned otherwise.
233+
* `<resolveImmediatelyOnCancel>` - An optional boolean that, if provided, can only be `true`. It is only required if the progress dialog gets cancelled and the developer needs the result of the cancelled step at the exact time of the cancellation. The default behavior is that the cancelled step will finish, and the whole dialog will return the state that exists when the cancelled step is completed. If the developer needs the state that exists at the exact time of cancellation, then they can pass `true` for this parameter.
233234

234235
A checkmark icon appears next to the step title when the step completes successfully. If one of the steps fails, the dialog closes and the remaining steps do not run.
235236

@@ -238,9 +239,11 @@ The `showProgressDialog` method returns a `Promise<ProgressDialogResult>`. `Prog
238239
* `result`A string that is either `Success`, `Failure`, or `UserCancelled`:
239240
* `Success`Returned when all steps return `true`.
240241
* `Failure`Returned when one step fails, causing the dialog to close.
241-
* `UserCancelled`Returned when the user closes the dialog and interrupts the process.
242+
* `UserCancelled`Returned when the user closes the dialog and interrupts the process. The cancelled step still finishes executing, and unless `resolveImmediatelyOnCancel` is `true`, the final state of the result will contain the changes performed by the step.
242243
* `failedStep` (optional) – An object of type `FailedProgressStepResult` that describes the step that failed.
243244

245+
If the last step is cancelled, but it completed successfully, the whole result of the progress dialog will be `Success`.
246+
244247
The `FailedProgressStepResult` object contains the following properties:
245248

246249
* `stepTitle`The title of the step that failed, causing the whole process to fail.
@@ -313,6 +316,59 @@ export const component: IComponent = {
313316
};
314317
```
315318

319+
To see how `resolveImmediatelyOnCancel` influences the final state of the result, let's use the example above modified to set a value twice for each step into a dictionary called `state`. If `resolveImmediatelyOnCancel` is omitted when calling `showProgressDialog` (which is the default behavior), then the cancelled step will finish executing and the final result will have a value of `2` for the dictionary value set at that step.
320+
If however, the developer needs the cancelled step to not influence the final result, they should pass `true` for `resolveImmediatelyOnCancel`, and once the user cancels the progress dialog, the `state` dictionary will contain a value of `1` instead of `2` for the cancelled step.
321+
322+
```typescript
323+
const state: { [step: string]: number } = {};
324+
325+
const step1: ProgressDialogStep = {
326+
title: "Step 1",
327+
description: "Executing Step 1",
328+
action: async () => {
329+
// perform action
330+
state["step1"] = 1;
331+
// other things happening...
332+
await sleep(5000);
333+
state["step1"] = 2;
334+
return true;
335+
}
336+
};
337+
338+
const step2: ProgressDialogStep = {
339+
title: "Step 2",
340+
description: "Executing Step 2",
341+
action: async () => {
342+
// perform action
343+
state["step2"] = 1;
344+
// other things happening...
345+
await sleep(5000);
346+
state["step2"] = 2;
347+
348+
return true;
349+
}
350+
};
351+
352+
const step3: ProgressDialogStep = {
353+
title: "Step 3",
354+
description: "Executing Step 3",
355+
action: async () => {
356+
// perform action
357+
state["step3"] = 1;
358+
// other things happening...
359+
await sleep(5000);
360+
state["step3"] = 2;
361+
return true;
362+
}
363+
};
364+
365+
const resolveImmediatelyOnCancel = true;
366+
const result = await studioPro.ui.dialogs.showProgressDialog("Cancel This Progress", [step1, step2, step3], resolveImmediatelyOnCancel);
367+
368+
if (result.result === "Success") await studioPro.ui.messageBoxes.show("info", "Process completed successfully");
369+
if (result.result === "UserCancelled") await studioPro.ui.messageBoxes.show("info", "Process was cancelled. Result: " + JSON.stringify(state));
370+
```
371+
316372
Mendix recommends wrapping your step action body in a `try/catch` block so you can control the error that is returned to the user:
317373

318374
```typescript

0 commit comments

Comments
 (0)