Skip to content

Commit 447bc3a

Browse files
committed
Merge branch 'react-panels' of github.com:grafana/grafana into react-panels
2 parents 09ad836 + ab9e1b3 commit 447bc3a

File tree

2 files changed

+67
-11
lines changed

2 files changed

+67
-11
lines changed

public/app/features/dashboard/dashgrid/PanelChrome.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import { PanelEditor } from './PanelEditor';
99
const TITLE_HEIGHT = 27;
1010
const PANEL_BORDER = 2;
1111

12-
export interface PanelChromeProps {
12+
export interface Props {
1313
panel: PanelModel;
1414
dashboard: DashboardModel;
1515
component: any;
1616
}
1717

18-
export class PanelChrome extends React.Component<PanelChromeProps, any> {
18+
export class PanelChrome extends React.Component<Props, any> {
1919
constructor(props) {
2020
super(props);
2121

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,79 @@
11
import React, { Component, ComponentClass } from 'react';
22
import _ from 'lodash';
33

4-
export interface Props {
4+
export interface OuterProps {
55
type: string;
6-
queries: Query[];
6+
queries: any[];
7+
isVisible: boolean;
78
}
89

9-
interface State {
10-
isLoading: boolean;
11-
timeSeries: TimeSeriesServerResponse[];
10+
export interface AddedProps {
11+
data: any[];
1212
}
1313

14-
export interface OriginalProps {
15-
data: TimeSeriesServerResponse[];
14+
interface State {
1615
isLoading: boolean;
16+
data: any[];
1717
}
1818

19-
const DataPanel = (ComposedComponent: ComponentClass<OriginalProps & Props>) => {
20-
class Wrapper extends Component<Props, State> {}
19+
const DataPanel = (ComposedComponent: ComponentClass<AddedProps & OuterProps>) => {
20+
class Wrapper extends Component<OuterProps, State> {
21+
public static defaultProps = {
22+
isVisible: true,
23+
};
24+
25+
constructor(props: OuterProps) {
26+
super(props);
27+
28+
this.state = {
29+
isLoading: false,
30+
data: [],
31+
};
32+
}
33+
34+
public componentDidMount() {
35+
this.issueQueries();
36+
}
37+
38+
public issueQueries = () => {
39+
const { queries, isVisible } = this.props;
40+
41+
if (!isVisible) {
42+
return;
43+
}
44+
45+
if (!queries.length) {
46+
this.setState({ data: [{ message: 'no queries' }] });
47+
return;
48+
}
49+
50+
this.setState({ isLoading: true });
51+
};
52+
53+
public render() {
54+
const { data, isLoading } = this.state;
55+
56+
if (!data.length) {
57+
return (
58+
<div className="no-data">
59+
<p>No Data</p>
60+
</div>
61+
);
62+
}
63+
64+
if (isLoading) {
65+
return (
66+
<div className="loading">
67+
<p>Loading</p>
68+
</div>
69+
);
70+
}
71+
72+
return <ComposedComponent {...this.props} data={data} />;
73+
}
74+
}
2175

2276
return Wrapper;
2377
};
78+
79+
export default DataPanel;

0 commit comments

Comments
 (0)