diff --git a/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormControllerChange.js b/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormControllerChange.js index 9866da44fdeeb5687433ab3e2113d1c243321a71..8bb6856515e20913d7db9eec99a6d6543fb3dc2b 100644 --- a/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormControllerChange.js +++ b/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormControllerChange.js @@ -1,3 +1,4 @@ +import _ from 'lodash' import PageControllerChange from '@src/js/components/common/page/PageControllerChange.js' import PluginFormSelectionType from '@src/js/components/tools/form/plugin/PluginFormSelectionType.js' import FormUtil from '@src/js/components/common/form/FormUtil.js' @@ -12,29 +13,86 @@ export default class PluginFormControllerChange extends PageControllerChange { } async _handleChangePlugin(params) { - await this.context.setState(state => { + await this.context.setState(oldState => { const { newObject } = FormUtil.changeObjectField( - state.plugin, + oldState.plugin, params.field, params.value ) - return { + + const newState = { + ...oldState, plugin: newObject } + + this._handleChangePluginEntityKind(oldState, newState) + + return newState }) await this.controller.changed(true) } + _handleChangePluginEntityKind(oldState, newState) { + const oldEntityKind = oldState.plugin.entityKind.value + const newEntityKind = newState.plugin.entityKind.value + + if (oldEntityKind !== newEntityKind) { + const newEvaluateEntityKind = newEntityKind + ? newEntityKind + : newState.evaluateParameters.entityKind.value + + const newEvaluateEntity = + newEntityKind && + newEntityKind !== newState.evaluateParameters.entityKind.value + ? null + : newState.evaluateParameters.entity.value + + _.assign(newState, { + evaluateParameters: { + ...newState.evaluateParameters, + entityKind: { + ...newState.evaluateParameters.entityKind, + value: newEvaluateEntityKind, + enabled: !newEntityKind + }, + entity: { + ...newState.evaluateParameters.entity, + value: newEvaluateEntity, + enabled: !!newEvaluateEntityKind + } + } + }) + } + } + async _handleChangeEvaluateParameter(params) { await this.context.setState(state => { - const { newObject } = FormUtil.changeObjectField( + const { oldObject, newObject } = FormUtil.changeObjectField( state.evaluateParameters, params.field, params.value ) + + this._handleChangeEvaluateParameterEntityKind(oldObject, newObject) + return { evaluateParameters: newObject } }) } + + _handleChangeEvaluateParameterEntityKind(oldParameters, newParameters) { + const oldEntityKind = oldParameters.entityKind.value + const newEntityKind = newParameters.entityKind.value + + if (oldEntityKind !== newEntityKind) { + _.assign(newParameters, { + entity: { + ...newParameters.entity, + value: null, + enabled: !!newEntityKind + } + }) + } + } } diff --git a/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormControllerLoad.js b/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormControllerLoad.js index fee629cb6e1479472de0e94c72a162a38ed4596c..b6c84199b0643b36d0e9a9cef55c07536c150290 100644 --- a/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormControllerLoad.js +++ b/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormControllerLoad.js @@ -15,7 +15,7 @@ export default class PluginFormControllerLoad extends PageControllerLoad { } const plugin = this._createPlugin(object, loadedPlugin) - const evaluateParameters = this._createEvaluateParameters() + const evaluateParameters = this._createEvaluateParameters(loadedPlugin) const evaluateResults = this._createEvaluateResults() return this.context.setState({ @@ -74,10 +74,16 @@ export default class PluginFormControllerLoad extends PageControllerLoad { return plugin } - _createEvaluateParameters() { + _createEvaluateParameters(loadedPlugin) { + const entityKinds = _.get(loadedPlugin, 'entityKinds', []) + const entityKind = entityKinds.length === 1 ? entityKinds[0] : null + return { - entityKind: FormUtil.createField(), - entity: FormUtil.createField(), + entityKind: FormUtil.createField({ + value: entityKind, + enabled: !entityKind + }), + entity: FormUtil.createField({ enabled: entityKind }), entityIsNew: FormUtil.createField() } } diff --git a/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormEvaluateParameters.jsx b/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormEvaluateParameters.jsx index ca5e7c251b0a12e7afcdd99647ae5fbfd3d4fe20..80037a471c9d1ef3d442cc1b1703d92dd85a8163 100644 --- a/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormEvaluateParameters.jsx +++ b/openbis_ng_ui/src/js/components/tools/form/plugin/PluginFormEvaluateParameters.jsx @@ -57,6 +57,7 @@ class PluginFormEvaluateParameters extends React.PureComponent { label='Entity Kind' name='entityKind' value={parameters.entityKind.value} + disabled={!parameters.entityKind.enabled} options={options} onChange={this.handleChange} /> @@ -75,6 +76,7 @@ class PluginFormEvaluateParameters extends React.PureComponent { name='entity' entityKind={parameters.entityKind.value} value={parameters.entity.value} + disabled={!parameters.entity.enabled} onChange={this.handleChange} /> </div> @@ -91,6 +93,7 @@ class PluginFormEvaluateParameters extends React.PureComponent { label='Is New Entity' name='entityIsNew' value={parameters.entityIsNew.value} + disabled={!parameters.entityIsNew.enabled} onChange={this.handleChange} /> </div>