From 88cb38adde9672ddea589d28da72f0d4faff83bc Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Thu, 31 Jan 2019 09:59:21 +0100 Subject: [PATCH] creating table data type --- .../src/components/Gauge/Gauge.test.tsx | 2 +- .../src/types/{series.ts => data.ts} | 17 +++++++++ packages/grafana-ui/src/types/datasource.ts | 3 +- packages/grafana-ui/src/types/index.ts | 2 +- packages/grafana-ui/src/types/panel.ts | 7 +++- .../features/dashboard/dashgrid/DataPanel.tsx | 35 ++++++++++++++++--- .../dashboard/dashgrid/PanelChrome.tsx | 4 +-- 7 files changed, 58 insertions(+), 12 deletions(-) rename packages/grafana-ui/src/types/{series.ts => data.ts} (81%) diff --git a/packages/grafana-ui/src/components/Gauge/Gauge.test.tsx b/packages/grafana-ui/src/components/Gauge/Gauge.test.tsx index d4051b5ea22..1d2151a0627 100644 --- a/packages/grafana-ui/src/components/Gauge/Gauge.test.tsx +++ b/packages/grafana-ui/src/components/Gauge/Gauge.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { Gauge, Props } from './Gauge'; -import { TimeSeriesVMs } from '../../types/series'; +import { TimeSeriesVMs } from '../../types/data'; import { ValueMapping, MappingType } from '../../types'; jest.mock('jquery', () => ({ diff --git a/packages/grafana-ui/src/types/series.ts b/packages/grafana-ui/src/types/data.ts similarity index 81% rename from packages/grafana-ui/src/types/series.ts rename to packages/grafana-ui/src/types/data.ts index 5cad1e4a72a..1e4ccba3948 100644 --- a/packages/grafana-ui/src/types/series.ts +++ b/packages/grafana-ui/src/types/data.ts @@ -52,3 +52,20 @@ export interface TimeSeriesVMs { [index: number]: TimeSeriesVM; 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; +} diff --git a/packages/grafana-ui/src/types/datasource.ts b/packages/grafana-ui/src/types/datasource.ts index ffcbbb5fe64..48fcbbdf29c 100644 --- a/packages/grafana-ui/src/types/datasource.ts +++ b/packages/grafana-ui/src/types/datasource.ts @@ -1,9 +1,8 @@ import { TimeRange, RawTimeRange } from './time'; -import { TimeSeries } from './series'; import { PluginMeta } from './plugin'; export interface DataQueryResponse { - data: TimeSeries[]; + data: any; } export interface DataQuery { diff --git a/packages/grafana-ui/src/types/index.ts b/packages/grafana-ui/src/types/index.ts index 575c749e07e..e23b5e63af8 100644 --- a/packages/grafana-ui/src/types/index.ts +++ b/packages/grafana-ui/src/types/index.ts @@ -1,4 +1,4 @@ -export * from './series'; +export * from './data'; export * from './time'; export * from './panel'; export * from './plugin'; diff --git a/packages/grafana-ui/src/types/panel.ts b/packages/grafana-ui/src/types/panel.ts index f2a699839b8..ad09b3aba9f 100644 --- a/packages/grafana-ui/src/types/panel.ts +++ b/packages/grafana-ui/src/types/panel.ts @@ -1,4 +1,4 @@ -import { TimeSeries, LoadingState } from './series'; +import { TimeSeries, LoadingState, TableData } from './data'; import { TimeRange } from './time'; export type InterpolateFunction = (value: string, format?: string | Function) => string; @@ -14,6 +14,11 @@ export interface PanelProps { onInterpolate: InterpolateFunction; } +export interface PanelData { + timeSeries?: TimeSeries[]; + tableData?: TableData; +} + export interface PanelOptionsProps { options: T; onChange: (options: T) => void; diff --git a/public/app/features/dashboard/dashgrid/DataPanel.tsx b/public/app/features/dashboard/dashgrid/DataPanel.tsx index a681428f4bd..db71072f189 100644 --- a/public/app/features/dashboard/dashgrid/DataPanel.tsx +++ b/public/app/features/dashboard/dashgrid/DataPanel.tsx @@ -11,13 +11,21 @@ import { getDatasourceSrv, DatasourceSrv } from 'app/features/plugins/datasource import kbn from 'app/core/utils/kbn'; // Types -import { TimeRange, TimeSeries, LoadingState, DataQueryResponse, DataQueryOptions } from '@grafana/ui/src/types'; +import { + TimeRange, + TimeSeries, + LoadingState, + DataQueryResponse, + DataQueryOptions, + PanelData, + TableData, +} from '@grafana/ui/src/types'; const DEFAULT_PLUGIN_ERROR = 'Error in plugin'; interface RenderProps { loading: LoadingState; - timeSeries: TimeSeries[]; + panelData: PanelData; } export interface Props { @@ -121,6 +129,7 @@ export class DataPanel extends Component { console.log('Issuing DataPanel query', queryOptions); const resp = await ds.query(queryOptions); + console.log('Issuing DataPanel query Resp', resp); if (this.isUnmounted) { @@ -148,11 +157,27 @@ export class DataPanel extends Component { } }; + getPanelData = () => { + const { response } = this.state; + + if (response.data.length > 0 && (response.data[0] as TableData).type === 'table') { + return { + tableData: response.data, + timeSeries: [] as TimeSeries[], + }; + } + + return { + timeSeries: response.data, + tableData: {} as TableData, + }; + }; + render() { 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) { return this.renderLoadingStates(); @@ -178,8 +203,8 @@ export class DataPanel extends Component { return ( <> {this.props.children({ - timeSeries, loading, + panelData, })} ); diff --git a/public/app/features/dashboard/dashgrid/PanelChrome.tsx b/public/app/features/dashboard/dashgrid/PanelChrome.tsx index 6b4ef48c32e..6acff11b771 100644 --- a/public/app/features/dashboard/dashgrid/PanelChrome.tsx +++ b/public/app/features/dashboard/dashgrid/PanelChrome.tsx @@ -121,12 +121,12 @@ export class PanelChrome extends PureComponent { widthPixels={width} refreshCounter={refreshCounter} > - {({ loading, timeSeries }) => { + {({ loading, panelData }) => { return (