import { css } from '@emotion/css'; import React from 'react'; import Skeleton from 'react-loading-skeleton'; import { GrafanaTheme2 } from '@grafana/data'; import { reportInteraction } from '@grafana/runtime'; import { Icon, IconButton, Link, Spinner, useStyles2, Text } from '@grafana/ui'; import { getSvgSize } from '@grafana/ui/src/components/Icon/utils'; import { t } from 'app/core/internationalization'; import { getIconForKind } from 'app/features/search/service/utils'; import { Indent } from '../../../core/components/Indent/Indent'; import { useChildrenByParentUIDState } from '../state'; import { DashboardsTreeCellProps } from '../types'; import { makeRowID } from './utils'; const CHEVRON_SIZE = 'md'; const ICON_SIZE = 'sm'; type NameCellProps = DashboardsTreeCellProps & { onFolderClick: (uid: string, newOpenState: boolean) => void; }; export function NameCell({ row: { original: data }, onFolderClick, treeID }: NameCellProps) { const styles = useStyles2(getStyles); const { item, level, isOpen } = data; const childrenByParentUID = useChildrenByParentUIDState(); const isLoading = isOpen && !childrenByParentUID[item.uid]; const iconName = getIconForKind(data.item.kind, isOpen); if (item.kind === 'ui') { return ( <> {item.uiKind === 'empty-folder' ? ( No items ) : ( )} ); } return ( <> {item.kind === 'folder' ? ( { onFolderClick(item.uid, !isOpen); }} name={isOpen ? 'angle-down' : 'angle-right'} aria-label={ isOpen ? t('browse-dashboards.dashboards-tree.collapse-folder-button', 'Collapse folder {{title}}', { title: item.title, }) : t('browse-dashboards.dashboards-tree.expand-folder-button', 'Expand folder {{title}}', { title: item.title, }) } /> ) : ( )}
{isLoading ? : } {item.url ? ( { reportInteraction('manage_dashboards_result_clicked'); }} href={item.url} className={styles.link} > {item.title} ) : ( item.title )}
); } const getStyles = (theme: GrafanaTheme2) => { return { chevron: css({ marginRight: theme.spacing(1), width: getSvgSize(CHEVRON_SIZE), }), emptyText: css({ // needed for text to truncate correctly overflow: 'hidden', }), // Should be the same size as the so Dashboard name is aligned to Folder name siblings folderButtonSpacer: css({ paddingLeft: `calc(${getSvgSize(CHEVRON_SIZE)}px + ${theme.spacing(1)})`, }), iconNameContainer: css({ alignItems: 'center', display: 'flex', gap: theme.spacing(1), overflow: 'hidden', }), link: css({ '&:hover': { textDecoration: 'underline', }, }), }; };