RIFT-15649: Boot priority fix
[osm/UI.git] / skyquake / plugins / composer / src / src / components / EditDescriptorModelProperties.js
index 20c84da..b3d8afb 100644 (file)
@@ -39,6 +39,7 @@ import SelectionManager from '../libraries/SelectionManager'
 import DeletionManager from '../libraries/DeletionManager'
 import DescriptorModelIconFactory from '../libraries/model/IconFactory'
 import getEventPath from '../libraries/getEventPath'
+import CatalogDataStore from '../stores/CatalogDataStore'
 
 import imgAdd from '../../../node_modules/open-iconic/svg/plus.svg'
 import imgRemove from '../../../node_modules/open-iconic/svg/trash.svg'
@@ -46,12 +47,12 @@ import imgRemove from '../../../node_modules/open-iconic/svg/trash.svg'
 import '../styles/EditDescriptorModelProperties.scss'
 
 function getDescriptorMetaBasicForType(type) {
-       const basicPropertiesFilter = d => _.contains(DESCRIPTOR_MODEL_FIELDS[type], d.name);
+       const basicPropertiesFilter = d => _.includes(DESCRIPTOR_MODEL_FIELDS[type], d.name);
        return DescriptorModelMetaFactory.getModelMetaForType(type, basicPropertiesFilter) || {properties: []};
 }
 
 function getDescriptorMetaAdvancedForType(type) {
-       const advPropertiesFilter = d => !_.contains(DESCRIPTOR_MODEL_FIELDS[type], d.name);
+       const advPropertiesFilter = d => !_.includes(DESCRIPTOR_MODEL_FIELDS[type], d.name);
        return DescriptorModelMetaFactory.getModelMetaForType(type, advPropertiesFilter) || {properties: []};
 }
 
