{annotation.builtIn ? (
| onEdit(idx)}>
- {annotation.name} (Built-in)
+ {getAnnotationName(annotation)}
|
) : (
onEdit(idx)}>
- {annotation.name}
+ {getAnnotationName(annotation)}
|
)}
onEdit(idx)}>
@@ -65,11 +89,13 @@ export const AnnotationSettingsList = ({ dashboard, onNew, onEdit }: Props) => {
) : null}
|
- onDelete(idx)}
- aria-label={`Delete query with title "${annotation.name}"`}
- />
+ {!annotation.builtIn && (
+ onDelete(idx)}
+ aria-label={`Delete query with title "${annotation.name}"`}
+ />
+ )}
|
))}
diff --git a/public/app/features/dashboard/components/DashboardSettings/AnnotationsSettings.test.tsx b/public/app/features/dashboard/components/DashboardSettings/AnnotationsSettings.test.tsx
index a12eda258b9..7c4cd7f208a 100644
--- a/public/app/features/dashboard/components/DashboardSettings/AnnotationsSettings.test.tsx
+++ b/public/app/features/dashboard/components/DashboardSettings/AnnotationsSettings.test.tsx
@@ -230,11 +230,23 @@ describe('AnnotationsSettings', () => {
});
test('Deleting annotation', async () => {
- setup(dashboard, 0);
+ dashboard.annotations.list = [
+ ...dashboard.annotations.list,
+ {
+ builtIn: 0,
+ datasource: { uid: 'uid3', type: 'prometheus' },
+ enable: true,
+ hide: true,
+ iconColor: 'rgba(0, 211, 255, 1)',
+ name: 'Annotation 2',
+ type: 'dashboard',
+ },
+ ];
+ setup(dashboard, 1); // Edit the not built-in annotations
await userEvent.click(screen.getByRole('button', { name: 'Delete' }));
expect(locationService.getSearchObject().editIndex).toBe(undefined);
- expect(dashboard.annotations.list.length).toBe(0);
+ expect(dashboard.annotations.list.length).toBe(1); // started with two
});
});
diff --git a/public/app/features/dashboard/state/DashboardModel.ts b/public/app/features/dashboard/state/DashboardModel.ts
index 86a16b949f1..de94075045f 100644
--- a/public/app/features/dashboard/state/DashboardModel.ts
+++ b/public/app/features/dashboard/state/DashboardModel.ts
@@ -1114,10 +1114,14 @@ export class DashboardModel implements TimeModel {
}
canAddAnnotations() {
- // If RBAC is enabled there are additional conditions to check.
- const canAdd = !contextSrv.accessControlEnabled() || Boolean(this.meta.annotationsPermissions?.dashboard.canAdd);
+ // When the builtin annotations are disabled, we should not add any in the UI
+ const found = this.annotations.list.find((item) => item.builtIn === 1);
+ if (found?.enable === false || !this.canEditDashboard()) {
+ return false;
+ }
- return this.canEditDashboard() && canAdd;
+ // If RBAC is enabled there are additional conditions to check.
+ return !contextSrv.accessControlEnabled() || Boolean(this.meta.annotationsPermissions?.dashboard.canAdd);
}
canEditDashboard() {