Skip to content

Commit

Permalink
[Synthetics] Fixes annotation update after event change !! (elastic#1…
Browse files Browse the repository at this point in the history
…99330)

## Summary

Fixes annotation update after event change !!

Fixes elastic#199418

In SLO details page, create an annotation by holding Command+Dragging on
chart, save and try to change the annotation type and it should be able
to save it/update it

<img width="1728" alt="image"
src="https://github.com/user-attachments/assets/a1ac92f6-1c0c-4544-b405-1c3c45c63739">
  • Loading branch information
shahzad31 authored Nov 8, 2024
1 parent 22a7c82 commit 3094dc4
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EuiForm, EuiFormRow, EuiHorizontalRule, EuiSpacer } from '@elastic/eui'
import { i18n } from '@kbn/i18n';
import React from 'react';
import { useFormContext, Controller } from 'react-hook-form';
import { defaultAnnotationColor } from '@kbn/event-annotation-common';
import { CreateAnnotationForm } from './components/create_annotation';
import { AnnotationApplyTo } from './components/annotation_apply_to';
import { Annotation } from '../../../common/annotations';
Expand All @@ -17,7 +18,8 @@ import { AnnotationRange } from './components/annotation_range';
import { AnnotationAppearance } from './annotation_apearance';

export function AnnotationForm({ editAnnotation }: { editAnnotation?: Annotation | null }) {
const { control, formState, watch, trigger } = useFormContext<CreateAnnotationForm>();
const { control, formState, watch, trigger, unregister, setValue } =
useFormContext<CreateAnnotationForm>();

const timestampStart = watch('@timestamp');

Expand All @@ -39,7 +41,14 @@ export function AnnotationForm({ editAnnotation }: { editAnnotation?: Annotation
)}
checked={Boolean(value)}
onChange={(evt) => {
field.onChange(evt.target.checked ? timestampStart : null);
if (evt.target.checked) {
field.onChange(timestampStart);
} else {
// we need to do this to avoid validation errors
unregister('event.end');
field.onChange(null);
setValue('annotation.style.color', defaultAnnotationColor);
}
}}
compressed
/>
Expand Down

0 comments on commit 3094dc4

Please sign in to comment.