import { css } from '@emotion/css'; import * as React from 'react'; import { GrafanaTheme2 } from '@grafana/data'; import { Stack, useStyles2 } from '@grafana/ui'; import { PopupCard } 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 ( Notification template data Available in the context of a notification.{' '} } dataItems={GlobalTemplateData} typeRenderer={(type) => type === '[]Alert' ? (
{type}
) : type === 'KeyValue' ? ( }>
{type}
) : ( type ) } />
); } export const getTemplateDataDocsStyles = (theme: GrafanaTheme2) => ({ header: css({ color: theme.colors.text.primary, span: { color: theme.colors.text.secondary, fontSize: 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 ( {caption && } {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}
); } export const getTemplateDataTableStyles = (theme: GrafanaTheme2) => ({ table: css({ borderCollapse: 'collapse', width: '100%', caption: { captionSide: 'top', }, 'td, th': { padding: theme.spacing(1, 1), }, thead: { fontWeight: theme.typography.fontWeightBold, }, 'tbody tr:nth-child(2n + 1)': { backgroundColor: theme.colors.background.secondary, }, 'tbody td:nth-child(1)': { fontWeight: theme.typography.fontWeightBold, }, 'tbody td:nth-child(2)': { fontStyle: 'italic', }, }), });