import React, { ReactElement, useState } from 'react'; import { css } from '@emotion/css'; import { GrafanaTheme2 } from '@grafana/data'; import { Icon, Link, useStyles2 } from '@grafana/ui'; import { LibraryElementDTO } from '../../types'; import { PanelTypeCard } from 'app/features/dashboard/components/VizTypePicker/PanelTypeCard'; import { DeleteLibraryPanelModal } from '../DeleteLibraryPanelModal/DeleteLibraryPanelModal'; import { config } from '@grafana/runtime'; import { getPanelPluginNotFound } from 'app/features/panel/components/PanelPluginError'; export interface LibraryPanelCardProps { libraryPanel: LibraryElementDTO; onClick: (panel: LibraryElementDTO) => void; onDelete?: (panel: LibraryElementDTO) => void; showSecondaryActions?: boolean; } export const LibraryPanelCard: React.FC = ({ libraryPanel, onClick, onDelete, showSecondaryActions, }) => { const [showDeletionModal, setShowDeletionModal] = useState(false); const onDeletePanel = () => { onDelete?.(libraryPanel); setShowDeletionModal(false); }; const panelPlugin = config.panels[libraryPanel.model.type] ?? getPanelPluginNotFound(libraryPanel.model.type).meta; return ( <> onClick?.(libraryPanel)} onDelete={showSecondaryActions ? () => setShowDeletionModal(true) : undefined} > {showDeletionModal && ( setShowDeletionModal(false)} /> )} ); }; interface FolderLinkProps { libraryPanel: LibraryElementDTO; } function FolderLink({ libraryPanel }: FolderLinkProps): ReactElement | null { const styles = useStyles2(getStyles); if (!libraryPanel.meta.folderUid && !libraryPanel.meta.folderName) { return null; } if (!libraryPanel.meta.folderUid) { return ( {libraryPanel.meta.folderName} ); } return ( {libraryPanel.meta.folderName} ); } function getStyles(theme: GrafanaTheme2) { return { metaContainer: css` display: flex; align-items: center; color: ${theme.colors.text.secondary}; font-size: ${theme.typography.bodySmall.fontSize}; padding-top: ${theme.spacing(0.5)}; svg { margin-right: ${theme.spacing(0.5)}; margin-bottom: 3px; } `, }; }