Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibraryPanels: Don't include ScopedVars with persisted model #67843

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/app/features/library-panels/state/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getSaveModel should never include scopedVars, it should be safe to add scopedVars to non persisted props in PanelModel?

It is cleaned as part of DashboardModel.getPanelSaveModels but maybe it's better to do that in PanelModel ?

dash.destroy(); // kill event listeners
return {
...result,
Expand Down
2 changes: 1 addition & 1 deletion public/app/features/library-panels/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 13 additions & 5 deletions public/app/features/panel/state/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down