Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Loading