mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
creating table data type
This commit is contained in:
parent
67756c43a7
commit
88cb38adde
@ -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 {
|
|||||||
[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;
|
||||||
|
}
|
@ -1,9 +1,8 @@
|
|||||||
import { TimeRange, RawTimeRange } from './time';
|
import { TimeRange, RawTimeRange } from './time';
|
||||||
import { TimeSeries } from './series';
|
|
||||||
import { PluginMeta } from './plugin';
|
import { PluginMeta } from './plugin';
|
||||||
|
|
||||||
export interface DataQueryResponse {
|
export interface DataQueryResponse {
|
||||||
data: TimeSeries[];
|
data: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DataQuery {
|
export interface DataQuery {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export * from './series';
|
export * from './data';
|
||||||
export * from './time';
|
export * from './time';
|
||||||
export * from './panel';
|
export * from './panel';
|
||||||
export * from './plugin';
|
export * from './plugin';
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
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> {
|
|||||||
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;
|
||||||
|
@ -11,13 +11,21 @@ import { getDatasourceSrv, DatasourceSrv } from 'app/features/plugins/datasource
|
|||||||
import kbn from 'app/core/utils/kbn';
|
import kbn from 'app/core/utils/kbn';
|
||||||
|
|
||||||
// Types
|
// 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';
|
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 {
|
||||||
@ -121,6 +129,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) {
|
||||||
@ -148,11 +157,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,
|
||||||
|
timeSeries: [] as TimeSeries[],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
timeSeries: response.data,
|
||||||
|
tableData: {} as TableData,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
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();
|
||||||
@ -178,8 +203,8 @@ export class DataPanel extends Component<Props, State> {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{this.props.children({
|
{this.props.children({
|
||||||
timeSeries,
|
|
||||||
loading,
|
loading,
|
||||||
|
panelData,
|
||||||
})}
|
})}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
@ -121,12 +121,12 @@ export class PanelChrome extends PureComponent<Props, State> {
|
|||||||
widthPixels={width}
|
widthPixels={width}
|
||||||
refreshCounter={refreshCounter}
|
refreshCounter={refreshCounter}
|
||||||
>
|
>
|
||||||
{({ loading, timeSeries }) => {
|
{({ loading, panelData }) => {
|
||||||
return (
|
return (
|
||||||
<div className="panel-content">
|
<div className="panel-content">
|
||||||
<PanelComponent
|
<PanelComponent
|
||||||
loading={loading}
|
loading={loading}
|
||||||
timeSeries={timeSeries}
|
timeSeries={panelData.timeSeries}
|
||||||
timeRange={timeRange}
|
timeRange={timeRange}
|
||||||
options={panel.getOptions(plugin.exports.PanelDefaults)}
|
options={panel.getOptions(plugin.exports.PanelDefaults)}
|
||||||
width={width - 2 * variables.panelHorizontalPadding}
|
width={width - 2 * variables.panelHorizontalPadding}
|
||||||
|
Loading…
Reference in New Issue
Block a user