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
This commit is contained in:
Dominik Prokop 2023-10-31 12:43:15 +01:00 committed by GitHub
parent d7c50eb650
commit 2f88d02ebc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<HTMLInputElement>) => {