Skip to content

Commit bd8f007

Browse files
author
Daman Arora
committed
Hide empty webhooks on rule details and hint the default cooldown
1 parent 541fa7f commit bd8f007

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎plugins/resource-alerts/src/main/java/org/apache/cloudstack/resourcealert/ResourceAlertServiceImpl.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ private ResourceAlertRuleResponse toRuleResponse(ResourceAlertRuleJoinVO vo) {
295295
r.setResetInterval(vo.getResetInterval());
296296
List<Pair<String, String>> webhooks = describeWebhooks(vo.getId());
297297
r.setWebhookIds(webhooks.stream().map(Pair::first).collect(Collectors.toList()));
298-
r.setWebhookNames(webhooks.stream().map(Pair::second).collect(Collectors.toList()));
298+
// Left out when empty so the UI hides it
299+
r.setWebhookNames(webhooks.isEmpty() ? null : webhooks.stream().map(Pair::second).collect(Collectors.toList()));
299300
r.setAccountName(vo.getAccountName());
300301
r.setDomainId(vo.getDomainUuid());
301302
r.setDomainName(vo.getDomainName());

‎plugins/resource-alerts/src/test/java/org/apache/cloudstack/resourcealert/ResourceAlertServiceImplTest.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.cloudstack.resourcealert;
1919

2020
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertNull;
2122
import static org.mockito.ArgumentMatchers.any;
2223
import static org.mockito.ArgumentMatchers.eq;
2324
import static org.mockito.Mockito.doReturn;
@@ -520,4 +521,16 @@ public void testRuleResponseIncludesWebhookIdsAndNames() {
520521
assertEquals(List.of("wh-1"), org.springframework.test.util.ReflectionTestUtils.getField(response, "webhookIds"));
521522
assertEquals(List.of("ops-hook"), org.springframework.test.util.ReflectionTestUtils.getField(response, "webhookNames"));
522523
}
524+
525+
@Test
526+
public void testRuleResponseLeavesOutWebhookNamesWhenNone() {
527+
ResourceAlertRuleJoinVO joined = mock(ResourceAlertRuleJoinVO.class);
528+
when(joined.getResourceType()).thenReturn(ResourceAlertRule.ResourceType.VirtualMachine);
529+
when(ruleJoinDao.findById(Mockito.anyLong())).thenReturn(joined);
530+
531+
ResourceAlertRuleResponse response = service.createResourceAlertRule(validVmCreateCmd());
532+
533+
assertEquals(List.of(), org.springframework.test.util.ReflectionTestUtils.getField(response, "webhookIds"));
534+
assertNull(org.springframework.test.util.ReflectionTestUtils.getField(response, "webhookNames"));
535+
}
523536
}

‎ui/public/locales/en.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,7 @@
23282328
"label.message": "Message",
23292329
"label.resetinterval": "Cooldown (seconds)",
23302330
"label.resource.alert.all.resources": "All resources",
2331+
"label.resource.alert.cooldown.default": "Leave empty to use the default",
23312332
"label.resource.alert.owner.self": "Your own account",
23322333
"label.alertrulename": "Alert rule",
23332334
"label.webhookids": "Webhooks",

‎ui/src/views/resourcealert/CreateResourceAlertRule.vue‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115

116116
<a-form-item name="resetinterval" ref="resetinterval">
117117
<template #label>{{ $t('label.resetinterval') }}</template>
118-
<a-input-number v-model:value="form.resetinterval" :min="0" style="width: 100%" />
118+
<a-input-number v-model:value="form.resetinterval" :min="0" :placeholder="$t('label.resource.alert.cooldown.default')" style="width: 100%" />
119119
</a-form-item>
120120

121121
<a-form-item name="webhookids" ref="webhookids" v-if="'listWebhooks' in $store.getters.apis">

0 commit comments

Comments
 (0)