Files
grafana/public/app/features/explore/Graph/GraphContainer.tsx
Gilles De Mey b94fceddad Alerting: Make Loki & Prometheus instant vector by default (#66797)
Co-authored-by: Konrad Lalik <konrad.lalik@grafana.com>
2023-04-27 17:38:22 +03:00

86 lines
2.2 KiB
TypeScript

import React, { useCallback, useState } from 'react';
import {
DataFrame,
EventBus,
AbsoluteTimeRange,
TimeZone,
SplitOpen,
LoadingState,
ThresholdsConfig,
} from '@grafana/data';
import { GraphThresholdsStyleConfig, PanelChrome, PanelChromeProps } from '@grafana/ui';
import { ExploreGraphStyle } from 'app/types';
import { storeGraphStyle } from '../state/utils';
import { ExploreGraph } from './ExploreGraph';
import { ExploreGraphLabel } from './ExploreGraphLabel';
import { loadGraphStyle } from './utils';
interface Props extends Pick<PanelChromeProps, 'width' | 'height' | 'statusMessage'> {
loading: boolean;
data: DataFrame[];
annotations?: DataFrame[];
eventBus: EventBus;
absoluteRange: AbsoluteTimeRange;
timeZone: TimeZone;
onChangeTime: (absoluteRange: AbsoluteTimeRange) => void;
splitOpenFn: SplitOpen;
loadingState: LoadingState;
thresholdsConfig?: ThresholdsConfig;
thresholdsStyle?: GraphThresholdsStyleConfig;
}
export const GraphContainer = ({
data,
eventBus,
height,
width,
absoluteRange,
timeZone,
annotations,
onChangeTime,
splitOpenFn,
thresholdsConfig,
thresholdsStyle,
loadingState,
statusMessage,
}: Props) => {
const [graphStyle, setGraphStyle] = useState(loadGraphStyle);
const onGraphStyleChange = useCallback((graphStyle: ExploreGraphStyle) => {
storeGraphStyle(graphStyle);
setGraphStyle(graphStyle);
}, []);
return (
<PanelChrome
title="Graph"
width={width}
height={height}
loadingState={loadingState}
statusMessage={statusMessage}
actions={<ExploreGraphLabel graphStyle={graphStyle} onChangeGraphStyle={onGraphStyleChange} />}
>
{(innerWidth, innerHeight) => (
<ExploreGraph
graphStyle={graphStyle}
data={data}
height={innerHeight}
width={innerWidth}
absoluteRange={absoluteRange}
onChangeTime={onChangeTime}
timeZone={timeZone}
annotations={annotations}
splitOpenFn={splitOpenFn}
loadingState={loadingState}
thresholdsConfig={thresholdsConfig}
thresholdsStyle={thresholdsStyle}
eventBus={eventBus}
/>
)}
</PanelChrome>
);
};