Fix problem where the connection-point UI was not updating list correctly when button...
[osm/UI.git] / skyquake / plugins / composer / src / src / components / EditDescriptorModelProperties.js
index 41e87b3..01cd5b2 100644 (file)
@@ -25,6 +25,10 @@ import _includes from 'lodash/includes'
 import _isArray from 'lodash/isArray'
 import _cloneDeep from 'lodash/cloneDeep'
 import _debounce from 'lodash/debounce';
+import _uniqueId from 'lodash/uniqueId';
+import _set from 'lodash/set';
+import _get from 'lodash/get';
+import _has from 'lodash/has';
 import utils from '../libraries/utils'
 import React from 'react'
 import ClassNames from 'classnames'
@@ -48,6 +52,16 @@ import imgRemove from '../../../node_modules/open-iconic/svg/trash.svg'
 
 import '../styles/EditDescriptorModelProperties.scss'
 
+const EMPTY_LEAF_PRESENT = '--empty-leaf-set--';
+
+function resolveReactKey(value) {
+       const keyPath =  ['uiState', 'fieldKey'];
+       if (!_has(value, keyPath)) {
+               _set(value, keyPath, _uniqueId());
+       }
+       return _get(value, keyPath);
+}
+
 function getDescriptorMetaBasicForType(type) {
        const basicPropertiesFilter = d => _includes(DESCRIPTOR_MODEL_FIELDS[type], d.name);
        return DescriptorModelMetaFactory.getModelMetaForType(type, basicPropertiesFilter) || {properties: []};
@@ -292,7 +306,37 @@ export default function EditDescriptorModelProperties(props) {
                                        key={fieldKey} 
                                        id={fieldKey} 
                                        className={ClassNames({'-value-not-set': !isValueSet})} 
-                                       defaultValue={val && val.toUpperCase()} title={pathToProperty} 
+                                       defaultValue={val && val.toUpperCase()} 
+                                       title={pathToProperty} 
+                                       onChange={onSelectChange} 
+                                       onFocus={onFocus} 
+                                       onBlur={endEditing} 
+                                       onMouseDown={startEditing} 
+                                       onMouseOver={startEditing} 
+                                       readOnly={!isEditable}>
+                                               {options}
+                               </select>
+                       );
+               }
+               
+               if (Property.isLeafEmpty(property)) {
+                       // A null value indicates the leaf exists (as opposed to undefined).
+                       // We stick in a string when the user actually sets it to simplify things
+                       // but the correct thing happens when we serialize to user data
+                       let isEmptyLeafPresent = (value === EMPTY_LEAF_PRESENT || value === null); 
+                       let present = isEmptyLeafPresent ? EMPTY_LEAF_PRESENT : "";
+                       const options = [
+                               <option key={'true'} value={EMPTY_LEAF_PRESENT}>Enabled</option>,
+                               <option key={'false'} value="">Not Enabled</option>
+                       ]
+
+                       return (
+                               <select 
+                                       key={fieldKey} 
+                                       id={fieldKey} 
+                                       className={ClassNames({'-value-not-set': !isEmptyLeafPresent})} 
+                                       defaultValue={present} 
+                                       title={pathToProperty} 
                                        onChange={onSelectChange} 
                                        onFocus={onFocus} 
                                        onBlur={endEditing} 
@@ -624,7 +668,7 @@ export default function EditDescriptorModelProperties(props) {
 
                        if (isArray) {
                                valuePath.push(index);
-                               fieldId += index;
+                               fieldId = resolveReactKey(value);
                        }
 
                        if (isMetaField) {