mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
LibraryPanels: Don't include ScopedVars with persisted model (#67843)
Closes #65518
This commit is contained in:
@@ -64,7 +64,7 @@ export async function getLibraryPanel(uid: string, isHandled = false): Promise<L
|
||||
schemaVersion: 35, // should be saved in the library panel
|
||||
panels: [result.model],
|
||||
});
|
||||
const model = dash.panels[0].getSaveModel(); // migrated panel
|
||||
const { scopedVars, ...model } = dash.panels[0].getSaveModel(); // migrated panel
|
||||
dash.destroy(); // kill event listeners
|
||||
return {
|
||||
...result,
|
||||
|
||||
@@ -21,7 +21,7 @@ export async function saveAndRefreshLibraryPanel(panel: PanelModel, folderUid: s
|
||||
}
|
||||
|
||||
function toPanelSaveModel(panel: PanelModel): any {
|
||||
let panelSaveModel = panel.getSaveModel();
|
||||
let { scopedVars, ...panelSaveModel } = panel.getSaveModel();
|
||||
panelSaveModel = {
|
||||
libraryPanel: {
|
||||
name: panel.title,
|
||||
|
||||
@@ -5,14 +5,14 @@ import { LibraryElementDTO } from 'app/features/library-panels/types';
|
||||
import { getPanelPluginNotFound } from 'app/features/panel/components/PanelPluginError';
|
||||
import { loadPanelPlugin } from 'app/features/plugins/admin/state/actions';
|
||||
import { ThunkResult } from 'app/types';
|
||||
import { PanelOptionsChangedEvent, PanelQueriesChangedEvent } from 'app/types/events';
|
||||
import { DashboardPanelsChangedEvent, PanelOptionsChangedEvent, PanelQueriesChangedEvent } from 'app/types/events';
|
||||
|
||||
import { changePanelKey, panelModelAndPluginReady, removePanel } from './reducers';
|
||||
|
||||
export function initPanelState(panel: PanelModel): ThunkResult<void> {
|
||||
export function initPanelState(panel: PanelModel): ThunkResult<Promise<void>> {
|
||||
return async (dispatch, getStore) => {
|
||||
if (panel.libraryPanel?.uid && !('model' in panel.libraryPanel)) {
|
||||
// this will call init with a loaded libary panel if it loads succesfully
|
||||
// this will call init with a loaded library panel if it loads succesfully
|
||||
dispatch(loadLibraryPanelAndUpdate(panel));
|
||||
return;
|
||||
}
|
||||
@@ -142,12 +142,20 @@ export function changeToLibraryPanel(panel: PanelModel, libraryPanel: LibraryEle
|
||||
}
|
||||
|
||||
export function loadLibraryPanelAndUpdate(panel: PanelModel): ThunkResult<void> {
|
||||
return async (dispatch) => {
|
||||
return async (dispatch, getStore) => {
|
||||
const uid = panel.libraryPanel!.uid!;
|
||||
try {
|
||||
const libPanel = await getLibraryPanel(uid, true);
|
||||
panel.initLibraryPanel(libPanel);
|
||||
dispatch(initPanelState(panel));
|
||||
await dispatch(initPanelState(panel));
|
||||
const dashboard = getStore().dashboard.getModel();
|
||||
|
||||
if (panel.repeat && dashboard) {
|
||||
const panelIndex = dashboard.panels.findIndex((p) => p.id === panel.id);
|
||||
dashboard.repeatPanel(panel, panelIndex);
|
||||
dashboard.sortPanelsByGridPos();
|
||||
dashboard.events.publish(new DashboardPanelsChangedEvent());
|
||||
}
|
||||
} catch (ex) {
|
||||
console.log('ERROR: ', ex);
|
||||
dispatch(
|
||||
|
||||
Reference in New Issue
Block a user