import { css } from '@emotion/css'; import React, { FC, MouseEvent } from 'react'; import { AnnotationEvent, DateTimeInput, GrafanaTheme2, PanelProps } from '@grafana/data'; import { Card, TagList, Tooltip, useStyles2 } from '@grafana/ui'; import { AnnoOptions } from './types'; interface Props extends Pick, 'options'> { annotation: AnnotationEvent; formatDate: (date: DateTimeInput, format?: string) => string; onClick: (annotation: AnnotationEvent) => void; onAvatarClick: (annotation: AnnotationEvent) => void; onTagClick: (tag: string, remove?: boolean) => void; } export const AnnotationListItem: FC = ({ options, annotation, formatDate, onClick, onAvatarClick, onTagClick, }) => { const styles = useStyles2(getStyles); const { showUser, showTags, showTime } = options; const { text, login, email, avatarUrl, tags, time, timeEnd } = annotation; const onItemClick = () => { onClick(annotation); }; const onLoginClick = () => { onAvatarClick(annotation); }; const showAvatar = login && showUser; const showTimeStamp = time && showTime; const showTimeStampEnd = timeEnd && timeEnd !== time && showTime; return ( {text} {showTimeStamp && ( {showTimeStampEnd && ( <> - {' '} )} )} {showAvatar && ( )} {showTags && tags && ( onTagClick(tag, false)} /> )} ); }; interface AvatarProps { login: string; onClick: () => void; avatarUrl?: string; email?: string; } const Avatar: FC = ({ onClick, avatarUrl, login, email }) => { const styles = useStyles2(getStyles); const onAvatarClick = (e: MouseEvent) => { e.stopPropagation(); onClick(); }; const tooltipContent = ( Created by:
{email}
); return ( ); }; interface TimeStampProps { time: number; formatDate: (date: DateTimeInput, format?: string) => string; } const TimeStamp: FC = ({ time, formatDate }) => { const styles = useStyles2(getStyles); return ( {formatDate(time)} ); }; function getStyles(theme: GrafanaTheme2) { return { card: css({ gridTemplateAreas: `"Heading Description Meta Tags"`, gridTemplateColumns: 'auto 1fr auto auto', padding: theme.spacing(1), margin: theme.spacing(0.5), width: 'inherit', }), meta: css({ margin: 0, position: 'relative', justifyContent: 'end', }), timestamp: css({ margin: 0, alignSelf: 'center', }), time: css({ marginLeft: theme.spacing(1), marginRight: theme.spacing(1), fontSize: theme.typography.bodySmall.fontSize, color: theme.colors.text.secondary, }), avatar: css({ border: 'none', background: 'inherit', margin: 0, padding: theme.spacing(0.5), img: { borderRadius: '50%', width: theme.spacing(2), height: theme.spacing(2), }, }), }; }