|
|
|
|
@ -1,8 +1,9 @@ |
|
|
|
|
import { css } from '@emotion/css'; |
|
|
|
|
import React, { useState } from 'react'; |
|
|
|
|
|
|
|
|
|
import { arrayUtils, AnnotationQuery } from '@grafana/data'; |
|
|
|
|
import { getDataSourceSrv } from '@grafana/runtime'; |
|
|
|
|
import { Button, DeleteButton, IconButton, VerticalGroup } from '@grafana/ui'; |
|
|
|
|
import { Button, DeleteButton, IconButton, useStyles2, VerticalGroup } from '@grafana/ui'; |
|
|
|
|
import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA'; |
|
|
|
|
|
|
|
|
|
import { DashboardModel } from '../../state/DashboardModel'; |
|
|
|
|
@ -15,6 +16,7 @@ type Props = { |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export const AnnotationSettingsList = ({ dashboard, onNew, onEdit }: Props) => { |
|
|
|
|
const styles = useStyles2(getStyles); |
|
|
|
|
const [annotations, updateAnnotations] = useState(dashboard.annotations.list); |
|
|
|
|
|
|
|
|
|
const onMove = (idx: number, direction: number) => { |
|
|
|
|
@ -53,54 +55,56 @@ export const AnnotationSettingsList = ({ dashboard, onNew, onEdit }: Props) => { |
|
|
|
|
return ( |
|
|
|
|
<VerticalGroup> |
|
|
|
|
{annotations.length > 0 && ( |
|
|
|
|
<table role="grid" className="filter-table filter-table--hover"> |
|
|
|
|
<thead> |
|
|
|
|
<tr> |
|
|
|
|
<th>Query name</th> |
|
|
|
|
<th>Data source</th> |
|
|
|
|
<th colSpan={3}></th> |
|
|
|
|
</tr> |
|
|
|
|
</thead> |
|
|
|
|
<tbody> |
|
|
|
|
{dashboard.annotations.list.map((annotation, idx) => ( |
|
|
|
|
<tr key={`${annotation.name}-${idx}`}> |
|
|
|
|
{annotation.builtIn ? ( |
|
|
|
|
<td role="gridcell" style={{ width: '90%' }} className="pointer" onClick={() => onEdit(idx)}> |
|
|
|
|
<Button size="sm" fill="text" variant="secondary"> |
|
|
|
|
{getAnnotationName(annotation)} |
|
|
|
|
</Button> |
|
|
|
|
</td> |
|
|
|
|
) : ( |
|
|
|
|
<div className={styles.table}> |
|
|
|
|
<table role="grid" className="filter-table filter-table--hover"> |
|
|
|
|
<thead> |
|
|
|
|
<tr> |
|
|
|
|
<th>Query name</th> |
|
|
|
|
<th>Data source</th> |
|
|
|
|
<th colSpan={3}></th> |
|
|
|
|
</tr> |
|
|
|
|
</thead> |
|
|
|
|
<tbody> |
|
|
|
|
{dashboard.annotations.list.map((annotation, idx) => ( |
|
|
|
|
<tr key={`${annotation.name}-${idx}`}> |
|
|
|
|
{annotation.builtIn ? ( |
|
|
|
|
<td role="gridcell" style={{ width: '90%' }} className="pointer" onClick={() => onEdit(idx)}> |
|
|
|
|
<Button size="sm" fill="text" variant="secondary"> |
|
|
|
|
{getAnnotationName(annotation)} |
|
|
|
|
</Button> |
|
|
|
|
</td> |
|
|
|
|
) : ( |
|
|
|
|
<td role="gridcell" className="pointer" onClick={() => onEdit(idx)}> |
|
|
|
|
<Button size="sm" fill="text" variant="secondary"> |
|
|
|
|
{getAnnotationName(annotation)} |
|
|
|
|
</Button> |
|
|
|
|
</td> |
|
|
|
|
)} |
|
|
|
|
<td role="gridcell" className="pointer" onClick={() => onEdit(idx)}> |
|
|
|
|
<Button size="sm" fill="text" variant="secondary"> |
|
|
|
|
{getAnnotationName(annotation)} |
|
|
|
|
</Button> |
|
|
|
|
{dataSourceSrv.getInstanceSettings(annotation.datasource)?.name || annotation.datasource?.uid} |
|
|
|
|
</td> |
|
|
|
|
)} |
|
|
|
|
<td role="gridcell" className="pointer" onClick={() => onEdit(idx)}> |
|
|
|
|
{dataSourceSrv.getInstanceSettings(annotation.datasource)?.name || annotation.datasource?.uid} |
|
|
|
|
</td> |
|
|
|
|
<td role="gridcell" style={{ width: '1%' }}> |
|
|
|
|
{idx !== 0 && <IconButton name="arrow-up" onClick={() => onMove(idx, -1)} tooltip="Move up" />} |
|
|
|
|
</td> |
|
|
|
|
<td role="gridcell" style={{ width: '1%' }}> |
|
|
|
|
{dashboard.annotations.list.length > 1 && idx !== dashboard.annotations.list.length - 1 ? ( |
|
|
|
|
<IconButton name="arrow-down" onClick={() => onMove(idx, 1)} tooltip="Move down" /> |
|
|
|
|
) : null} |
|
|
|
|
</td> |
|
|
|
|
<td role="gridcell" style={{ width: '1%' }}> |
|
|
|
|
{!annotation.builtIn && ( |
|
|
|
|
<DeleteButton |
|
|
|
|
size="sm" |
|
|
|
|
onConfirm={() => onDelete(idx)} |
|
|
|
|
aria-label={`Delete query with title "${annotation.name}"`} |
|
|
|
|
/> |
|
|
|
|
)} |
|
|
|
|
</td> |
|
|
|
|
</tr> |
|
|
|
|
))} |
|
|
|
|
</tbody> |
|
|
|
|
</table> |
|
|
|
|
<td role="gridcell" style={{ width: '1%' }}> |
|
|
|
|
{idx !== 0 && <IconButton name="arrow-up" onClick={() => onMove(idx, -1)} tooltip="Move up" />} |
|
|
|
|
</td> |
|
|
|
|
<td role="gridcell" style={{ width: '1%' }}> |
|
|
|
|
{dashboard.annotations.list.length > 1 && idx !== dashboard.annotations.list.length - 1 ? ( |
|
|
|
|
<IconButton name="arrow-down" onClick={() => onMove(idx, 1)} tooltip="Move down" /> |
|
|
|
|
) : null} |
|
|
|
|
</td> |
|
|
|
|
<td role="gridcell" style={{ width: '1%' }}> |
|
|
|
|
{!annotation.builtIn && ( |
|
|
|
|
<DeleteButton |
|
|
|
|
size="sm" |
|
|
|
|
onConfirm={() => onDelete(idx)} |
|
|
|
|
aria-label={`Delete query with title "${annotation.name}"`} |
|
|
|
|
/> |
|
|
|
|
)} |
|
|
|
|
</td> |
|
|
|
|
</tr> |
|
|
|
|
))} |
|
|
|
|
</tbody> |
|
|
|
|
</table> |
|
|
|
|
</div> |
|
|
|
|
)} |
|
|
|
|
{showEmptyListCTA && ( |
|
|
|
|
<EmptyListCTA |
|
|
|
|
@ -127,3 +131,10 @@ export const AnnotationSettingsList = ({ dashboard, onNew, onEdit }: Props) => { |
|
|
|
|
</VerticalGroup> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const getStyles = () => ({ |
|
|
|
|
table: css` |
|
|
|
|
width: 100%; |
|
|
|
|
overflow-x: scroll; |
|
|
|
|
`,
|
|
|
|
|
}); |
|
|
|
|
|