DashNavTimeControls.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Libaries
  2. import React, { Component } from 'react';
  3. // Types
  4. import { DashboardModel } from '../../state';
  5. import { LocationState } from 'app/types';
  6. // State
  7. import { updateLocation } from 'app/core/actions';
  8. // Components
  9. import { RefreshPicker } from '@grafana/ui';
  10. // Utils & Services
  11. import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv';
  12. export interface Props {
  13. dashboard: DashboardModel;
  14. updateLocation: typeof updateLocation;
  15. location: LocationState;
  16. }
  17. export class DashNavTimeControls extends Component<Props> {
  18. timeSrv: TimeSrv = getTimeSrv();
  19. get refreshParamInUrl(): string {
  20. return this.props.location.query.refresh as string;
  21. }
  22. onChangeRefreshInterval = (interval: string) => {
  23. this.timeSrv.setAutoRefresh(interval);
  24. this.forceUpdate();
  25. };
  26. onRefresh = () => {
  27. this.timeSrv.refreshDashboard();
  28. return Promise.resolve();
  29. };
  30. render() {
  31. const { dashboard } = this.props;
  32. const intervals = dashboard.timepicker.refresh_intervals;
  33. return (
  34. <RefreshPicker
  35. onIntervalChanged={this.onChangeRefreshInterval}
  36. onRefresh={this.onRefresh}
  37. value={dashboard.refresh}
  38. intervals={intervals}
  39. tooltip="Refresh dashboard"
  40. />
  41. );
  42. }
  43. }