mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Library Panels: Change unsaved change detection logic (#31477)
* Library Panels: Change unsaved change detection logic Change logic from diffing panel models to setting dirty flag
This commit is contained in:
@@ -36,6 +36,7 @@ import {
|
||||
isStandardFieldProp,
|
||||
restoreCustomOverrideRules,
|
||||
} from './getPanelOptionsWithDefaults';
|
||||
import { QueryGroupOptions } from 'app/types';
|
||||
import { PanelModelLibraryPanel } from '../../library-panels/types';
|
||||
|
||||
export interface GridPos {
|
||||
@@ -57,6 +58,7 @@ const notPersistedProperties: { [str: string]: boolean } = {
|
||||
queryRunner: true,
|
||||
replaceVariables: true,
|
||||
editSourceId: true,
|
||||
hasChanged: true,
|
||||
};
|
||||
|
||||
// For angular panels we need to clean up properties when changing type
|
||||
@@ -157,6 +159,7 @@ export class PanelModel implements DataConfigSource {
|
||||
isViewing: boolean;
|
||||
isEditing: boolean;
|
||||
isInView: boolean;
|
||||
hasChanged: boolean;
|
||||
|
||||
hasRefreshed: boolean;
|
||||
events: EventBus;
|
||||
@@ -228,12 +231,14 @@ export class PanelModel implements DataConfigSource {
|
||||
|
||||
updateOptions(options: object) {
|
||||
this.options = options;
|
||||
this.hasChanged = true;
|
||||
this.events.publish(new PanelOptionsChangedEvent());
|
||||
this.render();
|
||||
}
|
||||
|
||||
updateFieldConfig(config: FieldConfigSource) {
|
||||
this.fieldConfig = config;
|
||||
this.hasChanged = true;
|
||||
this.events.publish(new PanelOptionsChangedEvent());
|
||||
|
||||
this.resendLastResult();
|
||||
@@ -392,6 +397,7 @@ export class PanelModel implements DataConfigSource {
|
||||
// switch
|
||||
this.type = pluginId;
|
||||
this.plugin = newPlugin;
|
||||
this.hasChanged = true;
|
||||
|
||||
// For some reason I need to rebind replace variables here, otherwise the viz repeater does not work
|
||||
this.replaceVariables = this.replaceVariables.bind(this);
|
||||
@@ -402,20 +408,30 @@ export class PanelModel implements DataConfigSource {
|
||||
}
|
||||
}
|
||||
|
||||
updateQueries(queries: DataQuery[]) {
|
||||
updateQueries(options: QueryGroupOptions) {
|
||||
this.datasource = options.dataSource.default ? null : options.dataSource.name!;
|
||||
this.timeFrom = options.timeRange?.from;
|
||||
this.timeShift = options.timeRange?.shift;
|
||||
this.hideTimeOverride = options.timeRange?.hide;
|
||||
this.interval = options.minInterval;
|
||||
this.maxDataPoints = options.maxDataPoints;
|
||||
this.targets = options.queries;
|
||||
this.hasChanged = true;
|
||||
|
||||
this.events.publish(new PanelQueriesChangedEvent());
|
||||
this.targets = queries;
|
||||
}
|
||||
|
||||
addQuery(query?: Partial<DataQuery>) {
|
||||
query = query || { refId: 'A' };
|
||||
query.refId = getNextRefIdChar(this.targets);
|
||||
this.targets.push(query as DataQuery);
|
||||
this.hasChanged = true;
|
||||
}
|
||||
|
||||
changeQuery(query: DataQuery, index: number) {
|
||||
// ensure refId is maintained
|
||||
query.refId = this.targets[index].refId;
|
||||
this.hasChanged = true;
|
||||
|
||||
// update query in array
|
||||
this.targets = this.targets.map((item, itemIndex) => {
|
||||
@@ -486,9 +502,15 @@ export class PanelModel implements DataConfigSource {
|
||||
setTransformations(transformations: DataTransformerConfig[]) {
|
||||
this.transformations = transformations;
|
||||
this.resendLastResult();
|
||||
this.hasChanged = true;
|
||||
this.events.publish(new PanelTransformationsChangedEvent());
|
||||
}
|
||||
|
||||
setProperty(key: keyof this, value: any) {
|
||||
this[key] = value;
|
||||
this.hasChanged = true;
|
||||
}
|
||||
|
||||
replaceVariables(value: string, extraVars: ScopedVars | undefined, format?: string | Function) {
|
||||
let vars = this.scopedVars;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user