Browse Source

IoT Hub device package delete: kept entities in one list, a group per reason (PROD-9340 review)

pull/16694/head
dpinkevych 3 weeks ago
parent
commit
f8b8fa18e5
  1. 14
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.html
  2. 36
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.scss
  3. 37
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.ts
  4. 3
      ui-ngx/src/assets/locale/locale.constant-en_US.json

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

@ -8,13 +8,21 @@
<div class="flex flex-col gap-5 p-6"> <div class="flex flex-col gap-5 p-6">
<h2 class="tb-iot-hub-delete-title">{{ 'iot-hub.remove-confirm-title' | translate:{ name: data.itemName } }}</h2> <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> <p class="tb-iot-hub-delete-desc">{{ description }}</p>
@if (keptReferences) { @if (keptGroups.length) {
<div class="tb-form-hint tb-primary-fill"> <div class="tb-form-hint tb-primary-fill">
<mat-icon>info_outline</mat-icon> <mat-icon>info_outline</mat-icon>
<div class="flex flex-col"> <div class="flex flex-col">
<div class="font-medium">{{ keptTitle }}</div> <div class="font-medium">{{ keptTitle }}</div>
<div>{{ keptReason }}</div> <!-- One list, a group per reason: the reason is over the entities it is about -->
<tb-image-references class="mt-3" [references]="keptReferences"></tb-image-references> <div class="tb-iot-hub-kept-groups mt-2">
@for (group of keptGroups; track group.reason; let first = $first) {
@if (!first) {
<div class="tb-iot-hub-kept-divider"></div>
}
<div class="tb-iot-hub-kept-reason">{{ group.reason }}</div>
<tb-image-references [references]="group.references"></tb-image-references>
}
</div>
</div> </div>
</div> </div>
} }

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

@ -23,3 +23,39 @@
color: rgba(0, 0, 0, 0.54); color: rgba(0, 0, 0, 0.54);
margin: 0; margin: 0;
} }
// The kept entities: one white list as tb-image-references draws it, a group per reason
.tb-iot-hub-kept-groups {
display: flex;
flex-direction: column;
gap: 4px;
padding: 8px 0;
border-radius: 4px;
background: #fff;
border: 1px solid color-mix(in srgb, var(--tb-primary-500) 40%, transparent);
// The groups share the outer border: no border of its own around each group's list
::ng-deep tb-image-references table.tb-entities-list-table {
padding: 0 10px 0 4px !important;
background: transparent !important;
&:before {
display: none !important;
}
}
}
.tb-iot-hub-kept-reason {
padding: 4px 12px 2px;
font-size: 12px;
font-weight: 500;
line-height: 16px;
letter-spacing: 0.4px;
color: rgba(0, 0, 0, 0.6);
}
.tb-iot-hub-kept-divider {
height: 1px;
margin: 6px 12px 4px;
background: rgba(0, 0, 0, 0.08);
}

37
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.ts

