Browse Source

refactor(iot-hub): move installed-item delete API call into the delete dialog

Push the deleteInstalledItem call from IotHubActionsService into the dialog's confirm() handler so the dialog itself manages its lifetime. Pass installedItemId in the dialog data and have confirm() fire the API call, then close with true on success. Drop the now-unused isLoading flips in the installed-items table since loading state is no longer optimistically toggled around the dialog.
pull/15842/head
Igor Kulikov 3 months ago
parent
commit
61ce61bf5c
  1. 10
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-actions.service.ts
  2. 12
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-delete-dialog.component.ts
  3. 6
      ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts

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

@ -17,7 +17,6 @@
import { Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Observable, of, EMPTY } from 'rxjs';
import { map, mergeMap } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core';
import { DialogService } from '@core/services/dialog.service';
import { MpItemVersionView } from '@shared/models/iot-hub/iot-hub-version.models';
@ -120,13 +119,8 @@ export class IotHubActionsService {
panelClass: ['tb-dialog'],
disableClose: true,
autoFocus: false,
data: { itemName: installedItem.itemName, itemType: installedItem.itemType }
}).afterClosed().pipe(
mergeMap((confirmed) =>
confirmed
? this.iotHubApiService.deleteInstalledItem(installedItem.id.id).pipe(map(() => true))
: of(false) )
);
data: { installedItemId: installedItem.id.id, itemName: installedItem.itemName, itemType: installedItem.itemType }
}).afterClosed();
}
installDevice(item: MpItemVersionView): Observable<string> {

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

@ -20,8 +20,11 @@ import { Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state';
import { DialogComponent } from '@shared/components/dialog.component';
import { IotHubInstalledItem } from 'src/app/shared/models/iot-hub/iot-hub-installed-item.models';
import { IotHubApiService } from '@core/http/iot-hub-api.service';
export interface IotHubDeleteDialogData {
installedItemId: string;
itemName: string;
itemType?: string;
}
@ -38,13 +41,18 @@ export class TbIotHubDeleteDialogComponent extends DialogComponent<TbIotHubDelet
protected store: Store<AppState>,
protected router: Router,
protected dialogRef: MatDialogRef<TbIotHubDeleteDialogComponent, boolean>,
@Inject(MAT_DIALOG_DATA) public data: IotHubDeleteDialogData
@Inject(MAT_DIALOG_DATA) public data: IotHubDeleteDialogData,
private iotHubApiService: IotHubApiService
) {
super(store, router, dialogRef);
}
confirm(): void {
this.dialogRef.close(true);
this.iotHubApiService.deleteInstalledItem(this.data.installedItemId).subscribe(
() => {
this.dialogRef.close(true);
}
);
}
cancel(): void {

6
ui-ngx/src/app/modules/home/components/iot-hub/iot-hub-installed-items-table.component.ts

@ -156,12 +156,9 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
}
deleteItem(item: IotHubInstalledItem): void {
this.isLoading = true;
this.iotHubActions.deleteItem(item).subscribe(deleted => {
if (deleted) {
this.loadData();
} else {
this.isLoading = false;
}
});
}
@ -247,12 +244,9 @@ export class TbIotHubInstalledItemsTableComponent implements OnInit, OnChanges,
}
updateItem(item: IotHubInstalledItem, publishedInfo: ItemPublishedVersionInfo): void {
this.isLoading = true;
this.iotHubActions.updateItem(item, publishedInfo.publishedVersion, publishedInfo.publishedVersionId).subscribe(result => {
if (result === 'updated') {
this.loadData();
} else {
this.isLoading = false;
}
});
}

Loading…
Cancel
Save