remove type field and add helper functions to check if data isTableData
This commit is contained in:
@@ -63,5 +63,4 @@ export interface Column {
|
||||
export interface TableData {
|
||||
columns: Column[];
|
||||
rows: any[];
|
||||
type: string;
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user