From 34b52cb8359acf84829297ba4adc547aef116ffb Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Sun, 9 Feb 2020 18:48:14 +0100 Subject: [PATCH] New Editor: refresh when time values change (#22049) --- .../src/components/FieldConfigs/units.tsx | 4 +-- .../components/PanelEditor/PanelEditor.tsx | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/packages/grafana-ui/src/components/FieldConfigs/units.tsx b/packages/grafana-ui/src/components/FieldConfigs/units.tsx index f71407c1034..c5061e675cc 100644 --- a/packages/grafana-ui/src/components/FieldConfigs/units.tsx +++ b/packages/grafana-ui/src/components/FieldConfigs/units.tsx @@ -11,12 +11,12 @@ export const UnitValueEditor: React.FC { - return ; + return ; }; export const UnitOverrideEditor: React.FC> = ({ value, onChange, }) => { - return ; + return ; }; diff --git a/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx b/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx index 838bec9fb0a..4f98435abba 100644 --- a/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx +++ b/public/app/features/dashboard/components/PanelEditor/PanelEditor.tsx @@ -7,6 +7,7 @@ import { DefaultTimeRange, PanelEvents, SelectableValue, + TimeRange, } from '@grafana/data'; import { stylesFactory, @@ -33,6 +34,8 @@ import { Unsubscribable } from 'rxjs'; import { PanelTitle } from './PanelTitle'; import { DisplayMode, displayModes } from './types'; import { PanelEditorTabs } from './PanelEditorTabs'; +import { DashNavTimeControls } from '../DashNav/DashNavTimeControls'; +import { LocationState, CoreEvents } from 'app/types'; const getStyles = stylesFactory((theme: GrafanaTheme) => { const handleColor = selectThemeVariant( @@ -111,6 +114,7 @@ interface Props { dashboard: DashboardModel; sourcePanel: PanelModel; updateLocation: typeof updateLocation; + location: LocationState; } interface State { @@ -147,11 +151,16 @@ export class PanelEditor extends PureComponent { const { sourcePanel } = this.props; const { panel } = this.state; panel.events.on(PanelEvents.panelInitialized, () => { + const { panel } = this.state; + if (panel.angularPanel) { + console.log('Refresh angular panel in new editor'); + } this.setState(state => ({ pluginLoadedCounter: state.pluginLoadedCounter + 1, })); }); - // Get data from any pending + + // Get data from any pending queries sourcePanel .getQueryRunner() .getData() @@ -167,6 +176,9 @@ export class PanelEditor extends PureComponent { this.querySubscription = queryRunner.getData().subscribe({ next: (data: PanelData) => this.setState({ data }), }); + + // Listen to timepicker changes + this.props.dashboard.on(CoreEvents.timeRangeUpdated, this.onTimeRangeUpdated); } componentWillUnmount() { @@ -174,8 +186,18 @@ export class PanelEditor extends PureComponent { this.querySubscription.unsubscribe(); } //this.cleanUpAngularOptions(); + + // Remove the time listener + this.props.dashboard.off(CoreEvents.timeRangeUpdated, this.onTimeRangeUpdated); } + onTimeRangeUpdated = (timeRange: TimeRange) => { + const { panel } = this.state; + if (panel) { + panel.refresh(); + } + }; + onPanelUpdate = () => { const { panel } = this.state; const { dashboard } = this.props; @@ -320,6 +342,7 @@ export class PanelEditor extends PureComponent { } render() { + const { dashboard, location } = this.props; const { panel, mode, showPanelOptions } = this.state; const styles = getStyles(config.theme); @@ -346,6 +369,10 @@ export class PanelEditor extends PureComponent { Discard + +
+ +