mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
|
import { PanelModel, DashboardModel } from '../../../state';
|
||
|
import { PanelData } from '@grafana/data';
|
||
|
import { ThunkResult } from 'app/types';
|
||
|
import { setEditorPanelData, updateEditorInitState } from './reducers';
|
||
|
|
||
|
export function initPanelEditor(sourcePanel: PanelModel, dashboard: DashboardModel): ThunkResult<void> {
|
||
|
return dispatch => {
|
||
|
const panel = dashboard.initPanelEditor(sourcePanel);
|
||
|
|
||
|
const queryRunner = panel.getQueryRunner();
|
||
|
const querySubscription = queryRunner.getData().subscribe({
|
||
|
next: (data: PanelData) => dispatch(setEditorPanelData(data)),
|
||
|
});
|
||
|
|
||
|
dispatch(
|
||
|
updateEditorInitState({
|
||
|
panel,
|
||
|
sourcePanel,
|
||
|
querySubscription,
|
||
|
})
|
||
|
);
|
||
|
};
|
||
|
}
|
||
|
|
||
|
export function panelEditorCleanUp(): ThunkResult<void> {
|
||
|
return (dispatch, getStore) => {
|
||
|
const dashboard = getStore().dashboard.getModel();
|
||
|
const { getPanel, querySubscription, shouldDiscardChanges } = getStore().panelEditorNew;
|
||
|
|
||
|
if (!shouldDiscardChanges) {
|
||
|
dashboard.updatePanel(getPanel());
|
||
|
}
|
||
|
|
||
|
dashboard.exitPanelEditor();
|
||
|
querySubscription.unsubscribe();
|
||
|
};
|
||
|
}
|