2020-02-11 07:57:16 -06:00
|
|
|
import { PanelModel, DashboardModel } from '../../../state';
|
|
|
|
import { PanelData } from '@grafana/data';
|
|
|
|
import { ThunkResult } from 'app/types';
|
2020-02-12 11:36:32 -06:00
|
|
|
import { setEditorPanelData, updateEditorInitState, closeCompleted } from './reducers';
|
2020-02-11 07:57:16 -06:00
|
|
|
|
|
|
|
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();
|
2020-02-12 11:36:32 -06:00
|
|
|
|
|
|
|
dispatch(closeCompleted());
|
2020-02-11 07:57:16 -06:00
|
|
|
};
|
|
|
|
}
|