Browse Source

fix(iot-hub): review of the device package update: new access tokens in the warning, a package's own entity stays its own, the close prompt only once entities may be gone

- update-desc-device says again that the new devices get new access tokens
- an existing entity the wizard created a moment ago is recorded as created, not use-existing
- the close prompt shows only after the removal, a partial removal or a lost answer
- query params go through InterceptorHttpParams (also fixes force losing the interceptor config)
- one iotHubErrorMessage helper on parseHttpErrorMessage for the iot-hub dialogs
- removingReplaced is one signal, stepError a field, no template method calls or extra detectChanges
- fewer comments, readonly fields in the update dialog, cdr renamed to cd
pull/16553/head
dpinkevych 4 weeks ago
parent
commit
e8683bd85a
  1. 21
      ui-ngx/src/app/core/http/iot-hub-api.service.ts
  2. 31
      ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html
  3. 122
      ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts
  4. 6
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-actions.service.ts
  5. 4
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-add-item-dialog.component.ts
  6. 3
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.ts
  7. 37
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-update-dialog.component.ts
  8. 8
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-utils.ts
  9. 2
      ui-ngx/src/assets/locale/locale.constant-en_US.json

21
ui-ngx/src/app/core/http/iot-hub-api.service.ts

@ -182,20 +182,18 @@ export class IotHubApiService {
replaceInstalledItemId?: string,
config?: IotHubRequestConfig
): Observable<InstallItemVersionResult> {
// In the URL: HttpParams.set() would drop the interceptor config (ignoreLoading, ignoreErrors) of buildParams.
const replace = replaceInstalledItemId ? `&replaceInstalledItemId=${replaceInstalledItemId}` : '';
return this.http.post<InstallItemVersionResult>(
`/api/iot-hub/device/register?versionId=${versionId}${replace}`,
`/api/iot-hub/device/register`,
{ type: 'DEVICE', ...descriptor },
{ params: this.buildParams(config) }
{ params: this.buildParams(config, { versionId, replaceInstalledItemId }) }
);
}
public removeDevicePackageEntities(installedItemId: string, versionId: string, config?: IotHubRequestConfig): Observable<void> {
return this.http.post<void>(
`/api/iot-hub/installedItems/${installedItemId}/device/removeEntities?versionId=${versionId}`,
`/api/iot-hub/installedItems/${installedItemId}/device/removeEntities`,
null,
{ params: this.buildParams(config) }
{ params: this.buildParams(config, { versionId }) }
);
}
@ -223,10 +221,7 @@ export class IotHubApiService {
}
public updateItemVersion(installedItemId: string, versionId: string, config?: IotHubRequestConfig, force?: boolean): Observable<UpdateItemVersionResult> {
let params = this.buildParams(config);
if (force) {
params = params.set('force', 'true');
}
const params = this.buildParams(config, { force: force ? 'true' : undefined });
return this.http.post<UpdateItemVersionResult>(
`/api/iot-hub/installedItems/${installedItemId}/update/${versionId}`,
null,
@ -294,9 +289,11 @@ export class IotHubApiService {
);
}
private buildParams(config?: IotHubRequestConfig): HttpParams {
private buildParams(config?: IotHubRequestConfig, params?: Record<string, string | undefined>): HttpParams {
const defined = Object.fromEntries(Object.entries(params ?? {}).filter(([, value]) => value != null));
return new InterceptorHttpParams(
new InterceptorConfig(config?.ignoreLoading ?? false, config?.ignoreErrors ?? false)
new InterceptorConfig(config?.ignoreLoading ?? false, config?.ignoreErrors ?? false),
defined
);
}
}

31
ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.html

@ -133,24 +133,25 @@
{{ ('iot-hub.device-install-step-type-' + ep.step.type | translate) + ' — ' + (ep.resolvedName || ep.step.name) }}
</span>
<span class="tb-progress-status">
@if (ep.status === 'success') {
<span class="tb-progress-status-done">{{ 'iot-hub.done' | translate }}</span>
}
@if (ep.status === 'running') {
<span class="tb-progress-status-progress">{{ 'iot-hub.in-progress' | translate }}</span>
@switch (ep.status) {
@case ('success') {
<span class="tb-progress-status-done">{{ 'iot-hub.done' | translate }}</span>
}
@case ('running') {
<span class="tb-progress-status-progress">{{ 'iot-hub.in-progress' | translate }}</span>
}
}
</span>
</div>
}
}
@if (ws.removingReplaced) {
@if (removingReplaced()) {
<div class="mt-4 flex items-center gap-2">
<mat-spinner diameter="18"></mat-spinner>
<span class="tb-progress-status">{{ 'iot-hub.device-update-removing' | translate }}</span>
</div>
}
@if (stepLevelError(ws); as error) {
<span class="tb-progress-alert-msg tb-progress-alert-msg-error mt-4">{{ error }}</span>
} @else if (ws.stepError) {
<span class="tb-progress-alert-msg tb-progress-alert-msg-error mt-4">{{ ws.stepError }}</span>
}
</div>
}
@ -166,7 +167,7 @@
} @else {
<div class="tb-device-install-header flex items-center gap-3 py-2 pl-6 pr-2">
<h2 class="tb-device-install-title">{{ 'iot-hub.device-install-title' | translate:{ name: packageInfo?.name || data.item.name } }}</h2>
<button mat-icon-button [disabled]="removingReplaced" (click)="cancel()" tabindex="-1">
<button mat-icon-button [disabled]="removingReplaced()" (click)="cancel()" tabindex="-1">
<mat-icon>close</mat-icon>
</button>
</div>
@ -206,7 +207,7 @@
</ng-template>
@for (ws of wizardSteps; track ws.label) {
<mat-step [editable]="!removingReplaced"
<mat-step [editable]="!removingReplaced()"
[completed]="ws.completed"
[stepControl]="ws.type === 'form' ? ws.formGroup : null">
<ng-template matStepLabel>{{ ws.label }}</ng-template>
@ -220,13 +221,13 @@
@if (allProgressDone) {
<button mat-button (click)="done()">{{ 'action.close' | translate }}</button>
} @else {
<button mat-button [disabled]="removingReplaced" (click)="cancel()">{{ 'action.cancel' | translate }}</button>
<button mat-button [disabled]="removingReplaced()" (click)="cancel()">{{ 'action.cancel' | translate }}</button>
}
</ng-template>
<mat-dialog-actions>
@if (!isFirstWizardStep) {
<button mat-stroked-button [disabled]="removingReplaced" (click)="previousStep()">{{ 'action.back' | translate }}</button>
<button mat-stroked-button [disabled]="removingReplaced()" (click)="previousStep()">{{ 'action.back' | translate }}</button>
}
<span class="flex-1"></span>
@if (currentWizardStep; as step) {
@ -261,7 +262,7 @@
</button>
}
@case ('progress') {
@if (step.progressError) {
@if (step.progressError || step.stepError) {
<ng-container *ngTemplateOutlet="closeOrCancel"></ng-container>
<button mat-flat-button color="primary" (click)="retryEntitySteps(step)">
{{ 'action.retry' | translate }}
@ -273,7 +274,7 @@
{{ action.label }}
</button>
}
} @else if (!step.progressError) {
} @else {
<ng-container *ngTemplateOutlet="closeOrCancel"></ng-container>
<button mat-stroked-button color="primary" [disabled]="!step.progressDone" (click)="nextStep()">
{{ 'action.next' | translate }}@if (nextWizardStepLabel) {: {{ nextWizardStepLabel }}}

122
ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts

@ -1,6 +1,6 @@
// SPDX-FileCopyrightText: Copyright The Thingsboard Authors
// SPDX-License-Identifier: Apache-2.0
import { ChangeDetectorRef, Component, Inject, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ChangeDetectorRef, Component, Inject, OnDestroy, OnInit, signal, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog';
import {
@ -42,18 +42,15 @@ import {
stepTypeAliasMap
} from '@shared/models/iot-hub/device-package.models';
import { mergeMap } from 'rxjs/operators';
import { HttpErrorResponse } from '@angular/common/http';
import { iotHubErrorMessage } from '../iot-hub-utils';
export interface DeviceInstallDialogData {
item: MpItemVersionView;
reviewMode?: boolean;
selectedInstallMethod?: string;
installState?: Record<string, any>;
/**
* Update of an installed device package: the installed item of the current version. Its entities are removed
* right before the wizard creates the new version's entities, not earlier, so closing the wizard before that
* leaves the package as it was; the item takes the new version when the wizard registers it. The forms start
* from installState and the connection method from selectedInstallMethod, as the user filled them before.
*/
/** Update: the installed item whose entities are replaced by this version's. */
replaceInstalledItemId?: string;
}
@ -73,8 +70,8 @@ export interface WizardStep {
entitySteps?: EntityStepProgress[];
progressError?: string;
progressDone?: boolean;
/** Update only: the entities of the replaced version are being removed. */
removingReplaced?: boolean;
/** An error of the whole step (removal of the replaced entities, registration), not of one entity. */
stepError?: string;
}
const ENTITY_STEP_MIN_DELAY = 2000;
@ -112,23 +109,14 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
* has to report 'installed', or the caller keeps showing pre-install counts and badges.
*/
private installRegistered = false;
/** Update only: whether the removal of the replaced version's entities was sent, and whether it is done. */
private replaceStarted = false;
readonly removingReplaced = signal(false);
private replacedEntitiesRemoved = false;
/**
* The installed item this wizard registers: the wizard registers again after each group of entities, and each
* registration updates that item. On an update it is the replaced item from the start.
*/
private replacedEntitiesMayBeGone = false;
private registeredItemId: string | undefined;
/**
* Every entity this wizard created or chose, kept as soon as it exists: each registration sends them all, so none is
* left untracked when the user goes back from a group of steps (to change a form or the connection method) or a
* step or a registration failed.
*/
// Kept as soon as an entity exists: going back resets a progress step, but every registration must still track it.
private packageEntityIds: { entityType: string; id: string }[] = [];
/** Update only: the connection method of the installed version, preselected until the user confirms it. */
private createdInThisWizard = new Set<string>();
private methodPreselected = false;
/** The dialog is closed: a run of the entity steps that is still waiting must not create anything. */
private closed = false;
// Variable resolution state
@ -147,7 +135,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
protected router: Router,
protected dialogRef: MatDialogRef<TbDeviceInstallDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: DeviceInstallDialogData,
private cdr: ChangeDetectorRef,
private cd: ChangeDetectorRef,
private deviceProfileService: DeviceProfileService,
private deviceService: DeviceService,
private dashboardService: DashboardService,
@ -229,7 +217,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
}
}
this.loading = false;
this.cdr.detectChanges();
this.cd.detectChanges();
}
ngOnDestroy() {
@ -250,8 +238,6 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
return;
}
if (this.selectedInstallMethod === ct && this.methodPreselected) {
// Update: the card of the installed version's method is preselected; clicking it confirms it.
this.methodPreselected = false;
this.confirmConnectivity();
return;
}
@ -304,7 +290,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
this.wizardSteps.length = 1;
this.appendInstallSteps();
connectivityStep.completed = true;
this.cdr.detectChanges();
this.cd.detectChanges();
// Wait for new mat-step children to register before advancing.
setTimeout(() => this.stepper?.next(), 0);
return;
@ -366,7 +352,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
return;
}
step.completed = true;
this.cdr.detectChanges();
this.cd.detectChanges();
this.stepper.next();
}
@ -416,17 +402,11 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
this.dialogRef.close('installed');
}
get removingReplaced(): boolean {
return this.wizardSteps.some(ws => ws.removingReplaced);
}
async cancel(): Promise<void> {
if (this.removingReplaced) {
// The removal is irreversible and already running: closing now would leave the outcome unknown.
if (this.removingReplaced()) {
return;
}
if (this.replaceStarted && !this.installRegistered) {
// The installed version may already be gone while the new one is not installed: the user has to know before leaving.
if (this.replacedEntitiesMayBeGone && !this.installRegistered) {
const close = await firstValueFrom(this.dialogService.confirm(
this.translate.instant('iot-hub.device-update-close-title'),
this.translate.instant('iot-hub.device-update-close-text'),
@ -437,19 +417,19 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
}
}
this.closed = true;
// Once the replaced version's entities may be gone, the caller has to reload its installed items as well.
this.dialogRef.close(this.installRegistered || this.replaceStarted ? 'installed' : false);
this.dialogRef.close(this.installRegistered || this.replacedEntitiesMayBeGone ? 'installed' : false);
}
retryEntitySteps(step: WizardStep): void {
step.progressError = null;
step.stepError = null;
void this.runEntitySteps(step);
}
async resolveConflict(ws: WizardStep, ep: EntityStepProgress, resolution: string): Promise<void> {
ep.status = 'running';
ep.errorMessage = null;
this.cdr.detectChanges();
this.cd.detectChanges();
try {
let output: EntityStepOutput;
if (resolution === 'use-existing') {
@ -471,14 +451,16 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
await this.saveStepAttributes(ep.step, output);
ep.existingEntity = null;
ep.conflictType = null;
this.markEntityStepSuccess(ws, ep, output, resolution);
// An entity this wizard created a moment ago (the user went back and ran the step again) stays the package's own.
const recorded = resolution === 'use-existing' && this.createdInThisWizard.has(output.id) ? 'created' : resolution;
this.markEntityStepSuccess(ws, ep, output, recorded);
// Resume running remaining steps
await this.runEntitySteps(ws);
} catch (err: any) {
ep.status = 'error';
ep.errorMessage = this.errorText(err);
ep.errorMessage = iotHubErrorMessage(err, this.translate);
ws.progressError = ep.errorMessage;
this.cdr.detectChanges();
this.cd.detectChanges();
}
}
@ -491,6 +473,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
const progressStep = this.wizardSteps[currentIdx];
progressStep.entitySteps = null;
progressStep.progressError = null;
progressStep.stepError = null;
progressStep.progressDone = false;
progressStep.completed = false;
// Allow navigation back by making intermediate steps editable
@ -821,6 +804,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
resolvedName: this.resolveVariables(s.name)
}));
ws.progressError = null;
ws.stepError = null;
ws.progressDone = false;
void this.runEntitySteps(ws);
}
@ -830,7 +814,9 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
ep.entityOutput = output;
ep.resolution = resolution;
ep.status = 'success';
// Kept from the moment it exists: going back resets the step, and the entity must still be registered.
if (resolution !== 'use-existing') {
this.createdInThisWizard.add(output.id);
}
const entityType = this.stepTypeToEntityType(ep.step.type);
if (entityType && !this.packageEntityIds.some(known => known.id === output.id)) {
this.packageEntityIds.push({ entityType, id: output.id });
@ -844,12 +830,11 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
remaining.resolvedName = this.resolveVariables(remaining.step.name);
}
}
this.cdr.detectChanges();
this.cd.detectChanges();
}
private async runEntitySteps(ws: WizardStep): Promise<void> {
if (!await this.removeReplacedEntities(ws) || this.closed) {
// The dialog was closed meanwhile (navigating away): create nothing.
return;
}
for (const ep of ws.entitySteps) {
@ -858,7 +843,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
}
ep.status = 'running';
ep.errorMessage = null;
this.cdr.detectChanges();
this.cd.detectChanges();
try {
// Pre-check for existing entity
const existing = await this.preCheckEntity(ep.step);
@ -866,7 +851,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
ep.status = 'conflict';
ep.existingEntity = existing;
ep.conflictType = this.getConflictType(ep.step.type);
this.cdr.detectChanges();
this.cd.detectChanges();
return; // Pause — user must choose a resolution
}
const startTime = Date.now();
@ -881,15 +866,14 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
this.markEntityStepSuccess(ws, ep, output, 'created');
} catch (err: any) {
ep.status = 'error';
ep.errorMessage = this.errorText(err);
ep.errorMessage = iotHubErrorMessage(err, this.translate);
ws.progressError = ep.errorMessage;
this.cdr.detectChanges();
this.cd.detectChanges();
return;
}
}
// All done — register install with created entity IDs. The step is done only then: until it is registered,
// nothing tracks the entities, so the package could be neither updated nor removed from IoT Hub.
// All done — register install with created entity IDs. Until then nothing tracks them, so the step is not done.
try {
const createdEntityIds = [...this.packageEntityIds];
const dashboardId = this.findCreatedDashboardId();
@ -907,9 +891,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
this.installRegistered = true;
this.registeredItemId = result.installedItemId ?? this.registeredItemId;
} catch (err: any) {
// The entities stay as they are: Retry registers them again.
ws.progressError = this.translate.instant('iot-hub.device-install-register-error', { error: this.errorText(err) });
this.cdr.detectChanges();
ws.stepError = this.translate.instant('iot-hub.device-install-register-error', { error: iotHubErrorMessage(err, this.translate) });
return;
}
ws.progressDone = true;
@ -919,45 +901,35 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
if (!this.isLastWizardStep) {
await this.delay(500);
this.stepper.next();
this.cdr.detectChanges();
this.cd.detectChanges();
}
}
/**
* Update of a device package: remove the entities of the current version before the new version's entities are
* created, or they would conflict by name. The installed item keeps its version until the new one is registered,
* and removing again is safe, so Retry simply repeats it.
*/
/** Update: the replaced version's entities are removed right before the new ones are created, or their names conflict. */
private async removeReplacedEntities(ws: WizardStep): Promise<boolean> {
if (!this.data.replaceInstalledItemId || this.replacedEntitiesRemoved) {
return true;
}
this.replaceStarted = true;
ws.removingReplaced = true;
this.cdr.detectChanges();
this.removingReplaced.set(true);
try {
await firstValueFrom(this.iotHubApiService.removeDevicePackageEntities(this.data.replaceInstalledItemId,
this.data.item.id as string, { ignoreLoading: true, ignoreErrors: true }));
this.replacedEntitiesRemoved = true;
this.replacedEntitiesMayBeGone = true;
return true;
} catch (err: any) {
ws.progressError = this.translate.instant('iot-hub.device-update-remove-error', { error: this.errorText(err) });
const error = iotHubErrorMessage(err, this.translate);
// Refused before removing anything, unless some entities could not be removed or the answer was lost.
if (error.includes('not removed:') || (err instanceof HttpErrorResponse && err.status === 0)) {
this.replacedEntitiesMayBeGone = true;
}
ws.stepError = this.translate.instant('iot-hub.device-update-remove-error', { error });
return false;
} finally {
ws.removingReplaced = false;
this.cdr.detectChanges();
this.removingReplaced.set(false);
}
}
/** An error of the step that is not one entity's (removing the replaced entities, registering), shown below them. */
stepLevelError(ws: WizardStep): string | null {
return ws.progressError && !ws.entitySteps?.some(ep => ep.status === 'error') ? ws.progressError : null;
}
private errorText(err: any): string {
return err?.error?.message || err?.message || 'Unknown error';
}
private fitsField(field: FormFieldDefinition, value: any): boolean {
switch (field.type) {
case FormFieldType.BOOLEAN:

6
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-actions.service.ts

@ -170,11 +170,7 @@ export class IotHubActionsService {
);
}
/**
* A device package is updated by installing the new version through the install wizard: it needs the user's
* input, so the server cannot install it alone. The wizard removes the installed version's entities only when it starts
* creating the new ones, so closing it before that leaves the package as it was.
*/
/** The install wizard of the new version updates a device package: it needs the user's input. */
private reinstallDevice(installedItem: IotHubInstalledItem, versionId: string): Observable<string | boolean> {
const descriptor = installedItem.descriptor as DeviceInstalledItemDescriptor;
return this.iotHubApiService.getVersionInfo(versionId).pipe(

4
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-add-item-dialog.component.ts

@ -13,7 +13,7 @@ import { DialogService } from '@core/services/dialog.service';
import { TranslateService } from '@ngx-translate/core';
import { EntityId } from '@shared/models/id/entity-id';
import { IotHubActionsService } from './iot-hub-actions.service';
import { isBuiltInItem } from './iot-hub-utils';
import { iotHubErrorMessage, isBuiltInItem } from './iot-hub-utils';
export interface IotHubAddItemDialogData {
itemType: ItemType;
@ -96,7 +96,7 @@ export class TbIotHubAddItemDialogComponent extends DialogComponent<TbIotHubAddI
},
error: (err) => {
this.isInstalling = false;
const message = err?.error?.message || err?.message || this.translate.instant('iot-hub.install-error', { name: item.name });
const message = iotHubErrorMessage(err, this.translate, this.translate.instant('iot-hub.install-error', { name: item.name }));
this.dialogService.alert(
this.translate.instant('iot-hub.install-error-title'),
message

3
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-install-dialog.component.ts

@ -30,6 +30,7 @@ import { DeviceProfileService } from '@core/http/device-profile.service';
import { AssetProfileService } from '@core/http/asset-profile.service';
import { RuleChainService } from '@core/http/rule-chain.service';
import { RuleChainId } from '@shared/models/id/rule-chain-id';
import { iotHubErrorMessage } from './iot-hub-utils';
interface SelectEntityConfig {
allowed: EntityType[];
@ -317,7 +318,7 @@ export class TbIotHubInstallDialogComponent extends DialogComponent<TbIotHubInst
private handleApiError(err: any): void {
this.state = 'error';
this.errorMessage = err?.error?.message || err?.message || '';
this.errorMessage = iotHubErrorMessage(err, this.translate);
}
private handlePlanResult(result: InstallPlanResult): void {

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

@ -15,6 +15,7 @@ import { IotHubApiService } from '@core/http/iot-hub-api.service';
import { DialogService } from '@core/services/dialog.service';
import { TranslateService } from '@ngx-translate/core';
import { SolutionInstallDialogComponent } from '@home/components/iot-hub/solution-install-dialog.component';
import { iotHubErrorMessage } from './iot-hub-utils';
export interface IotHubUpdateDialogData {
installedItemId: string;
@ -40,6 +41,14 @@ export class TbIotHubUpdateDialogComponent extends DialogComponent<TbIotHubUpdat
state: UpdateState = 'confirm';
errorMessage = '';
entityDetailsUrl: string | null = null;
/** A device package is reinstalled: its entities and their data are removed, as on Remove. */
readonly reinstalls: boolean;
/**
* Updating a solution template is a delete + reinstall of every entity it created, and unlike the other item
* types it is not stopped by the modified-entity check, so the tenant's own edits to those dashboards, devices
* and rule chains are lost. Say that instead of the generic "replace the current version" wording.
*/
readonly updateDescKey: string;
constructor(
protected store: Store<AppState>,
@ -52,6 +61,9 @@ export class TbIotHubUpdateDialogComponent extends DialogComponent<TbIotHubUpdat
private iotHubApiService: IotHubApiService
) {
super(store, router, dialogRef);
this.reinstalls = data.itemType === ItemType.DEVICE;
this.updateDescKey = data.itemType === ItemType.SOLUTION_TEMPLATE ? 'iot-hub.update-desc-solution-template'
: this.reinstalls ? 'iot-hub.update-desc-device' : 'iot-hub.update-desc';
}
getTypeLabel(): string {
@ -59,29 +71,8 @@ export class TbIotHubUpdateDialogComponent extends DialogComponent<TbIotHubUpdat
return key ? this.translate.instant(key) : '';
}
/** A device package is reinstalled: its entities and their data are removed, as on Remove. */
get reinstalls(): boolean {
return this.data?.itemType === ItemType.DEVICE;
}
/**
* Updating a solution template is a delete + reinstall of every entity it created, and unlike the other item
* types it is not stopped by the modified-entity check, so the tenant's own edits to those dashboards, devices
* and rule chains are lost. Say that instead of the generic "replace the current version" wording.
*/
get updateDescKey(): string {
switch (this.data?.itemType) {
case ItemType.SOLUTION_TEMPLATE:
return 'iot-hub.update-desc-solution-template';
case ItemType.DEVICE:
return 'iot-hub.update-desc-device';
default:
return 'iot-hub.update-desc';
}
}
update(force = false): void {
if (this.data.itemType === ItemType.DEVICE) {
if (this.reinstalls) {
// The install wizard of the new version does the update: it needs the user's input.
this.dialogRef.close('reinstall');
return;
@ -121,7 +112,7 @@ export class TbIotHubUpdateDialogComponent extends DialogComponent<TbIotHubUpdat
},
error: (err) => {
this.state = 'error';
this.errorMessage = err?.error?.message || err?.message || this.translate.instant('iot-hub.update-error', { name: this.data.itemName });
this.errorMessage = iotHubErrorMessage(err, this.translate, this.translate.instant('iot-hub.update-error', { name: this.data.itemName }));
}
});
}

8
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-utils.ts

@ -3,6 +3,9 @@
import { FilterParamInfo, ItemType } from '@shared/models/iot-hub/iot-hub-item.models';
import { MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models';
import { IotHubApiService } from '@core/http/iot-hub-api.service';
import { HttpErrorResponse } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
import { parseHttpErrorMessage } from '@core/utils';
export const IOT_HUB_FILTER_GROUPING_THRESHOLD = 11;
export const IOT_HUB_FILTER_POPULAR_LIMIT = 10;
@ -123,3 +126,8 @@ export function resolveIotHubItemImageUrl(item: MpItemVersionView, api: IotHubAp
}
return null;
}
export function iotHubErrorMessage(err: any, translate: TranslateService, fallback?: string): string {
const message = err instanceof HttpErrorResponse ? parseHttpErrorMessage(err, translate).message : err?.message;
return message || fallback || translate.instant('error.unknown-error');
}

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

@ -3876,7 +3876,7 @@
"device-update-close-title": "Close the installation wizard?",
"device-update-remove-error": "Removing the entities of the installed version failed: {{error}}. Retry removes them again",
"device-install-register-error": "The package is not recorded as installed: {{error}}. Retry records it again",
"update-desc-device": "Device packages can't be updated without reinstalling on this ThingsBoard version. Updating removes the installed entities and their data and installs the new version from scratch",
"update-desc-device": "Device packages can't be updated without reinstalling on this ThingsBoard version. Updating removes the installed entities and their data and installs the new version from scratch. The new devices get new access tokens: set up your physical devices and gateways again with the new credentials",
"update-desc-solution-template": "Updating this solution template will delete and recreate all entities it created, including dashboards, rule chains, devices, and other associated resources within your tenant. Any changes you made to them will be lost",
"update-success-desc": "'{{name}}' has been updated successfully",
"updating": "Updating...",

Loading…
Cancel
Save