From 16f9830fc3bc49d0b6cb50fce20762f4fddf2bbe Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Mon, 4 Jul 2022 10:27:27 +0200 Subject: [PATCH] State Timeline: Enable support for annotations (#47887) * WIP: Enable annotations display and annotations editor in State timeline panel * Note support for annotations in module file * Lint fix * Post review Co-authored-by: Kyle Cunningham --- .../state-timeline/StateTimelinePanel.tsx | 43 ++++++++++++++++++- .../plugins/panel/state-timeline/module.tsx | 3 +- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/public/app/plugins/panel/state-timeline/StateTimelinePanel.tsx b/public/app/plugins/panel/state-timeline/StateTimelinePanel.tsx index 09746ba56c8..d65827d48a9 100644 --- a/public/app/plugins/panel/state-timeline/StateTimelinePanel.tsx +++ b/public/app/plugins/panel/state-timeline/StateTimelinePanel.tsx @@ -4,6 +4,9 @@ import { DataFrame, FieldType, PanelProps } from '@grafana/data'; import { TooltipPlugin, useTheme2, ZoomPlugin, usePanelContext } from '@grafana/ui'; import { getLastStreamingDataFramePacket } from 'app/features/live/data/StreamingDataFrame'; +import { AnnotationEditorPlugin } from '../timeseries/plugins/AnnotationEditorPlugin'; +import { AnnotationsPlugin } from '../timeseries/plugins/AnnotationsPlugin'; +import { ContextMenuPlugin } from '../timeseries/plugins/ContextMenuPlugin'; import { OutsideRangePlugin } from '../timeseries/plugins/OutsideRangePlugin'; import { StateTimelineTooltip } from './StateTimelineTooltip'; @@ -23,10 +26,11 @@ export const StateTimelinePanel: React.FC = ({ options, width, height, + replaceVariables, onChangeTimeRange, }) => { const theme = useTheme2(); - const { sync } = usePanelContext(); + const { sync, canAddAnnotations } = usePanelContext(); const { frames, warn } = useMemo( () => prepareTimelineFields(data?.series, options.mergeValues ?? true, timeRange, theme), @@ -92,6 +96,7 @@ export const StateTimelinePanel: React.FC = ({ // console.log('STREAM Packet', packet); } } + const enableAnnotationCreation = Boolean(canAddAnnotations && canAddAnnotations()); return ( = ({ renderTooltip={renderCustomTooltip} /> + + {data.annotations && ( + + )} + + {enableAnnotationCreation && ( + + {({ startAnnotating }) => { + return ( + { + if (!p) { + return; + } + startAnnotating({ coords: p.coords }); + }, + }, + ], + }, + ]} + /> + ); + }} + + )} ); }} diff --git a/public/app/plugins/panel/state-timeline/module.tsx b/public/app/plugins/panel/state-timeline/module.tsx index b807fb42f4a..5fdd2ab1bbb 100644 --- a/public/app/plugins/panel/state-timeline/module.tsx +++ b/public/app/plugins/panel/state-timeline/module.tsx @@ -107,4 +107,5 @@ export const plugin = new PanelPlugin(Stat commonOptionsBuilder.addLegendOptions(builder, false); commonOptionsBuilder.addTooltipOptions(builder, true); }) - .setSuggestionsSupplier(new StatTimelineSuggestionsSupplier()); + .setSuggestionsSupplier(new StatTimelineSuggestionsSupplier()) + .setDataSupport({ annotations: true });