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