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 * as React from "react"
20 import { FormControl, InputLabel, Paper, Chip, FormHelperText, Dialog, DialogTitle, DialogContentText, DialogActions, Button, DialogContent } from "@mui/material";
21 import makeStyles from '@mui/styles/makeStyles';
22 import AddIcon from '@mui/icons-material/Add';
24 import { Theme } from '@mui/material/styles';
25 import { ViewElement } from "../models/uiModels";
27 import { BaseProps } from "./baseProps";
29 type LeafListProps = BaseProps<any []> & {
30 getEditorForViewElement: (uiElement: ViewElement) => (null | React.ComponentType<BaseProps<any>>)
33 const useStyles = makeStyles((theme: Theme) => {
34 const light = theme.palette.mode === 'light';
35 const bottomLineColor = light ? 'rgba(0, 0, 0, 0.42)' : 'rgba(255, 255, 255, 0.7)';
40 justifyContent: 'left',
41 verticalAlign: 'bottom',
46 paddingTop: theme.spacing(0.5),
47 marginTop: theme.spacing(1),
50 margin: theme.spacing(0.5),
54 borderBottom: `2px solid ${theme.palette.primary.main}`,
57 // Doing the other way around crash on IE 11 "''" https://github.com/cssinjs/jss/issues/242
61 transform: 'scaleX(0)',
62 transition: theme.transitions.create('transform', {
63 duration: theme.transitions.duration.shorter,
64 easing: theme.transitions.easing.easeOut,
66 pointerEvents: 'none', // Transparent to the hover style.
68 '&.Mui-focused:after': {
69 transform: 'scaleX(1)',
71 '&.Mui-error:after': {
72 borderBottomColor: theme.palette.error.main,
73 transform: 'scaleX(1)', // error is always underlined in red
76 borderBottom: `1px solid ${bottomLineColor}`,
79 // Doing the other way around crash on IE 11 "''" https://github.com/cssinjs/jss/issues/242
83 transition: theme.transitions.create('border-bottom-color', {
84 duration: theme.transitions.duration.shorter,
86 pointerEvents: 'none', // Transparent to the hover style.
88 '&:hover:not($disabled):before': {
89 borderBottom: `2px solid ${theme.palette.text.primary}`,
90 // Reset on touch devices, it doesn't add specificity
91 '@media (hover: none)': {
92 borderBottom: `1px solid ${bottomLineColor}`,
95 '&.Mui-disabled:before': {
96 borderBottomStyle: 'dotted',
102 export const UiElementLeafList = (props: LeafListProps) => {
103 const { value: element, inputValue, onChange } = props;
105 const classes = useStyles();
107 const [open, setOpen] = React.useState(false);
108 const [editorValue, setEditorValue] = React.useState("");
109 const [editorValueIndex, setEditorValueIndex] = React.useState(-1);
112 const handleClickOpen = () => {
116 const handleClose = () => {
120 const onApplyButton = () => {
121 if (editorValue != null && editorValue != "" && editorValueIndex < 0) {
126 } else if (editorValue != null && editorValue != "") {
128 ...inputValue.slice(0, editorValueIndex),
130 ...inputValue.slice(editorValueIndex+1),
136 const onDelete = (index : number) => {
137 const newValue : any[] = [
138 ...inputValue.slice(0, index),
139 ...inputValue.slice(index+1),
144 const ValueEditor = props.getEditorForViewElement(props.value);
148 <FormControl variant="standard" style={{ width: 485, marginLeft: 20, marginRight: 20 }}>
149 <InputLabel htmlFor={`list-${element.id}`} shrink={!props.readOnly || !!(inputValue && inputValue.length)} >{element.label}</InputLabel>
150 <ul className={`${classes.root} ${classes.underline}`} id={`list-${element.id}`}>
151 { !props.readOnly ? <li>
155 className={classes.chip}
161 setEditorValueIndex(-1);
166 { inputValue.map((val, ind) => (
169 className={classes.chip}
173 onDelete={ !props.readOnly ? () => { onDelete(ind); } : undefined }
174 onClick={ !props.readOnly ? () => {
177 setEditorValueIndex(ind);
185 {/* <FormHelperText>{ "Value is mandetory"}</FormHelperText> */}
187 <Dialog open={open} onClose={handleClose} aria-labelledby="form-dialog-title">
188 <DialogTitle id="form-dialog-title">{editorValueIndex < 0 ? "Add new value" : "Edit value" } </DialogTitle>
190 { ValueEditor && <ValueEditor
191 inputValue={ editorValue }
192 value={{ ...element, isList: false}}
194 readOnly={props.readOnly}
195 onChange={ setEditorValue }
199 <Button color="inherit" onClick={ handleClose }> Cancel </Button>
200 <Button disabled={editorValue == null || editorValue === "" } onClick={ onApplyButton } color="secondary"> {editorValueIndex < 0 ? "Add" : "Apply"} </Button>