3 * Copyright 2016-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.
19 * Created by onvelocity on 1/18/16.
21 * This class generates the form fields used to edit the CONFD JSON model.
24 import React from 'react'
25 import ClassNames from 'classnames'
26 import changeCase from 'change-case'
27 import Property from '../../libraries/model/DescriptorModelMetaProperty'
28 import CatalogDataStore from '../../stores/CatalogDataStore'
30 import { startEditing, endEditing, onFocusPropertyFormInputElement } from './EditDescriptorUtils'
31 import '../../styles/EditDescriptorModelProperties.scss'
33 export default function Select(props) {
34 const { id, label, value, options, title, required, readOnly, onChange } = props;
35 const selectOptions = options.map((o, i) => <option key={':' + i} value={o.value}>{o.name}</option>);
36 if (!value || !required) {
37 let placeholder = props.placeholder || " ";
38 placeholder = changeCase.title(placeholder);
39 const noValueDisplayText = placeholder;
40 selectOptions.unshift(<option key={'(value-not-set)'} value="" placeholder={placeholder}>{noValueDisplayText}</option>);
42 function onSelectChange(e) {
44 onChange(e.target.value);
49 className={ClassNames({ '-value-not-set': !value, '-is-required': required })}
52 onChange={onSelectChange}
53 onFocus={onFocusPropertyFormInputElement}
55 onMouseDown={startEditing}
56 onMouseOver={startEditing}