From 320364a7a2fdcbef076017ad7a33b57ea31557b4 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Wed, 21 Sep 2022 16:48:47 +0200 Subject: [PATCH] UI: Get derived state from props in AdvancedMultiSelect --- .../components/ui-components/AdvancedMultiSelect.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/ui/src/components/ui-components/AdvancedMultiSelect.js b/monkey/monkey_island/cc/ui/src/components/ui-components/AdvancedMultiSelect.js index bd6933ac2..cb5ef1594 100644 --- a/monkey/monkey_island/cc/ui/src/components/ui-components/AdvancedMultiSelect.js +++ b/monkey/monkey_island/cc/ui/src/components/ui-components/AdvancedMultiSelect.js @@ -32,7 +32,6 @@ function AdvancedMultiSelectHeader(props) { class AdvancedMultiSelect extends React.Component { constructor(props) { super(props); - let selectedPluginNames = this.props.value.map(v => v.name); let allPluginNames = this.props.options.enumOptions.map(v => v.value); @@ -162,6 +161,16 @@ class AdvancedMultiSelect extends React.Component { this.onChange(safePluginNames); } + static getDerivedStateFromProps(props, current_state) { + let propsPluginNames = props.value.map(v => v.name); + if (current_state.selectedPluginNames !== propsPluginNames) { + return { + selectedPluginNames: propsPluginNames + } + } + return null + } + render() { const { autofocus,