import React, { FC, MouseEvent } from 'react'; import { css, cx } from '@emotion/css'; import { AnnotationEvent, DateTimeInput, GrafanaTheme2, PanelProps } from '@grafana/data'; import { styleMixins, Tooltip, useStyles2 } from '@grafana/ui'; import { AnnoOptions } from './types'; import { AnnotationListItemTags } from './AnnotationListItemTags'; 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 = (e: MouseEvent) => { e.stopPropagation(); onClick(annotation); }; const onLoginClick = () => { onAvatarClick(annotation); }; const showAvatar = login && showUser; const showTimeStamp = time && showTime; const showTimeStampEnd = timeEnd && timeEnd !== time && showTime; return (
{text} {showTimeStamp ? : null} {showTimeStampEnd ? - : null} {showTimeStampEnd ? : null}
{showAvatar ? : null} {showTags ? : null}
); }; 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 (
avatar icon
); }; 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 { pointer: css` cursor: pointer; `, item: css` margin: ${theme.spacing(0.5)}; padding: ${theme.spacing(1)}; ${styleMixins.listItem(theme)}// display: flex; `, title: css` flex-basis: 80%; `, link: css` display: flex; .fa { padding-top: ${theme.spacing(0.5)}; } .fa-star { color: ${theme.v1.palette.orange}; } `, login: css` align-self: center; flex: auto; display: flex; justify-content: flex-end; font-size: ${theme.typography.bodySmall.fontSize}; `, time: css` margin-left: ${theme.spacing(1)}; margin-right: ${theme.spacing(1)} font-size: ${theme.typography.bodySmall.fontSize}; color: ${theme.colors.text.secondary}; `, avatar: css` padding: ${theme.spacing(0.5)}; img { border-radius: 50%; width: ${theme.spacing(2)}; height: ${theme.spacing(2)}; } `, }; }