Skip to content

Commit

Permalink
apply requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nevio18324 committed Jan 23, 2025
1 parent f3e7712 commit 3c95c6b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { FormGroup, Validators } from '@angular/forms';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { KeyResultMetric } from '../../../shared/types/model/key-result-metric';
import { CheckInMin } from '../../../shared/types/model/check-in-min';
import { formInputCheck, hasFormFieldErrors } from '../../../shared/common';
Expand All @@ -12,7 +12,7 @@ import { CheckInMetricMin } from '../../../shared/types/model/check-in-metric-mi
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false
})
export class CheckInFormMetricComponent implements OnInit {
export class CheckInFormMetricComponen {

Check failure on line 15 in frontend/src/app/components/checkin/check-in-form-metric/check-in-form-metric.component.ts

View workflow job for this annotation

GitHub Actions / frontend

Component class names should end with one of these suffixes: "Component" (https://angular.dev/style-guide#style-02-03)
@Input()
keyResult!: KeyResultMetric;

Expand All @@ -28,11 +28,6 @@ export class CheckInFormMetricComponent implements OnInit {

constructor(private translate: TranslateService) {}

ngOnInit() {
this.dialogForm.controls['metricValue'].setValidators([Validators.required,
Validators.pattern('^\\s*-?\\d+\\.?\\d*\\s*$')]);
}

generateUnitLabel(): string {
switch (this.keyResult.unit) {
case 'PERCENT':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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/check-in';
import { CheckInMetricMin } from '../../../shared/types/model/check-in-metric-min';
import { CheckInOrdinalMin } from '../../../shared/types/model/check-in-ordinal-min';
import { BehaviorSubject } from 'rxjs';
Expand All @@ -35,7 +34,8 @@ export class CheckInFormComponent implements OnInit {
isAddingAction = false;

dialogForm = new FormGroup({
metricValue: new FormControl<number | undefined>(undefined, [Validators.required]),
metricValue: new FormControl<number | undefined>(undefined, [Validators.required,
Validators.pattern('^\\s*-?\\d+\\.?\\d*\\s*$')]),
ordinalZone: new FormControl<Zone>(Zone.COMMIT, [Validators.required]),
confidence: new FormControl<number>(5, [Validators.required,
Validators.min(0),
Expand Down Expand Up @@ -80,12 +80,10 @@ export class CheckInFormComponent implements OnInit {
this.dialogForm.controls.actionList.setValue(this.keyResult.actionList);
if (this.data.checkIn != null) {
this.checkIn = this.data.checkIn;
this.keyResult.keyResultType === 'metric'
? this.dialogForm.controls.metricValue.setValue(Number.parseFloat(this.getCheckInValue()))
: this.dialogForm.controls.ordinalZone.setValue(this.valueToZone(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);
this.setValueOrZone();
return;
}

Expand All @@ -103,6 +101,12 @@ export class CheckInFormComponent implements OnInit {
this.checkIn = { confidence: 5 } as CheckInMin;
}

setValueOrZone() {
this.keyResult.keyResultType === 'metric'
? this.dialogForm.controls.metricValue.setValue(Number.parseFloat(this.getCheckInValue()))
: this.dialogForm.controls.ordinalZone.setValue(this.getCheckInValue() as Zone);
}

calculateTarget(keyResult: KeyResultMetric): number {
return keyResult.stretchGoal - (keyResult.stretchGoal - keyResult.baseline) * 0.3;
}
Expand All @@ -121,13 +125,11 @@ export class CheckInFormComponent implements OnInit {
changeInfo: this.dialogForm.controls.changeInfo.value,
initiatives: this.dialogForm.controls.initiatives.value
};
const checkIn: CheckIn = {
...baseCheckIn,
[this.keyResult.keyResultType === 'ordinal' ? 'zone' : 'value']:
this.dialogForm.controls[this.keyResult.keyResultType === 'ordinal' ? 'ordinalZone' : 'metricValue'].value
};
this.keyResult.keyResultType === 'metric'
? baseCheckIn.value = this.dialogForm.controls.metricValue.value
: baseCheckIn.zone = this.dialogForm.controls.ordinalZone.value;

this.checkInService.saveCheckIn(checkIn)
this.checkInService.saveCheckIn(baseCheckIn)
.subscribe(() => {
this.actionService.updateActions(this.dialogForm.value.actionList!)
.subscribe(() => {
Expand Down Expand Up @@ -194,13 +196,4 @@ export class CheckInFormComponent implements OnInit {
this.dialogForm.get(this.checkInTypes.filter((formName) => formName.includes(type)))
?.enable({ emitEvent: false });
}

valueToZone(value: string) {
for (const zone in Zone) {
if (zone === value) {
return zone as Zone;
}
}
return;
}
}

0 comments on commit 3c95c6b

Please sign in to comment.