The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/dashboard/dashgrid/DataPanel.tsx

82 lines
1.6 KiB

7 years ago
import React, { Component, ComponentClass } from 'react';
export interface OuterProps {
7 years ago
type: string;
queries: any[];
isVisible: boolean;
7 years ago
}
export interface PanelProps extends OuterProps {
data: any[];
7 years ago
}
export interface DataPanel extends ComponentClass<OuterProps> {}
interface State {
7 years ago
isLoading: boolean;
data: any[];
7 years ago
}
export const DataPanelWrapper = (ComposedComponent: ComponentClass<PanelProps>) => {
class Wrapper extends Component<OuterProps, State> {
static defaultProps = {
isVisible: true,
};
constructor(props: OuterProps) {
super(props);
this.state = {
isLoading: false,
data: [],
};
}
componentDidMount() {
console.log('data panel mount');
this.issueQueries();
}
issueQueries = async () => {
const { isVisible } = this.props;
if (!isVisible) {
return;
}
this.setState({ isLoading: true });
await new Promise(resolve => {
setTimeout(() => {
this.setState({ isLoading: false, data: [{ value: 10 }] });
}, 500);
});
};
render() {
const { data, isLoading } = this.state;
console.log('data panel render');
if (!data.length) {
return (
<div className="no-data">
<p>No Data</p>
</div>
);
}
if (isLoading) {
return (
<div className="loading">
<p>Loading</p>
</div>
);
}
return <ComposedComponent {...this.props} data={data} />;
}
}
7 years ago
return Wrapper;
};