@@ -6,6 +6,7 @@ import { css, cx } from "@emotion/css";
6
6
import { useStyles2 } from "@grafana/ui" ;
7
7
import GlobalView from "./views/GlobalView" ;
8
8
import RegionView from "./views/RegionView" ;
9
+ import { LoadingState } from "@grafana/schema" ;
9
10
10
11
interface Props extends PanelProps < CoreOptions > { }
11
12
@@ -29,6 +30,39 @@ const getStyles = () => {
29
30
} ;
30
31
} ;
31
32
33
+ export const CorePanel : React . FC < Props > = ( { options, data, width, height } ) => {
34
+ const styles = useStyles2 ( getStyles ) ;
35
+
36
+ if ( data . state === LoadingState . Loading ) {
37
+ return < div > Loading...</ div > ;
38
+ }
39
+
40
+ const systemState : SystemState = options . useSampleData ? sampleSystemState : data . series [ 0 ] . fields . find ( f => f . name === "Balancers" ) ?. values [ 0 ] ?? [ ] ;
41
+
42
+ let view ;
43
+ if ( options . view === "global" ) {
44
+ view = < GlobalView height = { height } width = { width } systemState = { systemState } /> ;
45
+ } else if ( options . view === "region" ) {
46
+ view = < RegionView height = { height } width = { width } systemState = { systemState } /> ;
47
+ } else {
48
+ view = < div > Invalid view</ div > ;
49
+ }
50
+
51
+ return (
52
+ < div
53
+ className = { cx (
54
+ styles . wrapper ,
55
+ css `
56
+ width : ${ width } px;
57
+ height : ${ height } px;
58
+ `
59
+ ) }
60
+ >
61
+ { view }
62
+ </ div >
63
+ ) ;
64
+ } ;
65
+
32
66
const sampleSystemState : SystemState = [
33
67
{
34
68
id : "154d9d41-128c-45ab-83d8-28661882c9e3" ,
@@ -103,30 +137,3 @@ const sampleSystemState: SystemState = [
103
137
] ,
104
138
} ,
105
139
] ;
106
-
107
- export const CorePanel : React . FC < Props > = ( { options, data, width, height } ) => {
108
- const styles = useStyles2 ( getStyles ) ;
109
-
110
- let view ;
111
- if ( options . view === "global" ) {
112
- view = < GlobalView height = { height } width = { width } systemState = { sampleSystemState } /> ;
113
- } else if ( options . view === "region" ) {
114
- view = < RegionView height = { height } width = { width } systemState = { sampleSystemState } /> ;
115
- } else {
116
- view = < div > Invalid view</ div > ;
117
- }
118
-
119
- return (
120
- < div
121
- className = { cx (
122
- styles . wrapper ,
123
- css `
124
- width : ${ width } px;
125
- height : ${ height } px;
126
- `
127
- ) }
128
- >
129
- { view }
130
- </ div >
131
- ) ;
132
- } ;
0 commit comments