PanelEvents: Refactors and removes unnecessary events, fixes panel editor update issue when panel options change (#29414)

* Refactoring some events to new events

* More refactoring

* Make panel editor subscribe to new event

* Minor change and comment added

* Updated snapshot
This commit is contained in:
Torkel Ödegaard
2020-11-26 15:14:57 +01:00
committed by GitHub
parent 26e3b61f92
commit bba1208c3d
8 changed files with 87 additions and 156 deletions

View File

@@ -5,12 +5,10 @@ import { getTemplateSrv } from '@grafana/runtime';
import { getNextRefIdChar } from 'app/core/utils/query';
// Types
import {
AppEvent,
DataConfigSource,
DataLink,
DataQuery,
DataTransformerConfig,
eventFactory,
FieldColorConfigSettings,
FieldColorModeId,
fieldColorModeRegistry,
@@ -29,10 +27,7 @@ import { EDIT_PANEL_ID } from 'app/core/constants';
import config from 'app/core/config';
import { PanelQueryRunner } from './PanelQueryRunner';
import { getDatasourceSrv } from '../../plugins/datasource_srv';
import { CoreEvents } from '../../../types';
export const panelAdded = eventFactory<PanelModel | undefined>('panel-added');
export const panelRemoved = eventFactory<PanelModel | undefined>('panel-removed');
import { PanelOptionsChangedEvent, PanelQueriesChangedEvent, PanelTransformationsChangedEvent } from 'app/types/events';
export interface GridPos {
x: number;
@@ -219,6 +214,7 @@ export class PanelModel implements DataConfigSource {
updateOptions(options: object) {
this.options = options;
this.events.publish(new PanelOptionsChangedEvent());
this.render();
}
@@ -291,10 +287,6 @@ export class PanelModel implements DataConfigSource {
}
}
initialized() {
this.events.emit(PanelEvents.panelInitialized);
}
private getOptionsToRemember() {
return Object.keys(this).reduce((acc, property) => {
if (notPersistedProperties[property] || mustKeepProps[property]) {
@@ -418,7 +410,7 @@ export class PanelModel implements DataConfigSource {
}
updateQueries(queries: DataQuery[]) {
this.events.emit(CoreEvents.queryChanged);
this.events.publish(new PanelQueriesChangedEvent());
this.targets = queries;
}
@@ -501,9 +493,9 @@ export class PanelModel implements DataConfigSource {
}
setTransformations(transformations: DataTransformerConfig[]) {
this.events.emit(CoreEvents.transformationChanged);
this.transformations = transformations;
this.resendLastResult();
this.events.publish(new PanelTransformationsChangedEvent());
}
replaceVariables(value: string, extraVars?: ScopedVars, format?: string) {
@@ -529,14 +521,6 @@ export class PanelModel implements DataConfigSource {
getSavedId(): number {
return this.editSourceId ?? this.id;
}
on<T>(event: AppEvent<T>, callback: (payload?: T) => void) {
this.events.on(event, callback);
}
off<T>(event: AppEvent<T>, callback: (payload?: T) => void) {
this.events.off(event, callback);
}
}
function applyFieldConfigDefaults(fieldConfig: FieldConfigSource, defaults: FieldConfigSource): FieldConfigSource {