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-29 13:24:14 -05:00
|
|
|
export const StatusHistoryPanel: 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]);
|
|
|
|
|
2021-05-20 01:17:50 -05:00
|
|
|
const legendItems = useMemo(() => prepareTimelineLegendItems(frames, options.legend, theme), [
|
|
|
|
frames,
|
|
|
|
options.legend,
|
|
|
|
theme,
|
|
|
|
]);
|
2021-05-19 23:38:31 -05:00
|
|
|
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-20 01:46:39 -05:00
|
|
|
// Status grid requires some space between values
|
|
|
|
if (frames[0].length > width / 2) {
|
|
|
|
return (
|
|
|
|
<div className="panel-empty">
|
|
|
|
<p>
|
|
|
|
Too many points to visualize properly. <br />
|
|
|
|
Update the query to return fewer points. <br />({frames[0].length} points recieved)
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-04-06 18:06:46 -05:00
|
|
|
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
|
|
|
);
|
|
|
|
};
|