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/uiElementNumber.tsx             | 81 ++++++++++------------
 1 file changed, 37 insertions(+), 44 deletions(-)

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

diff --git a/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementNumber.tsx b/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementNumber.tsx
index cf462052e..ac4afc1d9 100644
--- a/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementNumber.tsx
+++ b/sdnr/wt/odlux/apps/configurationApp/src/components/uiElementNumber.tsx
@@ -19,59 +19,52 @@
 import { ViewElementNumber } from "models/uiModels";
 import { Tooltip, InputAdornment } from "@material-ui/core";
 import * as React from 'react';
-import { baseProps } from "./baseProps";
+import { BaseProps } from "./baseProps";
 import { IfWhenTextInput } from "./ifWhenTextInput";
 import { checkRange } from "./verifyer";
 
-type numberInputProps = baseProps;
+type numberInputProps = BaseProps<number>;
 
 export const UiElementNumber = (props: numberInputProps) => {
 
 
-    const [error, setError] = React.useState(false);
-    const [helperText, setHelperText] = React.useState("");
-    const [isTooltipVisible, setTooltipVisibility] = React.useState(true);
+  const [error, setError] = React.useState(false);
+  const [helperText, setHelperText] = React.useState("");
+  const [isTooltipVisible, setTooltipVisibility] = React.useState(true);
 
-    const element = props.value as ViewElementNumber;
+  const element = props.value as ViewElementNumber;
 
-    const verifyValue = (data: string) => {
-
-        if (data.trim().length > 0) {
-            const num = Number(data);
-            if (!isNaN(num)) {
-                const result = checkRange(element, num);
-                if (result.length > 0) {
-                    setError(true);
-                    setHelperText(result);
-                } else {
-                    setError(false);
-                    setHelperText("");
-                }
-            } else {
-                setError(true);
-                setHelperText("Input is not a number.");
-            }
-        } else {
-            setError(false);
-            setHelperText("");
-        }
-
-        props.onChange(data);
+  const verifyValue = (data: string) => {
+    const num = Number(data);
+    if (!isNaN(num)) {
+      const result = checkRange(element, num);
+      if (result.length > 0) {
+        setError(true);
+        setHelperText(result);
+      } else {
+        setError(false);
+        setHelperText("");
+      }
+    } else {
+      setError(true);
+      setHelperText("Input is not a number.");
     }
+    props.onChange(num);
+  }
 
-    return (
-        <Tooltip title={isTooltipVisible ? element.description || '' : ''}>
-            <IfWhenTextInput element={element} toogleTooltip={(val: boolean) => setTooltipVisibility(val)}
-                spellCheck={false} autoFocus margin="dense"
-                id={element.id} label={element.label} type="text" value={props.inputValue}
-                style={{ width: 485, marginLeft: 20, marginRight: 20 }}
-                onChange={(e: any) => { verifyValue(e.target.value) }}
-                error={error}
-                readOnly={props.readOnly}
-                disabled={props.disabled}
-                helperText={helperText}
-                startAdornment={element.units != null ? <InputAdornment position="start">{element.units}</InputAdornment> : undefined}
-            />
-        </Tooltip>
-    );
+  return (
+    <Tooltip title={isTooltipVisible ? element.description || '' : ''}>
+      <IfWhenTextInput element={element} onChangeTooltipVisuability={setTooltipVisibility}
+        spellCheck={false} autoFocus margin="dense"
+        id={element.id} label={element.label} type="text" value={props.inputValue}
+        style={{ width: 485, marginLeft: 20, marginRight: 20 }}
+        onChange={(e) => { verifyValue(e.target.value) }}
+        error={error}
+        readOnly={props.readOnly}
+        disabled={props.disabled}
+        helperText={helperText}
+        startAdornment={element.units != null ? <InputAdornment position="start">{element.units}</InputAdornment> : undefined}
+      />
+    </Tooltip>
+  );
 }
\ No newline at end of file
-- 
cgit 1.2.3-korg

