Skip to content

Commit

Permalink
Feature - customAlertHandler (SAP#2304)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesDoberer authored Oct 27, 2021
1 parent 4f9fda6 commit a47559a
Show file tree
Hide file tree
Showing 5 changed files with 10,694 additions and 20 deletions.
12 changes: 10 additions & 2 deletions core/src/App.html
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,10 @@
};

export const showAlert = (settings, openFromClient = false) => {
const customAlertHandler = LuigiConfig.getConfigValue('settings.customAlertHandler');
if (GenericHelpers.isFunction(customAlertHandler)) {
return customAlertHandler(settings, openFromClient);
}
const currentAlerts = alerts;

if (!settings.id) {
Expand Down Expand Up @@ -1477,8 +1481,12 @@

if ('luigi.ux.alert.show' === e.data.msg) {
const { settings } = e.data.data;

if (!settings.text) {
if (
!settings.text &&
!GenericHelpers.isFunction(
LuigiConfig.getConfigValue('settings.customAlertHandler')
)
) {
console.error(
"Luigi Client alert: 'text' field for alert is empty or not present, therefore alert will not be displayed"
);
Expand Down
15 changes: 15 additions & 0 deletions docs/general-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ theming : {
}
}
```
* **customAlertHandler** is a function which will be called if it is defined. With this function, Luigi alerts will be disabled and you can implement your own alerts. This function gets `settings` and `openFromClient` as parameters. In addition, we recommend to return a [promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise):
```javascript
Luigi.setConfig({
...,
settings: {
customAlertHandler: ()=>{
return new Promise((resolve, reject) => {
//custom alert implementation
});
}
}
})
```
### Third-party cookies support check
Expand Down
4 changes: 4 additions & 0 deletions docs/luigi-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,10 @@ Returns **[promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/

- **since**: 0.6.4

<!-- add-attribute:class:warning -->

> **NOTE:** You can also define a [customAlertHandler](general-settings.md#general-parameters) function to implement custom alerts.
#### showConfirmationModal

Shows a confirmation modal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Settings {
featureToggles = {
queryStringParam: 'ft'
};

// customAlertHandler = (settings, openFromClient = false) =>{
// window.open('http://localhost:4200',settings.title , `width=${settings.width},height=${settings.height}`);
// }

// sideNavCompactMode = true;
// allowRules = ['microphone'];
// iframeCreationInterceptor = (iframe, viewGroup, navigationNode, microFrontendType) => { };
Expand Down
Loading

0 comments on commit a47559a

Please sign in to comment.