Skip to content

Commit 326f451

Browse files
authored
hook up ott-vis-datasource to ott-vis (#1367)
* hook up `ott-vis-datasource` to `ott-vis` * format
1 parent a1a95fb commit 326f451

File tree

3 files changed

+40
-63
lines changed

3 files changed

+40
-63
lines changed

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

+36-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,41 @@ 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
41+
? sampleSystemState
42+
: data.series[0].fields.find(f => f.name === "Balancers")?.values[0] ?? [];
43+
44+
let view;
45+
if (options.view === "global") {
46+
view = <GlobalView height={height} width={width} systemState={systemState} />;
47+
} else if (options.view === "region") {
48+
view = <RegionView height={height} width={width} systemState={systemState} />;
49+
} else {
50+
view = <div>Invalid view</div>;
51+
}
52+
53+
return (
54+
<div
55+
className={cx(
56+
styles.wrapper,
57+
css`
58+
width: ${width}px;
59+
height: ${height}px;
60+
`
61+
)}
62+
>
63+
{view}
64+
</div>
65+
);
66+
};
67+
3268
const sampleSystemState: SystemState = [
3369
{
3470
id: "154d9d41-128c-45ab-83d8-28661882c9e3",
@@ -103,30 +139,3 @@ const sampleSystemState: SystemState = [
103139
],
104140
},
105141
];
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)