Bug-Fix Last instance does not disappear when deleted 47/6847/7
authorychacon <yennifer.chacon@est.tech>
Fri, 8 Oct 2021 12:50:46 +0000 (14:50 +0200)
committerychacon <yennifer.chacon@est.tech>
Fri, 15 Oct 2021 09:29:32 +0000 (11:29 +0200)
Issue-ID: NONRTRIC-555
Signed-off-by: ychacon <yennifer.chacon@est.tech>
Change-Id: I24c6a3d25a8fff352d9979d6f2703a6e3e19ab1f

webapp-frontend/src/app/ei-coordinator/jobs-list/jobs-list.component.ts
webapp-frontend/src/app/ei-coordinator/producers-list/producers-list.component.spec.ts
webapp-frontend/src/app/ei-coordinator/producers-list/producers-list.component.ts
webapp-frontend/src/app/policy/policy-instance/policy-instance.component.ts

index 95d1040..ce6c9a7 100644 (file)
@@ -27,7 +27,6 @@ import { BehaviorSubject } from "rxjs/BehaviorSubject";
 import { mergeMap, finalize, map, tap, concatMap, delay, skip, catchError } from "rxjs/operators";
 import { ConsumerService } from "@services/ei/consumer.service";
 import { UiService } from "@services/ui/ui.service";
-import { EmptyObservable } from 'rxjs/observable/EmptyObservable';
 
 export interface Job {
   jobId: string;
@@ -56,6 +55,7 @@ export class JobsListComponent implements OnInit {
   subscription: Subscription;
   checked: boolean = false;
   firstTime: boolean = true;
+  jobList: Job[] = [];
 
   constructor(private consumerService: ConsumerService, private ui: UiService) {
     this.jobForm = new FormGroup({
@@ -97,6 +97,9 @@ export class JobsListComponent implements OnInit {
 
   dataSubscription(): Subscription {
     const jobsInfo$ = this.consumerService.getJobIds().pipe(
+      tap((_) => {
+        this.jobList = [] as Job[];
+      }),
       mergeMap((jobIds) =>
         forkJoin(jobIds.map((jobId) => {
           return forkJoin([
@@ -113,7 +116,8 @@ export class JobsListComponent implements OnInit {
         }))
       ),
       finalize(() => {
-        this.loadingSubject$.next(false)
+        this.loadingSubject$.next(false);
+        this.jobsSubject$.next(this.jobList);
       })
 
     );
@@ -139,7 +143,7 @@ export class JobsListComponent implements OnInit {
         concatMap((value) => {
           let pollCondition = value == 0 || this.checked;
           return pollCondition ? refreshedJobs$ : EMPTY;
-        }),
+        })
       )
       .subscribe();
   }
@@ -225,7 +229,6 @@ export class JobsListComponent implements OnInit {
 
   private extractJobs(res: any) {
     this.clearFilter();
-    let jobList = [];
     res.forEach(element => {
       if(element[1] != -1 && element[2] != -1){
         let jobObj = <Job>{};
@@ -234,19 +237,23 @@ export class JobsListComponent implements OnInit {
         jobObj.targetUri = element[1].job_result_uri;
         jobObj.typeId = element[1].info_type_id;
         jobObj.prodIds = (element[2].producers) ? element[2].producers : ["No Producers"];
-        jobList = jobList.concat(jobObj);
+        this.jobList = this.jobList.concat(jobObj);
       }
     });
 
-    this.jobsSubject$.next(jobList);
-    if (this.firstTime && jobList.length > 0) {
-      this.polling$.next(jobList.length);
+    if (this.firstTime && this.jobList.length > 0) {
+      this.polling$.next(this.jobList.length);
       this.firstTime = false;
     }
-    return jobList;
+    return this.jobList;
   }
 
   refreshDataClick() {
     this.refresh$.next("");
   }
+
+  hasJobs(): boolean {
+    return this.jobs().length > 0;
+  }
+
 }
index d7542e8..5846ffd 100644 (file)
@@ -105,7 +105,6 @@ describe('ProducersListComponent', () => {
 
     it('should contain data after initialization', async () => {
       setServiceSpy();
-      component.ngOnInit();
       const expectedProducerRows = [
         expectedProducer1Row,
         { id: 'producer2', types: 'type2,type3', status: 'DISABLED' }
@@ -127,8 +126,8 @@ describe('ProducersListComponent', () => {
       producerServiceSpy.getProducer.and.returnValues(of({} as ProducerRegistrationInfo));
       producerServiceSpy.getProducerStatus.and.returnValues(of({} as ProducerStatus));
 
-      component.ngOnInit();
       const expectedProducerRow = { id: 'producer1', types: '< No types >', status: '< No status >' };
+
       let producersTable = await loader.getHarness(MatTableHarness.with({ selector: '#producersTable' }));
       let producerRows = await producersTable.getRows();
       expect(await producerRows[0].getCellTextByColumnName()).toEqual(expectedProducerRow);
@@ -136,7 +135,6 @@ describe('ProducersListComponent', () => {
 
     it('filtering', async () => {
       setServiceSpy();
-      component.ngOnInit();
       let producersTable = await loader.getHarness(MatTableHarness.with({ selector: '#producersTable' }));
 
       let idFilterInput = await loader.getHarness(MatInputHarness.with({ selector: '#producerIdFilter' }));
index 725117d..5fe0c85 100644 (file)
@@ -149,7 +149,10 @@ export class ProducersListComponent implements OnInit {
           ])
         })
         )),
-      finalize(() => this.loadingSubject.next(false)),
+      finalize(() => {
+        this.loadingSubject.next(false);
+        this.producerSubject.next(producers);
+      })
     ).subscribe(result => {
       producers = result.map(producer => {
         let producerObj = <Producer>{};
@@ -162,9 +165,13 @@ export class ProducersListComponent implements OnInit {
         }
         return producerObj;
       });
-      this.producerSubject.next(producers);
     }, err => {
       console.error("Subscribe function error:" + err);
     });
   }
+
+  hasProducers(): boolean {
+    return this.producers().length > 0;
+  }
+
 }
index 5e29f3a..43afc94 100644 (file)
@@ -121,7 +121,10 @@ export class PolicyInstanceComponent implements OnInit {
             })
           )
         ),
-        finalize(() => this.loadingSubject$.next(false))
+        finalize(() => {
+          this.loadingSubject$.next(false);
+          this.policyInstanceSubject.next(this.policyInstances);
+        })
       )
       .subscribe((res) => {
         this.policyInstances = res.map((policy) => {
@@ -130,7 +133,6 @@ export class PolicyInstanceComponent implements OnInit {
           policyInstance.lastModified = policy[1].last_modified;
           return policyInstance;
         });
-        this.policyInstanceSubject.next(this.policyInstances);
       });
   }
 
@@ -194,7 +196,7 @@ export class PolicyInstanceComponent implements OnInit {
   }
 
   instanceCount(): number {
-    return this.policyInstances.length;
+    return this.instanceDataSource.data.length;
   }
 
   toLocalTime(utcTime: string): string {