Commit 59dc91ad by Torkel Ödegaard Committed by GitHub

Merge pull request #15163 from grafana/table-data-support

Table data support
parents 53331772 ed0f5b71
...@@ -2,7 +2,7 @@ import React from 'react'; ...@@ -2,7 +2,7 @@ import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { Gauge, Props } from './Gauge'; import { Gauge, Props } from './Gauge';
import { TimeSeriesVMs } from '../../types/series'; import { TimeSeriesVMs } from '../../types/data';
import { ValueMapping, MappingType } from '../../types'; import { ValueMapping, MappingType } from '../../types';
jest.mock('jquery', () => ({ jest.mock('jquery', () => ({
......
...@@ -52,3 +52,20 @@ export interface TimeSeriesVMs { ...@@ -52,3 +52,20 @@ export interface TimeSeriesVMs {
[index: number]: TimeSeriesVM; [index: number]: TimeSeriesVM;
length: number; length: number;
} }
interface Column {
text: string;
title?: string;
type?: string;
sort?: boolean;
desc?: boolean;
filterable?: boolean;
unit?: string;
}
export interface TableData {
columns: Column[];
rows: any[];
type: string;
columnMap: any;
}
import { TimeRange, RawTimeRange } from './time'; import { TimeRange, RawTimeRange } from './time';
import { TimeSeries } from './series';
import { PluginMeta } from './plugin'; import { PluginMeta } from './plugin';
import { TableData, TimeSeries } from './data';
export interface DataQueryResponse { export interface DataQueryResponse {
data: TimeSeries[]; data: TimeSeries[] | [TableData];
} }
export interface DataQuery { export interface DataQuery {
......
export * from './series'; export * from './data';
export * from './time'; export * from './time';
export * from './panel'; export * from './panel';
export * from './plugin'; export * from './plugin';
......
import { TimeSeries, LoadingState } from './series'; import { TimeSeries, LoadingState, TableData } from './data';
import { TimeRange } from './time'; import { TimeRange } from './time';
export type InterpolateFunction = (value: string, format?: string | Function) => string; export type InterpolateFunction = (value: string, format?: string | Function) => string;
...@@ -14,6 +14,11 @@ export interface PanelProps<T = any> { ...@@ -14,6 +14,11 @@ export interface PanelProps<T = any> {
onInterpolate: InterpolateFunction; onInterpolate: InterpolateFunction;
} }
export interface PanelData {
timeSeries?: TimeSeries[];
tableData?: TableData;
}
export interface PanelOptionsProps<T = any> { export interface PanelOptionsProps<T = any> {
options: T; options: T;
onChange: (options: T) => void; onChange: (options: T) => void;
......
...@@ -8,13 +8,21 @@ import { DatasourceSrv, getDatasourceSrv } from 'app/features/plugins/datasource ...@@ -8,13 +8,21 @@ import { DatasourceSrv, getDatasourceSrv } from 'app/features/plugins/datasource
// Utils // Utils
import kbn from 'app/core/utils/kbn'; import kbn from 'app/core/utils/kbn';
// Types // Types
import { DataQueryOptions, DataQueryResponse, LoadingState, TimeRange, TimeSeries } from '@grafana/ui/src/types'; import {
DataQueryOptions,
DataQueryResponse,
LoadingState,
PanelData,
TableData,
TimeRange,
TimeSeries,
} from '@grafana/ui';
const DEFAULT_PLUGIN_ERROR = 'Error in plugin'; const DEFAULT_PLUGIN_ERROR = 'Error in plugin';
interface RenderProps { interface RenderProps {
loading: LoadingState; loading: LoadingState;
timeSeries: TimeSeries[]; panelData: PanelData;
} }
export interface Props { export interface Props {
...@@ -129,6 +137,7 @@ export class DataPanel extends Component<Props, State> { ...@@ -129,6 +137,7 @@ export class DataPanel extends Component<Props, State> {
console.log('Issuing DataPanel query', queryOptions); console.log('Issuing DataPanel query', queryOptions);
const resp = await ds.query(queryOptions); const resp = await ds.query(queryOptions);
console.log('Issuing DataPanel query Resp', resp); console.log('Issuing DataPanel query Resp', resp);
if (this.isUnmounted) { if (this.isUnmounted) {
...@@ -160,11 +169,27 @@ export class DataPanel extends Component<Props, State> { ...@@ -160,11 +169,27 @@ export class DataPanel extends Component<Props, State> {
} }
}; };
getPanelData = () => {
const { response } = this.state;
if (response.data.length > 0 && (response.data[0] as TableData).type === 'table') {
return {
tableData: response.data[0] as TableData,
timeSeries: null,
};
}
return {
timeSeries: response.data as TimeSeries[],
tableData: null,
};
};
render() { render() {
const { queries } = this.props; const { queries } = this.props;
const { response, loading, isFirstLoad } = this.state; const { loading, isFirstLoad } = this.state;
const timeSeries = response.data; const panelData = this.getPanelData();
if (isFirstLoad && loading === LoadingState.Loading) { if (isFirstLoad && loading === LoadingState.Loading) {
return this.renderLoadingStates(); return this.renderLoadingStates();
...@@ -190,8 +215,8 @@ export class DataPanel extends Component<Props, State> { ...@@ -190,8 +215,8 @@ export class DataPanel extends Component<Props, State> {
return ( return (
<> <>
{this.props.children({ {this.props.children({
timeSeries,
loading, loading,
panelData,
})} })}
</> </>
); );
......
...@@ -14,8 +14,7 @@ import { applyPanelTimeOverrides } from 'app/features/dashboard/utils/panel'; ...@@ -14,8 +14,7 @@ import { applyPanelTimeOverrides } from 'app/features/dashboard/utils/panel';
import { PANEL_HEADER_HEIGHT } from 'app/core/constants'; import { PANEL_HEADER_HEIGHT } from 'app/core/constants';
// Types // Types
import { PanelModel } from '../state/PanelModel'; import { DashboardModel, PanelModel } from '../state';
import { DashboardModel } from '../state/DashboardModel';
import { PanelPlugin } from 'app/types'; import { PanelPlugin } from 'app/types';
import { TimeRange } from '@grafana/ui'; import { TimeRange } from '@grafana/ui';
...@@ -139,7 +138,6 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -139,7 +138,6 @@ export class PanelChrome extends PureComponent<Props, State> {
scopedVars={panel.scopedVars} scopedVars={panel.scopedVars}
links={panel.links} links={panel.links}
/> />
{panel.snapshotData ? ( {panel.snapshotData ? (
this.renderPanel(false, panel.snapshotData, width, height) this.renderPanel(false, panel.snapshotData, width, height)
) : ( ) : (
...@@ -152,8 +150,8 @@ export class PanelChrome extends PureComponent<Props, State> { ...@@ -152,8 +150,8 @@ export class PanelChrome extends PureComponent<Props, State> {
refreshCounter={refreshCounter} refreshCounter={refreshCounter}
onDataResponse={this.onDataResponse} onDataResponse={this.onDataResponse}
> >
{({ loading, timeSeries }) => { {({ loading, panelData }) => {
return this.renderPanel(loading, timeSeries, width, height); return this.renderPanel(loading, panelData.timeSeries, width, height);
}} }}
</DataPanel> </DataPanel>
)} )}
......
...@@ -5,6 +5,7 @@ import _ from 'lodash'; ...@@ -5,6 +5,7 @@ import _ from 'lodash';
import { Emitter } from 'app/core/utils/emitter'; import { Emitter } from 'app/core/utils/emitter';
import { PANEL_OPTIONS_KEY_PREFIX } from 'app/core/constants'; import { PANEL_OPTIONS_KEY_PREFIX } from 'app/core/constants';
import { DataQuery, TimeSeries } from '@grafana/ui'; import { DataQuery, TimeSeries } from '@grafana/ui';
import { TableData } from '@grafana/ui/src';
export interface GridPos { export interface GridPos {
x: number; x: number;
...@@ -87,7 +88,7 @@ export class PanelModel { ...@@ -87,7 +88,7 @@ export class PanelModel {
datasource: string; datasource: string;
thresholds?: any; thresholds?: any;
snapshotData?: TimeSeries[]; snapshotData?: TimeSeries[] | [TableData];
timeFrom?: any; timeFrom?: any;
timeShift?: any; timeShift?: any;
hideTimeOverride?: any; hideTimeOverride?: any;
......
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