mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user