|
|
|
@ -511,14 +511,14 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> { |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public createLibraryPanel(gridItemToReplace: DashboardGridItem, libPanel: LibraryPanel) { |
|
|
|
|
public createLibraryPanel(panelToReplace: VizPanel, libPanel: LibraryPanel) { |
|
|
|
|
const layout = this.state.body; |
|
|
|
|
|
|
|
|
|
if (!(layout instanceof SceneGridLayout)) { |
|
|
|
|
throw new Error('Trying to add a panel in a layout that is not SceneGridLayout'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const panelKey = gridItemToReplace?.state.body.state.key; |
|
|
|
|
const panelKey = panelToReplace.state.key; |
|
|
|
|
|
|
|
|
|
const body = new LibraryVizPanel({ |
|
|
|
|
title: libPanel.model?.title ?? 'Panel', |
|
|
|
@ -527,35 +527,13 @@ export class DashboardScene extends SceneObjectBase<DashboardSceneState> { |
|
|
|
|
panelKey: panelKey ?? getVizPanelKeyForPanelId(dashboardSceneGraph.getNextPanelId(this)), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const newGridItem = gridItemToReplace.clone({ body }); |
|
|
|
|
const gridItem = panelToReplace.parent; |
|
|
|
|
|
|
|
|
|
if (!(newGridItem instanceof DashboardGridItem)) { |
|
|
|
|
throw new Error('Could not build library viz panel griditem'); |
|
|
|
|
if (!(gridItem instanceof DashboardGridItem)) { |
|
|
|
|
throw new Error("Trying to replace a panel that doesn't have a parent grid item"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const key = gridItemToReplace?.state.key; |
|
|
|
|
|
|
|
|
|
if (gridItemToReplace.parent instanceof SceneGridRow) { |
|
|
|
|
const children = gridItemToReplace.parent.state.children.map((rowChild) => { |
|
|
|
|
if (rowChild.state.key === key) { |
|
|
|
|
return newGridItem; |
|
|
|
|
} |
|
|
|
|
return rowChild; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
gridItemToReplace.parent.setState({ children }); |
|
|
|
|
layout.forceRender(); |
|
|
|
|
} else { |
|
|
|
|
// Find the grid item in the layout and replace it
|
|
|
|
|
const children = layout.state.children.map((child) => { |
|
|
|
|
if (child.state.key === key) { |
|
|
|
|
return newGridItem; |
|
|
|
|
} |
|
|
|
|
return child; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
layout.setState({ children }); |
|
|
|
|
} |
|
|
|
|
gridItem.setState({ body }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public duplicatePanel(vizPanel: VizPanel) { |
|
|
|
|