Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / apps / configurationApp / src / components / uiElementSelection.tsx
1 /**
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt odlux
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 import React from 'react';
20 import { BaseProps } from './baseProps';
21 import { ViewElementSelection } from '../models/uiModels';
22 import { FormControl, InputLabel, Select, FormHelperText, MenuItem, Tooltip } from '@mui/material';
23
24 type selectionProps = BaseProps;
25
26 export const UiElementSelection = (props: selectionProps) => {
27
28   const element = props.value as ViewElementSelection;
29
30   let error = '';
31   const value = String(props.inputValue);
32   if (element.mandatory && Boolean(!value)) {
33     error = 'Error';
34   }
35
36   return (props.readOnly || props.inputValue != null
37     ? (<FormControl variant="standard" style={{ width: 485, marginLeft: 20, marginRight: 20 }}>
38          <InputLabel htmlFor={`select-${element.id}`} >{element.label}</InputLabel>
39             <Select variant="standard"
40                 required={!!element.mandatory}
41                 error={!!error}
42                 onChange={(e) => { props.onChange(e.target.value as string); }}
43                 readOnly={props.readOnly}
44                 disabled={props.disabled}
45                 value={value.toString()}
46                 aria-label={element.label + '-selection'}
47                 inputProps={{
48                   name: element.id,
49                   id: `select-${element.id}`,
50                 }}
51             >
52                 {element.options.map(option => (
53                     <MenuItem
54                         key={option.key}
55                         value={option.key}
56                         aria-label={option.key}>
57                         <Tooltip disableInteractive title={option.description || ''}>
58                             <div style={{ width: '100%' }}>
59                                 {option.key}
60                             </div>
61                         </Tooltip>
62                     </MenuItem>
63                 ))}
64             </Select>
65             <FormHelperText>{error}</FormHelperText>
66         </FormControl>)
67     : null
68   );
69 };