@@ -173,16 +174,20 @@ export default function EditDescriptorModelProperties(props) {
        }
 
        function buildField(container, property, path, value, fieldKey) {
+               let cds = CatalogDataStore;
+               let catalogs = cds.getTransientCatalogs();
 
                const name = path.join('.');
                const isEditable = true;
                const isGuid = Property.isGuid(property);
+               const isBoolean = Property.isBoolean(property);
                const onChange = onFormFieldValueChanged.bind(container);
                const isEnumeration = Property.isEnumeration(property);
+               const isLeafRef = Property.isLeafRef(property);
                const onFocus = onFocusPropertyFormInputElement.bind(container, property, path, value);
                const placeholder = changeCase.title(property.name);
                const className = ClassNames(property.name + '-input', {'-is-guid': isGuid});
-               const fieldValue = value ? (value.constructor.name != "Object") ? value : '' : undefined;
+               const fieldValue = value ? (value.constructor.name != "Object") ? value : '' : (isNaN(value) ? undefined : value);
                if (isEnumeration) {
                        const enumeration = Property.getEnumeration(property, value);
                        const options = enumeration.map((d, i) => {
@@ -200,6 +205,51 @@ export default function EditDescriptorModelProperties(props) {
                        return <select key={fieldKey.toString()} id={fieldKey.toString()} className={ClassNames({'-value-not-set': !isValueSet})} name={name} value={value} title={name} onChange={onChange} onFocus={onFocus} onBlur={endEditing} onMouseDown={startEditing} onMouseOver={startEditing} readOnly={!isEditable}>{options}</select>;
                }
 
+               if (isLeafRef) {
+                       let fullFieldKey = _.isArray(fieldKey) ? fieldKey.join(':') : fieldKey;
+                       let containerRef = container;
+                       while (containerRef.parent) {
+                               fullFieldKey = containerRef.parent.key + ':' + fullFieldKey;
+                               containerRef = containerRef.parent;
+                       }
+                       const leafRefPathValues = Property.getLeafRef(property, path, value, fullFieldKey, catalogs, container);
+
+                       const options = leafRefPathValues && leafRefPathValues.map((d, i) => {
+                               return <option key={fieldKey.toString() + ':' + i} value={d.value}>{d.value}</option>;
+                       });
+                       const isValueSet = leafRefPathValues.filter(d => d.isSelected).length > 0;
+                       if (!isValueSet || property.cardinality === '0..1') {
+                               const noValueDisplayText = changeCase.title(property.name);
+                               options.unshift(<option key={'(value-not-in-leafref)' + fieldKey.toString()} value="" placeholder={placeholder}>{noValueDisplayText}</option>);
+                       }
+                       return <select key={fieldKey.toString()} id={fieldKey.toString()} className={ClassNames({'-value-not-set': !isValueSet})} name={name} value={value} title={name} onChange={onChange} onFocus={onFocus} onBlur={endEditing} onMouseDown={startEditing} onMouseOver={startEditing} readOnly={!isEditable}>{options}</select>;
+               }
+
+               if (isBoolean) {
+                       let fullFieldKey = _.isArray(fieldKey) ? fieldKey.join(':') : fieldKey;
+                       let containerRef = container;
+                       while (containerRef.parent) {
+                               fullFieldKey = containerRef.parent.key + ':' + fullFieldKey;
+                               containerRef = containerRef.parent;
+                       }
+
+                       const options = [
+                               <option key={fieldKey.toString() + '-true'} value="TRUE">TRUE</option>,
+                               <option key={fieldKey.toString() + '-false'} value="FALSE">FALSE</option>
+                       ]
+
+                       // if (!isValueSet) {
+                               const noValueDisplayText = changeCase.title(property.name);
+                               options.unshift(<option key={'(value-not-in-leafref)' + fieldKey.toString()} value="" placeholder={placeholder}></option>);
+                       // }
+                       let val = value;
+                       if(typeof(val) == 'number') {
+                               val = value ? "TRUE" : "FALSE"
+                       }
+                       const isValueSet = (val != '' && val)
+                       return <select key={fieldKey.toString()} id={fieldKey.toString()} className={ClassNames({'-value-not-set': !isValueSet})} name={name} value={val && val.toUpperCase()} title={name} onChange={onChange} onFocus={onFocus} onBlur={endEditing} onMouseDown={startEditing} onMouseOver={startEditing} readOnly={!isEditable}>{options}</select>;
+               }
+
                if (property['preserve-line-breaks']) {
                        return <textarea key={fieldKey.toString()} cols="5" id={fieldKey.toString()} name={name} value={value} placeholder={placeholder} onChange={onChange} onFocus={onFocus} onBlur={endEditing} onMouseDown={startEditing} onMouseOver={startEditing} onMouseOut={endEditing} onMouseLeave={endEditing} readOnly={!isEditable} />;
                }
@@ -287,16 +337,16 @@ export default function EditDescriptorModelProperties(props) {
                                }
                                utils.assignPathValue(stateObject, [selected].join('.'), _.cloneDeep(choiceObject));
 
-                               if(this.model.uiState.choice.hasOwnProperty(name)) {
-                                       delete this.model[selected];
-                                       utils.removePathValue(this.model, [name, selected].join('.'), isTopCase);
-                               } else {
-                                       // remove the current choice value from the model
-                               utils.removePathValue(this.model, [name, selected].join('.'), isTopCase);
+                               if(selected) {
+                                       if(this.model.uiState.choice.hasOwnProperty(name)) {
+                                               delete this.model[selected];
+                                               utils.removePathValue(this.model, [name, selected].join('.'), isTopCase);
+                                       } else {
+                                               // remove the current choice value from the model
+                                               utils.removePathValue(this.model, [name, selected].join('.'), isTopCase);
+                                       }
                                }
 
-
-
                                // get any state for the new selected choice
                                const newChoiceObject = utils.resolvePath(stateObject, [value].join('.')) || {};
 
@@ -321,7 +371,8 @@ export default function EditDescriptorModelProperties(props) {
 
                const cases = property.properties.map(d => {
                        if (d.type === 'case') {
-                               caseByNameMap[d.name] = d.properties[0];
+                               //Previous it was assumed that a case choice would have only one property. Now we pass on either the only item or the
+                               caseByNameMap[d.name] = d.properties && (d.properties.length == 1 ? d.properties[0] : d.properties);
                                return {
                                        optionName: d.name,
                                        optionTitle: d.description,
@@ -333,7 +384,7 @@ export default function EditDescriptorModelProperties(props) {
                        return {optionName: d.name};
                });
 
-               const options = [{optionName: ''}].concat(cases).map((d, i) => {
+               const options = [{optionName: '', optionValue: false}].concat(cases).map((d, i) => {
                        return (
                                <option key={i} value={d.optionValue} title={d.optionTitle}>
                                        {d.optionName}
@@ -353,7 +404,7 @@ export default function EditDescriptorModelProperties(props) {
                        if(fieldProperties) {
                                //Check each case statement in model and see if it is present in container model.
                                cases.map(function(c){
-                                       if(fieldProperties.hasOwnProperty(c.optionName)) {
+                                       if(fieldProperties.hasOwnProperty(c.optionValue.split('.')[1])) {
                                                utils.assignPathValue(container.model, ['uiState.choice', selectName, 'selected'].join('.'), c.optionValue);
                                        }
                                });
@@ -374,7 +425,9 @@ export default function EditDescriptorModelProperties(props) {
                const hasProperties = _.isArray(valueProperty.properties) && valueProperty.properties.length;
                const isMissingDescriptorMeta = !hasProperties && !Property.isLeaf(valueProperty);
                //Some magic that prevents errors for arising
-               const valueResponse = valueProperty.properties.length ? valueProperty.properties.map((d, i) => {
+               const valueResponse = valueProperty.properties && valueProperty.properties.length ? valueProperty.properties.map(valuePropertyFn) : (!isMissingDescriptorMeta) ? build(container, valueProperty, path.concat(valueProperty.name), utils.resolvePath(container.model, path.concat(valueProperty.name).join('.')) || container.model[valueProperty.name]) :
+               valueProperty.map && valueProperty.map(valuePropertyFn);
+               function valuePropertyFn(d, i) {
                        const childPath = path.concat(valueProperty.name, d.name);
                        const childValue = utils.resolvePath(container.model, childPath.join('.'));
                        return (
@@ -382,7 +435,7 @@ export default function EditDescriptorModelProperties(props) {
                                        {build(container, d, childPath, childValue, props)}
                                </div>
                        );
-               }) : (!isMissingDescriptorMeta) ? build(container, valueProperty, path.concat(valueProperty.name), utils.resolvePath(container.model, path.concat(valueProperty.name).join('.')) || container.model[valueProperty.name]) : null
+               }
                // end magic
                const onFocus = onFocusPropertyFormInputElement.bind(container, property, path, value);