From 4bd84bebdaa0c2d82050fbedd1fa8260eb62146d Mon Sep 17 00:00:00 2001
From: Aijana Schumann <aijana.schumann@highstreet-technologies.com>
Date: Thu, 27 Aug 2020 09:01:53 +0200
Subject: Add link calculation app

Add link calculation app to odlux

Issue-ID: CCSDK-2562
Signed-off-by: Aijana Schumann <aijana.schumann@highstreet-technologies.com>
Change-Id: Ifc0a5b2a8bb974dfd85d70a9f05990b1f11925a3
Signed-off-by: Aijana Schumann <aijana.schumann@highstreet-technologies.com>
---
 .../src/components/uiElementUnion.tsx              | 100 ++++++++++-----------
 1 file changed, 49 insertions(+), 51 deletions(-)

(limited to 'sdnr/wt/odlux/apps/configurationApp/src/components/uiElementUnion.tsx')

diff --git a/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementUnion.tsx b/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementUnion.tsx
index 25378d767..669e39360 100644
--- a/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementUnion.tsx
+++ b/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementUnion.tsx
@@ -17,77 +17,75 @@
  */
 
 import * as React from 'react'
-import { baseProps } from './baseProps';
+import { BaseProps } from './baseProps';
 import { Tooltip } from '@material-ui/core';
 import { IfWhenTextInput } from './ifWhenTextInput';
 import { ViewElementUnion, isViewElementString, isViewElementNumber, isViewElementObject, ViewElementNumber } from '../models/uiModels';
 import { checkRange, checkPattern } from './verifyer';
 
-type UiElementUnionProps = { isKey: boolean } & baseProps;
+type UiElementUnionProps = { isKey: boolean } & BaseProps;
 
 export const UIElementUnion = (props: UiElementUnionProps) => {
 
-    const [isError, setError] = React.useState(false);
-    const [helperText, setHelperText] = React.useState("");
-    const [isTooltipVisible, setTooltipVisibility] = React.useState(true);
+  const [isError, setError] = React.useState(false);
+  const [helperText, setHelperText] = React.useState("");
+  const [isTooltipVisible, setTooltipVisibility] = React.useState(true);
 
-    const element = props.value as ViewElementUnion;
+  const element = props.value as ViewElementUnion;
 
-    const verifyValues = (data: string) => {
+  const verifyValues = (data: string) => {
 
-        let foundObjectElements = 0;
-        let errorMessage = "";
-        let isPatternCorrect = null;
+    let foundObjectElements = 0;
+    let errorMessage = "";
+    let isPatternCorrect = null;
 
-        for (let i = 0; i < element.elements.length; i++) {
-            const unionElement = element.elements[i];
+    for (let i = 0; i < element.elements.length; i++) {
+      const unionElement = element.elements[i];
 
-            if (isViewElementNumber(unionElement)) {
+      if (isViewElementNumber(unionElement)) {
 
-                errorMessage = checkRange(unionElement, Number(data));
+        errorMessage = checkRange(unionElement, Number(data));
 
-            } else if (isViewElementString(unionElement)) {
-                errorMessage += checkRange(unionElement, data.length);
-                isPatternCorrect = checkPattern(unionElement.pattern, data).isValid;
+      } else if (isViewElementString(unionElement)) {
+        errorMessage += checkRange(unionElement, data.length);
+        isPatternCorrect = checkPattern(unionElement.pattern, data).isValid;
 
 
-            } else if (isViewElementObject(unionElement)) {
-                foundObjectElements++;
-            }
+      } else if (isViewElementObject(unionElement)) {
+        foundObjectElements++;
+      }
 
-            if (isPatternCorrect || errorMessage.length === 0) {
-                break;
-            }
-        }
+      if (isPatternCorrect || errorMessage.length === 0) {
+        break;
+      }
+    }
 
-        if (errorMessage.length > 0 || isPatternCorrect !== null && !isPatternCorrect) {
-            setError(true);
-            setHelperText("Input is wrong.");
-        } else {
-            setError(false);
-            setHelperText("");
-        }
+    if (errorMessage.length > 0 || isPatternCorrect !== null && !isPatternCorrect) {
+      setError(true);
+      setHelperText("Input is wrong.");
+    } else {
+      setError(false);
+      setHelperText("");
+    }
 
-        if (foundObjectElements > 0 && foundObjectElements != element.elements.length) {
-            throw new Error(`The union element ${element.id} can't be changed.`);
+    if (foundObjectElements > 0 && foundObjectElements != element.elements.length) {
+      throw new Error(`The union element ${element.id} can't be changed.`);
 
-        } else {
-            props.onChange(data);
-        }
-    };
+    } else {
+      props.onChange(data);
+    }
+  };
 
-
-
-    return <Tooltip title={isTooltipVisible ? element.description || '' : ''}>
-        <IfWhenTextInput element={element} toogleTooltip={(val: boolean) => setTooltipVisibility(val)}
-            spellCheck={false} autoFocus margin="dense"
-            id={element.id} label={props.isKey ? "🔑 " + element.label : element.label} type="text" value={props.inputValue}
-            onChange={(e: any) => { verifyValues(e.target.value) }}
-            error={isError}
-            style={{ width: 485, marginLeft: 20, marginRight: 20 }}
-            readOnly={props.readOnly}
-            disabled={props.disabled}
-            helperText={helperText}
-        />
-    </Tooltip>;
+  return <Tooltip title={isTooltipVisible ? element.description || '' : ''}>
+    <IfWhenTextInput element={element} onChangeTooltipVisuability={setTooltipVisibility}
+      spellCheck={false} autoFocus margin="dense"
+      id={element.id} label={props.isKey ? "🔑 " + element.label : element.label} type="text" value={props.inputValue}
+      onChange={(e: any) => { verifyValues(e.target.value) }}
+      error={isError}
+      style={{ width: 485, marginLeft: 20, marginRight: 20 }}
+      readOnly={props.readOnly}
+      disabled={props.disabled}
+      helperText={helperText}
+    />
+  </Tooltip>;
 }
\ No newline at end of file
-- 
cgit 1.2.3-korg

