import { css } from '@emotion/css'; import { Draggable } from '@hello-pangea/dnd'; import pluralize from 'pluralize'; import { ReactNode } from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; import { Icon, IconButton, useStyles2, Spinner, IconName } from '@grafana/ui'; import { TagBadge } from 'app/core/components/TagFilter/TagBadge'; import { t, Trans } from 'app/core/internationalization'; import { PlaylistItem } from './types'; interface Props { items: PlaylistItem[]; onDelete: (idx: number) => void; } export const PlaylistTableRows = ({ items, onDelete }: Props) => { const styles = useStyles2(getStyles); if (!items?.length) { return (
Playlist is empty. Add dashboards below.
); } const renderItem = (item: PlaylistItem) => { let icon: IconName = item.type === 'dashboard_by_tag' ? 'apps' : 'tag-alt'; const info: ReactNode[] = []; const first = item.dashboards?.[0]; if (!item.dashboards) { info.push(); } else if (item.type === 'dashboard_by_tag') { info.push(); if (!first) { icon = 'exclamation-triangle'; info.push(  No dashboards found); } else { info.push(  {pluralize('dashboard', item.dashboards.length, true)}); } } else if (first) { info.push( item.dashboards.length > 1 ? ( Multiple items found: ${item.value} ) : ( {first.name ?? item.value} ) ); } else { icon = 'exclamation-triangle'; info.push(  Not found: {item.value}); } return ( <> {info} ); }; return ( <> {items.map((item, index) => ( {(provided) => (
{renderItem(item)}
onDelete(index)} data-testid={selectors.pages.PlaylistForm.itemDelete} tooltip={t('playlist-edit.form.table-delete', 'Delete playlist item')} />
)}
))} ); }; function getStyles(theme: GrafanaTheme2) { return { row: css({ padding: theme.spacing(0.75), background: theme.colors.background.secondary, borderRadius: theme.shape.radius.default, display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: '3px', border: `1px solid ${theme.colors.border.medium}`, '&:hover': { border: `1px solid ${theme.colors.border.strong}`, }, }), rightMargin: css({ marginRight: '5px', }), actions: css({ alignItems: 'center', justifyContent: 'center', display: 'flex', }), settings: css({ label: 'settings', textAlign: 'right', }), }; }