mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Annotations: Disable "Add annotation" button when annotations are disabled (#57481)
This commit is contained in:
@@ -121,9 +121,11 @@ export const AnnotationSettingsEdit = ({ editIdx, dashboard }: Props) => {
|
||||
{ds && !ds.annotations && <AngularEditorLoader datasource={ds} annotation={annotation} onChange={onUpdate} />}
|
||||
</FieldSet>
|
||||
<Stack>
|
||||
<Button variant="destructive" onClick={onDelete}>
|
||||
Delete
|
||||
</Button>
|
||||
{!annotation.builtIn && (
|
||||
<Button variant="destructive" onClick={onDelete}>
|
||||
Delete
|
||||
</Button>
|
||||
)}
|
||||
<Button variant="secondary" onClick={onPreview}>
|
||||
Preview in dashboard
|
||||
</Button>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useState } from 'react';
|
||||
|
||||
import { arrayUtils } from '@grafana/data';
|
||||
import { arrayUtils, AnnotationQuery } from '@grafana/data';
|
||||
import { getDataSourceSrv } from '@grafana/runtime';
|
||||
import { DeleteButton, Icon, IconButton, VerticalGroup } from '@grafana/ui';
|
||||
import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA';
|
||||
@@ -29,6 +29,30 @@ export const AnnotationSettingsList = ({ dashboard, onNew, onEdit }: Props) => {
|
||||
|
||||
const showEmptyListCTA = annotations.length === 0 || (annotations.length === 1 && annotations[0].builtIn);
|
||||
|
||||
const getAnnotationName = (anno: AnnotationQuery) => {
|
||||
if (anno.enable === false) {
|
||||
return (
|
||||
<>
|
||||
<Icon name="times" /> <em className="muted">(Disabled) {anno.name}</em>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
if (anno.builtIn) {
|
||||
return (
|
||||
<>
|
||||
<Icon name="comment-alt" /> <em className="muted">{anno.name} (Built-in)</em>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Icon name="comment-alt" /> {anno.name}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const dataSourceSrv = getDataSourceSrv();
|
||||
return (
|
||||
<VerticalGroup>
|
||||
@@ -46,11 +70,11 @@ export const AnnotationSettingsList = ({ dashboard, onNew, onEdit }: Props) => {
|
||||
<tr key={`${annotation.name}-${idx}`}>
|
||||
{annotation.builtIn ? (
|
||||
<td style={{ width: '90%' }} className="pointer" onClick={() => onEdit(idx)}>
|
||||
<Icon name="comment-alt" /> <em className="muted">{annotation.name} (Built-in)</em>
|
||||
{getAnnotationName(annotation)}
|
||||
</td>
|
||||
) : (
|
||||
<td className="pointer" onClick={() => onEdit(idx)}>
|
||||
<Icon name="comment-alt" /> {annotation.name}
|
||||
{getAnnotationName(annotation)}
|
||||
</td>
|
||||
)}
|
||||
<td className="pointer" onClick={() => onEdit(idx)}>
|
||||
@@ -65,11 +89,13 @@ export const AnnotationSettingsList = ({ dashboard, onNew, onEdit }: Props) => {
|
||||
) : null}
|
||||
</td>
|
||||
<td style={{ width: '1%' }}>
|
||||
<DeleteButton
|
||||
size="sm"
|
||||
onConfirm={() => onDelete(idx)}
|
||||
aria-label={`Delete query with title "${annotation.name}"`}
|
||||
/>
|
||||
{!annotation.builtIn && (
|
||||
<DeleteButton
|
||||
size="sm"
|
||||
onConfirm={() => onDelete(idx)}
|
||||
aria-label={`Delete query with title "${annotation.name}"`}
|
||||
/>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user