import { css } from '@emotion/css'; import React, { FC, useCallback } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; import { Card, Icon, IconName, TagList, useStyles2 } from '@grafana/ui'; import { SEARCH_ITEM_HEIGHT } from '../constants'; import { DashboardSectionItem, OnToggleChecked } from '../types'; import { SearchCheckbox } from './SearchCheckbox'; export interface Props { item: DashboardSectionItem; editable?: boolean; onTagSelected: (name: string) => any; onToggleChecked?: OnToggleChecked; } const selectors = e2eSelectors.components.Search; const getIconFromMeta = (meta = ''): IconName => { const metaIconMap = new Map([ ['errors', 'info-circle'], ['views', 'eye'], ]); return metaIconMap.has(meta) ? metaIconMap.get(meta)! : 'sort-amount-down'; }; export const SearchItem: FC = ({ item, editable, onToggleChecked, onTagSelected }) => { const styles = useStyles2(getStyles); const tagSelected = useCallback( (tag: string, event: React.MouseEvent) => { event.stopPropagation(); event.preventDefault(); onTagSelected(tag); }, [onTagSelected] ); const handleCheckboxClick = useCallback( (ev: React.MouseEvent) => { ev.stopPropagation(); ev.preventDefault(); if (onToggleChecked) { onToggleChecked(item); } }, [item, onToggleChecked] ); const folderTitle = item.folderTitle || 'General'; return ( {item.title} {folderTitle} {item.sortMetaName && ( {item.sortMeta} {item.sortMetaName} )} `Filter by tag "${tag}"`} /> ); }; const getStyles = (theme: GrafanaTheme2) => { return { container: css` margin-bottom: ${theme.spacing(0.75)}; padding: ${theme.spacing(1)} ${theme.spacing(2)}; `, metaContainer: css` display: flex; align-items: center; margin-right: ${theme.spacing(1)}; svg { margin-right: ${theme.spacing(0.5)}; } `, checkbox: css` margin-right: 0; `, }; };