Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/937 DTO Umbenennung value -> zone #1218

Merged
merged 17 commits into from
Dec 6, 2024
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
Expand Up @@ -7,6 +7,6 @@

@JsonDeserialize(as = CheckInOrdinalDto.class)
public record CheckInOrdinalDto(Long id, int version, String changeInfo, String initiatives, Integer confidence,
Long keyResultId, LocalDateTime createdOn, LocalDateTime modifiedOn, Zone value, boolean writeable)
Long keyResultId, LocalDateTime createdOn, LocalDateTime modifiedOn, Zone zone, boolean writeable)
implements CheckInDto {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

import java.time.LocalDateTime;

public record KeyResultLastCheckInOrdinalDto(Long id, int version, Zone value, Integer confidence,
public record KeyResultLastCheckInOrdinalDto(Long id, int version, Zone zone, Integer confidence,
LocalDateTime createdOn, String changeInfo, String initiatives) implements KeyResultLastCheckIn {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import java.time.LocalDateTime;

public record OverviewLastCheckInOrdinalDto(Long id, String value, Integer confidence, LocalDateTime createdOn)
public record OverviewLastCheckInOrdinalDto(Long id, String zone, Integer confidence, LocalDateTime createdOn)
implements OverviewLastCheckInDto {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CheckInOrdinalDto toDto(CheckInOrdinal checkInOrdinal) {

public CheckIn toCheckInOrdinal(CheckInOrdinalDto checkInOrdinalDto) {
return CheckInOrdinal.Builder.builder() //
.withZone(checkInOrdinalDto.value()) //
.withZone(checkInOrdinalDto.zone()) //
.withId(checkInOrdinalDto.id()) //
.withVersion(checkInOrdinalDto.version()) //
.withChangeInfo(checkInOrdinalDto.changeInfo()) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void assertCheckInOrdinalDto(CheckInOrdinalDto checkInOrdinalDto) {
assertEquals("Initiatives", checkInOrdinalDto.initiatives());
assertEquals(7, checkInOrdinalDto.confidence());
assertEquals(1001, checkInOrdinalDto.keyResultId());
assertEquals(Zone.STRETCH, checkInOrdinalDto.value());
assertEquals(Zone.STRETCH, checkInOrdinalDto.zone());
}

private void assertKeyResultMetricDto(KeyResultMetricDto keyResultMetricDto) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void toDtoShouldReturnOneElementWhenTwoObjectivesWithKeyResultAndCheckInFound()
assertEquals("commit", ((OverviewKeyResultOrdinalDto) keyResultDto).commitZone());
assertEquals("target", ((OverviewKeyResultOrdinalDto) keyResultDto).targetZone());
assertEquals("stretch", ((OverviewKeyResultOrdinalDto) keyResultDto).stretchZone());
assertEquals("checkIn", ((OverviewKeyResultOrdinalDto) keyResultDto).lastCheckIn().value());
assertEquals("checkIn", ((OverviewKeyResultOrdinalDto) keyResultDto).lastCheckIn().zone());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void assertCheckInOrdinalDto(CheckInOrdinal expected, CheckInOrdin
assertEquals(expected.getKeyResult().getId(), actual.keyResultId());
assertEquals(expected.getCreatedOn(), actual.createdOn());
assertEquals(expected.getModifiedOn(), actual.modifiedOn());
assertEquals(expected.getZone(), actual.value());
assertEquals(expected.getZone(), actual.zone());
assertEquals(expected.isWriteable(), actual.writeable());
}

Expand All @@ -58,7 +58,7 @@ public static void assertCheckInOrdinal(CheckInOrdinalDto checkInOrdinalDto, Che
assertEquals(checkInOrdinalDto.keyResultId(), checkInOrdinal.getKeyResult().getId());
assertEquals(checkInOrdinalDto.createdOn(), checkInOrdinal.getCreatedOn());
assertEquals(checkInOrdinalDto.modifiedOn(), checkInOrdinal.getModifiedOn());
assertEquals(checkInOrdinalDto.value(), checkInOrdinal.getZone());
assertEquals(checkInOrdinalDto.zone(), checkInOrdinal.getZone());
assertFalse(checkInOrdinal.isWriteable());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private static void assertCheckInOrdinalDto(KeyResultLastCheckInOrdinalDto expec
KeyResultLastCheckInOrdinalDto actual) {
assertEquals(expected.id(), actual.id());
assertEquals(expected.version(), actual.version());
assertEquals(expected.value(), actual.value());
assertEquals(expected.zone(), actual.zone());
assertEquals(expected.confidence(), actual.confidence());
assertEquals(expected.createdOn(), actual.createdOn());
assertEquals(expected.changeInfo(), actual.changeInfo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class CheckInTestHelpers {
public static final String JSON_PATH_CREATED_ON = "$.createdOn";

public static final String JSON_PATH_VALUE = "$.value";
public static final String JSON_PATH_ZONE = "$.value";
public static final String JSON_PATH_ZONE = "$.zone";

/* Test entities */
static final Objective objective = Objective.Builder.builder().withId(1L).build();
Expand Down Expand Up @@ -90,7 +90,7 @@ public class CheckInTestHelpers {
"keyResultId": 1001,
"createdOn": null,
"modifiedOn": null,
"value": "STRETCH",
"zone": "STRETCH",
"writeable": false
}
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class KeyResultTestHelpers {
public static final String JSON_PATH_TARGET_ZONE = "$.targetZone";
public static final String JSON_PATH_STRETCH_ZONE = "$.stretchZone";
public static final String JSON_PATH_LAST_CHECK_IN_ID = "$.lastCheckIn.id";
public static final String JSON_PATH_LAST_CHECK_IN_ZONE = "$.lastCheckIn.value";
public static final String JSON_PATH_LAST_CHECK_IN_ZONE = "$.lastCheckIn.zone";
public static final String JSON_PATH_QUARTER_LABEL = "$.objective.keyResultQuarterDto.label";
public static final String JSON_PATH_QUARTER_START_DATE = "$.objective.keyResultQuarterDto.startDate";
public static final String JSON = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
<div class="okr-form-row row-cols-4">
<h4 class="col-auto">Wert:</h4>
<span class="col">
<ng-container *ngIf="keyResult.keyResultType === 'metric'">
{{ +checkIn.value! | unitTransformation: getMetricKeyResult().unit }}
<ng-container *ngIf="keyResult.keyResultType === 'metric' && getCheckInMetric(checkIn) as metricCheckIn">
{{ metricCheckIn.value! | unitTransformation: getMetricKeyResult().unit }}
</ng-container>
<ng-container *ngIf="keyResult.keyResultType === 'ordinal'">
{{ checkIn.value }}
<ng-container
*ngIf="keyResult.keyResultType === 'ordinal' && getCheckInOrdinal(checkIn) as ordinalCheckIn"
>
{{ ordinalCheckIn.zone! }}
</ng-container>
</span>
<h4 class="col-auto">Confidence:</h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Observable, of } from 'rxjs';
import { KeyResultMetric } from '../../shared/types/model/KeyResultMetric';
import { RefreshDataService } from '../../services/refresh-data.service';
import { DialogService } from '../../services/dialog.service';
import { CheckInMetricMin } from '../../shared/types/model/CheckInMetricMin';
import { CheckInOrdinalMin } from '../../shared/types/model/CheckInOrdinalMin';

@Component({
selector: 'app-check-in-history-dialog',
Expand Down Expand Up @@ -60,4 +62,12 @@ export class CheckInHistoryDialogComponent implements OnInit {
getMetricKeyResult(): KeyResultMetric {
return this.keyResult as KeyResultMetric;
}

getCheckInMetric(checkIn: CheckInMin): CheckInMetricMin {
return checkIn as CheckInMetricMin;
}

getCheckInOrdinal(checkIn: CheckInMin): CheckInOrdinalMin {
return checkIn as CheckInOrdinalMin;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
</div>

<div class="col">
<div *ngIf="checkIn.value" class="okr-form-row okr-form-label-input-container">
<div *ngIf="getCheckInMetric() as metricCheckIn" class="okr-form-row okr-form-label-input-container">
<p class="okr-form-label okr-form-col">Letzter Wert</p>
<div class="okr-form-col text-black">
<div class="dialog-data-show dialog-form-field py-2">{{ checkIn.value }}{{ generateUnitLabel() }}</div>
<div class="dialog-data-show dialog-form-field py-2">{{ metricCheckIn.value }}{{ generateUnitLabel() }}</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { KeyResultMetric } from '../../../shared/types/model/KeyResultMetric';
import { CheckInMin } from '../../../shared/types/model/CheckInMin';
import { formInputCheck, hasFormFieldErrors } from '../../../shared/common';
import { TranslateService } from '@ngx-translate/core';
import { CheckInMetricMin } from '../../../shared/types/model/CheckInMetricMin';

@Component({
selector: 'app-check-in-form-metric',
Expand Down Expand Up @@ -45,4 +46,8 @@ export class CheckInFormMetricComponent implements OnInit {
getErrorMessage(error: string, field: string): string {
return field + this.translate.instant('DIALOG_ERRORS.' + error);
}

getCheckInMetric(): CheckInMetricMin {
return this.checkIn as CheckInMetricMin;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,20 @@ describe('CheckInFormComponent', () => {
it('should save check-in correctly if key result is ordinal', waitForAsync(async () => {
component.checkIn = checkInOrdinal;
component.keyResult = keyResultOrdinal;
component.dialogForm.controls['value'].setValue(checkInOrdinal?.value as string);
component.dialogForm.controls['value'].setValue(checkInOrdinal?.zone!.toString());
component.dialogForm.controls['confidence'].setValue(checkInOrdinal.confidence);
component.dialogForm.controls['changeInfo'].setValue(checkInOrdinal.changeInfo);
component.dialogForm.controls['initiatives'].setValue(checkInOrdinal.initiatives);

checkInServiceMock.saveCheckIn.mockReturnValue(of(checkInOrdinal));
actionServiceMock.updateActions.mockReturnValue(of(action2));
component.saveCheckIn();

expect(checkInServiceMock.saveCheckIn).toHaveBeenCalledWith({
id: checkInOrdinal.id,
version: checkInOrdinal.version,
confidence: checkInOrdinal.confidence,
value: checkInOrdinal.value,
zone: checkInOrdinal.zone,
changeInfo: checkInOrdinal.changeInfo,
initiatives: checkInOrdinal.initiatives,
keyResultId: keyResultOrdinal.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { Action } from '../../../shared/types/model/Action';
import { ActionService } from '../../../services/action.service';
import { formInputCheck, hasFormFieldErrors } from '../../../shared/common';
import { TranslateService } from '@ngx-translate/core';
import { CheckIn } from '../../../shared/types/model/CheckIn';
import { CheckInMetricMin } from '../../../shared/types/model/CheckInMetricMin';
import { CheckInOrdinalMin } from '../../../shared/types/model/CheckInOrdinalMin';

@Component({
selector: 'app-check-in-form',
Expand Down Expand Up @@ -56,15 +59,18 @@ export class CheckInFormComponent implements OnInit {
this.dialogForm.controls.actionList.setValue(this.keyResult.actionList);
if (this.data.checkIn != null) {
this.checkIn = this.data.checkIn;
this.dialogForm.controls.value.setValue(this.checkIn.value!.toString());
this.dialogForm.controls.value.setValue(this.getCheckInValue());
this.dialogForm.controls.confidence.setValue(this.checkIn.confidence);
this.dialogForm.controls.changeInfo.setValue(this.checkIn.changeInfo);
this.dialogForm.controls.initiatives.setValue(this.checkIn.initiatives);
return;
}
/* If KeyResult has lastCheckIn set checkIn to this value */
if (this.keyResult.lastCheckIn != null) {
this.checkIn = { ...this.keyResult.lastCheckIn, id: undefined };
if ((this.keyResult as KeyResultMetric | KeyResultOrdinal).lastCheckIn != null) {
this.checkIn = {
...(this.keyResult as KeyResultMetric | KeyResultOrdinal).lastCheckIn,
id: undefined,
} as CheckInMin;
this.dialogForm.controls.confidence.setValue(this.checkIn.confidence);
return;
}
Expand All @@ -78,11 +84,18 @@ export class CheckInFormComponent implements OnInit {

saveCheckIn() {
this.dialogForm.controls.confidence.setValue(this.checkIn.confidence);
let checkIn: any = {
...this.dialogForm.value,
const baseCheckIn: any = {
id: this.checkIn.id,
version: this.checkIn.version,
keyResultId: this.keyResult.id,
confidence: this.dialogForm.controls.confidence.value,
changeInfo: this.dialogForm.controls.changeInfo.value,
initiatives: this.dialogForm.controls.initiatives.value,
actionList: this.dialogForm.controls.actionList.value,
};
const checkIn: CheckIn = {
...baseCheckIn,
[this.keyResult.keyResultType === 'ordinal' ? 'zone' : 'value']: this.dialogForm.controls.value.value,
};

this.checkInService.saveCheckIn(checkIn).subscribe(() => {
Expand All @@ -92,6 +105,14 @@ export class CheckInFormComponent implements OnInit {
});
}

getCheckInValue(): string {
if ((this.checkIn as CheckInMetricMin).value != null) {
return (this.checkIn as CheckInMetricMin).value!.toString();
} else {
return (this.checkIn as CheckInOrdinalMin).zone!;
}
}

getKeyResultMetric(): KeyResultMetric {
return this.keyResult as KeyResultMetric;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ <h4 *ngIf="keyResult?.objective?.quarter as quarter">{{ quarter.label }}</h4>
</section>

<section class="scoring-section mb-2-rem">
<app-scoring class="scoring-detail" [keyResult]="keyResult" [isDetail]="true"></app-scoring>
<app-scoring
class="scoring-detail"
[keyResult]="getKeyResultWithCorrectType(keyResult)"
[isDetail]="true"
></app-scoring>
<span class="text-small d-flex align-items-center flex-column ms-3 confidence-container">
<h4 class="confidence-label">Confidence</h4>
<app-confidence
[checkIn]="keyResult.lastCheckIn!"
[checkIn]="getKeyResultWithCorrectType(keyResult).lastCheckIn!"
[edit]="false"
class="bg-display-element"
></app-confidence>
Expand Down Expand Up @@ -102,7 +106,7 @@ <h3>Action Plan</h3>
</div>
</section>

<section *ngIf="keyResult.lastCheckIn as checkIn" class="mb-2-rem">
<section *ngIf="getKeyResultWithCorrectType(keyResult).lastCheckIn as checkIn" class="mb-2-rem">
<h3 class="mb-1">Letztes Check-in ({{ checkIn.createdOn | date: DATE_FORMAT }})</h3>
<p class="linebreak" *ngIf="checkIn.changeInfo">{{ checkIn.changeInfo }}</p>
<span class="d-flex justify-content-start all-checkins-button">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import { DATE_FORMAT } from '../../shared/constantLibary';
import { calculateCurrentPercentage, isLastCheckInNegative } from '../../shared/common';
import { KeyresultDialogComponent } from '../keyresult-dialog/keyresult-dialog.component';
import { DialogService } from '../../services/dialog.service';
import { KeyresultMin } from '../../shared/types/model/KeyresultMin';
import { KeyResultMetricMin } from '../../shared/types/model/KeyResultMetricMin';
import { KeyResultOrdinalMin } from '../../shared/types/model/KeyResultOrdinalMin';
import { CheckInOrdinal } from '../../shared/types/model/CheckInOrdinal';
import { CheckInMetric } from '../../shared/types/model/CheckInMetric';

@Component({
selector: 'app-keyresult-detail',
Expand Down Expand Up @@ -142,5 +147,13 @@ export class KeyresultDetailComponent implements OnInit, OnDestroy {
this.router.navigate(['']);
}

getKeyResultWithCorrectType(keyResult: KeyResult): KeyResultOrdinalMin | KeyResultMetricMin {
if (keyResult.keyResultType === 'metric') {
return keyResult as KeyresultMin as KeyResultMetricMin;
} else {
return keyResult as KeyresultMin as KeyResultOrdinalMin;
}
}

protected readonly calculateCurrentPercentage = calculateCurrentPercentage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class KeyresultDialogComponent {
? ({ ...value, objective: this.data.objective } as KeyResultMetricDTO)
: ({ ...value, objective: this.data.objective, id: this.data.keyResult?.id } as KeyResultOrdinalDTO);
keyResult.id = this.data.keyResult?.id;
keyResult.version = this.data.keyResult?.version;
keyResult.version = this.data.keyResult?.version!;
keyResult.actionList = keyResult.actionList!.filter((action: Action) => action.action !== '');
this.keyResultService.saveKeyResult(keyResult).subscribe((returnValue) => {
this.dialogRef.close({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class KeyresultTypeComponent implements OnInit {

ngOnInit(): void {
if (this.keyresult) {
this.typeChangeAllowed = this.keyresult.lastCheckIn?.id == null;
this.typeChangeAllowed = (this.keyresult as KeyResultMetric | KeyResultOrdinal).lastCheckIn?.id == null;
this.isMetric = this.keyresult.keyResultType == 'metric';
this.isMetric
? this.keyResultForm.patchValue({ ...this.castToMetric(this.keyresult) })
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/app/components/keyresult/keyresult.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
tabindex="0"
>
<h3 class="linebreak mb-3">{{ keyResult.title }}</h3>
<app-scoring [keyResult]="keyResult" [isDetail]="false" [attr.data-testId]="'scoring-component'"></app-scoring>
<app-scoring
[keyResult]="getKeyResultWithCorrectType()"
[isDetail]="false"
[attr.data-testId]="'scoring-component'"
></app-scoring>
<div class="d-flex justify-content-between mt-2">
<div class="d-flex justify-content-center align-items-center flex-wrap">
<h4 class="text-nowrap me-2">Letztes Check-in</h4>
<span class="keyResult-attribute-show">{{
keyResult.lastCheckIn == null ? "Keines" : (keyResult!.lastCheckIn!.createdOn | date: DATE_FORMAT)
getKeyResultWithCorrectType().lastCheckIn == null
? "Keines"
: (getKeyResultWithCorrectType().lastCheckIn!.createdOn | date: DATE_FORMAT)
}}</span>
</div>

Expand All @@ -20,7 +26,7 @@ <h4 class="me-2">Confidence</h4>
<app-confidence
[edit]="false"
[isDetail]="false"
[checkIn]="keyResult.lastCheckIn!"
[checkIn]="getKeyResultWithCorrectType().lastCheckIn!"
class="bg-keyResult-attribute"
></app-confidence>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { keyResultMetricMin } from '../../shared/testData';
import { MatDialogModule } from '@angular/material/dialog';
import { ScoringComponent } from '../../shared/custom/scoring/scoring.component';
import { ConfidenceComponent } from '../confidence/confidence.component';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';

describe('KeyresultComponent', () => {
let component: KeyresultComponent;
Expand All @@ -13,6 +14,7 @@ describe('KeyresultComponent', () => {
await TestBed.configureTestingModule({
declarations: [KeyresultComponent, ScoringComponent, ConfidenceComponent],
imports: [MatDialogModule],
providers: [provideHttpClient(withInterceptorsFromDi())],
}).compileComponents();

fixture = TestBed.createComponent(KeyresultComponent);
Expand Down
Loading
Loading