import {ViewDefinition} from 'idai-components-2/configuration';

/**
 * @author Thomas Kleinke
 * @author Daniel de Oliveira
 */
export class OperationViews {


    constructor(
        private _: any
    ) {
        if (!_) _ = [];
    }


    public get() {

        return this._;
    }


    public getLabelForName(name: string) {

        const view = this.namedView(name);
        return (view) ? view.mainTypeLabel : undefined;
    }


    public getTypeForName(name: string) {

        const view = this.namedView(name);
        return (view) ? view.operationSubtype : undefined;
    }


    private namedView = (name: string) => this._.find(this.sameViewName(name));


    private sameViewName = (name: string) => (view: any) => name == view.name;


    public getViewNameForOperationSubtype(operationSubtypeName: string): string|undefined {

        const viewDefinitions: Array<ViewDefinition> = this._;
        let viewName: string|undefined = undefined;
        for (let view of viewDefinitions) {
            if (view.operationSubtype == operationSubtypeName) {
                viewName = view.name;
                break;
            }
        }

        return viewName;
    }
}
import {ViewDefinition} from 'idai-components-2/configuration';

/**
 * @author Thomas Kleinke
 * @author Daniel de Oliveira
 */
export class OperationViews {


    constructor(
        private _: any
    ) {
        if (!_) _ = [];
    }


    public get() {

        return this._;
    }


    public getLabelForName(name: any) {

        for (let view of this._) {
            if (view.name == name) return view.mainTypeLabel;
        }
        return undefined;
    }


    public getTypeForName(name: any) {

        for (let view of this._) {
            if (view.name == name) return view.operationSubtype;
        }
        return undefined;
    }


    public getViewNameForOperationSubtype(operationSubtypeName: string): string|undefined {

        const viewDefinitions: Array<ViewDefinition> = this._;
        let viewName: string|undefined = undefined;
        for (let view of viewDefinitions) {
            if (view.operationSubtype == operationSubtypeName) {
                viewName = view.name;
                break;
            }
        }

        return viewName;
    }
}
--- 
+++ 
@@ -20,22 +20,24 @@
     }
 
 
-    public getLabelForName(name: any) {
+    public getLabelForName(name: string) {
 
-        for (let view of this._) {
-            if (view.name == name) return view.mainTypeLabel;
-        }
-        return undefined;
+        const view = this.namedView(name);
+        return (view) ? view.mainTypeLabel : undefined;
     }
 
 
-    public getTypeForName(name: any) {
+    public getTypeForName(name: string) {
 
-        for (let view of this._) {
-            if (view.name == name) return view.operationSubtype;
-        }
-        return undefined;
+        const view = this.namedView(name);
+        return (view) ? view.operationSubtype : undefined;
     }
+
+
+    private namedView = (name: string) => this._.find(this.sameViewName(name));
+
+
+    private sameViewName = (name: string) => (view: any) => name == view.name;
 
 
     public getViewNameForOperationSubtype(operationSubtypeName: string): string|undefined {
Use fp and find method
