Skip to content

Commit eda7723

Browse files
committed
hook up ott-vis-datasource to ott-vis
1 parent a1a95fb commit eda7723

File tree

3 files changed

+38
-63
lines changed

3 files changed

+38
-63
lines changed

packages/ott-vis/src/components/CorePanel.tsx

+34-27
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { css, cx } from "@emotion/css";
66
import { useStyles2 } from "@grafana/ui";
77
import GlobalView from "./views/GlobalView";
88
import RegionView from "./views/RegionView";
9+
import { LoadingState } from "@grafana/schema";
910

1011
interface Props extends PanelProps<CoreOptions> {}
1112

@@ -29,6 +30,39 @@ const getStyles = () => {
2930
};
3031
};
3132

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+
3266
const sampleSystemState: SystemState = [
3367
{
3468
id: "154d9d41-128c-45ab-83d8-28661882c9e3",
@@ -103,30 +137,3 @@ const sampleSystemState: SystemState = [
103137
],
104138
},
105139
];
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-
};

packages/ott-vis/src/module.ts

+3-31
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,9 @@ export const plugin = new PanelPlugin<CoreOptions>(CorePanel).setPanelOptions(bu
2222
],
2323
},
2424
})
25-
.addTextInput({
26-
path: "text",
27-
name: "Allowed Entities",
28-
description: "Number of entities allowed to be displayed in the panel at one time",
29-
defaultValue: "25",
30-
})
3125
.addBooleanSwitch({
32-
path: "showSeriesCount",
33-
name: "Show series counter",
34-
defaultValue: false,
35-
})
36-
.addRadio({
37-
path: "seriesCountSize",
38-
defaultValue: "sm",
39-
name: "Series counter size",
40-
settings: {
41-
options: [
42-
{
43-
value: "sm",
44-
label: "Small",
45-
},
46-
{
47-
value: "md",
48-
label: "Medium",
49-
},
50-
{
51-
value: "lg",
52-
label: "Large",
53-
},
54-
],
55-
},
56-
showIf: config => config.showSeriesCount,
26+
path: "useSampleData",
27+
name: "Use Sample Data",
28+
description: "Use sample data instead of querying the datasource",
5729
});
5830
});

packages/ott-vis/src/types.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
type SeriesSize = "sm" | "md" | "lg";
2-
31
export interface CoreOptions {
42
view: "global" | "region";
5-
text: string;
6-
showSeriesCount: boolean;
7-
seriesCountSize: SeriesSize;
3+
useSampleData: boolean;
84
}

0 commit comments

Comments
 (0)