X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FUI.git;a=blobdiff_plain;f=skyquake%2Fplugins%2Fcomposer%2Fsrc%2Fsrc%2Fcomponents%2FEditDescriptorModelProperties.js;h=0e1746dda78f4af8ecf757e55d0cbe8b8b35e0f0;hp=aa189637c6a3d1ebccb2d4b295428d4c9829d910;hb=79dc9d2eaabb4e0eb77aacb16a620ca254c8d983;hpb=2681ded51ca622c9e44052e439a64e7008c2a23d diff --git a/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js b/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js index aa189637c..0e1746dda 100644 --- a/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js +++ b/skyquake/plugins/composer/src/src/components/EditDescriptorModelProperties.js @@ -20,11 +20,15 @@ * * This class generates the form fields used to edit the CONFD JSON model. */ -'use strict'; 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: []}; @@ -168,17 +182,7 @@ export default function EditDescriptorModelProperties(props) { ); } - function onFormFieldValueChanged(event) { - if (DescriptorModelFactory.isContainer(this)) { - event.preventDefault(); - const name = event.target.name; - const value = event.target.value; - utils.assignPathValue(this.model, name, value); - CatalogItemsActions.catalogItemDescriptorChanged(this.getRoot()); - } - } - - function buildField(container, property, path, value, fieldId) { + function buildField(container, property, path, value, fieldKey) { let cds = CatalogDataStore; let catalogs = cds.getTransientCatalogs(); @@ -186,13 +190,35 @@ export default function EditDescriptorModelProperties(props) { 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 : '' : (isNaN(value) ? undefined : value); + + // process the named field value change + function processFieldValueChange(name, value) { + console.debug('processed change for -- ' + name + ' -- with value -- ' + value); + // this = the container being edited + if (DescriptorModelFactory.isContainer(this)) { + utils.assignPathValue(this.model, name, value); + CatalogItemsActions.catalogItemDescriptorChanged(this.getRoot()); + } + } + + // change handler used for onChange event + const changeHandler = (handleValueChange, event) => { + event.preventDefault(); + console.debug(event.target.value); + handleValueChange(event.target.value); + }; + // create an onChange event handler for a text field for the specified field path (debounced to accumulate chars) + const onTextChange = changeHandler.bind(null, _debounce( + processFieldValueChange.bind(container, pathToProperty), 2000, {maxWait: 5000})); // max wait for short-name + // create an onChange event handler for a select field for the specified field path + const onSelectChange = changeHandler.bind(null, processFieldValueChange.bind(container, pathToProperty)); + if (isEnumeration) { const enumeration = Property.getEnumeration(property, value); const options = enumeration.map((d, i) => { @@ -209,13 +235,12 @@ export default function EditDescriptorModelProperties(props) { } return ( + ); + } + + 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 = [ + , + + ] + + return ( + +
+ {valueResponse} @@ -540,7 +623,7 @@ export default function EditDescriptorModelProperties(props) { ); } - function buildLeafListItem(container, property, valuePath, value, index) { + function buildLeafListItem(container, property, valuePath, value, uniqueId, index) { // look at the type to determine how to parse the value return (
@@ -606,7 +689,7 @@ export default function EditDescriptorModelProperties(props) { if (isArray) { valuePath.push(index); - fieldId += index; + fieldId = isLeafList ? fieldId + index + value : resolveReactKey(value); } if (isMetaField) { @@ -638,7 +721,7 @@ export default function EditDescriptorModelProperties(props) { event.preventDefault(); event.stopPropagation(); this.getRoot().uiState.focusedPropertyPath = path.join('.'); - console.log('property selected', path.join('.')); + console.debug('property selected', path.join('.')); ComposerAppActions.propertySelected([path.join('.')]); } @@ -710,11 +793,7 @@ export default function EditDescriptorModelProperties(props) {

Basic

- {basicProperties.map(property => { - const path = [property.name]; - const value = container.model[property.name]; - return build(container, property, path, value); - })} + {buildComponentsForProperties(container, basicProperties, [], container.model)}
); @@ -734,11 +813,7 @@ export default function EditDescriptorModelProperties(props) { less…
- {properties.map(property => { - const path = [property.name]; - const value = container.model[property.name]; - return build(container, property, path, value, {toggle: true, width: props.width}); - })} + {buildComponentsForProperties(container, properties, [], container.model, {toggle: true, width: props.width})}
We need this so when the user closes the panel it won't shift away and scare the bj out of them!
@@ -767,5 +842,5 @@ export default function EditDescriptorModelProperties(props) { {buildAdvancedGroup()}
); +}; -}