Browse Source

Changed noQueries to a dataFormats array that will allow a panel to define supported formats and prefered (first in array)

Torkel Ödegaard 6 years ago
parent
commit
a1453607a9

+ 1 - 1
pkg/api/frontendsettings.go

@@ -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,
 		}
 	}
 

+ 0 - 1
pkg/plugins/models.go

@@ -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:"-"`

+ 5 - 0
pkg/plugins/panel_plugin.go

@@ -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
 }

+ 7 - 12
public/app/features/dashboard/dashgrid/PanelChrome.tsx

@@ -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;

+ 1 - 0
public/app/features/dashboard/dashgrid/PanelPluginNotFound.tsx

@@ -46,6 +46,7 @@ export function getPanelPluginNotFound(id: string): PanelPlugin {
     sort: 100,
     module: '',
     baseUrl: '',
+    dataFormats: [],
     info: {
       author: {
         name: '',

+ 3 - 3
public/app/features/dashboard/panel_editor/PanelEditor.tsx

@@ -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

+ 2 - 1
public/app/features/plugins/__mocks__/pluginMocks.ts

@@ -1,4 +1,4 @@
-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',

+ 2 - 0
public/app/plugins/panel/alertlist/plugin.json

@@ -3,6 +3,8 @@
   "name": "Alert List",
   "id": "alertlist",
 
+  "dataFormats": [],
+
   "info": {
     "description": "Shows list of alerts and their current status",
     "author": {

+ 3 - 1
public/app/plugins/panel/dashlist/plugin.json

@@ -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"

+ 2 - 0
public/app/plugins/panel/pluginlist/plugin.json

@@ -3,6 +3,8 @@
   "name": "Plugin list",
   "id": "pluginlist",
 
+  "dataFormats": [],
+
   "info": {
     "description": "Plugin List for Grafana",
     "author": {

+ 6 - 1
public/app/types/plugins.ts

@@ -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 {