From 60b8e633508acbabbd171e961580652235668149 Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Thu, 4 Feb 2021 16:28:44 +0100 Subject: [PATCH] improve disabling of checkboxes for non-external ICs --- src/common/table-column.js | 1 + src/common/table.js | 7 +++-- src/ic/ics.js | 6 ++++ src/scenario/scenario.js | 58 +++++++++++++++++++++++++++++--------- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/common/table-column.js b/src/common/table-column.js index df68140..9d77606 100644 --- a/src/common/table-column.js +++ b/src/common/table-column.js @@ -35,6 +35,7 @@ class TableColumn extends Component { labelKey: null, checkbox: false, checkboxKey: '', + checkboxDisabled: null, labelStyle: null, labelModifier: null diff --git a/src/common/table.js b/src/common/table.js index 6b22c19..f87df60 100644 --- a/src/common/table.js +++ b/src/common/table.js @@ -116,12 +116,15 @@ class CustomTable extends Component { if (child.props.checkbox) { const checkboxKey = child.props.checkboxKey; - + let isDisabled = false; + if (child.props.checkboxDisabled != null){ + isDisabled = !child.props.checkboxDisabled(index) + } cell.push( child.props.onChecked(index, e)} />); diff --git a/src/ic/ics.js b/src/ic/ics.js index 5614d8d..0144b5d 100644 --- a/src/ic/ics.js +++ b/src/ic/ics.js @@ -372,6 +372,11 @@ class InfrastructureComponents extends Component { } + isExternalIC(index){ + let ic = this.state.ics[index] + return ic.managedexternally + } + render() { const buttonStyle = { @@ -395,6 +400,7 @@ class InfrastructureComponents extends Component { this.isExternalIC(index)} onChecked={(index, event) => this.onICChecked(index, event)} width='30' /> diff --git a/src/scenario/scenario.js b/src/scenario/scenario.js index 569e73c..e65b2e6 100644 --- a/src/scenario/scenario.js +++ b/src/scenario/scenario.js @@ -103,6 +103,7 @@ class Scenario extends React.Component { files: FileStore.getState().filter(file => file.scenarioID === parseInt(props.match.params.scenario, 10)), ics: ICStore.getState(), + ExternalICInUse: false, deleteConfigModal: false, importConfigModal: false, @@ -361,6 +362,29 @@ class Scenario extends React.Component { this.setState({ selectedConfigs: selectedConfigs }); } + usesExternalIC(index){ + let icID = this.state.configs[index].icID; + + let ic = null; + for (let component of this.state.ics) { + if (component.id === this.state.configs[index].icID) { + ic = component; + } + } + + if (ic == null) { + return false; + } + + if (ic.managedexternally === true){ + this.setState({ExternalICInUse: true}) + return true + } + + return false + + } + runAction(action, delay) { // delay in seconds @@ -780,7 +804,11 @@ class Scenario extends React.Component {
- this.onConfigChecked(index, event)} width='30' /> + this.usesExternalIC(index)} + onChecked={(index, event) => this.onConfigChecked(index, event)} + width='30' /> this.getListOfFiles(fileIDs, ['json', 'JSON'])} />
-
- this.runAction(action, delay)} - actions={[ - { id: '-1', title: 'Select command', data: { action: 'none' } }, - { id: '0', title: 'Start', data: { action: 'start' } }, - { id: '1', title: 'Stop', data: { action: 'stop' } }, - { id: '2', title: 'Pause', data: { action: 'pause' } }, - { id: '3', title: 'Resume', data: { action: 'resume' } } - ]} /> -
- + { this.state.ExternalICInUse ? ( +
+ this.runAction(action, delay)} + actions={[ + {id: '-1', title: 'Select command', data: {action: 'none'}}, + {id: '0', title: 'Start', data: {action: 'start'}}, + {id: '1', title: 'Stop', data: {action: 'stop'}}, + {id: '2', title: 'Pause', data: {action: 'pause'}}, + {id: '3', title: 'Resume', data: {action: 'resume'}} + ]}/> +
+ ) : (
) + }