From b4aca1b2861f348dd48eb3de552866426f59f98c Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Thu, 25 Mar 2021 14:21:40 +0100 Subject: [PATCH] Fix a bug in config table for externally managed ICs --- src/componentconfig/config-table.js | 37 +++++++++++++++++------------ 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/componentconfig/config-table.js b/src/componentconfig/config-table.js index 1452949..082caa2 100644 --- a/src/componentconfig/config-table.js +++ b/src/componentconfig/config-table.js @@ -47,6 +47,24 @@ class ConfigTable extends Component { } } + static getDerivedStateFromProps(props, state){ + + let ExternalICInUse = false + + for (let config of props.configs){ + for (let component of props.ics) { + if ((config.icID === component.id) && (component.managedexternally === true)) { + ExternalICInUse = true; + break; + } + } + } + + return { + ExternalICInUse: ExternalICInUse + }; + } + addConfig() { const config = { scenarioID: this.props.scenario.id, @@ -181,24 +199,13 @@ class ConfigTable extends Component { } usesExternalIC(index) { - let icID = this.props.configs[index].icID; - - let ic = null; for (let component of this.props.ics) { - if (component.id === icID) { - ic = component; + if (component.id === this.props.configs[index].icID) { + if (component.managedexternally === true) { + return true + } } } - - if (ic == null) { - return false; - } - - if (ic.managedexternally === true) { - this.setState({ ExternalICInUse: true }) - return true - } - return false }