3 * Copyright 2017 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 import React from 'react';
19 import changeCase from 'change-case'
20 import Button from '../Button'
21 import ClassNames from 'classnames'
22 import CatalogItemsActions from '../../actions/CatalogItemsActions'
23 import DescriptorModelMetaFactory from '../../libraries/model/DescriptorModelMetaFactory'
24 import Property from '../../libraries/model/DescriptorModelMetaProperty'
25 import utils from '../../libraries/utils'
27 import PropertyPanel from './PropertyPanel'
28 import PanelHeader from './PanelHeader'
29 import RemoveItemButton from './RemoveItemButton'
31 import '../../styles/EditDescriptorModelProperties.scss'
32 import imgAdd from '../../../../node_modules/open-iconic/svg/plus.svg'
33 import imgRemove from '../../../../node_modules/open-iconic/svg/trash.svg'
35 function ListItemHeader(props) {
37 property, showOpened, onChangeOpenState,
38 info, summary, readOnly, removeItemHandler } = props;
39 const className = ClassNames(property.name + '-property');
40 const title = changeCase.title(property.name);
41 const name = showOpened ? title : summary ? '' : title;
42 const newInfo = showOpened ? info : summary || info;
44 <div className={className}>
45 <PanelHeader name={name} info={newInfo}
46 showOpened={showOpened} onChangeOpenState={onChangeOpenState}
47 action={readOnly ? null : { invoke: removeItemHandler, icon: imgRemove, title: "Remove" }} />
51 function ListItem(props) {
53 property, info, summary, readOnly,
54 showOpened, onChangeOpenState, children, removeItemHandler } = props;
56 <div className={'property-content'}>
57 <ListItemHeader property={property} info={info} summary={summary}
58 showOpened={showOpened} onChangeOpenState={onChangeOpenState}
59 readOnly={readOnly} removeItemHandler={removeItemHandler} />
60 {showOpened ? children : null}
66 class List extends React.Component {
72 property, value, readOnly, showHelp, tip, showOpened,
73 onChangeOpenState, children, addItemHandler, id } = this.props;
74 const title = changeCase.titleCase(property.name);
75 const info = (children ? children.length : '0') + ' items';
76 const description = property.description;
77 const nodeType = property.type;
78 const tipText = tip && !readOnly ?
79 <span key="tip" className={nodeType + '-tip tip'}>{tip}</span>
82 let classNames = ['-is-array'];
83 if (property.type === 'leaf_list') {
84 classNames.push('-is-leaf');
88 <div id={id} className={ClassNames(classNames)}>
89 <PropertyPanel title={title} info={info} helpText={showHelp ? description : null}
90 showOpened={showOpened} onChangeOpenState={onChangeOpenState}
91 action={readOnly ? null : { invoke: addItemHandler, icon: imgAdd, title: "Add" }}>
92 {tipText ? [tipText].concat(children) : children}