Skip to content

Commit

Permalink
chore: porting config for toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
SteKoe committed Dec 20, 2022
1 parent 98ea756 commit 4854284
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
4 changes: 4 additions & 0 deletions spring-boot-admin-docs/src/site/asciidoc/server.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ In addition when the reverse proxy terminates the https connection, it may be ne
| Polling duration in ms to fetch new threads data.
| `2500`

| spring.boot.admin.ui.enable-toasts
| Allows to enable toast notifications.
| `false`

|===

include::_server-discovery.adoc[]
Expand Down
32 changes: 17 additions & 15 deletions spring-boot-admin-server-ui/src/main/frontend/utils/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ instance.create = axios.create;
export default instance;

export const registerErrorToastInterceptor = (axios) => {
axios.interceptors.response.use(
(response) => response,
(error) => {
const data = error.request;
let message = `
Request failed: ${data.statusText}<br>
<small>${data.responseURL}</small>
`;
nc.error(message, {
context: data.status ?? 'axios',
title: `Error ${data.status}`,
duration: 10_000,
});
}
);
if (sbaConfig.uiSettings.enableToasts === true) {
axios.interceptors.response.use(
(response) => response,
(error) => {
const data = error.request;
let message = `
Request failed: ${data.statusText}<br>
<small>${data.responseURL}</small>
`;
nc.error(message, {
context: data.status ?? 'axios',
title: `Error ${data.status}`,
duration: 10000,
});
}
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public UiController homeUiController(UiExtensions uiExtensions) throws IOExcepti

Settings uiSettings = Settings.builder().brand(this.adminUi.getBrand()).title(this.adminUi.getTitle())
.loginIcon(this.adminUi.getLoginIcon()).favicon(this.adminUi.getFavicon())
.faviconDanger(this.adminUi.getFaviconDanger())
.faviconDanger(this.adminUi.getFaviconDanger()).enableToasts(this.adminUi.getEnableToasts())
.notificationFilterEnabled(
!this.applicationContext.getBeansOfType(NotificationFilterController.class).isEmpty())
.routes(routes).rememberMeEnabled(this.adminUi.isRememberMeEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public class AdminServerUiProperties {
*/
private List<String> additionalRouteExcludes = new ArrayList<>();

/**
* Allows to enable toast notifications in SBA.
*/
private Boolean enableToasts = false;

private UiTheme theme = new UiTheme();

@lombok.Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public static class Settings {

private final List<ViewSettings> viewSettings;

private final Boolean enableToasts;

}

@lombok.Data
Expand Down

0 comments on commit 4854284

Please sign in to comment.