From 8eae49be51e029bf3344ef14f811a09e2b4c5f1f Mon Sep 17 00:00:00 2001 From: pkupczyk <piotr.kupczyk@id.ethz.ch> Date: Sun, 8 Dec 2019 20:43:39 +0100 Subject: [PATCH] SSDM-7583 : ObjectTypeForm - added dynamic plugin to property parameters --- .../types/objectType/ObjectTypeHandlerLoad.js | 2 +- .../types/objectType/ObjectTypeHandlerSave.js | 8 ++- .../ObjectTypeParametersProperty.jsx | 57 +++++++++++++++++-- .../objectType/ObjectTypeParametersType.jsx | 4 +- 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeHandlerLoad.js b/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeHandlerLoad.js index 425888f9227..6ce7be07fec 100644 --- a/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeHandlerLoad.js +++ b/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeHandlerLoad.js @@ -57,7 +57,7 @@ export default class ObjectTypeHandlerLoad { label: assignment.propertyType.label, description: assignment.propertyType.description, dataType: assignment.propertyType.dataType, - pluginId: assignment.plugin ? assignment.plugin.name : null, + plugin: assignment.plugin ? assignment.plugin.name : null, vocabulary: assignment.propertyType.vocabulary ? assignment.propertyType.vocabulary.code : null, diff --git a/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeHandlerSave.js b/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeHandlerSave.js index 5029a4befd3..131abceee1a 100644 --- a/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeHandlerSave.js +++ b/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeHandlerSave.js @@ -89,10 +89,12 @@ export default class ObjectTypeHandlerSave { function isUpdatePossible(type, property) { const typeVocabulary = type.vocabulary ? type.vocabulary.code : null const typeMaterialType = type.materialType ? type.materialType.code : null + const originalPlugin = property.original ? property.original.plugin : null return ( type.dataType === property.dataType && typeVocabulary === property.vocabulary && - typeMaterialType === property.materialType + typeMaterialType === property.materialType && + originalPlugin === property.plugin ) } @@ -228,8 +230,8 @@ export default class ObjectTypeHandlerSave { ) } - if (property.pluginId) { - updateProperties.setPluginId(new dto.PluginPermId(property.pluginId)) + if (property.plugin) { + updateProperty.setPluginId(new dto.PluginPermId(property.plugin)) } return updateProperty diff --git a/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeParametersProperty.jsx b/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeParametersProperty.jsx index 09f41c32f5a..99bec516392 100644 --- a/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeParametersProperty.jsx +++ b/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeParametersProperty.jsx @@ -43,6 +43,7 @@ class ObjectTypeParametersProperty extends React.PureComponent { transformation: React.createRef(), initialValueForExistingEntities: React.createRef(), mandatory: React.createRef(), + plugin: React.createRef(), showInEditView: React.createRef() } this.handleChange = this.handleChange.bind(this) @@ -85,9 +86,23 @@ class ObjectTypeParametersProperty extends React.PureComponent { } else if (dataType === dto.DataType.MATERIAL) { this.loadMaterialTypes() } + + this.loadDynamicPlugins() } } + loadDynamicPlugins() { + let criteria = new dto.PluginSearchCriteria() + criteria.withPluginType().thatEquals(dto.PluginType.DYNAMIC_PROPERTY) + let fo = new dto.PluginFetchOptions() + + return facade.searchPlugins(criteria, fo).then(result => { + this.setState(() => ({ + dynamicPlugins: result.objects + })) + }) + } + loadVocabularies() { let criteria = new dto.VocabularySearchCriteria() let fo = new dto.VocabularyFetchOptions() @@ -170,6 +185,7 @@ class ObjectTypeParametersProperty extends React.PureComponent { {this.renderTransformation(property)} {this.renderLabel(property)} {this.renderDescription(property)} + {this.renderDynamicPlugin(property)} {this.renderVisible(property)} {this.renderMandatory(property)} {this.renderInitialValue(property)} @@ -283,11 +299,11 @@ class ObjectTypeParametersProperty extends React.PureComponent { renderVocabulary(property) { if (property.dataType === dto.DataType.CONTROLLEDVOCABULARY) { const { classes } = this.props - const { vocabularies } = this.state + const { vocabularies = [] } = this.state let options = [] - if (vocabularies) { + if (vocabularies.length > 0) { options = vocabularies.map(vocabulary => { return { label: vocabulary.code, @@ -322,11 +338,11 @@ class ObjectTypeParametersProperty extends React.PureComponent { renderMaterialType(property) { if (property.dataType === dto.DataType.MATERIAL) { const { classes } = this.props - const { materialTypes } = this.state + const { materialTypes = [] } = this.state let options = [] - if (materialTypes) { + if (materialTypes.length > 0) { options = materialTypes.map(materialType => { return { label: materialType.code, @@ -404,6 +420,39 @@ class ObjectTypeParametersProperty extends React.PureComponent { } } + renderDynamicPlugin(property) { + const { classes } = this.props + const { dynamicPlugins = [] } = this.state + + let options = [] + + if (dynamicPlugins.length > 0) { + options = dynamicPlugins.map(dynamicPlugin => { + return { + label: dynamicPlugin.name, + value: dynamicPlugin.name + } + }) + options.unshift({}) + } + + return ( + <div className={classes.field}> + <SelectField + reference={this.references.plugin} + label='Dynamic Plugin' + name='plugin' + error={property.errors.plugin} + value={property.plugin} + options={options} + onChange={this.handleChange} + onFocus={this.handleFocus} + onBlur={this.handleBlur} + /> + </div> + ) + } + renderMandatory(property) { const { classes } = this.props return ( diff --git a/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeParametersType.jsx b/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeParametersType.jsx index 2f417d56dd8..3cd95c5dd4d 100644 --- a/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeParametersType.jsx +++ b/openbis_ng_ui/src/js/components/types/objectType/ObjectTypeParametersType.jsx @@ -176,11 +176,11 @@ class ObjectTypeParametersType extends React.PureComponent { renderValidationPlugin(type) { const { classes } = this.props - const { validationPlugins } = this.state + const { validationPlugins = [] } = this.state let options = [] - if (validationPlugins) { + if (validationPlugins.length > 0) { options = validationPlugins.map(validationPlugin => { return { label: validationPlugin.name, -- GitLab