Skip to content

Commit ab9e1b3

Browse files
committed
wip: minor progress on DataPanel
1 parent 682c792 commit ab9e1b3

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React, { Component, ComponentClass } from 'react';
2+
3+
export interface OuterProps {
4+
type: string;
5+
queries: any[];
6+
isVisible: boolean;
7+
}
8+
9+
export interface AddedProps {
10+
data: any[];
11+
}
12+
13+
interface State {
14+
isLoading: boolean;
15+
data: any[];
16+
}
17+
18+
const DataPanel = (ComposedComponent: ComponentClass<AddedProps & OuterProps>) => {
19+
class Wrapper extends Component<OuterProps, State> {
20+
public static defaultProps = {
21+
isVisible: true,
22+
};
23+
24+
constructor(props: OuterProps) {
25+
super(props);
26+
27+
this.state = {
28+
isLoading: false,
29+
data: [],
30+
};
31+
}
32+
33+
public componentDidMount() {
34+
this.issueQueries();
35+
}
36+
37+
public issueQueries = () => {
38+
const { queries, isVisible } = this.props;
39+
40+
if (!isVisible) {
41+
return;
42+
}
43+
44+
if (!queries.length) {
45+
this.setState({ data: [{ message: 'no queries' }] });
46+
return;
47+
}
48+
49+
this.setState({ isLoading: true });
50+
};
51+
52+
public render() {
53+
const { data, isLoading } = this.state;
54+
55+
if (!data.length) {
56+
return (
57+
<div className="no-data">
58+
<p>No Data</p>
59+
</div>
60+
);
61+
}
62+
63+
if (isLoading) {
64+
return (
65+
<div className="loading">
66+
<p>Loading</p>
67+
</div>
68+
);
69+
}
70+
71+
return <ComposedComponent {...this.props} data={data} />;
72+
}
73+
}
74+
75+
return Wrapper;
76+
};
77+
78+
export default DataPanel;

0 commit comments

Comments
 (0)