diff --git a/public/app/features/library-panels/state/api.ts b/public/app/features/library-panels/state/api.ts index 7bb8f159ceb..27fca15ef04 100644 --- a/public/app/features/library-panels/state/api.ts +++ b/public/app/features/library-panels/state/api.ts @@ -64,7 +64,7 @@ export async function getLibraryPanel(uid: string, isHandled = false): Promise { +export function initPanelState(panel: PanelModel): ThunkResult> { 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 { - 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(