import { css } from '@emotion/css'; import React, { useState, useEffect } from 'react'; import { GrafanaTheme2, PanelData, QueryHint } from '@grafana/data'; import { Button, Tooltip, useStyles2 } from '@grafana/ui'; import { PrometheusDatasource } from '../../datasource'; import { promQueryModeller } from '../PromQueryModeller'; import { buildVisualQueryFromString } from '../parsing'; import { PromVisualQuery } from '../types'; export interface Props { query: PromVisualQuery; datasource: PrometheusDatasource; onChange: (update: PromVisualQuery) => void; data?: PanelData; } export const PromQueryBuilderHints = React.memo(({ datasource, query, onChange, data }) => { const [hints, setHints] = useState([]); const styles = useStyles2(getStyles); useEffect(() => { const promQuery = { expr: promQueryModeller.renderQuery(query), refId: '' }; // For now show only actionable hints const hints = datasource.getQueryHints(promQuery, data?.series || []).filter((hint) => hint.fix?.action); setHints(hints); }, [datasource, query, onChange, data, styles.hint]); return ( <> {hints.length > 0 && (
{hints.map((hint) => { return ( ); })}
)} ); }); PromQueryBuilderHints.displayName = 'PromQueryBuilderHints'; const getStyles = (theme: GrafanaTheme2) => { return { container: css` display: flex; margin-bottom: ${theme.spacing(1)}; align-items: center; `, hint: css` margin-right: ${theme.spacing(1)}; `, }; };