2021-05-19 23:38:31 -05:00
|
|
|
import React, { useMemo } from 'react';
|
2021-04-06 18:06:46 -05:00
|
|
|
import { PanelProps } from '@grafana/data';
|
2021-05-13 13:57:45 -05:00
|
|
|
import { useTheme2, ZoomPlugin } from '@grafana/ui';
|
2021-05-17 15:00:04 -05:00
|
|
|
import { StatusPanelOptions } from './types';
|
|
|
|
import { TimelineChart } from '../state-timeline/TimelineChart';
|
|
|
|
import { TimelineMode } from '../state-timeline/types';
|
2021-05-19 23:38:31 -05:00
|
|
|
import { prepareTimelineFields, prepareTimelineLegendItems } from '../state-timeline/utils';
|
2021-04-06 18:06:46 -05:00
|
|
|
|
2021-05-17 15:00:04 -05:00
|
|
|
interface TimelinePanelProps extends PanelProps<StatusPanelOptions> {}
|
2021-04-06 18:06:46 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @alpha
|
|
|
|
*/
|
2021-05-17 15:00:04 -05:00
|
|
|
export const StatusGridPanel: React.FC<TimelinePanelProps> = ({
|
2021-05-13 13:57:45 -05:00
|
|
|
data,
|
|
|
|
timeRange,
|
|
|
|
timeZone,
|
|
|
|
options,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
onChangeTimeRange,
|
|
|
|
}) => {
|
2021-05-10 11:34:42 -05:00
|
|
|
const theme = useTheme2();
|
|
|
|
|
2021-05-19 23:38:31 -05:00
|
|
|
const { frames, warn } = useMemo(() => prepareTimelineFields(data?.series, false), [data]);
|
|
|
|
|
|
|
|
const legendItems = useMemo(() => prepareTimelineLegendItems(frames, options.legend), [frames, options.legend]);
|
|
|
|
|
|
|
|
if (!frames || warn) {
|
2021-04-06 18:06:46 -05:00
|
|
|
return (
|
|
|
|
<div className="panel-empty">
|
2021-05-19 23:38:31 -05:00
|
|
|
<p>{warn ?? 'No data found in response'}</p>
|
2021-04-06 18:06:46 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-04-07 01:16:14 -05:00
|
|
|
<TimelineChart
|
2021-05-10 11:34:42 -05:00
|
|
|
theme={theme}
|
2021-05-19 23:38:31 -05:00
|
|
|
frames={frames}
|
2021-04-26 06:30:04 -05:00
|
|
|
structureRev={data.structureRev}
|
2021-04-06 18:06:46 -05:00
|
|
|
timeRange={timeRange}
|
|
|
|
timeZone={timeZone}
|
|
|
|
width={width}
|
|
|
|
height={height}
|
2021-05-19 23:38:31 -05:00
|
|
|
legendItems={legendItems}
|
2021-04-06 18:06:46 -05:00
|
|
|
{...options}
|
2021-05-17 15:00:04 -05:00
|
|
|
// hardcoded
|
|
|
|
mode={TimelineMode.Samples}
|
2021-05-13 13:57:45 -05:00
|
|
|
>
|
2021-05-14 01:27:03 -05:00
|
|
|
{(config) => <ZoomPlugin config={config} onZoom={onChangeTimeRange} />}
|
2021-05-13 13:57:45 -05:00
|
|
|
</TimelineChart>
|
2021-04-06 18:06:46 -05:00
|
|
|
);
|
|
|
|
};
|