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

Bug/1279 metric checkin value is not validated correctly #1329

Merged
merged 21 commits into from
Jan 28, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
metric checkin error handling should work properly now
nevio18324 authored and peggimann committed Jan 28, 2025

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit df93053c4d86a48bfaf9cbb0ea70eed54438a7ae
Original file line number Diff line number Diff line change
@@ -8,16 +8,16 @@
<input
class="dialog-form-field pe-0"
[attr.data-testId]="'check-in-metric-value'"
[ngClass]="formInputCheck(dialogForm, 'value')"
formControlName="value"
[ngClass]="formInputCheck(dialogForm, 'metricValue')"
formControlName="metricValue"
id="value"
/>
</div>

<span class="okr-form-label col-auto h-fit ps-0">{{ generateUnitLabel() }}</span>
</form>
</div>
<mat-error *ngIf="hasFormFieldErrors(dialogForm, 'value')">
<mat-error *ngIf="hasFormFieldErrors(dialogForm, 'metricValue')">
<span>{{ getErrorMessage("MUST_BE_NUMBER", "Neuer Wert") }}</span>
</mat-error>
</div>
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ export class CheckInFormMetricComponent implements OnInit {
constructor(private translate: TranslateService) {}

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

Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
<div class="okr-form-row okr-form-label-input-container">
<label class="okr-form-label okr-form-col" for="ordinal-radio-group">Erreichte Zone wählen:</label>
<mat-radio-group
formControlName="value"
formControlName="ordinalZone"
class="d-flex flex-column gap-2"
id="ordinal-radio-group"
>
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ 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';
import { Zone } from '../../../shared/types/enums/zone';

@Component({
selector: 'app-check-in-form',
@@ -34,7 +35,8 @@ export class CheckInFormComponent implements OnInit {
isAddingAction = false;

dialogForm = new FormGroup({
value: new FormControl<string>('', [Validators.required]),
metricValue: new FormControl<number | undefined>(undefined, [Validators.required]),
ordinalZone: new FormControl<Zone>(Zone.COMMIT, [Validators.required]),
confidence: new FormControl<number>(5, [Validators.required,
Validators.min(0),
Validators.max(10)]),
@@ -43,6 +45,9 @@ export class CheckInFormComponent implements OnInit {
actionList: new FormControl<Action[]>([])
});

checkInTypes: string[] = ['metricValue',
'ordinalZone'];

protected readonly formInputCheck = formInputCheck;

protected readonly hasFormFieldErrors = hasFormFieldErrors;
@@ -57,6 +62,7 @@ export class CheckInFormComponent implements OnInit {
this.currentDate = new Date();
this.keyResult = data.keyResult;
this.setDefaultValues();
this.setValidators(this.keyResult.keyResultType);
}

ngOnInit() {
@@ -74,7 +80,9 @@ 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.getCheckInValue());
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);
@@ -115,7 +123,8 @@ export class CheckInFormComponent implements OnInit {
};
const checkIn: CheckIn = {
...baseCheckIn,
[this.keyResult.keyResultType === 'ordinal' ? 'zone' : 'value']: this.dialogForm.controls.value.value
[this.keyResult.keyResultType === 'ordinal' ? 'zone' : 'value']:
this.dialogForm.controls[this.keyResult.keyResultType === 'ordinal' ? 'ordinalZone' : 'metricValue'].value
};

this.checkInService.saveCheckIn(checkIn)
@@ -178,4 +187,20 @@ export class CheckInFormComponent implements OnInit {
this.dialogForm.patchValue({ actionList: actionList });
this.isAddingAction = false;
}

setValidators(type: string) {
this.checkInTypes.map((e) => this.dialogForm.get(e))
.forEach((e) => e?.disable({ emitEvent: false }));
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;
}
}
Original file line number Diff line number Diff line change
@@ -98,20 +98,6 @@ export class KeyResultDialogComponent implements OnInit {
.forEach((e) => e?.disable({ emitEvent: false }));
this.keyResultForm.get(type)
?.enable({ emitEvent: false });
/*
* if (type == 'metric') {
* this.keyResultForm.get('metric')
* ?.enable({ emitEvent: false });
* this.keyResultForm.get('ordinal')
* ?.disable({ emitEvent: false });
* }
* if (type == 'ordinal') {
* this.keyResultForm.get('metric')
* ?.disable({ emitEvent: false });
* this.keyResultForm.get('ordinal')
* ?.enable({ emitEvent: false });
* }
*/
}

ngOnInit(): void {