import React from 'react'; import { CoreApp, SelectableValue } from '@grafana/data'; import { EditorRow, EditorField } from '@grafana/experimental'; import { reportInteraction } from '@grafana/runtime'; import { RadioButtonGroup, Select } from '@grafana/ui'; import { AutoSizeInput } from 'app/plugins/datasource/prometheus/querybuilder/shared/AutoSizeInput'; import { QueryOptionGroup } from 'app/plugins/datasource/prometheus/querybuilder/shared/QueryOptionGroup'; import { preprocessMaxLines, queryTypeOptions, RESOLUTION_OPTIONS } from '../../components/LokiOptionFields'; import { isMetricsQuery } from '../../datasource'; import { LokiQuery, LokiQueryType } from '../../types'; export interface Props { query: LokiQuery; onChange: (update: LokiQuery) => void; onRunQuery: () => void; app?: CoreApp; } export const LokiQueryBuilderOptions = React.memo(({ app, query, onChange, onRunQuery }) => { const onQueryTypeChange = (value: LokiQueryType) => { onChange({ ...query, queryType: value }); onRunQuery(); }; const onResolutionChange = (option: SelectableValue) => { reportInteraction('grafana_loki_resolution_clicked', { app, resolution: option.value, }); onChange({ ...query, resolution: option.value }); onRunQuery(); }; const onLegendFormatChanged = (evt: React.FormEvent) => { onChange({ ...query, legendFormat: evt.currentTarget.value }); onRunQuery(); }; function onMaxLinesChange(e: React.SyntheticEvent) { const newMaxLines = preprocessMaxLines(e.currentTarget.value); if (query.maxLines !== newMaxLines) { onChange({ ...query, maxLines: newMaxLines }); onRunQuery(); } } let queryType = query.queryType ?? (query.instant ? LokiQueryType.Instant : LokiQueryType.Range); let showMaxLines = !isMetricsQuery(query.expr); return ( {showMaxLines && ( )}