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

139 lines
3.8 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';
2018-09-18 08:32:06 -05:00
import { store } from 'app/store/configureStore';
import { QueriesTab } from './QueriesTab';
import { PanelPlugin, PluginExports } from 'app/types/plugins';
import { VizTypePicker } from './VizTypePicker';
2018-09-18 08:32:06 -05:00
import { updateLocation } from 'app/core/actions';
2018-10-26 09:29:08 -05:00
import CustomScrollbar from 'app/core/components/CustomScrollbar/CustomScrollbar';
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
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-10-26 09:29:08 -05:00
{ id: 'alert', text: 'Alert', icon: 'gicon gicon-alert' },
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-10-26 09:29:08 -05:00
<VizTypePicker currentType={this.props.panel.type} onTypeChanged={this.props.onTypeChanged} />
<h5 className="page-heading p-t-2">Options</h5>
{this.renderPanelOptions()}
2018-07-06 06:42:59 -05:00
</div>
);
2018-06-19 14:25:57 -05:00
}
onChangeTab = (tab: PanelEditorTab) => {
2018-09-18 08:32:06 -05:00
store.dispatch(
updateLocation({
query: { tab: tab.id },
2018-10-10 02:26:17 -05:00
partial: true,
2018-09-18 08:32:06 -05:00
})
);
};
2018-06-26 09:45:42 -05:00
2018-10-27 03:14:38 -05:00
onClose = () => {
store.dispatch(
updateLocation({
query: { tab: false, fullscreen: false, edit: false },
partial: true,
})
);
};
2018-06-19 07:51:57 -05:00
render() {
2018-10-04 02:14:47 -05:00
const { location } = store.getState();
const activeTab = location.query.tab || 'queries';
2018-06-19 07:51:57 -05:00
return (
2018-10-26 06:20:10 -05:00
<div className="panel-editor-container__editor">
<div className="panel-editor__aside">
<h2 className="panel-editor__aside-header">
<i className="fa fa-cog" />
Edit Panel
</h2>
2018-10-27 03:14:38 -05:00
2018-10-26 06:20:10 -05:00
{this.tabs.map(tab => {
return <TabItem tab={tab} activeTab={activeTab} onClick={this.onChangeTab} key={tab.id} />;
})}
2018-10-27 03:14:38 -05:00
<div className="panel-editor__aside-actions">
<a className="btn btn-link" onClick={this.onClose}>
<i className="fa fa-check" /> Close
</a>
<a className="btn btn-link" onClick={this.onClose}>
<i className="fa fa-trash" /> Discard
</a>
<a className="btn btn-link" onClick={this.onClose}>
<i className="fa fa-copy" /> Save as master type
</a>
2018-10-26 06:20:10 -05:00
</div>
2018-06-19 07:51:57 -05:00
</div>
2018-10-26 06:20:10 -05:00
<div className="panel-editor__content">
2018-10-26 09:29:08 -05:00
<CustomScrollbar>
{activeTab === 'queries' && this.renderQueriesTab()}
{activeTab === 'visualization' && this.renderVizTab()}
</CustomScrollbar>
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({
2018-10-27 03:14:38 -05:00
'panel-editor__aside-item': true,
active: activeTab === tab.id,
});
return (
2018-10-26 06:20:10 -05:00
<a className={tabClasses} onClick={() => onClick(tab)}>
<i className={tab.icon} /> {tab.text}
</a>
);
}