mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 08:35:43 -06:00
Merge pull request #16115 from ryantxu/column-types
update TableData model
This commit is contained in:
commit
bb14be9148
@ -50,14 +50,29 @@ export enum NullValueMode {
|
||||
/** View model projection of many time series */
|
||||
export type TimeSeriesVMs = TimeSeriesVM[];
|
||||
|
||||
export enum ColumnType {
|
||||
time = 'time', // or date
|
||||
number = 'number',
|
||||
string = 'string',
|
||||
boolean = 'boolean',
|
||||
other = 'other', // Object, Array, etc
|
||||
}
|
||||
|
||||
export interface Column {
|
||||
text: string; // The column name
|
||||
type?: 'time' | 'number' | 'string' | 'object'; // not used anywhere? can we remove?
|
||||
filterable?: boolean; // currently only set by elasticsearch, and used in the table panel
|
||||
type?: ColumnType;
|
||||
filterable?: boolean;
|
||||
unit?: string;
|
||||
dateFormat?: string; // Source data format
|
||||
}
|
||||
|
||||
export interface Tags {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export interface TableData {
|
||||
name?: string;
|
||||
columns: Column[];
|
||||
rows: any[];
|
||||
rows: any[][];
|
||||
tags?: Tags;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import isNumber from 'lodash/isNumber';
|
||||
import Papa, { ParseError, ParseMeta } from 'papaparse';
|
||||
|
||||
// Types
|
||||
import { TableData, Column, TimeSeries } from '../types';
|
||||
import { TableData, Column, TimeSeries, ColumnType } from '../types';
|
||||
|
||||
// Subset of all parse options
|
||||
export interface TableParseOptions {
|
||||
@ -131,6 +131,7 @@ export function parseCSV(text: string, options?: TableParseOptions, details?: Ta
|
||||
|
||||
function convertTimeSeriesToTableData(timeSeries: TimeSeries): TableData {
|
||||
return {
|
||||
name: timeSeries.target,
|
||||
columns: [
|
||||
{
|
||||
text: timeSeries.target || 'Value',
|
||||
@ -138,7 +139,7 @@ function convertTimeSeriesToTableData(timeSeries: TimeSeries): TableData {
|
||||
},
|
||||
{
|
||||
text: 'Time',
|
||||
type: 'time',
|
||||
type: ColumnType.time,
|
||||
unit: 'dateTimeAsIso',
|
||||
},
|
||||
],
|
||||
|
@ -1,5 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import TableModel from 'app/core/table_model';
|
||||
import { ColumnType } from '@grafana/ui';
|
||||
|
||||
export default class InfluxSeries {
|
||||
series: any;
|
||||
@ -156,7 +157,7 @@ export default class InfluxSeries {
|
||||
// Check that the first column is indeed 'time'
|
||||
if (series.columns[0] === 'time') {
|
||||
// Push this now before the tags and with the right type
|
||||
table.columns.push({ text: 'Time', type: 'time' });
|
||||
table.columns.push({ text: 'Time', type: ColumnType.time });
|
||||
j++;
|
||||
}
|
||||
_.each(_.keys(series.tags), key => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import TableModel from 'app/core/table_model';
|
||||
import { TimeSeries } from '@grafana/ui';
|
||||
import { TimeSeries, ColumnType } from '@grafana/ui';
|
||||
|
||||
export class ResultTransformer {
|
||||
constructor(private templateSrv) {}
|
||||
@ -98,7 +98,7 @@ export class ResultTransformer {
|
||||
|
||||
// Sort metric labels, create columns for them and record their index
|
||||
const sortedLabels = _.keys(metricLabels).sort();
|
||||
table.columns.push({ text: 'Time', type: 'time' });
|
||||
table.columns.push({ text: 'Time', type: ColumnType.time });
|
||||
_.each(sortedLabels, (label, labelIndex) => {
|
||||
metricLabels[label] = labelIndex + 1;
|
||||
table.columns.push({ text: label, filterable: true });
|
||||
|
Loading…
Reference in New Issue
Block a user