Events: Migrate old timeRangeUpdate event to new event system to get rid of console.log warning (#35767)

* Events: Migrate old timeRangeUpdate event to new event system to get rid of console.log warning

* Review feedback
This commit is contained in:
Torkel Ödegaard
2021-06-16 15:44:50 +02:00
committed by GitHub
parent ef59020f3d
commit cfae7d8b97
6 changed files with 25 additions and 41 deletions

View File

@@ -5,7 +5,6 @@ import { css } from '@emotion/css';
// Types
import { DashboardModel } from '../../state';
import { CoreEvents } from 'app/types';
// Components
import { defaultIntervals, RefreshPicker, stylesFactory } from '@grafana/ui';
@@ -14,7 +13,8 @@ import { TimePickerWithHistory } from 'app/core/components/TimePicker/TimePicker
// Utils & Services
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { appEvents } from 'app/core/core';
import { ShiftTimeEvent, ShiftTimeEventPayload, ZoomOutEvent } from '../../../../types/events';
import { ShiftTimeEvent, ShiftTimeEventPayload, TimeRangeUpdatedEvent, ZoomOutEvent } from '../../../../types/events';
import { Unsubscribable } from 'rxjs';
export interface Props {
dashboard: DashboardModel;
@@ -22,21 +22,16 @@ export interface Props {
}
export class DashNavTimeControls extends Component<Props> {
private sub?: Unsubscribable;
componentDidMount() {
// Only reason for this is that sometimes time updates can happen via redux location changes
// and this happens before timeSrv has had chance to update state (as it listens to angular route-updated)
// This can be removed after timeSrv listens redux location
this.props.dashboard.on(CoreEvents.timeRangeUpdated, this.triggerForceUpdate);
this.sub = this.props.dashboard.events.subscribe(TimeRangeUpdatedEvent, () => this.forceUpdate());
}
componentWillUnmount() {
this.props.dashboard.off(CoreEvents.timeRangeUpdated, this.triggerForceUpdate);
this.sub?.unsubscribe();
}
triggerForceUpdate = () => {
this.forceUpdate();
};
onChangeRefreshInterval = (interval: string) => {
getTimeSrv().setAutoRefresh(interval);
this.forceUpdate();