Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
nevio18324 committed Jan 23, 2025
1 parent ea20ecd commit 1f58f63
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { CheckInMetricMin } from '../../../shared/types/model/check-in-metric-mi
import { CheckInOrdinalMin } from '../../../shared/types/model/check-in-ordinal-min';
import { BehaviorSubject } from 'rxjs';
import { Zone } from '../../../shared/types/enums/zone';
import { numberValidator } from '../../../shared/constant-library';

@Component({
selector: 'app-check-in-form',
Expand All @@ -35,7 +36,7 @@ export class CheckInFormComponent implements OnInit {

dialogForm = new FormGroup({
metricValue: new FormControl<number | undefined>(undefined, [Validators.required,
Validators.pattern('^\\s*-?\\d+\\.?\\d*\\s*$')]),
numberValidator()]),
ordinalZone: new FormControl<Zone>(Zone.COMMIT, [Validators.required]),
confidence: new FormControl<number>(5, [Validators.required,
Validators.min(0),
Expand Down Expand Up @@ -103,8 +104,8 @@ export class CheckInFormComponent implements OnInit {

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

calculateTarget(keyResult: KeyResultMetric): number {
Expand Down Expand Up @@ -138,14 +139,6 @@ 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
2 changes: 1 addition & 1 deletion frontend/src/app/shared/constant-library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function ownerValidator(): ValidatorFn {
};
}

function numberValidator(): ValidatorFn {
export function numberValidator(): ValidatorFn {
return (control: AbstractControl): ValidationErrors | null => {
const isAllowed = (/^-?\d+\.?\d*$/).test(control.value);
return isAllowed ? null : { number: { value: control.value } };
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/shared/types/model/check-in-metric-min.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CheckInMin } from './check-in-min';

export interface CheckInMetricMin extends CheckInMin {
value: number | undefined;
value: number;
}
3 changes: 2 additions & 1 deletion frontend/src/app/shared/types/model/check-in-ordinal-min.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { CheckInMin } from './check-in-min';
import { Zone } from '../enums/zone';

export interface CheckInOrdinalMin extends CheckInMin {
zone: string | undefined;
zone: Zone;
}

0 comments on commit 1f58f63

Please sign in to comment.