Skip to content

Commit

Permalink
add a Observable that triggers a refresh when called (#1041)
Browse files Browse the repository at this point in the history
* jar is now debuggable

* rename folder

* add a Observable that triggers a refresh when called

* add destroy observable to stop subscription of reloadKeySubject

* add tests to observables

---------

Co-authored-by: Yanick Minder <[email protected]>
  • Loading branch information
2 people authored and clean-coder committed Oct 24, 2024
1 parent eb458eb commit 153fbce
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .run/OkrApplication-local-prod-debug.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

<component name="ProjectRunConfigurationManager">
<configuration default="false" name="OkrApplication Local-prod debug" type="Remote">
<module name="exam-feedback-tool" />
<option name="USE_SOCKET_TRANSPORT" value="true" />
<option name="SERVER_MODE" value="false" />
<option name="SHMEM_ADDRESS" />
<option name="HOST" value="localhost" />
<option name="PORT" value="5005" />
<option name="AUTO_RESTART" value="false" />
<RunnerSettings RunnerId="Debug">
<option name="DEBUG_PORT" value="5005" />
<option name="LOCAL" value="false" />
</RunnerSettings>
<method v="2" />
</configuration>
</component>
9 changes: 9 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@
<version>3.26.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.8.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve ",
"start": "ng serve",
"build": "ng build",
"build:staging": "ng build --configuration staging",
"watch": "ng build --watch --configuration development",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class CheckInHistoryDialogComponent implements OnInit {
});
dialogRef.afterClosed().subscribe(() => {
this.loadCheckInHistory();
this.refreshDataService.reloadKeyResultSubject.next();
this.refreshDataService.markDataRefresh();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MatIconModule } from '@angular/material/icon';
import { ActivatedRoute } from '@angular/router';
import { ScoringComponent } from '../../shared/custom/scoring/scoring.component';
import { ConfidenceComponent } from '../confidence/confidence.component';
import { RefreshDataService } from '../../services/refresh-data.service';

const keyResultServiceMock = {
getFullKeyResult: jest.fn(),
Expand Down Expand Up @@ -87,4 +88,21 @@ describe('KeyresultDetailComponent', () => {
const button = fixture.debugElement.query(By.css('[data-testId="add-check-in"]'));
expect(button).toBeFalsy();
});

it('should trigger observable when subject gets next value', () => {
const spy = jest.spyOn(component, 'loadKeyResult');
const refreshDataService = TestBed.inject(RefreshDataService);
refreshDataService.reloadKeyResultSubject.next();
expect(spy).toHaveBeenCalled();
});

it('should close subscription on destroy', () => {
const spyNext = jest.spyOn(component.ngDestroy$, 'next');
const spyComplete = jest.spyOn(component.ngDestroy$, 'complete');

component.ngOnDestroy();

expect(spyNext).toHaveBeenCalled();
expect(spyComplete).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnDestroy, OnInit } from '@angular/core';
import { KeyResult } from '../../shared/types/model/KeyResult';
import { KeyresultService } from '../../services/keyresult.service';
import { KeyResultMetric } from '../../shared/types/model/KeyResultMetric';
import { KeyResultOrdinal } from '../../shared/types/model/KeyResultOrdinal';
import { CheckInHistoryDialogComponent } from '../check-in-history-dialog/check-in-history-dialog.component';
import { MatDialog } from '@angular/material/dialog';
import { BehaviorSubject, catchError, EMPTY } from 'rxjs';
import { BehaviorSubject, catchError, EMPTY, Subject, takeUntil } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
import { RefreshDataService } from '../../services/refresh-data.service';
import { CloseState } from '../../shared/types/enums/CloseState';
Expand All @@ -22,10 +22,11 @@ import { ConfirmDialogComponent } from '../../shared/dialog/confirm-dialog/confi
styleUrls: ['./keyresult-detail.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class KeyresultDetailComponent implements OnInit {
export class KeyresultDetailComponent implements OnInit, OnDestroy {
@Input() keyResultId!: number;

keyResult$: BehaviorSubject<KeyResult> = new BehaviorSubject<KeyResult>({} as KeyResult);
ngDestroy$: Subject<void> = new Subject();
isComplete: boolean = false;
protected readonly DATE_FORMAT = DATE_FORMAT;
protected readonly isLastCheckInNegative = isLastCheckInNegative;
Expand All @@ -41,6 +42,14 @@ export class KeyresultDetailComponent implements OnInit {
ngOnInit(): void {
this.keyResultId = this.getIdFromParams();
this.loadKeyResult(this.keyResultId);
this.refreshDataService.reloadKeyResultSubject.pipe(takeUntil(this.ngDestroy$)).subscribe(() => {
this.loadKeyResult(this.keyResultId);
});
}

ngOnDestroy() {
this.ngDestroy$.next();
this.ngDestroy$.complete();
}

private getIdFromParams(): number {
Expand Down Expand Up @@ -181,7 +190,7 @@ export class KeyresultDetailComponent implements OnInit {
},
});
dialogRef.afterClosed().subscribe(() => {
this.loadKeyResult(this.keyResult$.getValue().id);
this.refreshDataService.reloadKeyResultSubject.next();
this.refreshDataService.markDataRefresh();
});
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/services/refresh-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DEFAULT_HEADER_HEIGHT_PX } from '../shared/constantLibary';
})
export class RefreshDataService {
public reloadOverviewSubject: Subject<void> = new Subject();
public reloadKeyResultSubject: Subject<void> = new Subject();

public quarterFilterReady: Subject<void> = new Subject<void>();
public teamFilterReady: Subject<void> = new Subject<void>();
Expand Down

0 comments on commit 153fbce

Please sign in to comment.