Skip to content

Commit 733a3e9

Browse files
committed
Move content into Dialog API doc
1 parent 1b99a83 commit 733a3e9

2 files changed

Lines changed: 114 additions & 130 deletions

File tree

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

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ url: /apidocs-mxsdk/apidocs/web-extensibility-api-11/dialog-api/
88

99
This how-to describes how to open a modal dialog in Studio Pro from an extension, allowing you to display web content.
1010

11+
It also describes how to show a progress dialog that follows a sequence of steps and returns a result upon completion.
12+
1113
## Prerequisites
1214

1315
This how-to uses the results of [Get Started with the Web Extensibility API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/getting-started/). Please complete that how-to before starting this one. You should also be familiar with creating menus as described in [Create a Menu Using Web API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/menu-api/).
@@ -225,6 +227,118 @@ You can also modify the dimensions of a dialog using the dialog API's `update` m
225227

226228
You can also modify the dialog's dimensions while it is open.
227229

230+
## Showing a Progress Dialog
231+
232+
To show a progress dialog, you will need to call the method `studioPro.ui.dialogs.showProgressDialog(<title>, <steps>)`, where:
233+
234+
* `<title>` is a string which will be displayed in the title bar of the dialog.
235+
* `<steps>` is an array of `ProgressDialogStep`, which will run in the same order provided in the array. A `ProgressDialogStep` object containing the following properties:
236+
* `title`the title of the step. It is highlighted when the step is running
237+
* `description`the description of the step. It will show at the bottom of the dialog next to the progress bar
238+
* `action`the action that the step will perform. It returns `Promise<true | string>`. If the step fails, string should be the reason for the failure. Otherwise, `true` will be returned.
239+
240+
A checkmark icon will be shown next to the step title after the step has completed successfully. But if one of the steps fails, the dialog will close and the remaining steps will not be executed.
241+
242+
The `showProgressDialog` method returns a `Promise<ProgressDialogResult>`. `ProgressDialogResult` is an object that contains the following properties:
243+
244+
* `result` - a string that is either `Success`, `Failure` or `UserCancelled`
245+
* `Success` is returned when all the steps have returned true
246+
* `Failure` is returned when one step has failed, causing the dialog to close
247+
* `UserCancelled` is returned when the user closes the dialog themselves and interrupts the process
248+
* `failedStep` (optional) - it is an object of type `FailedProgressStepResult` which describes the actual step that has failed
249+
250+
The `FailedProgressStepResult` object contains the following properties:
251+
252+
* `stepTitle` - the title of the step that has failed, causing the whole process to fail
253+
* `error` - a string which describes the error or exception that has occurred during the step execution
254+
255+
In this example, we will create a menu to show the modal progress dialog, and run three steps. This is done inside the `loaded` event in the main entry point (`src/main/index.ts`).
256+
257+
```typescript
258+
import { ComponentContext, IComponent, ProgressDialogStep, getStudioProApi } from "@mendix/extensions-api";
259+
260+
export const component: IComponent = {
261+
async loaded(componentContext: ComponentContext) {
262+
const studioPro = getStudioProApi(componentContext);
263+
264+
const step1: ProgressDialogStep = {
265+
title: "Step 1",
266+
description: "Executing Step 1",
267+
action: async () => {
268+
// perform action
269+
return true;
270+
}
271+
};
272+
273+
const step2: ProgressDialogStep = {
274+
title: "Step 2",
275+
description: "Executing Step 2",
276+
action: async () => {
277+
// perform action
278+
return true;
279+
}
280+
};
281+
282+
const step3: ProgressDialogStep = {
283+
title: "Step 3",
284+
description: "Executing Step 3",
285+
action: async () => {
286+
// perform action
287+
return true;
288+
}
289+
};
290+
291+
// menu to call `showProgressDialog` method
292+
await studioPro.ui.extensionsMenu.add({
293+
caption: "Sample Progress Dialog",
294+
menuId: `myextension.start-progress-menu`,
295+
action: async () => {
296+
const steps = [step1, step2, step3];
297+
const progressDialogResult = await studioPro.ui.dialogs.showProgressDialog("Sample Progress Dialog", steps);
298+
299+
switch (progressDialogResult.result) {
300+
case "Success":
301+
await studioPro.ui.messageBoxes.show("info", "Process completed successfully");
302+
break;
303+
304+
case "UserCancelled":
305+
await studioPro.ui.messageBoxes.show("info", "Process was cancelled by the user");
306+
break;
307+
308+
case "Failure": {
309+
const errorMessage = `Step '${progressDialogResult.failedStep?.stepTitle}' has failed'`;
310+
const errorDetails = progressDialogResult.failedStep?.error ?? "";
311+
312+
await studioPro.ui.messageBoxes.show("error", errorMessage, errorDetails);
313+
break;
314+
}
315+
}
316+
}
317+
});
318+
}
319+
};
320+
```
321+
322+
It is recommended to always wrap your step action body in a `try/catch` block so that you can be in control of the error that gets returned to the user:
323+
324+
```typescript
325+
const step: ProgressDialogStep = {
326+
title: "Step X",
327+
description: "Executing Step X",
328+
action: async () => {
329+
try {
330+
// perform action
331+
return true;
332+
} catch (error: Error | unknown) {
333+
return error instanceof Error ? error.message : "An error occurred while performing Step X";
334+
}
335+
}
336+
};
337+
```
338+
339+
When running, the progress dialog will look like this:
340+
{{< figure src="/attachments/apidocs-mxsdk/apidocs/extensibility-api/web/dialogs/sample-progress-dialog.png" >}}
341+
228342
## Extensibility Feedback
229343

230344
If you would like to provide us with additional feedback, you can complete a small [survey](https://survey.alchemer.eu/s3/90801191/Extensibility-Feedback).

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

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)