diff --git a/apps/frontend/src/app/backups-overview/backups/backups/backups.component.html b/apps/frontend/src/app/backups-overview/backups/backups/backups.component.html
index 9685ee5..ed3609d 100644
--- a/apps/frontend/src/app/backups-overview/backups/backups/backups.component.html
+++ b/apps/frontend/src/app/backups-overview/backups/backups/backups.component.html
@@ -35,8 +35,8 @@
-
-
+
diff --git a/apps/frontend/src/app/data-stores/component/data-stores.component.html b/apps/frontend/src/app/data-stores/component/data-stores.component.html
index dbaf97d..5719a41 100644
--- a/apps/frontend/src/app/data-stores/component/data-stores.component.html
+++ b/apps/frontend/src/app/data-stores/component/data-stores.component.html
@@ -3,7 +3,8 @@
Data Stores
-
+
{{ dataStore.displayName }}
-
\ No newline at end of file
diff --git a/apps/frontend/src/app/data-stores/component/data-stores.component.spec.ts b/apps/frontend/src/app/data-stores/component/data-stores.component.spec.ts
index 96a9186..4ace022 100644
--- a/apps/frontend/src/app/data-stores/component/data-stores.component.spec.ts
+++ b/apps/frontend/src/app/data-stores/component/data-stores.component.spec.ts
@@ -4,6 +4,23 @@ import { randomUUID } from 'crypto';
import { DataStoresComponent } from './data-stores.component';
import { DataStore } from '../../shared/types/data-store';
+const dataStores: DataStore[] = [
+ {
+ id: randomUUID().toString(),
+ displayName: 'test',
+ capacity: 100,
+ filled: 50,
+ highWaterMark: 80,
+ },
+ {
+ id: randomUUID().toString(),
+ displayName: 'test2',
+ capacity: 100,
+ filled: 80,
+ highWaterMark: 80,
+ },
+];
+
describe('DataStoresComponent', () => {
let component: DataStoresComponent;
let mockDataStoresService: {
@@ -12,37 +29,19 @@ describe('DataStoresComponent', () => {
beforeEach(() => {
mockDataStoresService = {
- getAllDataStores: vi.fn(),
+ getAllDataStores: vi.fn().mockReturnValue(of(dataStores)),
};
- component = new DataStoresComponent(mockDataStoresService as any);
+ component = new DataStoresComponent(mockDataStoresService);
});
- describe('loadDataStores', () => {
- it('should load data stores correctly', () => {
- const dataStores: DataStore[] = [
- {
- id: randomUUID().toString(),
- displayName: 'test',
- capacity: 100,
- filled: 50,
- highWaterMark: 80,
- },
- {
- id: randomUUID().toString(),
- displayName: 'test2',
- capacity: 100,
- filled: 80,
- highWaterMark: 80,
- },
- ];
-
+ describe('dataStores$', () => {
+ it('should load data stores correctly', (done) => {
mockDataStoresService.getAllDataStores.mockReturnValue(of(dataStores));
- component.loadDataStores();
-
- expect(component.dataStores).toEqual(dataStores);
- expect(component.showAll).toBeFalsy();
+ component.dataStores$.subscribe((result) => {
+ expect(result).toEqual(dataStores);
+ });
});
});
diff --git a/apps/frontend/src/app/data-stores/component/data-stores.component.ts b/apps/frontend/src/app/data-stores/component/data-stores.component.ts
index ebd605d..bc92900 100644
--- a/apps/frontend/src/app/data-stores/component/data-stores.component.ts
+++ b/apps/frontend/src/app/data-stores/component/data-stores.component.ts
@@ -1,6 +1,6 @@
-import { Component, OnDestroy, OnInit } from '@angular/core';
+import { Component, OnDestroy } from '@angular/core';
import { DataStoresService } from '../service/data-stores-service.service';
-import { Subject, takeUntil } from 'rxjs';
+import { map, Observable, shareReplay, Subject, takeUntil } from 'rxjs';
import { DataStore } from '../../shared/types/data-store';
@Component({
@@ -8,15 +8,18 @@ import { DataStore } from '../../shared/types/data-store';
templateUrl: './data-stores.component.html',
styleUrl: './data-stores.component.css',
})
-export class DataStoresComponent implements OnInit, OnDestroy {
+export class DataStoresComponent implements OnDestroy {
private readonly destroy$ = new Subject();
- dataStores: DataStore[] = [];
- showAll = false;
+ dataStores$: Observable;
- constructor(private readonly dataStoresService: DataStoresService) {}
+ showAll = false;
- ngOnInit(): void {
- this.loadDataStores();
+ constructor(private readonly dataStoresService: DataStoresService) {
+ this.dataStores$ = this.dataStoresService
+ .getAllDataStores()
+ .pipe(takeUntil(this.destroy$),
+ map(dataStores => this.sortDataStores(dataStores)),
+ shareReplay(1));
}
ngOnDestroy(): void {
@@ -40,14 +43,7 @@ export class DataStoresComponent implements OnInit, OnDestroy {
this.showAll = !this.showAll;
}
- loadDataStores() {
- this.dataStoresService
- .getAllDataStores()
- .pipe(takeUntil(this.destroy$))
- .subscribe((dataStores) => {
- this.dataStores = dataStores.sort(
- (a, b) => this.getFilledPercentage(b) - this.getFilledPercentage(a)
- );
- });
+ private sortDataStores(dataStores: DataStore[]): DataStore[] {
+ return dataStores.sort((a, b) => this.getFilledPercentage(b) - this.getFilledPercentage(a));
}
}