The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/dashboard/dashgrid/PanelEditor.tsx

148 lines
3.9 KiB

import React, { PureComponent } from 'react';
import classNames from 'classnames';
7 years ago
import { QueriesTab } from './QueriesTab';
import { VizTypePicker } from './VizTypePicker';
7 years ago
import CustomScrollbar from 'app/core/components/CustomScrollbar/CustomScrollbar';
import { store } from 'app/store/configureStore';
7 years ago
import { updateLocation } from 'app/core/actions';
import { PanelModel } from '../panel_model';
import { DashboardModel } from '../dashboard_model';
import { PanelPlugin } from 'app/types/plugins';
interface PanelEditorProps {
panel: PanelModel;
dashboard: DashboardModel;
plugin: PanelPlugin;
onTypeChanged: (newType: PanelPlugin) => void;
}
interface PanelEditorTab {
id: string;
text: string;
icon: string;
}
export class PanelEditor extends PureComponent<PanelEditorProps> {
8 years ago
tabs: PanelEditorTab[];
constructor(props) {
super(props);
8 years ago
this.tabs = [
{ id: 'queries', text: 'Queries', icon: 'fa fa-database' },
{ id: 'visualization', text: 'Visualization', icon: 'fa fa-line-chart' },
7 years ago
{ id: 'alert', text: 'Alert', icon: 'gicon gicon-alert' },
8 years ago
];
}
renderQueriesTab() {
return <QueriesTab panel={this.props.panel} dashboard={this.props.dashboard} />;
}
renderPanelOptions() {
const { plugin, panel } = this.props;
const { PanelOptionsComponent } = plugin.exports;
if (PanelOptionsComponent) {
return <PanelOptionsComponent options={panel.getOptions()} onChange={this.onPanelOptionsChanged} />;
} else {
return <p>Visualization has no options</p>;
}
}
onPanelOptionsChanged = (options: any) => {
this.props.panel.updateOptions(options);
this.forceUpdate();
};
renderVizTab() {
return (
<div className="viz-editor">
<VizTypePicker current={this.props.plugin} onTypeChanged={this.props.onTypeChanged} />
7 years ago
{this.renderPanelOptions()}
</div>
);
}
onChangeTab = (tab: PanelEditorTab) => {
7 years ago
store.dispatch(
updateLocation({
query: { tab: tab.id },
partial: true,
7 years ago
})
);
this.forceUpdate();
};
8 years ago
onClose = () => {
store.dispatch(
updateLocation({
7 years ago
query: { tab: null, fullscreen: null, edit: null },
partial: true,
})
);
};
render() {
7 years ago
const { location } = store.getState();
const activeTab = location.query.tab || 'queries';
return (
<div className="panel-editor-container__editor">
7 years ago
<div className="panel-editor-resizer">
<div className="panel-editor-resizer__handle">
<div className="panel-editor-resizer__handle-dots" />
</div>
</div>
<div className="panel-editor__aside">
<h2 className="panel-editor__aside-header">
<i className="fa fa-cog" />
Edit Panel
</h2>
{this.tabs.map(tab => {
return <TabItem tab={tab} activeTab={activeTab} onClick={this.onChangeTab} key={tab.id} />;
})}
<div className="panel-editor__aside-actions">
7 years ago
<button className="btn btn-secondary" onClick={this.onClose}>
Back to dashboard
</button>
<button className="btn btn-inverse" onClick={this.onClose}>
Discard changes
</button>
</div>
</div>
<div className="panel-editor__content">
7 years ago
<CustomScrollbar>
{activeTab === 'queries' && this.renderQueriesTab()}
{activeTab === 'visualization' && this.renderVizTab()}
</CustomScrollbar>
</div>
</div>
);
}
}
interface TabItemParams {
tab: PanelEditorTab;
activeTab: string;
onClick: (tab: PanelEditorTab) => void;
}
function TabItem({ tab, activeTab, onClick }: TabItemParams) {
const tabClasses = classNames({
'panel-editor__aside-item': true,
active: activeTab === tab.id,
});
return (
<a className={tabClasses} onClick={() => onClick(tab)}>
<i className={tab.icon} /> {tab.text}
</a>
);
}