Skip to content

Commit 3fe4be2

Browse files
committed
Add doc and sample code for showing a progress dialog.
Also add info about action for the Menu object
1 parent 14a4643 commit 3fe4be2

5 files changed

Lines changed: 157 additions & 1 deletion

File tree

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/extensibility-api/web/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Below is a list of how-tos for you to begin with:
4444
* [How to Show a Popup Notification](/apidocs-mxsdk/apidocs/web-extensibility-api-11/notification-api/)
4545
* [How to View User Preferences](/apidocs-mxsdk/apidocs/web-extensibility-api-11/preference-api/)
4646
* [How to Show a Modal Dialog](/apidocs-mxsdk/apidocs/web-extensibility-api-11/dialog-api/)
47+
* [How to Show a Progress Dialog](/apidocs-mxsdk/apidocs/web-extensibility-api-11/progress-dialogs/)
4748
* [How to Open Documents](/apidocs-mxsdk/apidocs/web-extensibility-api-11/editor-api/)
4849
* [How to Exchange Information Between Active Views](/apidocs-mxsdk/apidocs/web-extensibility-api-11/message-passing-api/)
4950
* [How to Show Version Control Information](/apidocs-mxsdk/apidocs/web-extensibility-api-11/version-control-api/)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ url: /apidocs-mxsdk/apidocs/web-extensibility-api-11/dialog-api/
77
## Introduction
88

99
This how-to describes how to open a modal dialog in Studio Pro from an extension. This dialog will contain your web content.
10+
It will also describe how to show a progress dialog which contains a sequence of steps and return a result for the whole process.
1011

1112
## Prerequisites
1213

