import React, { PureComponent } from 'react'; import { QueryTransaction } from 'app/types/explore'; // TODO make this datasource-plugin-dependent import QueryField from './PromQueryField'; import QueryTransactions from './QueryTransactions'; function getFirstHintFromTransactions(transactions: QueryTransaction[]) { const transaction = transactions.find(qt => qt.hints && qt.hints.length > 0); if (transaction) { return transaction.hints[0]; } return undefined; } class QueryRow extends PureComponent { onChangeQuery = (value, override?: boolean) => { const { index, onChangeQuery } = this.props; if (onChangeQuery) { onChangeQuery(value, index, override); } }; onClickAddButton = () => { const { index, onAddQueryRow } = this.props; if (onAddQueryRow) { onAddQueryRow(index); } }; onClickClearButton = () => { this.onChangeQuery('', true); }; onClickHintFix = action => { const { index, onClickHintFix } = this.props; if (onClickHintFix) { onClickHintFix(action, index); } }; onClickRemoveButton = () => { const { index, onRemoveQueryRow } = this.props; if (onRemoveQueryRow) { onRemoveQueryRow(index); } }; onPressEnter = () => { const { onExecuteQuery } = this.props; if (onExecuteQuery) { onExecuteQuery(); } }; render() { const { history, query, request, supportsLogs, transactions } = this.props; const transactionWithError = transactions.find(t => t.error); const hint = getFirstHintFromTransactions(transactions); const queryError = transactionWithError ? transactionWithError.error : null; return (
); } } export default class QueryRows extends PureComponent { render() { const { className = '', queries, queryHints, transactions, ...handlers } = this.props; return (
{queries.map((q, index) => ( t.rowIndex === index)} {...handlers} /> ))}
); } }