From b07a804bf3a15d6dcd047a8ab9d86b4dbb6af983 Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Fri, 19 Jun 2020 09:51:25 +0200 Subject: [PATCH] Consider signal direction when connecting signals with widgets (out signals only for display widgets and in signals only for manipulation widgets) #218 --- .../edit-widget/edit-widget-control-creator.js | 18 +++++++++--------- .../edit-widget/edit-widget-signal-control.js | 10 ++++++---- .../edit-widget/edit-widget-signals-control.js | 16 +++++++++++++--- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/widget/edit-widget/edit-widget-control-creator.js b/src/widget/edit-widget/edit-widget-control-creator.js index 90ded85..1b2f996 100644 --- a/src/widget/edit-widget/edit-widget-control-creator.js +++ b/src/widget/edit-widget/edit-widget-control-creator.js @@ -47,20 +47,20 @@ export default function CreateControls(widgetType = null, widget = null, session break; case 'Action': DialogControls.push( - handleChange(e)} />, + handleChange(e)} direction={'in'} />, ); break; case 'Value': DialogControls.push( handleChange(e)} />, - handleChange(e)} />, + handleChange(e)} direction={'out'}/>, handleChange(e)} />, handleChange(e)} /> ); break; case 'Lamp': DialogControls.push( - handleChange(e)} />, + handleChange(e)} direction={'out'}/>, handleChange(e)} />, handleChange(e)} />, handleChange(e)} />, @@ -69,14 +69,14 @@ export default function CreateControls(widgetType = null, widget = null, session case 'Plot': DialogControls.push( handleChange(e)} />, - handleChange(e)} />, + handleChange(e)} direction={'out'}/>, handleChange(e)} />, handleChange(e)} /> ); break; case 'Table': DialogControls.push( - handleChange(e)} />, + handleChange(e)} direction={'out'}/>, handleChange(e)} /> ); break; @@ -91,7 +91,7 @@ export default function CreateControls(widgetType = null, widget = null, session case 'Gauge': DialogControls.push( handleChange(e)} />, - handleChange(e)} />, + handleChange(e)} direction={'out'}/>, handleChange(e)} />, handleChange(e)} />, handleChange(e)} /> @@ -101,7 +101,7 @@ export default function CreateControls(widgetType = null, widget = null, session DialogControls.push( handleChange(e)} />, handleChange(e)} />, - handleChange(e)} />, + handleChange(e)} direction={'in'}/>, handleChange(e)} />, handleChange(e)} />, handleChange(e)} />, @@ -112,7 +112,7 @@ export default function CreateControls(widgetType = null, widget = null, session case 'Button': DialogControls.push( handleChange(e)} />, - handleChange(e)} />, + handleChange(e)} direction={'in'}/>, handleChange(e)} />, handleChange(e)} />, handleChange(e)} /> @@ -148,7 +148,7 @@ export default function CreateControls(widgetType = null, widget = null, session case 'NumberInput': DialogControls.push( handleChange(e)} />, - handleChange(e)} />, + handleChange(e)} direction={'in'}/>, handleChange(e)} /> ); break; diff --git a/src/widget/edit-widget/edit-widget-signal-control.js b/src/widget/edit-widget/edit-widget-signal-control.js index aaa9c24..cc9135d 100644 --- a/src/widget/edit-widget/edit-widget-signal-control.js +++ b/src/widget/edit-widget/edit-widget-signal-control.js @@ -23,13 +23,15 @@ class EditWidgetSignalControl extends Component { super(props); this.state = { - widget: {} + widget: {}, + signals: [] }; } static getDerivedStateFromProps(props, state){ return { - widget: props.widget + widget: props.widget, + signals: props.signals.filter(s => s.direction === props.direction) }; } @@ -51,10 +53,10 @@ class EditWidgetSignalControl extends Component { this.handleSignalChange(e)}> { - this.props.signals.length === 0 ? ( + this.state.signals.length === 0 ? ( ) : ( - this.props.signals.map((signal, index) => ( + this.state.signals.map((signal, index) => ( )) ) diff --git a/src/widget/edit-widget/edit-widget-signals-control.js b/src/widget/edit-widget/edit-widget-signals-control.js index 109df2e..ad4658b 100644 --- a/src/widget/edit-widget/edit-widget-signals-control.js +++ b/src/widget/edit-widget/edit-widget-signals-control.js @@ -23,7 +23,17 @@ class EditWidgetSignalsControl extends Component { super(props); this.state = { + widget: {}, + signals: [], + checkedSignals: props.widget[props.controlId] + }; + } + + + static getDerivedStateFromProps(props, state){ + return { widget: props.widget, + signals: props.signals.filter(s => s.direction === props.direction), checkedSignals: props.widget[props.controlId] }; } @@ -48,10 +58,10 @@ class EditWidgetSignalsControl extends Component { Signals { - this.props.signals === 0 || !this.state.widget.hasOwnProperty(this.props.controlId)? ( + this.state.signals === 0 || !this.state.widget.hasOwnProperty(this.props.controlId)? ( No signals available ) : ( - this.props.signals.map((signal, index) => ( + this.state.signals.map((signal, index) => ( this.handleSignalChange(e.target.checked, signal.id)}> )) - ) + ) } );