From a1453607a9efc21e45a82d53dcc9979bb5ac0369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 12 Feb 2019 16:05:29 +0100 Subject: [PATCH] Changed noQueries to a dataFormats array that will allow a panel to define supported formats and prefered (first in array) --- pkg/api/frontendsettings.go | 2 +- pkg/plugins/models.go | 1 - pkg/plugins/panel_plugin.go | 5 +++++ .../dashboard/dashgrid/PanelChrome.tsx | 19 +++++++------------ .../dashgrid/PanelPluginNotFound.tsx | 1 + .../dashboard/panel_editor/PanelEditor.tsx | 6 +++--- .../features/plugins/__mocks__/pluginMocks.ts | 3 ++- .../app/plugins/panel/alertlist/plugin.json | 2 ++ public/app/plugins/panel/dashlist/plugin.json | 4 +++- .../app/plugins/panel/pluginlist/plugin.json | 2 ++ public/app/types/plugins.ts | 7 ++++++- 11 files changed, 32 insertions(+), 20 deletions(-) diff --git a/pkg/api/frontendsettings.go b/pkg/api/frontendsettings.go index cb401577140..d13f0a26ab0 100644 --- a/pkg/api/frontendsettings.go +++ b/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, } } diff --git a/pkg/plugins/models.go b/pkg/plugins/models.go index 7584981fc6c..5ac436205c1 100644 --- a/pkg/plugins/models.go +++ b/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:"-"` diff --git a/pkg/plugins/panel_plugin.go b/pkg/plugins/panel_plugin.go index 49cbfb19fc6..b90fd41e465 100644 --- a/pkg/plugins/panel_plugin.go +++ b/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 } diff --git a/public/app/features/dashboard/dashgrid/PanelChrome.tsx b/public/app/features/dashboard/dashgrid/PanelChrome.tsx index 309fa118251..b050b1ff5e1 100644 --- a/public/app/features/dashboard/dashgrid/PanelChrome.tsx +++ b/public/app/features/dashboard/dashgrid/PanelChrome.tsx @@ -99,18 +99,12 @@ export class PanelChrome extends PureComponent { 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 { const { datasource, targets } = panel; return ( <> - {this.hasDataPanel ? ( + {this.needsQueryExecution ? ( { 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 { )} ); - } + }; render() { const { dashboard, panel } = this.props; diff --git a/public/app/features/dashboard/dashgrid/PanelPluginNotFound.tsx b/public/app/features/dashboard/dashgrid/PanelPluginNotFound.tsx index 18b307b5ea5..3f835bdbac2 100644 --- a/public/app/features/dashboard/dashgrid/PanelPluginNotFound.tsx +++ b/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: '', diff --git a/public/app/features/dashboard/panel_editor/PanelEditor.tsx b/public/app/features/dashboard/panel_editor/PanelEditor.tsx index 7b8298deebf..74870b25f07 100644 --- a/public/app/features/dashboard/panel_editor/PanelEditor.tsx +++ b/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 { ]; // handle panels that do not have queries tab - if (plugin.noQueries) { + if (plugin.dataFormats.length === 0) { // remove queries tab tabs.shift(); // switch tab diff --git a/public/app/features/plugins/__mocks__/pluginMocks.ts b/public/app/features/plugins/__mocks__/pluginMocks.ts index b922840cb43..ab78f8094b3 100644 --- a/public/app/features/plugins/__mocks__/pluginMocks.ts +++ b/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', diff --git a/public/app/plugins/panel/alertlist/plugin.json b/public/app/plugins/panel/alertlist/plugin.json index ff36a572f2b..130c307ae6c 100644 --- a/public/app/plugins/panel/alertlist/plugin.json +++ b/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": { diff --git a/public/app/plugins/panel/dashlist/plugin.json b/public/app/plugins/panel/dashlist/plugin.json index 9dcde08a598..11f9db928b0 100644 --- a/public/app/plugins/panel/dashlist/plugin.json +++ b/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" diff --git a/public/app/plugins/panel/pluginlist/plugin.json b/public/app/plugins/panel/pluginlist/plugin.json index b955177f1bc..8927b25b880 100644 --- a/public/app/plugins/panel/pluginlist/plugin.json +++ b/public/app/plugins/panel/pluginlist/plugin.json @@ -3,6 +3,8 @@ "name": "Plugin list", "id": "pluginlist", + "dataFormats": [], + "info": { "description": "Plugin List for Grafana", "author": { diff --git a/public/app/types/plugins.ts b/public/app/types/plugins.ts index 101f649eda9..d812cf5d81e 100644 --- a/public/app/types/plugins.ts +++ b/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 {