瀏覽代碼

remove type field and add helper functions to check if data isTableData

ryan 6 年之前
父節點
當前提交
188dc86246

+ 0 - 1
packages/grafana-ui/src/types/data.ts

@@ -63,5 +63,4 @@ export interface Column {
 export interface TableData {
   columns: Column[];
   rows: any[];
-  type: string;
 }

+ 3 - 3
packages/grafana-ui/src/utils/processTimeSeries.ts

@@ -191,6 +191,8 @@ export function processTimeSeries({ data, xColumn, yColumn, nullValueMode }: Opt
   return vmSeries;
 }
 
+export const isTableData = (data: any): data is TableData => data && data.hasOwnProperty('columns');
+
 export const toTableData = (results: any[]): TableData[] => {
   const tables: TableData[] = [];
   if (results) {
@@ -202,15 +204,13 @@ export const toTableData = (results: any[]): TableData[] => {
         } else if (data.hasOwnProperty('datapoints')) {
           const ts = data as TimeSeries;
           tables.push({
-            type: 'timeseries',
             columns: [
               {
                 text: ts.target,
                 unit: ts.unit,
-                type: 'number', // Is this really true?
               },
               {
-                text: 'time',
+                text: 'Time',
                 type: 'time',
               },
             ],

+ 2 - 2
public/app/plugins/panel/singlestat/module.ts

@@ -8,7 +8,7 @@ import kbn from 'app/core/utils/kbn';
 import config from 'app/core/config';
 import TimeSeries from 'app/core/time_series2';
 import { MetricsPanelCtrl } from 'app/plugins/sdk';
-import { GrafanaThemeType, getValueFormat, getColorFromHexRgbOrName } from '@grafana/ui';
+import { GrafanaThemeType, getValueFormat, getColorFromHexRgbOrName, isTableData } from '@grafana/ui';
 
 class SingleStatCtrl extends MetricsPanelCtrl {
   static templateUrl = 'module.html';
@@ -112,7 +112,7 @@ class SingleStatCtrl extends MetricsPanelCtrl {
       scopedVars: _.extend({}, this.panel.scopedVars),
     };
 
-    if (dataList.length > 0 && dataList[0].type === 'table') {
+    if (dataList.length > 0 && isTableData(dataList[0])) {
       this.dataType = 'table';
       const tableData = dataList.map(this.tableHandler.bind(this));
       this.setTableValues(tableData, data);

+ 2 - 1
public/app/plugins/panel/table/module.ts

@@ -6,6 +6,7 @@ import { transformDataToTable } from './transformers';
 import { tablePanelEditor } from './editor';
 import { columnOptionsTab } from './column_options';
 import { TableRenderer } from './renderer';
+import { isTableData } from '@grafana/ui';
 
 class TablePanelCtrl extends MetricsPanelCtrl {
   static templateUrl = 'module.html';
@@ -104,7 +105,7 @@ class TablePanelCtrl extends MetricsPanelCtrl {
 
     // automatically correct transform mode based on data
     if (this.dataRaw && this.dataRaw.length) {
-      if (this.dataRaw[0].type === 'table') {
+      if (isTableData(this.dataRaw[0])) {
         this.panel.transform = 'table';
       } else {
         if (this.dataRaw[0].type === 'docs') {