@@ -16,7 +17,7 @@ This how-to uses the results of [Get Started with the Web Extensibility API](/ap
1617

1718
Create a menu item to open the dialog. This is done inside the `loaded` event in the main entry point (`src/main/index.ts`). For more information, see [Create a Menu Using Web API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/menu-api/).
1819

19-
In a listener event called `menuItemActivated`, the `studioPro.ui.dialogs.showModal(<dialogInfo>, <uiSpec>)` call opens a new tab where:
20+
In a listener event called `menuItemActivated`, the `studioPro.ui.dialogs.showModal(<dialogInfo>, <uiSpec>)` call opens a new dialog where:
2021

2122
* `<dialogInfo>` is an object containing the `title` of the dialog, which is shown in the title bar of your dialog in Studio Pro. It also contains the `contentSize` object, where `height` and `width` dimensions for the dialog can be provided.
2223
* `<uiSpec>` is an object containing two required properties and one optional property:

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ The menu has the following properties:
7979
* `hasSeparatorBefore` (default: `false`) – shows a visual separator before this menu item
8080
* `hasSeparatorAfter` (default: `false`) – shows a visual separator after this menu item
8181
* `enabled` (default: `true`) – indicates that this menu item notifies the listener when clicked
82+
* `commandId` (optional) - the id of the previously registered command which will execute when the menu is clicked
83+
* `action` (optional) - the action that will execute when the menu is clicked
8284

8385
{{< figure src="/attachments/apidocs-mxsdk/apidocs/extensibility-api/web/menus/grouped_menus.png" >}}
8486

@@ -201,6 +203,37 @@ Instead of listening to the `menuItemActivated` event, it is possible to registe
201203

202204
For a full explanation on how to register commands, see the [Commands API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/command-api/).
203205

206+
## Setting the Action Property on the Menu
207+
208+
It is also possible to set the `action` property on the menu directly.
209+
210+
```typescript
211+
import { IComponent, Menu, getStudioProApi } from "@mendix/extensions-api";
212+
213+
export const component: IComponent = {
214+
async loaded(componentContext) {
215+
const studioPro = getStudioProApi(componentContext);
216+
const menuApi = studioPro.ui.extensionsMenu;
217+
218+
const menuId = "my-menu-unique-id";
219+
const caption = "Menu with Action";
220+
221+
const menu: Menu = {
222+
caption: caption,
223+
menuId: menuId,
224+
action: async () => {
225+
await menuApi.update(menuId, {
226+
caption: `${caption} (Disabled)`,
227+
enabled: false
228+
});
229+
}
230+
};
231+
232+
await menuApi.add(menu);
233+
}
234+
}
235+
```
236+
204237
## Conclusion
205238

206239
You have seen how to create simple menu items and menu items with sub menus.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
title: "Show a Progress Dialog Using Web API"
3+
linktitle: "Show a Progress Dialog"
4+
url: /apidocs-mxsdk/apidocs/web-extensibility-api-11/progress-dialogs/
5+
---
6+
7+
## Showing a Progress Dialog
8+
First, create a menu that you will use to open the progress dialog.
9+
10+
To show a progress dialog, you will need to call the method `studioPro.ui.dialogs.showProgressDialog(<title>, <steps>)`, where:
11+
12+
* `<title>` is a string which will be displayed in the title bar of the dialog.
13+
* `<steps>` is an array of `ProgressDialogStep`, which will run in the same order provided in the array. A `ProgressDialogStep` object containing the following properties:
14+
* `title` — the title of the step. It is highlighted when the step is running
15+
* `description` — the description of the step. It will show at the bottom of the dialog next to the progress bar
16+
* `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.
17+
18+
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.
19+
20+
The `showProgressDialog` method returns a `Promise<ProgressDialogResult>`. `ProgressDialogResult` is an object that contains the following properties:
21+
* `result` - a string that is either `Success`, `Failure` or `UserCancelled`
22+
* `Success` is returned when all the steps have returned true
23+
* `Failure` is returned when one step has failed, causing the dialog to close
24+
* `UserCancelled` is returned when the user closes the dialog themselves and interrupts the process
25+
* `failedStep` (optional) - it is an object of type `FailedProgressStepResult` which describes the actual step that has failed
26+
27+
The `FailedProgressStepResult` object contains the following properties:
28+
* `stepTitle` - the title of the step that has failed, causing the whole process to fail
29+
* `error` - a string which describes the error or exception that has occurred during the step execution
30+
31+
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`). For more information, see [Create a Menu Using Web API](/apidocs-mxsdk/apidocs/web-extensibility-api-11/menu-api/).
32+
33+
```typescript
34+
import { ComponentContext, IComponent, ProgressDialogStep, getStudioProApi } from "@mendix/extensions-api";
35+
36+
export const component: IComponent = {
37+
async loaded(componentContext: ComponentContext) {
38+
const studioPro = getStudioProApi(componentContext);
39+
40+
const step1: ProgressDialogStep = {
41+
title: "Step 1",
42+
description: "Executing Step 1",
43+
action: async () => {
44+
// perform action
45+
return true;
46+
}
47+
};
48+
49+
const step2: ProgressDialogStep = {
50+
title: "Step 2",
51+
description: "Executing Step 2",
52+
action: async () => {
53+
// perform action
54+
return true;
55+
}
56+
};
57+
58+
const step3: ProgressDialogStep = {
59+
title: "Step 3",
60+
description: "Executing Step 3",
61+
action: async () => {
62+
// perform action
63+
return true;
64+
}
65+
};
66+
67+
// menu to call `showProgressDialog` method
68+
await studioPro.ui.extensionsMenu.add({
69+
caption: "Sample Progress Dialog",
70+
menuId: `myextension.start-progress-menu`,
71+
action: async () => {
72+
const steps = [step1, step2, step3];
73+
const progressDialogResult = await studioPro.ui.dialogs.showProgressDialog("Sample Progress Dialog", steps);
74+
75+
switch (progressDialogResult.result) {
76+
case "Success":
77+
await studioPro.ui.messageBoxes.show("info", "Process completed successfully");
78+
break;
79+
80+
case "UserCancelled":
81+
await studioPro.ui.messageBoxes.show("info", "Process was cancelled by the user");
82+
break;
83+
84+
case "Failure": {
85+
const errorMessage = `Step '${progressDialogResult.failedStep?.stepTitle}' has failed'`;
86+
const errorDetails = progressDialogResult.failedStep?.error ?? "";
87+
88+
await studioPro.ui.messageBoxes.show("error", errorMessage, errorDetails);
89+
break;
90+
}
91+
}
92+
}
93+
});
94+
}
95+
};
96+
```
97+
98+
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:
99+
```typescript
100+
const step: ProgressDialogStep = {
101+
title: "Step X",
102+
description: "Executing Step X",
103+
action: async () => {
104+
try {
105+
// perform action
106+
return true;
107+
} catch (error: Error | unknown) {
108+
return error instanceof Error ? error.message : "An error occurred while performing Step X";
109+
}
110+
}
111+
};
112+
```
113+
114+
When running, the progress dialog will look like this:
115+
{{< figure src="/attachments/apidocs-mxsdk/apidocs/extensibility-api/web/dialogs/sample-progress-dialog.png" >}}
116+
117+
## Extensibility Feedback
118+
119+
If you would like to provide us with additional feedback, you can complete a small [survey](https://survey.alchemer.eu/s3/90801191/Extensibility-Feedback).
120+
121+
Any feedback is appreciated.
32.8 KB
Loading

0 commit comments

Comments
 (0)