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:
@@ -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<Props, State> {
|
||||
|
||||
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<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() {
|
||||
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<Props, State> {
|
||||
return (
|
||||
<>
|
||||
{this.props.children({
|
||||
timeSeries,
|
||||
loading,
|
||||
panelData,
|
||||
})}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -121,12 +121,12 @@ export class PanelChrome extends PureComponent<Props, State> {
|
||||
widthPixels={width}
|
||||
refreshCounter={refreshCounter}
|
||||
>
|
||||
{({ loading, timeSeries }) => {
|
||||
{({ loading, panelData }) => {
|
||||
return (
|
||||
<div className="panel-content">
|
||||
<PanelComponent
|
||||
loading={loading}
|
||||
timeSeries={timeSeries}
|
||||
timeSeries={panelData.timeSeries}
|
||||
timeRange={timeRange}
|
||||
options={panel.getOptions(plugin.exports.PanelDefaults)}
|
||||
width={width - 2 * variables.panelHorizontalPadding}
|
||||
|
||||
Reference in New Issue
Block a user