From 2f88d02ebcef36b32fdc0de6064982f9f43e68d1 Mon Sep 17 00:00:00 2001 From: Dominik Prokop Date: Tue, 31 Oct 2023 12:43:15 +0100 Subject: [PATCH] Annotations settings: Do not preserve query properties when changing data source (#77422) * Annotations settings: Do not preserve query props when changing data source * Handle changing data source type --- .../AnnotationSettingsEdit.tsx | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/public/app/features/dashboard/components/AnnotationSettings/AnnotationSettingsEdit.tsx b/public/app/features/dashboard/components/AnnotationSettings/AnnotationSettingsEdit.tsx index 1e1daac9c33..7e656629641 100644 --- a/public/app/features/dashboard/components/AnnotationSettings/AnnotationSettingsEdit.tsx +++ b/public/app/features/dashboard/components/AnnotationSettings/AnnotationSettingsEdit.tsx @@ -72,10 +72,26 @@ export const AnnotationSettingsEdit = ({ editIdx, dashboard }: Props) => { }; const onDataSourceChange = (ds: DataSourceInstanceSettings) => { - onUpdate({ - ...annotation, - datasource: getDataSourceRef(ds), - }); + const dsRef = getDataSourceRef(ds); + + if (annotation.datasource?.type !== dsRef.type) { + onUpdate({ + datasource: dsRef, + builtIn: annotation.builtIn, + enable: annotation.enable, + iconColor: annotation.iconColor, + name: annotation.name, + hide: annotation.hide, + filter: annotation.filter, + mappings: annotation.mappings, + type: annotation.type, + }); + } else { + onUpdate({ + ...annotation, + datasource: dsRef, + }); + } }; const onChange = (ev: React.FocusEvent) => {