mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
parent
a2dad6157a
commit
7d0edb285d
@ -2,6 +2,7 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { Tooltip } from '@grafana/ui';
|
import { Tooltip } from '@grafana/ui';
|
||||||
|
|
||||||
|
import ErrorBoundary from 'app/core/components/ErrorBoundary/ErrorBoundary';
|
||||||
// Services
|
// Services
|
||||||
import { DatasourceSrv, getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
import { DatasourceSrv, getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||||
// Utils
|
// Utils
|
||||||
@ -17,6 +18,8 @@ import {
|
|||||||
TimeSeries,
|
TimeSeries,
|
||||||
} from '@grafana/ui';
|
} from '@grafana/ui';
|
||||||
|
|
||||||
|
const DEFAULT_PLUGIN_ERROR = 'Error in plugin';
|
||||||
|
|
||||||
interface RenderProps {
|
interface RenderProps {
|
||||||
loading: LoadingState;
|
loading: LoadingState;
|
||||||
panelData: PanelData;
|
panelData: PanelData;
|
||||||
@ -200,12 +203,24 @@ export class DataPanel extends Component<Props, State> {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{this.renderLoadingStates()}
|
{this.renderLoadingStates()}
|
||||||
|
<ErrorBoundary>
|
||||||
|
{({ error, errorInfo }) => {
|
||||||
|
if (errorInfo) {
|
||||||
|
this.onError(error.message || DEFAULT_PLUGIN_ERROR);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<>
|
||||||
{this.props.children({
|
{this.props.children({
|
||||||
loading,
|
loading,
|
||||||
panelData,
|
panelData,
|
||||||
})}
|
})}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
}}
|
||||||
|
</ErrorBoundary>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private renderLoadingStates(): JSX.Element {
|
private renderLoadingStates(): JSX.Element {
|
||||||
|
@ -8,7 +8,6 @@ import { getTimeSrv, TimeSrv } from '../services/TimeSrv';
|
|||||||
// Components
|
// Components
|
||||||
import { PanelHeader } from './PanelHeader/PanelHeader';
|
import { PanelHeader } from './PanelHeader/PanelHeader';
|
||||||
import { DataPanel } from './DataPanel';
|
import { DataPanel } from './DataPanel';
|
||||||
import ErrorBoundary from '../../../core/components/ErrorBoundary/ErrorBoundary';
|
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { applyPanelTimeOverrides } from 'app/features/dashboard/utils/panel';
|
import { applyPanelTimeOverrides } from 'app/features/dashboard/utils/panel';
|
||||||
@ -24,8 +23,6 @@ import variables from 'sass/_variables.scss';
|
|||||||
import templateSrv from 'app/features/templating/template_srv';
|
import templateSrv from 'app/features/templating/template_srv';
|
||||||
import { DataQueryResponse } from '@grafana/ui/src';
|
import { DataQueryResponse } from '@grafana/ui/src';
|
||||||
|
|
||||||
const DEFAULT_PLUGIN_ERROR = 'Error in plugin';
|
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
panel: PanelModel;
|
panel: PanelModel;
|
||||||
dashboard: DashboardModel;
|
dashboard: DashboardModel;
|
||||||
@ -37,9 +34,6 @@ export interface State {
|
|||||||
renderCounter: number;
|
renderCounter: number;
|
||||||
timeInfo?: string;
|
timeInfo?: string;
|
||||||
timeRange?: TimeRange;
|
timeRange?: TimeRange;
|
||||||
loading: LoadingState;
|
|
||||||
isFirstLoad: boolean;
|
|
||||||
errorMessage: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PanelChrome extends PureComponent<Props, State> {
|
export class PanelChrome extends PureComponent<Props, State> {
|
||||||
@ -49,11 +43,8 @@ export class PanelChrome extends PureComponent<Props, State> {
|
|||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
loading: LoadingState.NotStarted,
|
|
||||||
refreshCounter: 0,
|
refreshCounter: 0,
|
||||||
renderCounter: 0,
|
renderCounter: 0,
|
||||||
isFirstLoad: false,
|
|
||||||
errorMessage: '',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,16 +94,6 @@ export class PanelChrome extends PureComponent<Props, State> {
|
|||||||
return !this.props.dashboard.otherPanelInFullscreen(this.props.panel);
|
return !this.props.dashboard.otherPanelInFullscreen(this.props.panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
onError = (errorMessage: string) => {
|
|
||||||
if (this.state.loading !== LoadingState.Error || this.state.errorMessage !== errorMessage) {
|
|
||||||
this.setState({
|
|
||||||
loading: LoadingState.Error,
|
|
||||||
isFirstLoad: false,
|
|
||||||
errorMessage: errorMessage,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
renderPanel(loading, panelData, width, height): JSX.Element {
|
renderPanel(loading, panelData, width, height): JSX.Element {
|
||||||
const { panel, plugin } = this.props;
|
const { panel, plugin } = this.props;
|
||||||
const { timeRange, renderCounter } = this.state;
|
const { timeRange, renderCounter } = this.state;
|
||||||
@ -164,14 +145,7 @@ export class PanelChrome extends PureComponent<Props, State> {
|
|||||||
scopedVars={panel.scopedVars}
|
scopedVars={panel.scopedVars}
|
||||||
links={panel.links}
|
links={panel.links}
|
||||||
/>
|
/>
|
||||||
<ErrorBoundary>
|
{panel.snapshotData ? (
|
||||||
{({ error, errorInfo }) => {
|
|
||||||
if (errorInfo) {
|
|
||||||
this.onError(error.message || DEFAULT_PLUGIN_ERROR);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return panel.snapshotData ? (
|
|
||||||
this.renderPanel(false, panel.snapshotData, width, height)
|
this.renderPanel(false, panel.snapshotData, width, height)
|
||||||
) : (
|
) : (
|
||||||
<DataPanel
|
<DataPanel
|
||||||
@ -187,9 +161,7 @@ export class PanelChrome extends PureComponent<Props, State> {
|
|||||||
return this.renderPanel(loading, panelData, width, height);
|
return this.renderPanel(loading, panelData, width, height);
|
||||||
}}
|
}}
|
||||||
</DataPanel>
|
</DataPanel>
|
||||||
);
|
)}
|
||||||
}}
|
|
||||||
</ErrorBoundary>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
|
Loading…
Reference in New Issue
Block a user