mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Added types to query rows
This commit is contained in:
parent
3a1ece537c
commit
54a3e2d1d1
@ -1,12 +1,12 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
|
|
||||||
import { QueryTransaction } from 'app/types/explore';
|
import { QueryTransaction, HistoryItem, Query, QueryHint } from 'app/types/explore';
|
||||||
|
|
||||||
// TODO make this datasource-plugin-dependent
|
// TODO make this datasource-plugin-dependent
|
||||||
import QueryField from './PromQueryField';
|
import QueryField from './PromQueryField';
|
||||||
import QueryTransactions from './QueryTransactions';
|
import QueryTransactions from './QueryTransactions';
|
||||||
|
|
||||||
function getFirstHintFromTransactions(transactions: QueryTransaction[]) {
|
function getFirstHintFromTransactions(transactions: QueryTransaction[]): QueryHint {
|
||||||
const transaction = transactions.find(qt => qt.hints && qt.hints.length > 0);
|
const transaction = transactions.find(qt => qt.hints && qt.hints.length > 0);
|
||||||
if (transaction) {
|
if (transaction) {
|
||||||
return transaction.hints[0];
|
return transaction.hints[0];
|
||||||
@ -14,7 +14,30 @@ function getFirstHintFromTransactions(transactions: QueryTransaction[]) {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
class QueryRow extends PureComponent<any, {}> {
|
interface QueryRowEventHandlers {
|
||||||
|
onAddQueryRow: (index: number) => void;
|
||||||
|
onChangeQuery: (value: string, index: number, override?: boolean) => void;
|
||||||
|
onClickHintFix: (action: object, index?: number) => void;
|
||||||
|
onExecuteQuery: () => void;
|
||||||
|
onRemoveQueryRow: (index: number) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface QueryRowCommonProps {
|
||||||
|
className?: string;
|
||||||
|
history: HistoryItem[];
|
||||||
|
request: (url: string) => Promise<any>;
|
||||||
|
// Temporarily
|
||||||
|
supportsLogs?: boolean;
|
||||||
|
transactions: QueryTransaction[];
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueryRowProps = QueryRowCommonProps &
|
||||||
|
QueryRowEventHandlers & {
|
||||||
|
index: number;
|
||||||
|
query: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QueryRow extends PureComponent<QueryRowProps> {
|
||||||
onChangeQuery = (value, override?: boolean) => {
|
onChangeQuery = (value, override?: boolean) => {
|
||||||
const { index, onChangeQuery } = this.props;
|
const { index, onChangeQuery } = this.props;
|
||||||
if (onChangeQuery) {
|
if (onChangeQuery) {
|
||||||
@ -56,7 +79,7 @@ class QueryRow extends PureComponent<any, {}> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { history, query, request, supportsLogs, transactions } = this.props;
|
const { history, query, request, supportsLogs, transactions } = this.props;
|
||||||
const transactionWithError = transactions.find(t => t.error);
|
const transactionWithError = transactions.find(t => t.error !== undefined);
|
||||||
const hint = getFirstHintFromTransactions(transactions);
|
const hint = getFirstHintFromTransactions(transactions);
|
||||||
const queryError = transactionWithError ? transactionWithError.error : null;
|
const queryError = transactionWithError ? transactionWithError.error : null;
|
||||||
return (
|
return (
|
||||||
@ -93,9 +116,14 @@ class QueryRow extends PureComponent<any, {}> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class QueryRows extends PureComponent<any, {}> {
|
type QueryRowsProps = QueryRowCommonProps &
|
||||||
|
QueryRowEventHandlers & {
|
||||||
|
queries: Query[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class QueryRows extends PureComponent<QueryRowsProps> {
|
||||||
render() {
|
render() {
|
||||||
const { className = '', queries, queryHints, transactions, ...handlers } = this.props;
|
const { className = '', queries, transactions, ...handlers } = this.props;
|
||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
{queries.map((q, index) => (
|
{queries.map((q, index) => (
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
export function getQueryHints(query: string, series?: any[], datasource?: any): any[] {
|
import { QueryHint } from 'app/types/explore';
|
||||||
|
|
||||||
|
export function getQueryHints(query: string, series?: any[], datasource?: any): QueryHint[] {
|
||||||
const hints = [];
|
const hints = [];
|
||||||
|
|
||||||
// ..._bucket metric needs a histogram_quantile()
|
// ..._bucket metric needs a histogram_quantile()
|
||||||
|
@ -18,11 +18,28 @@ export interface Query {
|
|||||||
key?: string;
|
key?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface QueryFix {
|
||||||
|
type: string;
|
||||||
|
label: string;
|
||||||
|
action?: QueryFixAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QueryFixAction {
|
||||||
|
type: string;
|
||||||
|
query?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface QueryHint {
|
||||||
|
type: string;
|
||||||
|
label: string;
|
||||||
|
fix?: QueryFix;
|
||||||
|
}
|
||||||
|
|
||||||
export interface QueryTransaction {
|
export interface QueryTransaction {
|
||||||
id: string;
|
id: string;
|
||||||
done: boolean;
|
done: boolean;
|
||||||
error?: string;
|
error?: string;
|
||||||
hints?: any[];
|
hints?: QueryHint[];
|
||||||
latency: number;
|
latency: number;
|
||||||
options: any;
|
options: any;
|
||||||
query: string;
|
query: string;
|
||||||
|
Loading…
Reference in New Issue
Block a user