mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
569fb3f112
* fix viz * add datasource picker on query rows in mixed mode * add timerange, handle add/remove queryrunners * multiqueryrunner test * trying things out. * adding another test to verify running a induvidual query runner will update multirunner. * cleaned up tests a bit. * draft version working ok. * fixing so we base the refId from request targets. * reenable adding expression * layout fixes for alerting page * some cleanup * cleaning up code that we won't use * changed so we don't display the time range if params not passed. * remove unused things in querygroup * changed button to type button. * removed timerange from dataQuery and removed multiquery runner. * minor refactoring. * renamed callback function to make it more clear what it does. * renamed droppable area. * changed so we only display the query editor when selecting threshold. * removed the refresh picker. * revert * wip * extending with data query. * timerange fixes * it is now possible to add grafana queries. * removed unused type. * removed expect import. * added docs. * moved range converting methods to rangeUtil. * clean up some typings, remove file * making sure we don't blow up on component being unmounted. Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
127 lines
3.5 KiB
TypeScript
127 lines
3.5 KiB
TypeScript
import {
|
|
ApplyFieldOverrideOptions,
|
|
DataTransformerConfig,
|
|
dateMath,
|
|
FieldColorModeId,
|
|
NavModelItem,
|
|
PanelData,
|
|
} from '@grafana/data';
|
|
import { GraphNG, LegendDisplayMode, Table } from '@grafana/ui';
|
|
import { config } from 'app/core/config';
|
|
import React, { FC, useMemo, useState } from 'react';
|
|
import { useObservable } from 'react-use';
|
|
import { QueryGroup } from '../query/components/QueryGroup';
|
|
import { PanelQueryRunner } from '../query/state/PanelQueryRunner';
|
|
import { QueryGroupOptions } from 'app/types';
|
|
import Page from '../../core/components/Page/Page';
|
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
|
|
|
interface State {
|
|
queryRunner: PanelQueryRunner;
|
|
queryOptions: QueryGroupOptions;
|
|
data?: PanelData;
|
|
}
|
|
|
|
export const TestStuffPage: FC = () => {
|
|
const [state, setState] = useState<State>(getDefaultState());
|
|
const { queryOptions, queryRunner } = state;
|
|
|
|
const onRunQueries = () => {
|
|
const timeRange = { from: 'now-1h', to: 'now' };
|
|
|
|
queryRunner.run({
|
|
queries: queryOptions.queries,
|
|
datasource: queryOptions.dataSource.name!,
|
|
timezone: 'browser',
|
|
timeRange: { from: dateMath.parse(timeRange.from)!, to: dateMath.parse(timeRange.to)!, raw: timeRange },
|
|
maxDataPoints: queryOptions.maxDataPoints ?? 100,
|
|
minInterval: queryOptions.minInterval,
|
|
});
|
|
};
|
|
|
|
const onOptionsChange = (queryOptions: QueryGroupOptions) => {
|
|
setState({ ...state, queryOptions });
|
|
};
|
|
|
|
/**
|
|
* Subscribe to data
|
|
*/
|
|
const observable = useMemo(() => queryRunner.getData({ withFieldConfig: true, withTransforms: true }), [queryRunner]);
|
|
const data = useObservable(observable);
|
|
|
|
const node: NavModelItem = {
|
|
id: 'test-page',
|
|
text: 'Test page',
|
|
icon: 'dashboard',
|
|
subTitle: 'FOR TESTING!',
|
|
url: 'sandbox/test',
|
|
};
|
|
|
|
return (
|
|
<Page navModel={{ node: node, main: node }}>
|
|
<Page.Contents>
|
|
{data && (
|
|
<AutoSizer style={{ width: '100%', height: '600px' }}>
|
|
{({ width }) => {
|
|
return (
|
|
<div>
|
|
<GraphNG
|
|
width={width}
|
|
height={300}
|
|
data={data.series}
|
|
legend={{ displayMode: LegendDisplayMode.List, placement: 'bottom', calcs: [] }}
|
|
timeRange={data.timeRange}
|
|
timeZone="browser"
|
|
/>
|
|
<Table data={data.series[0]} width={width} height={300} />
|
|
</div>
|
|
);
|
|
}}
|
|
</AutoSizer>
|
|
)}
|
|
<div style={{ marginTop: '16px', height: '45%' }}>
|
|
<QueryGroup
|
|
options={queryOptions}
|
|
queryRunner={queryRunner}
|
|
onRunQueries={onRunQueries}
|
|
onOptionsChange={onOptionsChange}
|
|
/>
|
|
</div>
|
|
</Page.Contents>
|
|
</Page>
|
|
);
|
|
};
|
|
|
|
export function getDefaultState(): State {
|
|
const options: ApplyFieldOverrideOptions = {
|
|
fieldConfig: {
|
|
defaults: {
|
|
color: {
|
|
mode: FieldColorModeId.PaletteClassic,
|
|
},
|
|
},
|
|
overrides: [],
|
|
},
|
|
replaceVariables: (v: string) => v,
|
|
theme: config.theme,
|
|
};
|
|
|
|
const dataConfig = {
|
|
getTransformations: () => [] as DataTransformerConfig[],
|
|
getFieldOverrideOptions: () => options,
|
|
};
|
|
|
|
return {
|
|
queryRunner: new PanelQueryRunner(dataConfig),
|
|
queryOptions: {
|
|
queries: [],
|
|
dataSource: {
|
|
name: 'gdev-testdata',
|
|
},
|
|
maxDataPoints: 100,
|
|
},
|
|
};
|
|
}
|
|
|
|
export default TestStuffPage;
|