grafana/public/app/features/dashboard/dashgrid/PanelEditor.tsx

117 lines
3.1 KiB
TypeScript
Raw Normal View History

2018-06-19 07:51:57 -05:00
import React from 'react';
import classNames from 'classnames';
2018-06-19 07:51:57 -05:00
import { PanelModel } from '../panel_model';
import { DashboardModel } from '../dashboard_model';
import { store } from 'app/stores/store';
import { observer } from 'mobx-react';
import { QueriesTab } from './QueriesTab';
import { PanelPlugin, PluginExports } from 'app/types/plugins';
import { VizTypePicker } from './VizTypePicker';
2018-06-19 07:51:57 -05:00
interface PanelEditorProps {
panel: PanelModel;
dashboard: DashboardModel;
panelType: string;
pluginExports: PluginExports;
onTypeChanged: (newType: PanelPlugin) => void;
2018-06-19 07:51:57 -05:00
}
interface PanelEditorTab {
id: string;
text: string;
icon: string;
}
2018-06-19 14:25:57 -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' },
{ 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
}
renderQueriesTab() {
return <QueriesTab panel={this.props.panel} dashboard={this.props.dashboard} />;
}
2018-06-19 14:25:57 -05:00
renderPanelOptions() {
const { pluginExports } = this.props;
if (pluginExports.PanelOptions) {
const PanelOptions = pluginExports.PanelOptions;
return <PanelOptions />;
} else {
return <p>Visualization has no options</p>;
}
}
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">
<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">
<h5 className="page-heading">Options</h5>
{this.renderPanelOptions()}
2018-07-06 06:42:59 -05:00
</div>
</div>
);
2018-06-19 14:25:57 -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() {
const activeTab: string = store.view.query.get('tab') || 'queries';
2018-06-19 07:51:57 -05:00
return (
<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 => {
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">
{activeTab === 'queries' && this.renderQueriesTab()}
{activeTab === 'visualization' && this.renderVizTab()}
2018-06-19 14:25:57 -05:00
</div>
2018-06-19 07:51:57 -05:00
</div>
);
}
}
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)}>
<i className={tab.icon} /> {tab.text}
</a>
</li>
);
}