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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
19 import React from 'react';
20 import FormControl from '@mui/material/FormControl';
21 import InputLabel from '@mui/material/InputLabel';
22 import Chip from '@mui/material/Chip';
23 import Dialog from '@mui/material/Dialog';
24 import DialogTitle from '@mui/material/DialogTitle';
25 import DialogContent from '@mui/material/DialogContent';
26 import DialogActions from '@mui/material/DialogActions';
27 import Button from '@mui/material/Button';
29 import makeStyles from '@mui/styles/makeStyles';
30 import AddIcon from '@mui/icons-material/Add';
32 import { Theme } from '@mui/material/styles';
33 import { ViewElement } from '../models/uiModels';
35 import { BaseProps } from './baseProps';
37 const useStyles = makeStyles((theme: Theme) => {
38 const light = theme.palette.mode === 'light';
39 const bottomLineColor = light ? 'rgba(0, 0, 0, 0.42)' : 'rgba(255, 255, 255, 0.7)';
44 justifyContent: 'left',
45 verticalAlign: 'bottom',
50 paddingTop: theme.spacing(0.5),
51 marginTop: theme.spacing(1),
54 margin: theme.spacing(0.5),
58 borderBottom: `2px solid ${theme.palette.primary.main}`,
61 // Doing the other way around crash on IE 11 "''" https://github.com/cssinjs/jss/issues/242
65 transform: 'scaleX(0)',
66 transition: theme.transitions.create('transform', {
67 duration: theme.transitions.duration.shorter,
68 easing: theme.transitions.easing.easeOut,
70 pointerEvents: 'none', // Transparent to the hover style.
72 '&.Mui-focused:after': {
73 transform: 'scaleX(1)',
75 '&.Mui-error:after': {
76 borderBottomColor: theme.palette.error.main,
77 transform: 'scaleX(1)', // error is always underlined in red
80 borderBottom: `1px solid ${bottomLineColor}`,
83 // Doing the other way around crash on IE 11 "''" https://github.com/cssinjs/jss/issues/242
87 transition: theme.transitions.create('border-bottom-color', {
88 duration: theme.transitions.duration.shorter,
90 pointerEvents: 'none', // Transparent to the hover style.
92 '&:hover:not($disabled):before': {
93 borderBottom: `2px solid ${theme.palette.text.primary}`,
94 // Reset on touch devices, it doesn't add specificity
95 // eslint-disable-next-line @typescript-eslint/naming-convention
96 '@media (hover: none)': {
97 borderBottom: `1px solid ${bottomLineColor}`,
100 '&.Mui-disabled:before': {
101 borderBottomStyle: 'dotted',
107 type LeafListProps = BaseProps<any []> & {
108 getEditorForViewElement: (uiElement: ViewElement) => (null | React.ComponentType<BaseProps<any>>);
111 export const UiElementLeafList = (props: LeafListProps) => {
112 const { value: element, inputValue, onChange } = props;
114 const classes = useStyles();
116 const [open, setOpen] = React.useState(false);
117 const [editorValue, setEditorValue] = React.useState('');
118 const [editorValueIndex, setEditorValueIndex] = React.useState(-1);
120 const handleClose = () => {
124 const onApplyButton = () => {
125 if (editorValue != null && editorValue != '' && editorValueIndex < 0) {
130 } else if (editorValue != null && editorValue != '') {
132 ...inputValue.slice(0, editorValueIndex),
134 ...inputValue.slice(editorValueIndex + 1),
140 const onDelete = (index : number) => {
141 const newValue : any[] = [
142 ...inputValue.slice(0, index),
143 ...inputValue.slice(index + 1),
148 const ValueEditor = props.getEditorForViewElement(props.value);
152 <FormControl variant="standard" style={{ width: 485, marginLeft: 20, marginRight: 20 }}>
153 <InputLabel htmlFor={`list-${element.id}`} shrink={!props.readOnly || !!(inputValue && inputValue.length)} >{element.label}</InputLabel>
154 <ul className={`${classes.root} ${classes.underline}`} id={`list-${element.id}`}>
155 { !props.readOnly ? <li>
159 className={classes.chip}
165 setEditorValueIndex(-1);
170 { inputValue.map((val, ind) => (
173 className={classes.chip}
177 onDelete={ !props.readOnly ? () => { onDelete(ind); } : undefined }
178 onClick={ !props.readOnly ? () => {
181 setEditorValueIndex(ind);
189 {/* <FormHelperText>{ "Value is mandetory"}</FormHelperText> */}
191 <Dialog open={open} onClose={handleClose} aria-labelledby="form-dialog-title">
192 <DialogTitle id="form-dialog-title">{editorValueIndex < 0 ? 'Add new value' : 'Edit value' } </DialogTitle>
194 { ValueEditor && <ValueEditor
195 inputValue={ editorValue }
196 value={{ ...element, isList: false }}
198 readOnly={props.readOnly}
199 onChange={ setEditorValue }
203 <Button color="inherit" onClick={ handleClose }> Cancel </Button>
204 <Button disabled={editorValue == null || editorValue === '' } onClick={ onApplyButton } color="secondary"> {editorValueIndex < 0 ? 'Add' : 'Apply'} </Button>