mirror of
https://github.com/grafana/grafana.git
synced 2025-02-12 00:25:46 -06:00
0cc620aea7
* First iteration * Dev dash * Re-use StackingMode type * Fix ts and api issues * Stacking work resurected * Fix overrides * Correct values in tooltip and updated test dashboard * Update dev dashboard * Apply correct bands for stacking * Merge fix * Update snapshot * Revert go.sum * Handle null values correctyl and make filleBelowTo and stacking mutual exclusive * Snapshots update * Graph->Time series stacking migration * Review comments * Indicate overrides in StandardEditorContext * Change stacking UI editor, migrate stacking to object option * Small refactor, fix for hiding series and dev dashboard
105 lines
2.9 KiB
TypeScript
105 lines
2.9 KiB
TypeScript
import { ApplyFieldOverrideOptions, DataTransformerConfig, dateMath, FieldColorModeId, 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';
|
|
|
|
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);
|
|
|
|
return (
|
|
<div style={{ padding: '30px 50px' }} className="page-scrollbar-wrapper">
|
|
<h3>New page</h3>
|
|
<div>
|
|
<QueryGroup
|
|
options={queryOptions}
|
|
queryRunner={queryRunner}
|
|
onRunQueries={onRunQueries}
|
|
onOptionsChange={onOptionsChange}
|
|
/>
|
|
</div>
|
|
|
|
{data && (
|
|
<div style={{ padding: '16px' }}>
|
|
<GraphNG
|
|
width={1200}
|
|
height={300}
|
|
data={data.series}
|
|
legend={{ displayMode: LegendDisplayMode.List, placement: 'bottom', calcs: [] }}
|
|
timeRange={data.timeRange}
|
|
timeZone="browser"
|
|
/>
|
|
<hr />
|
|
<Table data={data.series[0]} width={1200} height={300} />
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
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;
|