import { css } from '@emotion/css'; import React from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { Stack } from '@grafana/experimental'; import { useStyles2 } from '@grafana/ui'; import { HoverCard } from '../HoverCard'; import { AlertTemplateData, GlobalTemplateData, KeyValueCodeSnippet, KeyValueTemplateFunctions, TemplateDataItem, } from './TemplateData'; export function TemplateDataDocs() { const styles = useStyles2(getTemplateDataDocsStyles); const AlertTemplateDataTable = ( Alert template data Available only when in the context of an Alert (e.g. inside .Alerts loop) } dataItems={AlertTemplateData} /> ); return ( Template Data} dataItems={GlobalTemplateData} typeRenderer={(type) => type === '[]Alert' ? (
{type}
) : type === 'KeyValue' ? ( }>
{type}
) : ( type ) } />
); } const getTemplateDataDocsStyles = (theme: GrafanaTheme2) => ({ header: css` color: ${theme.colors.text.primary}; span { color: ${theme.colors.text.secondary}; font-size: ${theme.typography.bodySmall.fontSize}; } `, interactiveType: css` color: ${theme.colors.text.link}; `, }); interface TemplateDataTableProps { dataItems: TemplateDataItem[]; caption: JSX.Element | string; typeRenderer?: (type: TemplateDataItem['type']) => React.ReactNode; } export function TemplateDataTable({ dataItems, caption, typeRenderer }: TemplateDataTableProps) { const styles = useStyles2(getTemplateDataTableStyles); return ( {dataItems.map(({ name, type, notes }, index) => ( ))}
{caption}
Name Type Notes
{name} {typeRenderer ? typeRenderer(type) : type} {notes}
); } function KeyValueTemplateDataTable() { const tableStyles = useStyles2(getTemplateDataTableStyles); return (
KeyValue is a set of key/value string pairs that represent labels and annotations.
        {KeyValueCodeSnippet}
      
{KeyValueTemplateFunctions.map(({ name, args, returns, notes }) => ( ))}
Key-value methods
Name Arguments Returns Notes
{name} {args} {returns} {notes}
); } const getTemplateDataTableStyles = (theme: GrafanaTheme2) => ({ table: css` border-collapse: collapse; width: 100%; caption { caption-side: top; } td, th { padding: ${theme.spacing(1, 1)}; } thead { font-weight: ${theme.typography.fontWeightBold}; } tbody tr:nth-child(2n + 1) { background-color: ${theme.colors.background.secondary}; } tbody td:nth-child(1) { font-weight: ${theme.typography.fontWeightBold}; } tbody td:nth-child(2) { font-style: italic; } `, });