2018-06-19 07:51:57 -05:00
|
|
|
import React from 'react';
|
2018-07-08 09:39:25 -05:00
|
|
|
import classNames from 'classnames';
|
2018-06-19 07:51:57 -05:00
|
|
|
import { PanelModel } from '../panel_model';
|
|
|
|
import { DashboardModel } from '../dashboard_model';
|
2018-06-26 14:07:41 -05:00
|
|
|
import { store } from 'app/stores/store';
|
|
|
|
import { observer } from 'mobx-react';
|
|
|
|
import { QueriesTab } from './QueriesTab';
|
2018-07-11 14:11:21 -05:00
|
|
|
import { PanelPlugin, PluginExports } from 'app/types/plugins';
|
2018-07-08 09:39:25 -05:00
|
|
|
import { VizTypePicker } from './VizTypePicker';
|
2018-06-19 07:51:57 -05:00
|
|
|
|
|
|
|
interface PanelEditorProps {
|
|
|
|
panel: PanelModel;
|
|
|
|
dashboard: DashboardModel;
|
2018-07-09 15:24:15 -05:00
|
|
|
panelType: string;
|
2018-07-11 14:11:21 -05:00
|
|
|
pluginExports: PluginExports;
|
2018-07-09 15:24:15 -05:00
|
|
|
onTypeChanged: (newType: PanelPlugin) => void;
|
2018-06-19 07:51:57 -05:00
|
|
|
}
|
|
|
|
|
2018-06-26 14:07:41 -05:00
|
|
|
interface PanelEditorTab {
|
|
|
|
id: string;
|
|
|
|
text: string;
|
|
|
|
icon: string;
|
|
|
|
}
|
2018-06-19 14:25:57 -05:00
|
|
|
|
2018-06-26 14:07:41 -05:00
|
|
|
@observer
|
|
|
|
export class PanelEditor extends React.Component<PanelEditorProps, any> {
|
2018-06-28 06:31:55 -05:00
|
|
|
tabs: PanelEditorTab[];
|
|
|
|
|
2018-06-19 14:25:57 -05:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-06-28 06:31:55 -05:00
|
|
|
|
|
|
|
this.tabs = [
|
|
|
|
{ id: 'queries', text: 'Queries', icon: 'fa fa-database' },
|
2018-08-25 14:22:50 -05:00
|
|
|
{ id: 'visualization', text: 'Visualization', icon: 'fa fa-line-chart' },
|
2018-06-28 06:31:55 -05:00
|
|
|
];
|
2018-06-19 14:25:57 -05:00
|
|
|
}
|
|
|
|
|
2018-06-26 14:07:41 -05:00
|
|
|
renderQueriesTab() {
|
|
|
|
return <QueriesTab panel={this.props.panel} dashboard={this.props.dashboard} />;
|
|
|
|
}
|
2018-06-19 14:25:57 -05:00
|
|
|
|
2018-07-11 14:11:21 -05:00
|
|
|
renderPanelOptions() {
|
|
|
|
const { pluginExports } = this.props;
|
|
|
|
|
|
|
|
if (pluginExports.PanelOptions) {
|
|
|
|
const PanelOptions = pluginExports.PanelOptions;
|
|
|
|
return <PanelOptions />;
|
|
|
|
} else {
|
|
|
|
return <p>Visualization has no options</p>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-26 14:07:41 -05:00
|
|
|
renderVizTab() {
|
2018-07-06 06:42:59 -05:00
|
|
|
return (
|
|
|
|
<div className="viz-editor">
|
2018-07-07 07:10:03 -05:00
|
|
|
<div className="viz-editor-col1">
|
2018-07-09 15:24:15 -05:00
|
|
|
<VizTypePicker currentType={this.props.panel.type} onTypeChanged={this.props.onTypeChanged} />
|
2018-07-06 06:42:59 -05:00
|
|
|
</div>
|
2018-07-07 07:10:03 -05:00
|
|
|
<div className="viz-editor-col2">
|
2018-07-08 09:39:25 -05:00
|
|
|
<h5 className="page-heading">Options</h5>
|
2018-07-11 14:11:21 -05:00
|
|
|
{this.renderPanelOptions()}
|
2018-07-06 06:42:59 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2018-06-19 14:25:57 -05:00
|
|
|
}
|
|
|
|
|
2018-06-26 14:07:41 -05:00
|
|
|
onChangeTab = (tab: PanelEditorTab) => {
|
|
|
|
store.view.updateQuery({ tab: tab.id }, false);
|
|
|
|
};
|
2018-06-26 09:45:42 -05:00
|
|
|
|
2018-06-19 07:51:57 -05:00
|
|
|
render() {
|
2018-06-26 14:07:41 -05:00
|
|
|
const activeTab: string = store.view.query.get('tab') || 'queries';
|
|
|
|
|
2018-06-19 07:51:57 -05:00
|
|
|
return (
|
2018-07-08 09:39:25 -05:00
|
|
|
<div className="tabbed-view tabbed-view--new">
|
2018-06-19 07:51:57 -05:00
|
|
|
<div className="tabbed-view-header">
|
|
|
|
<ul className="gf-tabs">
|
2018-06-28 06:31:55 -05:00
|
|
|
{this.tabs.map(tab => {
|
2018-06-26 14:07:41 -05:00
|
|
|
return <TabItem tab={tab} activeTab={activeTab} onClick={this.onChangeTab} key={tab.id} />;
|
|
|
|
})}
|
2018-06-19 07:51:57 -05:00
|
|
|
</ul>
|
|
|
|
|
|
|
|
<button className="tabbed-view-close-btn" ng-click="ctrl.exitFullscreen();">
|
|
|
|
<i className="fa fa-remove" />
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
2018-06-19 14:25:57 -05:00
|
|
|
<div className="tabbed-view-body">
|
2018-06-26 14:07:41 -05:00
|
|
|
{activeTab === 'queries' && this.renderQueriesTab()}
|
2018-08-25 14:22:50 -05:00
|
|
|
{activeTab === 'visualization' && this.renderVizTab()}
|
2018-06-19 14:25:57 -05:00
|
|
|
</div>
|
2018-06-19 07:51:57 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2018-06-26 14:07:41 -05:00
|
|
|
|
|
|
|
interface TabItemParams {
|
|
|
|
tab: PanelEditorTab;
|
|
|
|
activeTab: string;
|
|
|
|
onClick: (tab: PanelEditorTab) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
function TabItem({ tab, activeTab, onClick }: TabItemParams) {
|
|
|
|
const tabClasses = classNames({
|
|
|
|
'gf-tabs-link': true,
|
|
|
|
active: activeTab === tab.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li className="gf-tabs-item" key={tab.id}>
|
|
|
|
<a className={tabClasses} onClick={() => onClick(tab)}>
|
2018-08-25 14:22:50 -05:00
|
|
|
<i className={tab.icon} /> {tab.text}
|
2018-06-26 14:07:41 -05:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|