Commit a1453607 by Torkel Ödegaard

Changed noQueries to a dataFormats array that will allow a panel to define…

Changed noQueries to a dataFormats array that will allow a panel to define supported formats and prefered (first in array)
parent c3965e33
......@@ -145,7 +145,7 @@ func (hs *HTTPServer) getFrontendSettingsMap(c *m.ReqContext) (map[string]interf
"info": panel.Info,
"hideFromList": panel.HideFromList,
"sort": getPanelSort(panel.Id),
"noQueries": panel.NoQueries,
"dataFormats": panel.DataFormats,
}
}
......
......@@ -47,7 +47,6 @@ type PluginBase struct {
BaseUrl string `json:"baseUrl"`
HideFromList bool `json:"hideFromList,omitempty"`
State PluginState `json:"state,omitempty"`
NoQueries bool `json:"noQueries"`
IncludedInAppId string `json:"-"`
PluginDir string `json:"-"`
......
......@@ -4,6 +4,7 @@ import "encoding/json"
type PanelPlugin struct {
FrontendPluginBase
DataFormats []string `json:"dataFormats"`
}
func (p *PanelPlugin) Load(decoder *json.Decoder, pluginDir string) error {
......@@ -15,6 +16,10 @@ func (p *PanelPlugin) Load(decoder *json.Decoder, pluginDir string) error {
return err
}
if p.DataFormats == nil {
p.DataFormats = []string{"time_series", "table"}
}
Panels[p.Id] = p
return nil
}
......@@ -99,18 +99,12 @@ export class PanelChrome extends PureComponent<Props, State> {
return panel.snapshotData && panel.snapshotData.length;
}
get hasDataPanel() {
return !this.props.plugin.noQueries && !this.hasPanelSnapshot;
get needsQueryExecution() {
return this.hasPanelSnapshot || this.props.plugin.dataFormats.length > 0;
}
get getDataForPanel() {
const { panel, plugin } = this.props;
if (plugin.noQueries) {
return null;
}
return this.hasPanelSnapshot ? snapshotDataToPanelData(panel) : null;
return this.hasPanelSnapshot ? snapshotDataToPanelData(this.props.panel) : null;
}
renderPanelPlugin(loading: LoadingState, panelData: PanelData, width: number, height: number): JSX.Element {
......@@ -146,7 +140,7 @@ export class PanelChrome extends PureComponent<Props, State> {
const { datasource, targets } = panel;
return (
<>
{this.hasDataPanel ? (
{this.needsQueryExecution ? (
<DataPanel
panelId={panel.id}
datasource={datasource}
......@@ -155,7 +149,8 @@ export class PanelChrome extends PureComponent<Props, State> {
isVisible={this.isVisible}
widthPixels={width}
refreshCounter={refreshCounter}
onDataResponse={this.onDataResponse} >
onDataResponse={this.onDataResponse}
>
{({ loading, panelData }) => {
return this.renderPanelPlugin(loading, panelData, width, height);
}}
......@@ -165,7 +160,7 @@ export class PanelChrome extends PureComponent<Props, State> {
)}
</>
);
}
};
render() {
const { dashboard, panel } = this.props;
......
......@@ -46,6 +46,7 @@ export function getPanelPluginNotFound(id: string): PanelPlugin {
sort: 100,
module: '',
baseUrl: '',
dataFormats: [],
info: {
author: {
name: '',
......
......@@ -34,7 +34,7 @@ enum PanelEditorTabIds {
Queries = 'queries',
Visualization = 'visualization',
Advanced = 'advanced',
Alert = 'alert'
Alert = 'alert',
}
interface PanelEditorTab {
......@@ -52,7 +52,7 @@ const panelEditorTabTexts = {
const getPanelEditorTab = (tabId: PanelEditorTabIds): PanelEditorTab => {
return {
id: tabId,
text: panelEditorTabTexts[tabId]
text: panelEditorTabTexts[tabId],
};
};
......@@ -107,7 +107,7 @@ export class PanelEditor extends PureComponent<PanelEditorProps> {
];
// handle panels that do not have queries tab
if (plugin.noQueries) {
if (plugin.dataFormats.length === 0) {
// remove queries tab
tabs.shift();
// switch tab
......
import { Plugin, PanelPlugin } from 'app/types';
import { Plugin, PanelPlugin, PanelDataFormat } from 'app/types';
export const getMockPlugins = (amount: number): Plugin[] => {
const plugins = [];
......@@ -38,6 +38,7 @@ export const getPanelPlugin = (options: { id: string; sort?: number; hideFromLis
id: options.id,
name: options.id,
sort: options.sort || 1,
dataFormats: [PanelDataFormat.TimeSeries],
info: {
author: {
name: options.id + 'name',
......
......@@ -3,6 +3,8 @@
"name": "Alert List",
"id": "alertlist",
"dataFormats": [],
"info": {
"description": "Shows list of alerts and their current status",
"author": {
......
......@@ -3,12 +3,14 @@
"name": "Dashboard list",
"id": "dashlist",
"dataFormats": [],
"info": {
"description": "List of dynamic links to other dashboards",
"author": {
"name": "Grafana Project",
"url": "https://grafana.com"
},
},
"logos": {
"small": "img/icn-dashlist-panel.svg",
"large": "img/icn-dashlist-panel.svg"
......
......@@ -3,6 +3,8 @@
"name": "Plugin list",
"id": "pluginlist",
"dataFormats": [],
"info": {
"description": "Plugin List for Grafana",
"author": {
......
......@@ -9,7 +9,12 @@ export interface PanelPlugin {
info: any;
sort: number;
exports?: PluginExports;
noQueries?: boolean;
dataFormats: PanelDataFormat[];
}
export enum PanelDataFormat {
Table = 'table',
TimeSeries = 'time_series',
}
export interface Plugin {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment