diff --git a/src/core_plugins/metrics/public/components/vis_editor.js b/src/core_plugins/metrics/public/components/vis_editor.js index 2f97143de8594..3757e961348b7 100644 --- a/src/core_plugins/metrics/public/components/vis_editor.js +++ b/src/core_plugins/metrics/public/components/vis_editor.js @@ -4,13 +4,36 @@ import Visualization from './visualization'; import VisPicker from './vis_picker'; import PanelConfig from './panel_config'; import brushHandler from '../lib/create_brush_handler'; +import { get } from 'lodash'; class VisEditor extends Component { constructor(props) { super(props); - this.state = { model: props.vis.params, dirty: false, autoApply: true }; + const { appState } = props; + const reversed = get(appState, 'options.darkTheme', false); + this.state = { model: props.vis.params, dirty: false, autoApply: true, reversed }; this.onBrush = brushHandler(props.vis.API.timeFilter); + this.handleAppStateChange = this.handleAppStateChange.bind(this); + } + + componentWillMount() { + const { appState } = this.props; + if (appState) { + this.appState = appState; + this.appState.on('save_with_changes', this.handleAppStateChange); + } + } + + handleAppStateChange() { + const reversed = get(this.appState, 'options.darkTheme', false); + this.setState({ reversed }); + } + + componentWillUnmount() { + if (this.appState) { + this.appState.off('save_with_changes', this.handleAppStateChange); + } } render() { @@ -35,8 +58,10 @@ class VisEditor extends Component { }; if (!this.props.vis.isEditorMode()) { + const reversed = this.state.reversed; return ( { if (!this.visData) return reject(); const Component = this.vis.type.visConfig.component; - render(, this.el); + render(, this.el); }); }