mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
New Editor: refresh when time values change (#22049)
This commit is contained in:
@@ -11,12 +11,12 @@ export const UnitValueEditor: React.FC<FieldConfigEditorProps<string, UnitFieldC
|
|||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
}) => {
|
}) => {
|
||||||
return <UnitPicker value={value} onChange={onChange} />;
|
return <UnitPicker value={value} onChange={onChange} useNewForms />;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const UnitOverrideEditor: React.FC<FieldOverrideEditorProps<string, UnitFieldConfigSettings>> = ({
|
export const UnitOverrideEditor: React.FC<FieldOverrideEditorProps<string, UnitFieldConfigSettings>> = ({
|
||||||
value,
|
value,
|
||||||
onChange,
|
onChange,
|
||||||
}) => {
|
}) => {
|
||||||
return <UnitPicker value={value} onChange={onChange} />;
|
return <UnitPicker value={value} onChange={onChange} useNewForms />;
|
||||||
};
|
};
|
||||||
|
@@ -7,6 +7,7 @@ import {
|
|||||||
DefaultTimeRange,
|
DefaultTimeRange,
|
||||||
PanelEvents,
|
PanelEvents,
|
||||||
SelectableValue,
|
SelectableValue,
|
||||||
|
TimeRange,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import {
|
import {
|
||||||
stylesFactory,
|
stylesFactory,
|
||||||
@@ -33,6 +34,8 @@ import { Unsubscribable } from 'rxjs';
|
|||||||
import { PanelTitle } from './PanelTitle';
|
import { PanelTitle } from './PanelTitle';
|
||||||
import { DisplayMode, displayModes } from './types';
|
import { DisplayMode, displayModes } from './types';
|
||||||
import { PanelEditorTabs } from './PanelEditorTabs';
|
import { PanelEditorTabs } from './PanelEditorTabs';
|
||||||
|
import { DashNavTimeControls } from '../DashNav/DashNavTimeControls';
|
||||||
|
import { LocationState, CoreEvents } from 'app/types';
|
||||||
|
|
||||||
const getStyles = stylesFactory((theme: GrafanaTheme) => {
|
const getStyles = stylesFactory((theme: GrafanaTheme) => {
|
||||||
const handleColor = selectThemeVariant(
|
const handleColor = selectThemeVariant(
|
||||||
@@ -111,6 +114,7 @@ interface Props {
|
|||||||
dashboard: DashboardModel;
|
dashboard: DashboardModel;
|
||||||
sourcePanel: PanelModel;
|
sourcePanel: PanelModel;
|
||||||
updateLocation: typeof updateLocation;
|
updateLocation: typeof updateLocation;
|
||||||
|
location: LocationState;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
@@ -147,11 +151,16 @@ export class PanelEditor extends PureComponent<Props, State> {
|
|||||||
const { sourcePanel } = this.props;
|
const { sourcePanel } = this.props;
|
||||||
const { panel } = this.state;
|
const { panel } = this.state;
|
||||||
panel.events.on(PanelEvents.panelInitialized, () => {
|
panel.events.on(PanelEvents.panelInitialized, () => {
|
||||||
|
const { panel } = this.state;
|
||||||
|
if (panel.angularPanel) {
|
||||||
|
console.log('Refresh angular panel in new editor');
|
||||||
|
}
|
||||||
this.setState(state => ({
|
this.setState(state => ({
|
||||||
pluginLoadedCounter: state.pluginLoadedCounter + 1,
|
pluginLoadedCounter: state.pluginLoadedCounter + 1,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
// Get data from any pending
|
|
||||||
|
// Get data from any pending queries
|
||||||
sourcePanel
|
sourcePanel
|
||||||
.getQueryRunner()
|
.getQueryRunner()
|
||||||
.getData()
|
.getData()
|
||||||
@@ -167,6 +176,9 @@ export class PanelEditor extends PureComponent<Props, State> {
|
|||||||
this.querySubscription = queryRunner.getData().subscribe({
|
this.querySubscription = queryRunner.getData().subscribe({
|
||||||
next: (data: PanelData) => this.setState({ data }),
|
next: (data: PanelData) => this.setState({ data }),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Listen to timepicker changes
|
||||||
|
this.props.dashboard.on(CoreEvents.timeRangeUpdated, this.onTimeRangeUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@@ -174,8 +186,18 @@ export class PanelEditor extends PureComponent<Props, State> {
|
|||||||
this.querySubscription.unsubscribe();
|
this.querySubscription.unsubscribe();
|
||||||
}
|
}
|
||||||
//this.cleanUpAngularOptions();
|
//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 = () => {
|
onPanelUpdate = () => {
|
||||||
const { panel } = this.state;
|
const { panel } = this.state;
|
||||||
const { dashboard } = this.props;
|
const { dashboard } = this.props;
|
||||||
@@ -320,6 +342,7 @@ export class PanelEditor extends PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { dashboard, location } = this.props;
|
||||||
const { panel, mode, showPanelOptions } = this.state;
|
const { panel, mode, showPanelOptions } = this.state;
|
||||||
const styles = getStyles(config.theme);
|
const styles = getStyles(config.theme);
|
||||||
|
|
||||||
@@ -346,6 +369,10 @@ export class PanelEditor extends PureComponent<Props, State> {
|
|||||||
<Forms.Button variant="destructive" onClick={this.onDiscard}>
|
<Forms.Button variant="destructive" onClick={this.onDiscard}>
|
||||||
Discard
|
Discard
|
||||||
</Forms.Button>
|
</Forms.Button>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<DashNavTimeControls dashboard={dashboard} location={location} updateLocation={updateLocation} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.panes}>
|
<div className={styles.panes}>
|
||||||
|
Reference in New Issue
Block a user