mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Annotations: Fixing recursive angular watch loop (#33090)
This commit is contained in:
parent
58380368af
commit
76034ad1cb
@ -30,7 +30,9 @@ export class AngularEditorLoader extends React.PureComponent<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.angularComponent && prevProps.annotation !== this.props.annotation) {
|
if (this.angularComponent && prevProps.annotation !== this.props.annotation) {
|
||||||
this.angularComponent.getScope().ctrl.currentAnnotation = this.props.annotation;
|
const scope = this.angularComponent.getScope();
|
||||||
|
scope.ctrl.ignoreNextWatcherFiring = true;
|
||||||
|
scope.ctrl.currentAnnotation = this.props.annotation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,12 +47,19 @@ export class AngularEditorLoader extends React.PureComponent<Props> {
|
|||||||
ctrl: {
|
ctrl: {
|
||||||
currentDatasource: this.props.datasource,
|
currentDatasource: this.props.datasource,
|
||||||
currentAnnotation: this.props.annotation,
|
currentAnnotation: this.props.annotation,
|
||||||
|
ignoreNextWatcherFiring: false,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
this.angularComponent = loader.load(this.ref, scopeProps, template);
|
this.angularComponent = loader.load(this.ref, scopeProps, template);
|
||||||
this.angularComponent.digest();
|
this.angularComponent.digest();
|
||||||
this.angularComponent.getScope().$watch(() => {
|
this.angularComponent.getScope().$watch(() => {
|
||||||
|
// To avoid recursive loop when the annotation is updated from outside angular in componentDidUpdate
|
||||||
|
if (scopeProps.ctrl.ignoreNextWatcherFiring) {
|
||||||
|
scopeProps.ctrl.ignoreNextWatcherFiring = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.props.onChange({
|
this.props.onChange({
|
||||||
...scopeProps.ctrl.currentAnnotation,
|
...scopeProps.ctrl.currentAnnotation,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user