|
|
@@ -5,6 +5,8 @@ import config from 'app/core/config';
|
|
|
import { PanelModel } from '../panel_model';
|
|
|
import { PanelContainer } from './PanelContainer';
|
|
|
import ScrollBar from 'app/core/components/ScrollBar/ScrollBar';
|
|
|
+import store from 'app/core/store';
|
|
|
+import { LS_PANEL_COPY_KEY } from 'app/core/constants';
|
|
|
|
|
|
export interface AddPanelPanelProps {
|
|
|
panel: PanelModel;
|
|
|
@@ -14,7 +16,6 @@ export interface AddPanelPanelProps {
|
|
|
export interface AddPanelPanelState {
|
|
|
filter: string;
|
|
|
panelPlugins: any[];
|
|
|
- clipboardPanel: any;
|
|
|
}
|
|
|
|
|
|
export class AddPanelPanel extends React.Component<AddPanelPanelProps, AddPanelPanelState> {
|
|
|
@@ -23,12 +24,8 @@ export class AddPanelPanel extends React.Component<AddPanelPanelProps, AddPanelP
|
|
|
|
|
|
this.state = {
|
|
|
panelPlugins: this.getPanelPlugins(),
|
|
|
- clipboardPanel: this.getClipboardPanel(),
|
|
|
filter: '',
|
|
|
};
|
|
|
-
|
|
|
- this.onPanelSelected = this.onPanelSelected.bind(this);
|
|
|
- this.onClipboardPanelSelected = this.onClipboardPanelSelected.bind(this);
|
|
|
}
|
|
|
|
|
|
getPanelPlugins() {
|
|
|
@@ -40,15 +37,24 @@ export class AddPanelPanel extends React.Component<AddPanelPanelProps, AddPanelP
|
|
|
// add special row type
|
|
|
panels.push({ id: 'row', name: 'Row', sort: 8, info: { logos: { small: 'public/img/icn-row.svg' } } });
|
|
|
|
|
|
+ let copiedPanelJson = store.get(LS_PANEL_COPY_KEY);
|
|
|
+ if (copiedPanelJson) {
|
|
|
+ let copiedPanel = JSON.parse(copiedPanelJson);
|
|
|
+ let pluginInfo = _.find(panels, { id: copiedPanel.type });
|
|
|
+ if (pluginInfo) {
|
|
|
+ let pluginCopy = _.cloneDeep(pluginInfo);
|
|
|
+ pluginCopy.name = copiedPanel.title;
|
|
|
+ pluginCopy.sort = -1;
|
|
|
+ pluginCopy.defaults = copiedPanel;
|
|
|
+ panels.push(pluginCopy);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// add sort by sort property
|
|
|
return _.sortBy(panels, 'sort');
|
|
|
}
|
|
|
|
|
|
- getClipboardPanel() {
|
|
|
- return this.props.getPanelContainer().getClipboardPanel();
|
|
|
- }
|
|
|
-
|
|
|
- onPanelSelected(panelPluginInfo) {
|
|
|
+ onAddPanel = panelPluginInfo => {
|
|
|
const panelContainer = this.props.getPanelContainer();
|
|
|
const dashboard = panelContainer.getDashboard();
|
|
|
const { gridPos } = this.props.panel;
|
|
|
@@ -64,39 +70,23 @@ export class AddPanelPanel extends React.Component<AddPanelPanelProps, AddPanelP
|
|
|
newPanel.gridPos = { x: 0, y: 0 };
|
|
|
}
|
|
|
|
|
|
- dashboard.addPanel(newPanel);
|
|
|
- dashboard.removePanel(this.props.panel);
|
|
|
- }
|
|
|
-
|
|
|
- onClipboardPanelSelected(panel) {
|
|
|
- const panelContainer = this.props.getPanelContainer();
|
|
|
- const dashboard = panelContainer.getDashboard();
|
|
|
-
|
|
|
- const { gridPos } = this.props.panel;
|
|
|
- panel.gridPos.x = gridPos.x;
|
|
|
- panel.gridPos.y = gridPos.y;
|
|
|
+ // apply panel template / defaults
|
|
|
+ if (panelPluginInfo.defaults) {
|
|
|
+ _.defaults(newPanel, panelPluginInfo.defaults);
|
|
|
+ newPanel.gridPos.w = panelPluginInfo.defaults.gridPos.w;
|
|
|
+ newPanel.gridPos.h = panelPluginInfo.defaults.gridPos.h;
|
|
|
+ newPanel.title = panelPluginInfo.defaults.title;
|
|
|
+ store.delete(LS_PANEL_COPY_KEY);
|
|
|
+ }
|
|
|
|
|
|
- dashboard.addPanel(panel);
|
|
|
+ dashboard.addPanel(newPanel);
|
|
|
dashboard.removePanel(this.props.panel);
|
|
|
- }
|
|
|
-
|
|
|
- renderClipboardPanel(copiedPanel) {
|
|
|
- const panel = copiedPanel.panel;
|
|
|
- const title = `Paste copied panel '${panel.title}' from '${copiedPanel.dashboard}'`;
|
|
|
-
|
|
|
- return (
|
|
|
- <div className="add-panel__item" onClick={() => this.onClipboardPanelSelected(panel)} title={title}>
|
|
|
- <div className="add-panel__item-icon">
|
|
|
- <i className="fa fa-paste fa-2x fa-fw" />
|
|
|
- </div>
|
|
|
- <div className="add-panel__item-name">Paste copied panel</div>
|
|
|
- </div>
|
|
|
- );
|
|
|
- }
|
|
|
+ };
|
|
|
|
|
|
- renderPanelItem(panel) {
|
|
|
+ renderPanelItem(panel, index) {
|
|
|
+ console.log('render panel', index);
|
|
|
return (
|
|
|
- <div key={panel.id} className="add-panel__item" onClick={() => this.onPanelSelected(panel)} title={panel.name}>
|
|
|
+ <div key={index} className="add-panel__item" onClick={() => this.onAddPanel(panel)} title={panel.name}>
|
|
|
<img className="add-panel__item-img" src={panel.info.logos.small} />
|
|
|
<div className="add-panel__item-name">{panel.name}</div>
|
|
|
</div>
|
|
|
@@ -113,7 +103,6 @@ export class AddPanelPanel extends React.Component<AddPanelPanelProps, AddPanelP
|
|
|
<span className="add-panel__sub-title">Select a visualization</span>
|
|
|
</div>
|
|
|
<ScrollBar className="add-panel__items">
|
|
|
- {this.state.clipboardPanel && this.renderClipboardPanel(this.state.clipboardPanel)}
|
|
|
{this.state.panelPlugins.map(this.renderPanelItem.bind(this))}
|
|
|
</ScrollBar>
|
|
|
</div>
|