Browse Source

IoT Hub device package delete: the dialog scrolls and keeps long names in the box, log level checked in tests (PROD-9340 review)

pull/16694/head
dpinkevych 3 weeks ago
parent
commit
9cee5b499a
  1. 58
      application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java
  2. 7
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.html
  3. 6
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.scss

58
application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java

@ -3,6 +3,10 @@
// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
package org.thingsboard.server.service.iot_hub;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import jakarta.servlet.http.HttpServletRequest;
@ -14,6 +18,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.LoggerFactory;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.id.DashboardId;
@ -802,8 +807,10 @@ class DefaultIotHubServiceTest {
void findKeptEntities_devicePackage_aSharedProfileKeepsWhatItRefersTo() {
DeviceProfile profile = new DeviceProfile(new DeviceProfileId(UUID.randomUUID()));
RuleChainId ruleChainId = new RuleChainId(UUID.randomUUID());
RuleChainId edgeRuleChainId = new RuleChainId(UUID.randomUUID());
profile.setDefaultRuleChainId(ruleChainId);
IotHubInstalledItem checked = devicePackage(ruleChainId, profile.getId());
profile.setDefaultEdgeRuleChainId(edgeRuleChainId);
IotHubInstalledItem checked = devicePackage(ruleChainId, edgeRuleChainId, profile.getId());
IotHubInstalledItem other = devicePackage(profile.getId());
when(iotHubInstalledItemService.findById(tenantId, checked.getId())).thenReturn(checked);
when(iotHubInstalledItemService.findByTenantId(eq(tenantId), eq(List.of("DEVICE")), isNull(), any()))
@ -813,7 +820,8 @@ class DefaultIotHubServiceTest {
InstalledItemKeptEntities kept = service.findKeptEntities(tenantId, checked.getId());
assertThat(kept.getEntities()).extracting(InstalledItemKeptEntities.KeptEntity::getEntityId).containsExactly(profile.getId());
assertThat(kept.getReferencedEntities()).extracting(InstalledItemKeptEntities.KeptEntity::getEntityId).containsExactly(ruleChainId);
assertThat(kept.getReferencedEntities()).extracting(InstalledItemKeptEntities.KeptEntity::getEntityId)
.containsExactly(ruleChainId, edgeRuleChainId);
}
@Test
@ -860,7 +868,30 @@ class DefaultIotHubServiceTest {
}
@Test
void deleteInstalledItem_devicePackage_anEntitySomethingElseRefersToStays() throws Exception {
void deleteInstalledItem_devicePackage_anEntitySomethingElseRefersToStays_loggedAsKept() throws Exception {
// A profile the user made after the install uses the package's rule chain
List<ILoggingEvent> logs = deleteRuleChainFailingWith(
new DataValidationException("The rule chain referenced by the device profiles cannot be deleted!"));
assertThat(logs).anySatisfy(event -> {
assertThat(event.getLevel()).isEqualTo(Level.INFO);
assertThat(event.getFormattedMessage()).contains("Kept RULE_CHAIN").contains("referenced by the device profiles");
});
assertThat(logs).noneMatch(event -> event.getLevel() == Level.ERROR);
}
@Test
void deleteInstalledItem_devicePackage_aFailedDelete_staysAnError() throws Exception {
List<ILoggingEvent> logs = deleteRuleChainFailingWith(new RuntimeException("Database is down"));
assertThat(logs).anySatisfy(event -> {
assertThat(event.getLevel()).isEqualTo(Level.ERROR);
assertThat(event.getFormattedMessage()).contains("Failed to delete device package entity");
});
}
/** Deletes a package whose only entity is a rule chain that fails to delete with {@code failure}; the service's logs. */
private List<ILoggingEvent> deleteRuleChainFailingWith(Exception failure) throws Exception {
mockTenant();
RuleChain ruleChain = new RuleChain(new RuleChainId(UUID.randomUUID()));
IotHubInstalledItem deleted = devicePackage(ruleChain.getId());
@ -868,13 +899,22 @@ class DefaultIotHubServiceTest {
when(iotHubInstalledItemService.findByTenantId(eq(tenantId), eq(List.of("DEVICE")), isNull(), any()))
.thenReturn(new PageData<>(List.of(deleted), 1, 1, false));
when(ruleChainService.findRuleChainById(tenantId, ruleChain.getId())).thenReturn(ruleChain);
// A profile the user made after the install uses the package's rule chain
doThrow(new DataValidationException("The rule chain referenced by the device profiles cannot be deleted!"))
.when(tbRuleChainService).delete(ruleChain, user);
service.deleteInstalledItem(user, deleted.getId());
doThrow(failure).when(tbRuleChainService).delete(ruleChain, user);
Logger logger = (Logger) LoggerFactory.getLogger(DefaultIotHubService.class);
ListAppender<ILoggingEvent> appender = new ListAppender<>();
appender.start();
logger.addAppender(appender);
Level level = logger.getLevel();
logger.setLevel(Level.INFO);
try {
service.deleteInstalledItem(user, deleted.getId());
} finally {
logger.setLevel(level);
logger.detachAppender(appender);
}
// The delete goes on either way
verify(iotHubInstalledItemService).deleteById(tenantId, deleted.getId());
return appender.list;
}
private void noDevices(DeviceProfileId profileId) {

7
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.html

@ -5,15 +5,16 @@
SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1
-->
<div class="flex flex-col gap-5 p-6">
<!-- Scrolls when many entities stay, so the buttons stay in view -->
<div class="flex max-h-[65vh] flex-col gap-5 overflow-y-auto p-6">
<h2 class="tb-iot-hub-delete-title">{{ 'iot-hub.remove-confirm-title' | translate:{ name: data.itemName } }}</h2>
<p class="tb-iot-hub-delete-desc">{{ description }}</p>
@if (keptGroups.length) {
<div class="tb-form-hint tb-primary-fill">
<mat-icon>info_outline</mat-icon>
<div class="flex flex-col">
<div class="flex min-w-0 flex-col">
<div class="font-medium">{{ keptTitle }}</div>
<div class="tb-iot-hub-kept-groups mt-2 flex flex-col rounded bg-white">
<div class="tb-iot-hub-kept-groups mt-2 flex min-w-0 flex-col rounded bg-white">
@for (group of keptGroups; track group.reason; let i = $index; let first = $first) {
<div role="group" class="flex flex-col gap-1 py-2" [class.tb-iot-hub-kept-group-next]="!first"
[attr.aria-labelledby]="'tb-iot-hub-kept-reason-' + i">

6
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.scss

@ -35,9 +35,15 @@
&:before {
display: none;
}
// A long name breaks inside the box instead of running past its border
td.tb-entity-name {
overflow-wrap: anywhere;
}
}
}
// Not divide-y: with preflight off, divide-solid draws the side borders of the groups too
.tb-iot-hub-kept-group-next {
border-top: 1px solid rgba(0, 0, 0, 0.08);
}

Loading…
Cancel
Save