Skip to content

Commit

Permalink
fix: UI titles and message consistency (#3502)
Browse files Browse the repository at this point in the history
* Consistent UI Messages

Signed-off-by: Jakub Balhar <[email protected]>

* Consistent messaging
Add title explaining the state

Signed-off-by: Jakub Balhar <[email protected]>

* minor language fix

Signed-off-by: Andrew Jandacek <[email protected]>

---------

Signed-off-by: Jakub Balhar <[email protected]>
Signed-off-by: Andrew Jandacek <[email protected]>
Co-authored-by: Andrew Jandacek <[email protected]>
  • Loading branch information
balhar-jakub and janan07 authored May 28, 2024
1 parent ef78150 commit bcf992d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class GatewayHomepageController {

private static final String SUCCESS_ICON_NAME = "success";
private static final String WARNING_ICON_NAME = "warning";
protected static final String ERROR_TITLE = "The API Mediation Layer does not work";
protected static final String WARNING_TITLE = "There are limitations to how API Mediation Layer works";
protected static final String SUCCESS_TITLE = "The API Mediation Layer works properly";
private static final String UI_V1_ROUTE = "%s.ui-v1.%s";

private final DiscoveryClient discoveryClient;
Expand Down Expand Up @@ -101,6 +104,7 @@ private void initializeBuildInfos() {
private void initializeDiscoveryAttributes(Model model) {
String discoveryStatusText = null;
String discoveryIconName = null;
String discoveryTitleText = ERROR_TITLE;

List<ServiceInstance> serviceInstances = discoveryClient.getInstances("discovery");
if (serviceInstances != null) {
Expand All @@ -113,30 +117,36 @@ private void initializeDiscoveryAttributes(Model model) {
case 1:
discoveryStatusText = "The Discovery Service is running";
discoveryIconName = SUCCESS_ICON_NAME;
discoveryTitleText = SUCCESS_TITLE;
break;
default:
discoveryStatusText = discoveryCount + " Discovery Service instances are running";
discoveryIconName = SUCCESS_ICON_NAME;
discoveryTitleText = SUCCESS_TITLE;
break;
}
}

model.addAttribute("discoveryStatusText", discoveryStatusText);
model.addAttribute("discoveryIconName", discoveryIconName);
model.addAttribute("discoveryTitleText", discoveryTitleText);
}

private void initializeAuthenticationAttributes(Model model) {
String authStatusText = "The Authentication service is not running";
String authStatusText = "The Authentication Service is not running";
String authIconName = WARNING_ICON_NAME;
String authTitleText = WARNING_TITLE;
boolean authUp = authorizationServiceUp();

if (authUp) {
authStatusText = "The Authentication service is running";
authStatusText = "The Authentication Service is running";
authIconName = SUCCESS_ICON_NAME;
authTitleText = SUCCESS_TITLE;
}

model.addAttribute("authStatusText", authStatusText);
model.addAttribute("authIconName", authIconName);
model.addAttribute("authTitleText", authTitleText);
}

private void initializeCatalogAttributes(Model model) {
Expand All @@ -147,8 +157,9 @@ private void initializeCatalogAttributes(Model model) {
}

String catalogLink = null;
String catalogStatusText = "The API Catalog is not running";
String catalogStatusText = "The API Catalog Service is not running";
String catalogIconName = WARNING_ICON_NAME;
String catalogTitleText = WARNING_TITLE;
boolean linkEnabled = false;
boolean authServiceEnabled = authorizationServiceUp();

Expand All @@ -158,17 +169,19 @@ private void initializeCatalogAttributes(Model model) {
if (catalogCount > 0) {
linkEnabled = true;
catalogIconName = SUCCESS_ICON_NAME;
catalogTitleText = SUCCESS_TITLE;
catalogLink = getCatalogLink(serviceInstances.get(0));

catalogStatusText = catalogCount > 1 ?
catalogCount + " API Catalog instances are running" : "The API Catalog is running";
catalogCount + " API Catalog Service instances are running" : "The API Catalog Service is running";
}
}

model.addAttribute("catalogLink", catalogLink);
model.addAttribute("catalogIconName", catalogIconName);
model.addAttribute("catalogLinkEnabled", linkEnabled);
model.addAttribute("catalogStatusText", catalogStatusText);
model.addAttribute("catalogTitleText", catalogTitleText);
}

private String getCatalogLink(ServiceInstance catalogInstance) {
Expand All @@ -183,6 +196,7 @@ private void initializeMetricsAttributes(Model model) {
String metricsLink = null;
String metricsStatusText = "The Metrics Service is not running";
String metricsIconName = WARNING_ICON_NAME;
String metricsTitleText = WARNING_TITLE;

if (metricsServiceEnabled) {
List<ServiceInstance> metricsServiceInstances = discoveryClient.getInstances(metricsServiceId);
Expand All @@ -192,13 +206,15 @@ private void initializeMetricsAttributes(Model model) {
metricsIconName = SUCCESS_ICON_NAME;
metricsLink = getMetricsLink(metricsServiceInstances.get(0));
metricsStatusText = "The Metrics Service is running";
metricsTitleText = SUCCESS_TITLE;
}
}

model.addAttribute("metricsLinkEnabled", metricsLink != null);
model.addAttribute("metricsStatusText", metricsStatusText);
model.addAttribute("metricsIconName", metricsIconName);
model.addAttribute("metricsLink", metricsLink);
model.addAttribute("metricsTitleText", metricsTitleText);
}

private String getMetricsLink(ServiceInstance metricsInstance) {
Expand Down
12 changes: 8 additions & 4 deletions gateway-service/src/main/resources/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ <h1>API Mediation Layer</h1>
<li class="list-item">
<div class="wrap" th:if="${isAnyCatalogAvailable == true}"><img class="status-icon"
th:src="@{${'/images/icon-notification-intent-' + catalogIconName + '.png'}}"
alt="API Catalog status icon"/>
alt="API Catalog status icon"
th:title="${catalogTitleText}"/>
<a class="active"
th:if="${catalogLinkEnabled} == true"
th:href="${catalogLink}"
Expand All @@ -178,7 +179,8 @@ <h1>API Mediation Layer</h1>
<li class="list-item" th:if="${metricsEnabled == true}">
<div class="wrap"><img class="status-icon"
th:src="@{${'/images/icon-notification-intent-' + metricsIconName + '.png'}}"
alt="Metrics service running icon"/>
alt="Metrics service running icon"
th:title="${metricsTitleText}"/>
<a class="active"
th:if="${metricsLinkEnabled} == true"
th:href="${metricsLink}"
Expand All @@ -193,13 +195,15 @@ <h1>API Mediation Layer</h1>
<li class="list-item">
<div class="wrap"><img class="status-icon"
th:src="@{${'/images/icon-notification-intent-' + discoveryIconName + '.png'}}"
alt="Discovery service running icon"/>
alt="Discovery service running icon"
th:title="${discoveryTitleText}"/>
<p class="status-text" th:text="${discoveryStatusText}"/></div>
</li>
<li class="list-item">
<div class="wrap"><img class="status-icon"
th:src="@{${'/images/icon-notification-intent-' + authIconName + '.png'}}"
alt="Authentication service running icon"/>
alt="Authentication service running icon"
th:title="${authenticationTitleText}"/>
<p class="status-text" th:text="${authStatusText}"/></div>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ void givenOneApiCatalogInstance_whenHomePageCalled_thenHomePageModelShouldContai


assertCatalogIsUpMessageShown(model.asMap());
assertThat(model.asMap(), hasEntry("catalogStatusText", "The API Catalog is running"));
assertThat(model.asMap(), hasEntry("catalogStatusText", "The API Catalog Service is running"));
assertThat(model.asMap(), hasEntry("catalogTitleText", GatewayHomepageController.SUCCESS_TITLE));
}

@Test
Expand All @@ -170,20 +171,23 @@ void givenApiCatalogInstances_whenHomePageCalled_thenHomePageModelShouldContain(


assertCatalogIsUpMessageShown(model.asMap());
assertThat(model.asMap(), hasEntry("catalogStatusText", "2 API Catalog instances are running"));
assertThat(model.asMap(), hasEntry("catalogStatusText", "2 API Catalog Service instances are running"));
assertThat(model.asMap(), hasEntry("catalogTitleText", GatewayHomepageController.SUCCESS_TITLE));
}

private void assertCatalogIsDownMessageShown(Map<String, Object> preparedModelView) {
assertThat(preparedModelView, hasEntry("catalogIconName", "warning"));
assertThat(preparedModelView, hasEntry("catalogStatusText", "The API Catalog is not running"));
assertThat(preparedModelView, hasEntry("catalogStatusText", "The API Catalog Service is not running"));
assertThat(preparedModelView, hasEntry("catalogLinkEnabled", false));
assertThat(preparedModelView, not(hasKey("catalogLink")));
assertThat(preparedModelView, hasEntry("catalogTitleText", GatewayHomepageController.WARNING_TITLE));
}

private void assertCatalogIsUpMessageShown(Map<String, Object> preparedModelView) {
assertThat(preparedModelView, hasEntry("catalogIconName", "success"));
assertThat(preparedModelView, hasEntry("catalogLinkEnabled", true));
assertThat(preparedModelView, hasEntry("catalogLink", "/apicatalog/ui/v1"));
assertThat(preparedModelView, hasEntry("catalogTitleText", GatewayHomepageController.SUCCESS_TITLE));
}

private void discoveryReturnValidZosmfAuthorizationInstance() {
Expand Down Expand Up @@ -218,6 +222,7 @@ void givenDiscoveryServiceWithNullInstances_whenHomePageCalled_thenHomePageModel

assertThat(actualModelMap, IsMapContaining.hasEntry("discoveryIconName", "danger"));
assertThat(actualModelMap, IsMapContaining.hasEntry("discoveryStatusText", "The Discovery Service is not running"));
assertThat(actualModelMap, hasEntry("discoveryTitleText", GatewayHomepageController.ERROR_TITLE));
}


Expand All @@ -232,6 +237,7 @@ void givenDiscoveryServiceWithEmptyInstances_whenHomePageCalled_thenHomePageMode

assertThat(actualModelMap, IsMapContaining.hasEntry("discoveryIconName", "danger"));
assertThat(actualModelMap, IsMapContaining.hasEntry("discoveryStatusText", "The Discovery Service is not running"));
assertThat(actualModelMap, hasEntry("discoveryTitleText", GatewayHomepageController.ERROR_TITLE));
}

@Test
Expand All @@ -248,6 +254,7 @@ void givenDiscoveryServiceWithOneInstance_whenHomePageCalled_thenHomePageModelSh

assertThat(actualModelMap, IsMapContaining.hasEntry("discoveryIconName", "success"));
assertThat(actualModelMap, IsMapContaining.hasEntry("discoveryStatusText", "The Discovery Service is running"));
assertThat(actualModelMap, hasEntry("discoveryTitleText", GatewayHomepageController.SUCCESS_TITLE));
}

@Test
Expand All @@ -264,6 +271,7 @@ void givenDiscoveryServiceWithMoreThanOneInstance_whenHomePageCalled_thenHomePag

assertThat(actualModelMap, IsMapContaining.hasEntry("discoveryIconName", "success"));
assertThat(actualModelMap, IsMapContaining.hasEntry("discoveryStatusText", "2 Discovery Service instances are running"));
assertThat(actualModelMap, hasEntry("discoveryTitleText", GatewayHomepageController.SUCCESS_TITLE));
}


Expand All @@ -275,7 +283,8 @@ void givenDummyProvider_whenHomePageCalled_thenHomePageModelShouldContain() {
Map<String, Object> actualModelMap = model.asMap();

assertThat(actualModelMap, IsMapContaining.hasEntry("authIconName", "success"));
assertThat(actualModelMap, IsMapContaining.hasEntry("authStatusText", "The Authentication service is running"));
assertThat(actualModelMap, IsMapContaining.hasEntry("authStatusText", "The Authentication Service is running"));
assertThat(actualModelMap, hasEntry("authTitleText", GatewayHomepageController.SUCCESS_TITLE));
}

@Test
Expand All @@ -289,7 +298,8 @@ void givenZOSMFProviderIsntRunning_whenHomePageCalled_thenHomePageModelShouldCon
Map<String, Object> actualModelMap = model.asMap();

assertThat(actualModelMap, IsMapContaining.hasEntry("authIconName", "warning"));
assertThat(actualModelMap, IsMapContaining.hasEntry("authStatusText", "The Authentication service is not running"));
assertThat(actualModelMap, IsMapContaining.hasEntry("authStatusText", "The Authentication Service is not running"));
assertThat(actualModelMap, hasEntry("authTitleText", GatewayHomepageController.WARNING_TITLE));
}

@Test
Expand All @@ -303,7 +313,8 @@ void givenZOSMFProviderRunning_whenHomePageCalled_thenHomePageModelShouldContain
Map<String, Object> actualModelMap = model.asMap();

assertThat(actualModelMap, IsMapContaining.hasEntry("authIconName", "success"));
assertThat(actualModelMap, IsMapContaining.hasEntry("authStatusText", "The Authentication service is running"));
assertThat(actualModelMap, IsMapContaining.hasEntry("authStatusText", "The Authentication Service is running"));
assertThat(actualModelMap, hasEntry("authTitleText", GatewayHomepageController.SUCCESS_TITLE));
}

@Nested
Expand Down

0 comments on commit bcf992d

Please sign in to comment.