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 "@material-ui/core";
21 import { makeStyles } from '@material-ui/core/styles';
22 import AddIcon from '@material-ui/icons/Add';
24 import { ViewElement } from "../models/uiModels";
26 import { BaseProps } from "./baseProps";
28 type LeafListProps = BaseProps<any []> & {
29 getEditorForViewElement: (uiElement: ViewElement) => (null | React.ComponentType<BaseProps<any>>)
32 const useStyles = makeStyles((theme) => {
33 const light = theme.palette.type === 'light';
34 const bottomLineColor = light ? 'rgba(0, 0, 0, 0.42)' : 'rgba(255, 255, 255, 0.7)';
39 justifyContent: 'left',
40 verticalAlign: 'bottom',
45 paddingTop: theme.spacing(0.5),
46 marginTop: theme.spacing(1),
49 margin: theme.spacing(0.5),
53 borderBottom: `2px solid ${theme.palette.primary.main}`,
56 // Doing the other way around crash on IE 11 "''" https://github.com/cssinjs/jss/issues/242
60 transform: 'scaleX(0)',
61 transition: theme.transitions.create('transform', {
62 duration: theme.transitions.duration.shorter,
63 easing: theme.transitions.easing.easeOut,
65 pointerEvents: 'none', // Transparent to the hover style.
68 transform: 'scaleX(1)',
71 borderBottomColor: theme.palette.error.main,
72 transform: 'scaleX(1)', // error is always underlined in red
75 borderBottom: `1px solid ${bottomLineColor}`,
78 // Doing the other way around crash on IE 11 "''" https://github.com/cssinjs/jss/issues/242
82 transition: theme.transitions.create('border-bottom-color', {
83 duration: theme.transitions.duration.shorter,
85 pointerEvents: 'none', // Transparent to the hover style.
87 '&:hover:not($disabled):before': {
88 borderBottom: `2px solid ${theme.palette.text.primary}`,
89 // Reset on touch devices, it doesn't add specificity
90 '@media (hover: none)': {
91 borderBottom: `1px solid ${bottomLineColor}`,
94 '&$disabled:before': {
95 borderBottomStyle: 'dotted',
101 export const UiElementLeafList = (props: LeafListProps) => {
102 const { value: element, inputValue, onChange } = props;
104 const classes = useStyles();
106 const [open, setOpen] = React.useState(false);
107 const [editorValue, setEditorValue] = React.useState("");
108 const [editorValueIndex, setEditorValueIndex] = React.useState(-1);
111 const handleClickOpen = () => {
115 const handleClose = () => {
119 const onApplyButton = () => {
120 if (editorValue != null && editorValue != "" && editorValueIndex < 0) {
125 } else if (editorValue != null && editorValue != "") {
127 ...inputValue.slice(0, editorValueIndex),
129 ...inputValue.slice(editorValueIndex+1),
135 const onDelete = (index : number) => {
136 const newValue : any[] = [
137 ...inputValue.slice(0, index),
138 ...inputValue.slice(index+1),
143 const ValueEditor = props.getEditorForViewElement(props.value);
147 <FormControl style={{ width: 485, marginLeft: 20, marginRight: 20 }}>
148 <InputLabel htmlFor={`list-${element.id}`} shrink={!props.readOnly || !!(inputValue && inputValue.length)} >{element.label}</InputLabel>
149 <ul className={`${classes.root} ${classes.underline}`} id={`list-${element.id}`}>
150 { !props.readOnly ? <li>
154 className={classes.chip}
160 setEditorValueIndex(-1);
165 { inputValue.map((val, ind) => (
168 className={classes.chip}
172 onDelete={ !props.readOnly ? () => { onDelete(ind); } : undefined }
173 onClick={ !props.readOnly ? () => {
176 setEditorValueIndex(ind);
184 {/* <FormHelperText>{ "Value is mandetory"}</FormHelperText> */}
186 <Dialog open={open} onClose={handleClose} aria-labelledby="form-dialog-title">
187 <DialogTitle id="form-dialog-title">{editorValueIndex < 0 ? "Add new value" : "Edit value" } </DialogTitle>
189 { ValueEditor && <ValueEditor
190 inputValue={ editorValue }
191 value={{ ...element, isList: false}}
193 readOnly={props.readOnly}
194 onChange={ setEditorValue }
198 <Button onClick={ handleClose }> Cancel </Button>
199 <Button disabled={editorValue == null || editorValue === "" } onClick={ onApplyButton } color="secondary"> {editorValueIndex < 0 ? "Add" : "Apply"} </Button>