@ -7,7 +7,7 @@ import { Router } from '@angular/router';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
import { DialogComponent } from '@shared/components/dialog.component'; import { DialogComponent } from '@shared/components/dialog.component';
import { IotHubInstalledItemKeptEntities } from 'src/app/shared/models/iot-hub/iot-hub-installed-item.models'; import { IotHubInstalledItemKeptEntities, IotHubKeptEntity } from 'src/app/shared/models/iot-hub/iot-hub-installed-item.models';
import { IotHubApiService } from '@core/http/iot-hub-api.service'; import { IotHubApiService } from '@core/http/iot-hub-api.service';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { ResourceReferences } from '@shared/models/resource.models'; import { ResourceReferences } from '@shared/models/resource.models';
@ -30,10 +30,10 @@ export class TbIotHubDeleteDialogComponent extends DialogComponent<TbIotHubDelet
description: string; description: string;
// A device package keeps the entities other installed packages use, and the dialog lists them before the user confirms // A device package keeps some entities, and the dialog lists them before the user confirms: one group per reason,
keptReferences: ResourceReferences | null = null; // so a reason reads only for its own entities
keptGroups: { reason: string; references: ResourceReferences }[] = [];
keptTitle: string; keptTitle: string;
keptReason: string;
constructor( constructor(
protected store: Store<AppState>, protected store: Store<AppState>,
@ -48,23 +48,20 @@ export class TbIotHubDeleteDialogComponent extends DialogComponent<TbIotHubDelet
const kept = data.keptEntities; const kept = data.keptEntities;
const shared = kept?.entities ?? []; const shared = kept?.entities ?? [];
const withDevices = kept?.keptForDevices ?? []; const withDevices = kept?.keptForDevices ?? [];
if (shared.length || withDevices.length) { const references = (entities: IotHubKeptEntity[]): ResourceReferences =>
this.keptReferences = [...shared, ...withDevices].map(entity => ({ id: entity.entityId as EntityId, name: entity.name })); entities.map(entity => ({ id: entity.entityId as EntityId, name: entity.name }));
const reasons: string[] = []; if (shared.length) {
if (shared.length) { // Kept because other packages use them, because the user had them before the package, or both
// Kept because other packages use them, because the user had them before the package, or both const reasonKey = !kept.usedExistingCount ? 'iot-hub.remove-kept-used' :
const reasonKey = !kept.usedExistingCount ? 'iot-hub.remove-kept-used' : !kept.usedByItemsCount ? 'iot-hub.remove-kept-own' : 'iot-hub.remove-kept-own-or-used';
!kept.usedByItemsCount ? 'iot-hub.remove-kept-own' : 'iot-hub.remove-kept-own-or-used'; this.keptGroups.push({ reason: this.translate.instant(reasonKey, { kept: shared.length }), references: references(shared) });
reasons.push(this.translate.instant(reasonKey, { kept: shared.length })); }
} if (withDevices.length) {
if (withDevices.length) { // The profiles devices use, and what those profiles use (default rule chains, dashboard)
// The profiles devices use, and what they use (default rule chains, dashboard), which stays with them this.keptGroups.push({ reason: this.translate.instant('iot-hub.remove-kept-referenced'), references: references(withDevices) });
const profiles = withDevices.filter(entity => entity.entityId.entityType === 'DEVICE_PROFILE').length; }
const key = withDevices.length > profiles ? 'iot-hub.remove-kept-devices-with-references' : 'iot-hub.remove-kept-devices'; if (this.keptGroups.length) {
reasons.push(this.translate.instant(key, { profiles, devices: kept.devicesCount ?? 0 }));
}
this.keptTitle = this.translate.instant('iot-hub.remove-kept-title', { kept: shared.length + withDevices.length }); this.keptTitle = this.translate.instant('iot-hub.remove-kept-title', { kept: shared.length + withDevices.length });
this.keptReason = reasons.join(' ');
} }
} }

3
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -6449,8 +6449,7 @@
"remove-kept-title": "{ kept, plural, =1 {This entity will not be removed} other {These entities will not be removed} }", "remove-kept-title": "{ kept, plural, =1 {This entity will not be removed} other {These entities will not be removed} }",
"remove-kept-used": "Other installed packages use { kept, plural, =1 {it} other {them} }.", "remove-kept-used": "Other installed packages use { kept, plural, =1 {it} other {them} }.",
"remove-kept-own": "You had { kept, plural, =1 {it} other {them} } before the package was installed.", "remove-kept-own": "You had { kept, plural, =1 {it} other {them} } before the package was installed.",
"remove-kept-devices": "{ devices, plural, =1 {1 device still uses} other {# devices still use} } { profiles, plural, =1 {the device profile, so it stays} other {the device profiles, so they stay} }.", "remove-kept-referenced": "Referenced by other tenant entities.",
"remove-kept-devices-with-references": "{ devices, plural, =1 {1 device still uses} other {# devices still use} } { profiles, plural, =1 {the device profile, so it stays with the entities it uses} other {the device profiles, so they stay with the entities they use} }.",
"remove-kept-own-or-used": "You had { kept, plural, =1 {it} other {them} } before the package was installed, or other installed packages use { kept, plural, =1 {it} other {them} }.", "remove-kept-own-or-used": "You had { kept, plural, =1 {it} other {them} } before the package was installed, or other installed packages use { kept, plural, =1 {it} other {them} }.",
"remove-desc-solution-template": "Removing this solution template will also remove all created entities including dashboards, rule chains, devices, and other associated resources within your tenant", "remove-desc-solution-template": "Removing this solution template will also remove all created entities including dashboards, rule chains, devices, and other associated resources within your tenant",
"remove-anyway": "Remove anyway", "remove-anyway": "Remove anyway",

Loading…
Cancel
Save