Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TSVB Visualizations to honor darkTheme #12804

Merged
merged 3 commits into from
Jul 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions src/core_plugins/metrics/public/components/vis_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -35,8 +58,10 @@ class VisEditor extends Component {
};

if (!this.props.vis.isEditorMode()) {
const reversed = this.state.reversed;
return (
<Visualization
reversed={reversed}
onBrush={this.onBrush}
fields={this.props.vis.fields}
model={this.props.vis.params}
Expand Down Expand Up @@ -81,15 +106,10 @@ class VisEditor extends Component {
}

VisEditor.propTypes = {
fields: PropTypes.object,
model: PropTypes.object,
onBrush: PropTypes.func,
onChange: PropTypes.func,
onCommit: PropTypes.func,
onToggleAutoApply: PropTypes.func,
vis: PropTypes.object,
visData: PropTypes.object,
dirty: PropTypes.bool,
autoApply: PropTypes.bool
appState: PropTypes.object,
renderComplete: PropTypes.func,
};

export default VisEditor;
4 changes: 2 additions & 2 deletions src/ui/public/vis/vis_types/react_vis_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { VisTypeProvider } from 'ui/vis/vis_types';

export function ReactVisTypeProvider(Private) {
export function ReactVisTypeProvider(Private, getAppState) {
const VisType = Private(VisTypeProvider);

class ReactVisController {
Expand All @@ -17,7 +17,7 @@ export function ReactVisTypeProvider(Private) {
return new Promise((resolve, reject) => {
if (!this.visData) return reject();
const Component = this.vis.type.visConfig.component;
render(<Component vis={this.vis} visData={visData} renderComplete={resolve} />, this.el);
render(<Component vis={this.vis} appState={getAppState()} visData={visData} renderComplete={resolve} />, this.el);
});
}

Expand Down