2018-11-05 10:46:09 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
2018-07-08 09:39:25 -05:00
|
|
|
import classNames from 'classnames';
|
2018-11-05 10:46:09 -06:00
|
|
|
|
2018-06-26 14:07:41 -05:00
|
|
|
import { QueriesTab } from './QueriesTab';
|
2018-11-09 06:17:41 -06:00
|
|
|
import { VisualizationTab } from './VisualizationTab';
|
2018-11-14 10:57:37 -06:00
|
|
|
import { GeneralTab } from './GeneralTab';
|
2018-11-20 10:09:47 -06:00
|
|
|
import { AlertTab } from './AlertTab';
|
2018-11-05 10:46:09 -06:00
|
|
|
|
2018-11-20 10:09:47 -06:00
|
|
|
import config from 'app/core/config';
|
2018-11-07 02:50:17 -06:00
|
|
|
import { store } from 'app/store/store';
|
2018-09-18 08:32:06 -05:00
|
|
|
import { updateLocation } from 'app/core/actions';
|
2018-11-15 02:46:21 -06:00
|
|
|
import { AngularComponent } from 'app/core/services/AngularLoader';
|
2018-06-19 07:51:57 -05:00
|
|
|
|
2018-11-05 10:46:09 -06:00
|
|
|
import { PanelModel } from '../panel_model';
|
|
|
|
import { DashboardModel } from '../dashboard_model';
|
2018-11-06 11:14:29 -06:00
|
|
|
import { PanelPlugin } from 'app/types/plugins';
|
2018-11-05 10:46:09 -06:00
|
|
|
|
2018-06-19 07:51:57 -05:00
|
|
|
interface PanelEditorProps {
|
|
|
|
panel: PanelModel;
|
|
|
|
dashboard: DashboardModel;
|
2018-11-06 11:14:29 -06:00
|
|
|
plugin: PanelPlugin;
|
2018-11-15 02:46:21 -06:00
|
|
|
angularPanel?: AngularComponent;
|
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;
|
|
|
|
}
|
2018-06-19 14:25:57 -05:00
|
|
|
|
2018-11-05 10:46:09 -06:00
|
|
|
export class PanelEditor extends PureComponent<PanelEditorProps> {
|
2018-06-19 14:25:57 -05:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
2018-06-26 14:07:41 -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-11-05 10:46:09 -06:00
|
|
|
this.forceUpdate();
|
2018-06-26 14:07:41 -05:00
|
|
|
};
|
2018-06-26 09:45:42 -05:00
|
|
|
|
2018-11-20 10:09:47 -06:00
|
|
|
renderCurrentTab(activeTab: string) {
|
2018-11-15 02:46:21 -06:00
|
|
|
const { panel, dashboard, onTypeChanged, plugin, angularPanel } = this.props;
|
2018-11-20 10:09:47 -06:00
|
|
|
|
|
|
|
switch (activeTab) {
|
|
|
|
case 'general':
|
|
|
|
return <GeneralTab panel={panel} />;
|
|
|
|
case 'queries':
|
|
|
|
return <QueriesTab panel={panel} dashboard={dashboard} />;
|
|
|
|
case 'alert':
|
|
|
|
return <AlertTab angularPanel={angularPanel} />;
|
|
|
|
case 'visualization':
|
|
|
|
return (
|
|
|
|
<VisualizationTab
|
|
|
|
panel={panel}
|
|
|
|
dashboard={dashboard}
|
|
|
|
plugin={plugin}
|
|
|
|
onTypeChanged={onTypeChanged}
|
|
|
|
angularPanel={angularPanel}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { plugin } = this.props;
|
|
|
|
const activeTab = store.getState().location.query.tab || 'queries';
|
|
|
|
|
2018-11-22 01:46:54 -06:00
|
|
|
const tabs = [{ id: 'queries', text: 'Queries' }, { id: 'visualization', text: 'Visualization' }];
|
2018-11-20 10:09:47 -06:00
|
|
|
|
|
|
|
if (config.alertingEnabled && plugin.id === 'graph') {
|
|
|
|
tabs.push({
|
|
|
|
id: 'alert',
|
|
|
|
text: 'Alert',
|
|
|
|
});
|
|
|
|
}
|
2018-06-26 14:07:41 -05:00
|
|
|
|
2018-06-19 07:51:57 -05:00
|
|
|
return (
|
2018-10-26 06:20:10 -05:00
|
|
|
<div className="panel-editor-container__editor">
|
2018-11-22 01:46:54 -06:00
|
|
|
{
|
|
|
|
// <div className="panel-editor-resizer">
|
|
|
|
// <div className="panel-editor-resizer__handle">
|
|
|
|
// <div className="panel-editor-resizer__handle-dots" />
|
|
|
|
// </div>
|
|
|
|
// </div>
|
|
|
|
}
|
2018-11-08 05:25:22 -06:00
|
|
|
|
2018-11-09 06:17:41 -06:00
|
|
|
<div className="panel-editor-tabs">
|
2018-11-22 01:46:54 -06:00
|
|
|
{tabs.map(tab => {
|
|
|
|
return <TabItem tab={tab} activeTab={activeTab} onClick={this.onChangeTab} key={tab.id} />;
|
|
|
|
})}
|
2018-06-19 07:51:57 -05:00
|
|
|
</div>
|
2018-11-20 10:09:47 -06:00
|
|
|
{this.renderCurrentTab(activeTab)}
|
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({
|
2018-11-21 13:32:04 -06:00
|
|
|
'panel-editor-tabs__link': true,
|
2018-06-26 14:07:41 -05:00
|
|
|
active: activeTab === tab.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
2018-11-21 13:32:04 -06:00
|
|
|
<div className="panel-editor-tabs__item" onClick={() => onClick(tab)}>
|
2018-11-09 06:17:41 -06:00
|
|
|
<a className={tabClasses}>
|
2018-11-21 13:32:04 -06:00
|
|
|
<img src={`public/img/panel-tabs/${tab.id}${activeTab === tab.id ? '-selected' : ''}.svg`} />
|
2018-06-26 14:07:41 -05:00
|
|
|
</a>
|
2018-11-21 13:32:04 -06:00
|
|
|
</div>
|
2018-06-26 14:07:41 -05:00
|
|
|
);
|
|
|
|
}
|