|
|
|
|
@ -18,12 +18,12 @@ import { PanelModel } from '../state'; |
|
|
|
|
import { DashboardModel } from '../state'; |
|
|
|
|
import { VizPickerSearch } from './VizPickerSearch'; |
|
|
|
|
import PluginStateinfo from 'app/features/plugins/PluginStateInfo'; |
|
|
|
|
import { PanelPluginMeta } from '@grafana/ui'; |
|
|
|
|
import { PanelPlugin, PanelPluginMeta } from '@grafana/ui'; |
|
|
|
|
|
|
|
|
|
interface Props { |
|
|
|
|
panel: PanelModel; |
|
|
|
|
dashboard: DashboardModel; |
|
|
|
|
plugin: PanelPluginMeta; |
|
|
|
|
plugin: PanelPlugin; |
|
|
|
|
angularPanel?: AngularComponent; |
|
|
|
|
onTypeChanged: (newType: PanelPluginMeta) => void; |
|
|
|
|
updateLocation: typeof updateLocation; |
|
|
|
|
@ -41,7 +41,7 @@ export class VisualizationTab extends PureComponent<Props, State> { |
|
|
|
|
element: HTMLElement; |
|
|
|
|
angularOptions: AngularComponent; |
|
|
|
|
|
|
|
|
|
constructor(props) { |
|
|
|
|
constructor(props: Props) { |
|
|
|
|
super(props); |
|
|
|
|
|
|
|
|
|
this.state = { |
|
|
|
|
@ -54,7 +54,7 @@ export class VisualizationTab extends PureComponent<Props, State> { |
|
|
|
|
|
|
|
|
|
getReactPanelOptions = () => { |
|
|
|
|
const { panel, plugin } = this.props; |
|
|
|
|
return panel.getOptions(plugin.panelPlugin.defaults); |
|
|
|
|
return panel.getOptions(plugin.defaults); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
renderPanelOptions() { |
|
|
|
|
@ -64,12 +64,8 @@ export class VisualizationTab extends PureComponent<Props, State> { |
|
|
|
|
return <div ref={element => (this.element = element)} />; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (plugin.panelPlugin) { |
|
|
|
|
const PanelEditor = plugin.panelPlugin.editor; |
|
|
|
|
|
|
|
|
|
if (PanelEditor) { |
|
|
|
|
return <PanelEditor options={this.getReactPanelOptions()} onOptionsChange={this.onPanelOptionsChanged} />; |
|
|
|
|
} |
|
|
|
|
if (plugin.editor) { |
|
|
|
|
return <plugin.editor options={this.getReactPanelOptions()} onOptionsChange={this.onPanelOptionsChanged} />; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return <p>Visualization has no options</p>; |
|
|
|
|
@ -176,11 +172,12 @@ export class VisualizationTab extends PureComponent<Props, State> { |
|
|
|
|
renderToolbar = (): JSX.Element => { |
|
|
|
|
const { plugin } = this.props; |
|
|
|
|
const { isVizPickerOpen, searchQuery } = this.state; |
|
|
|
|
const { meta } = plugin; |
|
|
|
|
|
|
|
|
|
if (isVizPickerOpen) { |
|
|
|
|
return ( |
|
|
|
|
<VizPickerSearch |
|
|
|
|
plugin={plugin} |
|
|
|
|
plugin={meta} |
|
|
|
|
searchQuery={searchQuery} |
|
|
|
|
onChange={this.onSearchQueryChange} |
|
|
|
|
onClose={this.onCloseVizPicker} |
|
|
|
|
@ -189,8 +186,8 @@ export class VisualizationTab extends PureComponent<Props, State> { |
|
|
|
|
} else { |
|
|
|
|
return ( |
|
|
|
|
<div className="toolbar__main" onClick={this.onOpenVizPicker}> |
|
|
|
|
<img className="toolbar__main-image" src={plugin.info.logos.small} /> |
|
|
|
|
<div className="toolbar__main-name">{plugin.name}</div> |
|
|
|
|
<img className="toolbar__main-image" src={meta.info.logos.small} /> |
|
|
|
|
<div className="toolbar__main-name">{meta.name}</div> |
|
|
|
|
<i className="fa fa-caret-down" /> |
|
|
|
|
</div> |
|
|
|
|
); |
|
|
|
|
@ -198,14 +195,14 @@ export class VisualizationTab extends PureComponent<Props, State> { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
onTypeChanged = (plugin: PanelPluginMeta) => { |
|
|
|
|
if (plugin.id === this.props.plugin.id) { |
|
|
|
|
if (plugin.id === this.props.plugin.meta.id) { |
|
|
|
|
this.setState({ isVizPickerOpen: false }); |
|
|
|
|
} else { |
|
|
|
|
this.props.onTypeChanged(plugin); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
renderHelp = () => <PluginHelp plugin={this.props.plugin} type="help" />; |
|
|
|
|
renderHelp = () => <PluginHelp plugin={this.props.plugin.meta} type="help" />; |
|
|
|
|
|
|
|
|
|
setScrollTop = (event: React.MouseEvent<HTMLElement>) => { |
|
|
|
|
const target = event.target as HTMLElement; |
|
|
|
|
@ -215,6 +212,7 @@ export class VisualizationTab extends PureComponent<Props, State> { |
|
|
|
|
render() { |
|
|
|
|
const { plugin } = this.props; |
|
|
|
|
const { isVizPickerOpen, searchQuery, scrollTop } = this.state; |
|
|
|
|
const { meta } = plugin; |
|
|
|
|
|
|
|
|
|
const pluginHelp: EditorToolbarView = { |
|
|
|
|
heading: 'Help', |
|
|
|
|
@ -233,13 +231,13 @@ export class VisualizationTab extends PureComponent<Props, State> { |
|
|
|
|
<> |
|
|
|
|
<FadeIn in={isVizPickerOpen} duration={200} unmountOnExit={true} onExited={this.clearQuery}> |
|
|
|
|
<VizTypePicker |
|
|
|
|
current={plugin} |
|
|
|
|
current={meta} |
|
|
|
|
onTypeChanged={this.onTypeChanged} |
|
|
|
|
searchQuery={searchQuery} |
|
|
|
|
onClose={this.onCloseVizPicker} |
|
|
|
|
/> |
|
|
|
|
</FadeIn> |
|
|
|
|
<PluginStateinfo state={plugin.state} /> |
|
|
|
|
<PluginStateinfo state={meta.state} /> |
|
|
|
|
{this.renderPanelOptions()} |
|
|
|
|
</> |
|
|
|
|
</EditorTabBody> |
|
|
|
|
|