diff --git a/admin/webapp/websrc/app/routes/registries/registries-communication.service.ts b/admin/webapp/websrc/app/routes/registries/registries-communication.service.ts index d9b9cbc1..832767f2 100644 --- a/admin/webapp/websrc/app/routes/registries/registries-communication.service.ts +++ b/admin/webapp/websrc/app/routes/registries/registries-communication.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { BehaviorSubject, combineLatest, Observable, Subject } from 'rxjs'; +import { BehaviorSubject, combineLatest, Observable, Subject, timer, of } from 'rxjs'; import { RepoGetResponse, Summary } from '@common/types'; import { filter, @@ -8,6 +8,9 @@ import { startWith, switchMap, tap, + takeWhile, + take, + catchError } from 'rxjs/operators'; import { RegistriesService } from '@services/registries.service'; import { FormControl } from '@angular/forms'; @@ -138,6 +141,23 @@ export class RegistriesCommunicationService { } } + refreshUntilFound(expectedName: string, maxAttempts = 20, intervalMs = 500): void { + timer(0, intervalMs) + .pipe( + take(maxAttempts), + switchMap(() => this.registriesService.getRegistries().pipe(catchError(() => of({ summarys: [] })))), + tap(({ summarys }) => { + const found = summarys.some(s => s.name === expectedName); + if (found) { + // Push update into the normal data stream + this.refreshRegistriesSubject$.next(true); + } + }), + takeWhile(({ summarys }) => !summarys.some(s => s.name === expectedName), true) + ) + .subscribe(); + } + refreshDetails(): void { this.refreshDetailsSubject$.next(true); } diff --git a/admin/webapp/websrc/app/routes/registries/registries-table/add-registry-dialog/add-registry-dialog.component.ts b/admin/webapp/websrc/app/routes/registries/registries-table/add-registry-dialog/add-registry-dialog.component.ts index 06a1441a..8f424dad 100644 --- a/admin/webapp/websrc/app/routes/registries/registries-table/add-registry-dialog/add-registry-dialog.component.ts +++ b/admin/webapp/websrc/app/routes/registries/registries-table/add-registry-dialog/add-registry-dialog.component.ts @@ -11,12 +11,11 @@ import { MatDialogRef, } from '@angular/material/dialog'; import { RegistriesTableComponent } from '../registries-table.component'; -import { FormGroup, FormControl } from '@angular/forms'; +import { FormGroup } from '@angular/forms'; import { AddRegistryFieldConfig } from './add-registry-form-configs'; import { cloneDeep } from 'lodash'; import { INTERVAL_STEP_VALUES } from './add-registry-form-configs/constants/constants'; import { - AWSKey, ErrorResponse, GCRKey, RegistryConfig, @@ -31,7 +30,6 @@ import { GlobalConstant } from '@common/constants/global.constant'; import { NotificationService } from '@services/notification.service'; import { FormlyFieldConfig, FormlyFormOptions } from '@ngx-formly/core'; import { GlobalVariable } from '@common/variables/global.variable'; -import { MapConstant } from '@common/constants/map.constant'; import { ConfigHttpService } from '@common/api/config-http.service'; import { AuthUtilsService } from '@common/utils/auth.utils'; @@ -148,19 +146,16 @@ export class AddRegistryDialogComponent implements OnInit, AfterViewChecked { take(1), finalize(() => { this.submittingForm = false; + this.registriesCommunicationService.cancelSave(); }) ) .subscribe({ complete: () => { - this.registriesCommunicationService.refreshRegistries(1000); - this.saving$.subscribe(saving => { - if (!saving) { - this.dialogRef.close(true); - } - }); + this.registriesCommunicationService.initRefreshingRegistries(); + this.registriesCommunicationService.refreshRegistries(); + this.dialogRef.close(true); }, error: ({ error }: { error: ErrorResponse }) => { - this.registriesCommunicationService.cancelSave(); this.notificationService.open( error.message, GlobalConstant.NOTIFICATION_TYPE.ERROR @@ -171,21 +166,18 @@ export class AddRegistryDialogComponent implements OnInit, AfterViewChecked { this.registriesService .postRegistry(body) .pipe( + take(1), finalize(() => { this.submittingForm = false; + this.registriesCommunicationService.cancelSave(); }) ) .subscribe({ complete: () => { - this.registriesCommunicationService.refreshRegistries(1000); - this.saving$.subscribe(saving => { - if (!saving) { - this.dialogRef.close(true); - } - }); + this.dialogRef.close(true); + this.registriesCommunicationService.refreshUntilFound(body.config.name); }, error: ({ error }: { error: ErrorResponse }) => { - this.registriesCommunicationService.cancelSave(); this.notificationService.open( error.message, GlobalConstant.NOTIFICATION_TYPE.ERROR diff --git a/admin/webapp/websrc/app/routes/registries/registries-table/registries-table.component.ts b/admin/webapp/websrc/app/routes/registries/registries-table/registries-table.component.ts index 37d8bbb4..c16378ed 100644 --- a/admin/webapp/websrc/app/routes/registries/registries-table/registries-table.component.ts +++ b/admin/webapp/websrc/app/routes/registries/registries-table/registries-table.component.ts @@ -418,10 +418,12 @@ export class RegistriesTableComponent implements OnInit, OnChanges { }, }); dialog.afterClosed().subscribe(change => { - if (change && isEdit) { - this.registriesCommunicationService.setSelectedRegistry( - this.gridApi.getSelectedNodes()[0].data - ); + if (change) { + if (isEdit && this.gridApi && this.gridApi.getSelectedNodes().length > 0) { + this.registriesCommunicationService.setSelectedRegistry( + this.gridApi.getSelectedNodes()[0].data + ); + } } this.cd.markForCheck(); });