diff --git a/frontend/src/app/components/key-result-type/key-result-type.component.html b/frontend/src/app/components/key-result-type/key-result-type.component.html
index ce6ea2d7ad..b9c73c7821 100644
--- a/frontend/src/app/components/key-result-type/key-result-type.component.html
+++ b/frontend/src/app/components/key-result-type/key-result-type.component.html
@@ -45,7 +45,7 @@
(opened)="setUnits()"
[displayWith]="displayFn"
>
- Create new
+ Create new
{{unit.unitName}}
diff --git a/frontend/src/app/components/key-result-type/key-result-type.component.ts b/frontend/src/app/components/key-result-type/key-result-type.component.ts
index 721e0a65fd..df5a84b7c6 100644
--- a/frontend/src/app/components/key-result-type/key-result-type.component.ts
+++ b/frontend/src/app/components/key-result-type/key-result-type.component.ts
@@ -157,7 +157,7 @@ export class KeyResultTypeComponent implements AfterContentInit {
}), map((value) => this._filter(value || '')));
}
- createNew() {
+ createNewUnit() {
const newUnit = { unitName: this.unitSearchTerm };
this.unitOptions.push(newUnit);
this.keyResultForm.get('metric')
@@ -166,7 +166,6 @@ export class KeyResultTypeComponent implements AfterContentInit {
}
private _filter(value: string): Unit[] {
- console.log(value === '');
const filterValue = value.toString()
.toLowerCase();
return this.unitOptions.filter((option) => option.unitName.toLowerCase()
@@ -182,5 +181,16 @@ export class KeyResultTypeComponent implements AfterContentInit {
?.updateValueAndValidity();
});
}
+
+ canCreate(options: Unit[]) {
+ const rawValue = this.keyResultForm.get('metric')
+ ?.get('unit')
+ ?.getRawValue();
+ const value = rawValue?.unitName || rawValue;
+ const doesSearchAlreadyExist = this.unitOptions.some((option) => option.unitName.toLowerCase()
+ .trim() === value.toLowerCase()
+ .trim());
+ return options.length === 0 && !doesSearchAlreadyExist;
+ }
}