2018-04-26 04:58:42 -05:00
|
|
|
import React from 'react';
|
|
|
|
import { hot } from 'react-hot-loader';
|
2019-01-10 07:24:31 -06:00
|
|
|
import { connect } from 'react-redux';
|
2018-10-22 10:51:42 -05:00
|
|
|
import _ from 'lodash';
|
2019-01-11 11:26:56 -06:00
|
|
|
import { AutoSizer } from 'react-virtualized';
|
2019-01-10 07:24:31 -06:00
|
|
|
import { RawTimeRange, TimeRange } from '@grafana/ui';
|
2018-07-13 02:09:36 -05:00
|
|
|
|
2019-01-10 07:24:31 -06:00
|
|
|
import { DataSourceSelectItem } from 'app/types/datasources';
|
2019-01-11 11:26:56 -06:00
|
|
|
import { ExploreUrlState, HistoryItem, QueryTransaction, RangeScanner, ExploreId } from 'app/types/explore';
|
2018-12-23 02:15:32 -06:00
|
|
|
import { DataQuery } from 'app/types/series';
|
2019-01-11 11:26:56 -06:00
|
|
|
import { StoreState } from 'app/types';
|
2018-08-02 09:43:33 -05:00
|
|
|
import store from 'app/core/store';
|
2019-01-11 11:26:56 -06:00
|
|
|
import { LAST_USED_DATASOURCE_KEY, ensureQueries, DEFAULT_RANGE } from 'app/core/utils/explore';
|
2018-12-14 07:05:47 -06:00
|
|
|
import { DataSourcePicker } from 'app/core/components/Select/DataSourcePicker';
|
2018-11-23 08:12:20 -06:00
|
|
|
import { Emitter } from 'app/core/utils/emitter';
|
2019-01-10 07:24:31 -06:00
|
|
|
|
|
|
|
import {
|
|
|
|
addQueryRow,
|
|
|
|
changeDatasource,
|
|
|
|
changeQuery,
|
|
|
|
changeSize,
|
|
|
|
changeTime,
|
|
|
|
clickClear,
|
2019-01-11 11:26:56 -06:00
|
|
|
clickCloseSplit,
|
2019-01-10 07:24:31 -06:00
|
|
|
clickExample,
|
|
|
|
clickGraphButton,
|
|
|
|
clickLogsButton,
|
2019-01-11 11:26:56 -06:00
|
|
|
clickSplit,
|
2019-01-10 07:24:31 -06:00
|
|
|
clickTableButton,
|
|
|
|
highlightLogsExpression,
|
|
|
|
initializeExplore,
|
|
|
|
modifyQueries,
|
|
|
|
removeQueryRow,
|
|
|
|
runQueries,
|
|
|
|
scanStart,
|
|
|
|
scanStop,
|
|
|
|
} from './state/actions';
|
2019-01-11 11:26:56 -06:00
|
|
|
import { ExploreItemState } from './state/reducers';
|
2018-04-26 04:58:42 -05:00
|
|
|
|
2018-11-16 12:21:13 -06:00
|
|
|
import Panel from './Panel';
|
2018-10-30 08:38:34 -05:00
|
|
|
import QueryRows from './QueryRows';
|
|
|
|
import Graph from './Graph';
|
|
|
|
import Logs from './Logs';
|
|
|
|
import Table from './Table';
|
2018-10-26 11:16:00 -05:00
|
|
|
import ErrorBoundary from './ErrorBoundary';
|
2018-11-30 06:51:49 -06:00
|
|
|
import { Alert } from './Error';
|
2018-12-07 05:41:47 -06:00
|
|
|
import TimePicker, { parseTime } from './TimePicker';
|
2019-01-10 07:24:31 -06:00
|
|
|
import { LogsModel } from 'app/core/logs_model';
|
|
|
|
import TableModel from 'app/core/table_model';
|
2018-12-31 12:30:32 -06:00
|
|
|
|
2018-09-28 09:44:07 -05:00
|
|
|
interface ExploreProps {
|
2019-01-10 07:24:31 -06:00
|
|
|
StartPage?: any;
|
|
|
|
addQueryRow: typeof addQueryRow;
|
|
|
|
changeDatasource: typeof changeDatasource;
|
|
|
|
changeQuery: typeof changeQuery;
|
2019-01-11 11:26:56 -06:00
|
|
|
changeSize: typeof changeSize;
|
2019-01-10 07:24:31 -06:00
|
|
|
changeTime: typeof changeTime;
|
|
|
|
clickClear: typeof clickClear;
|
2019-01-11 11:26:56 -06:00
|
|
|
clickCloseSplit: typeof clickCloseSplit;
|
2019-01-10 07:24:31 -06:00
|
|
|
clickExample: typeof clickExample;
|
|
|
|
clickGraphButton: typeof clickGraphButton;
|
|
|
|
clickLogsButton: typeof clickLogsButton;
|
2019-01-11 11:26:56 -06:00
|
|
|
clickSplit: typeof clickSplit;
|
2019-01-10 07:24:31 -06:00
|
|
|
clickTableButton: typeof clickTableButton;
|
|
|
|
datasourceError: string;
|
|
|
|
datasourceInstance: any;
|
|
|
|
datasourceLoading: boolean | null;
|
|
|
|
datasourceMissing: boolean;
|
|
|
|
exploreDatasources: DataSourceSelectItem[];
|
2019-01-11 11:26:56 -06:00
|
|
|
exploreId: ExploreId;
|
2019-01-10 07:24:31 -06:00
|
|
|
graphResult?: any[];
|
|
|
|
highlightLogsExpression: typeof highlightLogsExpression;
|
|
|
|
history: HistoryItem[];
|
|
|
|
initialDatasource?: string;
|
|
|
|
initialQueries: DataQuery[];
|
|
|
|
initializeExplore: typeof initializeExplore;
|
|
|
|
logsHighlighterExpressions?: string[];
|
|
|
|
logsResult?: LogsModel;
|
|
|
|
modifyQueries: typeof modifyQueries;
|
|
|
|
queryTransactions: QueryTransaction[];
|
|
|
|
removeQueryRow: typeof removeQueryRow;
|
|
|
|
range: RawTimeRange;
|
|
|
|
runQueries: typeof runQueries;
|
|
|
|
scanner?: RangeScanner;
|
|
|
|
scanning?: boolean;
|
|
|
|
scanRange?: RawTimeRange;
|
|
|
|
scanStart: typeof scanStart;
|
|
|
|
scanStop: typeof scanStop;
|
2018-09-28 09:44:07 -05:00
|
|
|
split: boolean;
|
2019-01-10 07:24:31 -06:00
|
|
|
showingGraph: boolean;
|
|
|
|
showingLogs: boolean;
|
|
|
|
showingStartPage?: boolean;
|
|
|
|
showingTable: boolean;
|
|
|
|
supportsGraph: boolean | null;
|
|
|
|
supportsLogs: boolean | null;
|
|
|
|
supportsTable: boolean | null;
|
|
|
|
tableResult?: TableModel;
|
2018-09-28 09:44:07 -05:00
|
|
|
urlState: ExploreUrlState;
|
2018-04-27 11:21:20 -05:00
|
|
|
}
|
|
|
|
|
2018-11-21 07:45:57 -06:00
|
|
|
/**
|
|
|
|
* Explore provides an area for quick query iteration for a given datasource.
|
|
|
|
* Once a datasource is selected it populates the query section at the top.
|
|
|
|
* When queries are run, their results are being displayed in the main section.
|
|
|
|
* The datasource determines what kind of query editor it brings, and what kind
|
|
|
|
* of results viewers it supports.
|
2018-11-22 05:00:41 -06:00
|
|
|
*
|
|
|
|
* QUERY HANDLING
|
|
|
|
*
|
|
|
|
* TLDR: to not re-render Explore during edits, query editing is not "controlled"
|
|
|
|
* in a React sense: values need to be pushed down via `initialQueries`, while
|
|
|
|
* edits travel up via `this.modifiedQueries`.
|
|
|
|
*
|
|
|
|
* By default the query rows start without prior state: `initialQueries` will
|
|
|
|
* contain one empty DataQuery. While the user modifies the DataQuery, the
|
|
|
|
* modifications are being tracked in `this.modifiedQueries`, which need to be
|
|
|
|
* used whenever a query is sent to the datasource to reflect what the user sees
|
2018-12-05 03:17:22 -06:00
|
|
|
* on the screen. Query"react-popper": "^0.7.5", rows can be initialized or reset using `initialQueries`,
|
|
|
|
* by giving the respec"react-popper": "^0.7.5",tive row a new key. This wipes the old row and its state.
|
|
|
|
* This property is als"react-popper": "^0.7.5",o used to govern how many query rows there are (minimum 1).
|
2018-11-22 05:00:41 -06:00
|
|
|
*
|
|
|
|
* This flow makes sure that a query row can be arbitrarily complex without the
|
|
|
|
* fear of being wiped or re-initialized via props. The query row is free to keep
|
|
|
|
* its own state while the user edits or builds a query. Valid queries can be sent
|
|
|
|
* up to Explore via the `onChangeQuery` prop.
|
|
|
|
*
|
|
|
|
* DATASOURCE REQUESTS
|
|
|
|
*
|
|
|
|
* A click on Run Query creates transactions for all DataQueries for all expanded
|
|
|
|
* result viewers. New runs are discarding previous runs. Upon completion a transaction
|
|
|
|
* saves the result. The result viewers construct their data from the currently existing
|
|
|
|
* transactions.
|
|
|
|
*
|
|
|
|
* The result viewers determine some of the query options sent to the datasource, e.g.,
|
|
|
|
* `format`, to indicate eventual transformations by the datasources' result transformers.
|
2018-11-21 07:45:57 -06:00
|
|
|
*/
|
2019-01-11 11:26:56 -06:00
|
|
|
export class Explore extends React.PureComponent<ExploreProps> {
|
2018-07-17 08:13:44 -05:00
|
|
|
el: any;
|
2018-11-23 08:12:20 -06:00
|
|
|
exploreEvents: Emitter;
|
2018-11-23 10:53:16 -06:00
|
|
|
/**
|
|
|
|
* Timepicker to control scanning
|
|
|
|
*/
|
|
|
|
timepickerRef: React.RefObject<TimePicker>;
|
2018-07-17 08:13:44 -05:00
|
|
|
|
2018-04-26 04:58:42 -05:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-11-23 08:12:20 -06:00
|
|
|
this.exploreEvents = new Emitter();
|
2018-11-23 10:53:16 -06:00
|
|
|
this.timepickerRef = React.createRef();
|
2018-04-26 04:58:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2019-01-11 11:26:56 -06:00
|
|
|
const { exploreId, split, urlState } = this.props;
|
|
|
|
if (!split) {
|
|
|
|
// Load URL state and parse range
|
|
|
|
const { datasource, queries, range = DEFAULT_RANGE } = (urlState || {}) as ExploreUrlState;
|
|
|
|
const initialDatasource = datasource || store.get(LAST_USED_DATASOURCE_KEY);
|
|
|
|
const initialQueries: DataQuery[] = ensureQueries(queries);
|
|
|
|
const initialRange = { from: parseTime(range.from), to: parseTime(range.to) };
|
|
|
|
const width = this.el ? this.el.offsetWidth : 0;
|
|
|
|
this.props.initializeExplore(
|
|
|
|
exploreId,
|
|
|
|
initialDatasource,
|
|
|
|
initialQueries,
|
|
|
|
initialRange,
|
|
|
|
width,
|
|
|
|
this.exploreEvents
|
|
|
|
);
|
|
|
|
}
|
2018-04-26 04:58:42 -05:00
|
|
|
}
|
|
|
|
|
2018-11-27 07:27:33 -06:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.exploreEvents.removeAllListeners();
|
2018-07-13 02:09:36 -05:00
|
|
|
}
|
|
|
|
|
2018-07-17 08:13:44 -05:00
|
|
|
getRef = el => {
|
|
|
|
this.el = el;
|
|
|
|
};
|
|
|
|
|
2018-08-04 04:58:54 -05:00
|
|
|
onAddQueryRow = index => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.addQueryRow(this.props.exploreId, index);
|
2018-04-27 08:42:35 -05:00
|
|
|
};
|
|
|
|
|
2018-08-04 04:58:54 -05:00
|
|
|
onChangeDatasource = async option => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.changeDatasource(this.props.exploreId, option.value);
|
2018-07-13 02:09:36 -05:00
|
|
|
};
|
|
|
|
|
2019-01-10 07:24:31 -06:00
|
|
|
onChangeQuery = (query: DataQuery, index: number, override?: boolean) => {
|
2019-01-11 11:26:56 -06:00
|
|
|
const { changeQuery, datasourceInstance, exploreId } = this.props;
|
2018-11-22 04:14:46 -06:00
|
|
|
|
2019-01-11 11:26:56 -06:00
|
|
|
changeQuery(exploreId, query, index, override);
|
2019-01-10 07:24:31 -06:00
|
|
|
if (query && !override && datasourceInstance.getHighlighterExpression && index === 0) {
|
|
|
|
// Live preview of log search matches. Only use on first row for now
|
|
|
|
this.updateLogsHighlights(query);
|
2018-08-08 09:50:30 -05:00
|
|
|
}
|
2018-04-27 08:42:35 -05:00
|
|
|
};
|
|
|
|
|
2019-01-10 07:24:31 -06:00
|
|
|
onChangeTime = (range: TimeRange, changedByScanner?: boolean) => {
|
|
|
|
if (this.props.scanning && !changedByScanner) {
|
2018-11-27 09:35:37 -06:00
|
|
|
this.onStopScanning();
|
2018-11-23 10:53:16 -06:00
|
|
|
}
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.changeTime(this.props.exploreId, range);
|
2018-04-30 10:25:25 -05:00
|
|
|
};
|
|
|
|
|
2018-08-04 04:58:54 -05:00
|
|
|
onClickClear = () => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.clickClear(this.props.exploreId);
|
2018-08-04 04:58:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
onClickCloseSplit = () => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.clickCloseSplit();
|
2018-05-15 10:07:38 -05:00
|
|
|
};
|
|
|
|
|
2018-08-04 04:58:54 -05:00
|
|
|
onClickGraphButton = () => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.clickGraphButton(this.props.exploreId);
|
2018-04-26 04:58:42 -05:00
|
|
|
};
|
|
|
|
|
2018-08-04 04:58:54 -05:00
|
|
|
onClickLogsButton = () => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.clickLogsButton(this.props.exploreId);
|
2018-07-20 10:07:17 -05:00
|
|
|
};
|
|
|
|
|
2018-10-09 12:46:31 -05:00
|
|
|
// Use this in help pages to set page to a single query
|
2018-11-21 09:28:30 -06:00
|
|
|
onClickExample = (query: DataQuery) => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.clickExample(this.props.exploreId, query);
|
2018-10-09 12:46:31 -05:00
|
|
|
};
|
|
|
|
|
2018-08-04 04:58:54 -05:00
|
|
|
onClickSplit = () => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.clickSplit();
|
2018-05-15 10:07:38 -05:00
|
|
|
};
|
|
|
|
|
2018-08-04 04:58:54 -05:00
|
|
|
onClickTableButton = () => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.clickTableButton(this.props.exploreId);
|
2018-04-26 04:58:42 -05:00
|
|
|
};
|
|
|
|
|
2018-11-28 03:46:35 -06:00
|
|
|
onClickLabel = (key: string, value: string) => {
|
|
|
|
this.onModifyQueries({ type: 'ADD_FILTER', key, value });
|
2018-08-08 09:50:30 -05:00
|
|
|
};
|
|
|
|
|
2018-10-28 08:03:39 -05:00
|
|
|
onModifyQueries = (action, index?: number) => {
|
2019-01-10 07:24:31 -06:00
|
|
|
const { datasourceInstance } = this.props;
|
|
|
|
if (datasourceInstance && datasourceInstance.modifyQuery) {
|
|
|
|
const modifier = (queries: DataQuery, action: any) => datasourceInstance.modifyQuery(queries, action);
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.modifyQueries(this.props.exploreId, action, index, modifier);
|
2018-08-04 04:58:54 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
onRemoveQueryRow = index => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.removeQueryRow(this.props.exploreId, index);
|
|
|
|
};
|
|
|
|
|
|
|
|
onResize = (size: { height: number; width: number }) => {
|
|
|
|
this.props.changeSize(this.props.exploreId, size);
|
2018-04-26 04:58:42 -05:00
|
|
|
};
|
|
|
|
|
2018-11-27 09:35:37 -06:00
|
|
|
onStartScanning = () => {
|
2019-01-10 07:24:31 -06:00
|
|
|
// Scanner will trigger a query
|
|
|
|
const scanner = this.scanPreviousRange;
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.scanStart(this.props.exploreId, scanner);
|
2018-11-23 10:53:16 -06:00
|
|
|
};
|
|
|
|
|
2019-01-10 07:24:31 -06:00
|
|
|
scanPreviousRange = (): RawTimeRange => {
|
|
|
|
// Calling move() on the timepicker will trigger this.onChangeTime()
|
|
|
|
return this.timepickerRef.current.move(-1, true);
|
2018-11-23 10:53:16 -06:00
|
|
|
};
|
|
|
|
|
2018-11-27 09:35:37 -06:00
|
|
|
onStopScanning = () => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.scanStop(this.props.exploreId);
|
2018-11-23 10:53:16 -06:00
|
|
|
};
|
|
|
|
|
2018-08-04 04:58:54 -05:00
|
|
|
onSubmit = () => {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.runQueries(this.props.exploreId);
|
2018-04-26 04:58:42 -05:00
|
|
|
};
|
|
|
|
|
2019-01-10 07:24:31 -06:00
|
|
|
updateLogsHighlights = _.debounce((value: DataQuery) => {
|
|
|
|
const { datasourceInstance } = this.props;
|
|
|
|
if (datasourceInstance.getHighlighterExpression) {
|
|
|
|
const expressions = [datasourceInstance.getHighlighterExpression(value)];
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.highlightLogsExpression(this.props.exploreId, expressions);
|
2018-11-23 08:12:20 -06:00
|
|
|
}
|
2018-12-01 08:26:51 -06:00
|
|
|
}, 500);
|
|
|
|
|
2019-01-10 07:24:31 -06:00
|
|
|
// saveState = () => {
|
|
|
|
// const { stateKey, onSaveState } = this.props;
|
|
|
|
// onSaveState(stateKey, this.cloneState());
|
|
|
|
// };
|
2018-09-28 09:44:07 -05:00
|
|
|
|
2018-04-26 04:58:42 -05:00
|
|
|
render() {
|
|
|
|
const {
|
2018-10-30 08:38:34 -05:00
|
|
|
StartPage,
|
2019-01-10 07:24:31 -06:00
|
|
|
datasourceInstance,
|
2018-04-26 04:58:42 -05:00
|
|
|
datasourceError,
|
|
|
|
datasourceLoading,
|
2018-07-13 02:09:36 -05:00
|
|
|
datasourceMissing,
|
2018-10-01 08:09:10 -05:00
|
|
|
exploreDatasources,
|
2019-01-11 11:26:56 -06:00
|
|
|
exploreId,
|
2018-11-29 10:09:32 -06:00
|
|
|
graphResult,
|
2018-08-02 09:43:33 -05:00
|
|
|
history,
|
2018-11-21 09:28:30 -06:00
|
|
|
initialQueries,
|
2018-12-01 08:26:51 -06:00
|
|
|
logsHighlighterExpressions,
|
2018-11-29 10:09:32 -06:00
|
|
|
logsResult,
|
2018-10-22 10:51:42 -05:00
|
|
|
queryTransactions,
|
2018-04-30 10:25:25 -05:00
|
|
|
range,
|
2018-11-23 10:53:16 -06:00
|
|
|
scanning,
|
2018-11-27 09:35:37 -06:00
|
|
|
scanRange,
|
2018-04-26 04:58:42 -05:00
|
|
|
showingGraph,
|
2018-07-20 10:07:17 -05:00
|
|
|
showingLogs,
|
2018-11-16 12:21:13 -06:00
|
|
|
showingStartPage,
|
2018-04-26 04:58:42 -05:00
|
|
|
showingTable,
|
2019-01-10 07:24:31 -06:00
|
|
|
split,
|
2018-07-20 10:07:17 -05:00
|
|
|
supportsGraph,
|
|
|
|
supportsLogs,
|
|
|
|
supportsTable,
|
2018-11-29 10:09:32 -06:00
|
|
|
tableResult,
|
2019-01-10 07:24:31 -06:00
|
|
|
} = this.props;
|
2018-11-16 12:21:13 -06:00
|
|
|
const graphHeight = showingGraph && showingTable ? '200px' : '400px';
|
2018-05-15 10:07:38 -05:00
|
|
|
const exploreClass = split ? 'explore explore-split' : 'explore';
|
2019-01-10 07:24:31 -06:00
|
|
|
const selectedDatasource = datasourceInstance
|
|
|
|
? exploreDatasources.find(d => d.name === datasourceInstance.name)
|
|
|
|
: undefined;
|
2018-10-22 10:51:42 -05:00
|
|
|
const graphLoading = queryTransactions.some(qt => qt.resultType === 'Graph' && !qt.done);
|
|
|
|
const tableLoading = queryTransactions.some(qt => qt.resultType === 'Table' && !qt.done);
|
|
|
|
const logsLoading = queryTransactions.some(qt => qt.resultType === 'Logs' && !qt.done);
|
|
|
|
const loading = queryTransactions.some(qt => !qt.done);
|
2018-07-13 02:09:36 -05:00
|
|
|
|
2018-04-26 04:58:42 -05:00
|
|
|
return (
|
2018-07-17 08:13:44 -05:00
|
|
|
<div className={exploreClass} ref={this.getRef}>
|
2018-05-01 06:27:25 -05:00
|
|
|
<div className="navbar">
|
2019-01-11 11:26:56 -06:00
|
|
|
{exploreId === 'left' ? (
|
2018-05-15 10:07:38 -05:00
|
|
|
<div>
|
|
|
|
<a className="navbar-page-btn">
|
|
|
|
<i className="fa fa-rocket" />
|
|
|
|
Explore
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
) : (
|
2018-10-30 08:38:34 -05:00
|
|
|
<div className="navbar-buttons explore-first-button">
|
|
|
|
<button className="btn navbar-button" onClick={this.onClickCloseSplit}>
|
|
|
|
Close Split
|
2018-05-15 10:07:38 -05:00
|
|
|
</button>
|
2018-10-30 08:38:34 -05:00
|
|
|
</div>
|
|
|
|
)}
|
2018-07-13 02:09:36 -05:00
|
|
|
{!datasourceMissing ? (
|
|
|
|
<div className="navbar-buttons">
|
2018-12-14 07:05:47 -06:00
|
|
|
<DataSourcePicker
|
2018-08-04 04:58:54 -05:00
|
|
|
onChange={this.onChangeDatasource}
|
2018-12-14 07:05:47 -06:00
|
|
|
datasources={exploreDatasources}
|
|
|
|
current={selectedDatasource}
|
2018-07-13 02:09:36 -05:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
) : null}
|
2018-05-01 06:27:25 -05:00
|
|
|
<div className="navbar__spacer" />
|
2019-01-11 11:26:56 -06:00
|
|
|
{exploreId === 'left' && !split ? (
|
2018-05-15 10:07:38 -05:00
|
|
|
<div className="navbar-buttons">
|
2018-08-04 04:58:54 -05:00
|
|
|
<button className="btn navbar-button" onClick={this.onClickSplit}>
|
2018-05-15 10:07:38 -05:00
|
|
|
Split
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
) : null}
|
2018-11-23 10:53:16 -06:00
|
|
|
<TimePicker ref={this.timepickerRef} range={range} onChangeTime={this.onChangeTime} />
|
2018-05-01 06:27:25 -05:00
|
|
|
<div className="navbar-buttons">
|
2018-08-04 04:47:04 -05:00
|
|
|
<button className="btn navbar-button navbar-button--no-icon" onClick={this.onClickClear}>
|
|
|
|
Clear All
|
|
|
|
</button>
|
2018-05-01 06:27:25 -05:00
|
|
|
</div>
|
|
|
|
<div className="navbar-buttons relative">
|
2018-12-16 02:58:37 -06:00
|
|
|
<button className="btn navbar-button navbar-button--primary" onClick={this.onSubmit}>
|
2018-10-22 10:51:42 -05:00
|
|
|
Run Query{' '}
|
2019-01-07 08:07:08 -06:00
|
|
|
{loading ? <i className="fa fa-spinner fa-fw fa-spin run-icon" /> : <i className="fa fa-level-down fa-fw run-icon" />}
|
2018-05-01 06:27:25 -05:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{datasourceLoading ? <div className="explore-container">Loading datasource...</div> : null}
|
2018-07-13 02:09:36 -05:00
|
|
|
{datasourceMissing ? (
|
|
|
|
<div className="explore-container">Please add a datasource that supports Explore (e.g., Prometheus).</div>
|
|
|
|
) : null}
|
|
|
|
|
2018-11-30 06:51:49 -06:00
|
|
|
{datasourceError && (
|
|
|
|
<div className="explore-container">
|
|
|
|
<Alert message={`Error connecting to datasource: ${datasourceError}`} />
|
|
|
|
</div>
|
|
|
|
)}
|
2018-05-01 06:27:25 -05:00
|
|
|
|
2019-01-11 11:26:56 -06:00
|
|
|
{datasourceInstance &&
|
|
|
|
!datasourceError && (
|
|
|
|
<div className="explore-container">
|
|
|
|
<QueryRows
|
|
|
|
datasource={datasourceInstance}
|
|
|
|
history={history}
|
|
|
|
initialQueries={initialQueries}
|
|
|
|
onAddQueryRow={this.onAddQueryRow}
|
|
|
|
onChangeQuery={this.onChangeQuery}
|
|
|
|
onClickHintFix={this.onModifyQueries}
|
|
|
|
onExecuteQuery={this.onSubmit}
|
|
|
|
onRemoveQueryRow={this.onRemoveQueryRow}
|
|
|
|
transactions={queryTransactions}
|
|
|
|
exploreEvents={this.exploreEvents}
|
|
|
|
range={range}
|
|
|
|
/>
|
|
|
|
<AutoSizer onResize={this.onResize} disableHeight>
|
|
|
|
{({ width }) => (
|
|
|
|
<main className="m-t-2" style={{ width }}>
|
|
|
|
<ErrorBoundary>
|
|
|
|
{showingStartPage && <StartPage onClickExample={this.onClickExample} />}
|
|
|
|
{!showingStartPage && (
|
|
|
|
<>
|
|
|
|
{supportsGraph && (
|
|
|
|
<Panel
|
|
|
|
label="Graph"
|
|
|
|
isOpen={showingGraph}
|
|
|
|
loading={graphLoading}
|
|
|
|
onToggle={this.onClickGraphButton}
|
|
|
|
>
|
|
|
|
<Graph
|
|
|
|
data={graphResult}
|
|
|
|
height={graphHeight}
|
|
|
|
id={`explore-graph-${exploreId}`}
|
|
|
|
onChangeTime={this.onChangeTime}
|
|
|
|
range={range}
|
|
|
|
split={split}
|
|
|
|
/>
|
|
|
|
</Panel>
|
|
|
|
)}
|
|
|
|
{supportsTable && (
|
|
|
|
<Panel
|
|
|
|
label="Table"
|
|
|
|
loading={tableLoading}
|
|
|
|
isOpen={showingTable}
|
|
|
|
onToggle={this.onClickTableButton}
|
|
|
|
>
|
|
|
|
<Table data={tableResult} loading={tableLoading} onClickCell={this.onClickLabel} />
|
|
|
|
</Panel>
|
|
|
|
)}
|
|
|
|
{supportsLogs && (
|
|
|
|
<Panel
|
|
|
|
label="Logs"
|
|
|
|
loading={logsLoading}
|
|
|
|
isOpen={showingLogs}
|
|
|
|
onToggle={this.onClickLogsButton}
|
|
|
|
>
|
|
|
|
<Logs
|
|
|
|
data={logsResult}
|
|
|
|
exploreId={exploreId}
|
|
|
|
key={logsResult.id}
|
|
|
|
highlighterExpressions={logsHighlighterExpressions}
|
|
|
|
loading={logsLoading}
|
|
|
|
onChangeTime={this.onChangeTime}
|
|
|
|
onClickLabel={this.onClickLabel}
|
|
|
|
onStartScanning={this.onStartScanning}
|
|
|
|
onStopScanning={this.onStopScanning}
|
|
|
|
range={range}
|
|
|
|
scanning={scanning}
|
|
|
|
scanRange={scanRange}
|
|
|
|
/>
|
|
|
|
</Panel>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</ErrorBoundary>
|
|
|
|
</main>
|
2018-10-09 12:46:31 -05:00
|
|
|
)}
|
2019-01-11 11:26:56 -06:00
|
|
|
</AutoSizer>
|
|
|
|
</div>
|
|
|
|
)}
|
2018-04-26 04:58:42 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 11:26:56 -06:00
|
|
|
function mapStateToProps(state: StoreState, { exploreId }) {
|
|
|
|
const explore = state.explore;
|
|
|
|
const { split } = explore;
|
|
|
|
const item: ExploreItemState = explore[exploreId];
|
2019-01-10 07:24:31 -06:00
|
|
|
const {
|
|
|
|
StartPage,
|
|
|
|
datasourceError,
|
|
|
|
datasourceInstance,
|
|
|
|
datasourceLoading,
|
|
|
|
datasourceMissing,
|
|
|
|
exploreDatasources,
|
|
|
|
graphResult,
|
|
|
|
initialDatasource,
|
|
|
|
initialQueries,
|
|
|
|
history,
|
|
|
|
logsHighlighterExpressions,
|
|
|
|
logsResult,
|
|
|
|
queryTransactions,
|
|
|
|
range,
|
|
|
|
scanning,
|
|
|
|
scanRange,
|
|
|
|
showingGraph,
|
|
|
|
showingLogs,
|
|
|
|
showingStartPage,
|
|
|
|
showingTable,
|
|
|
|
supportsGraph,
|
|
|
|
supportsLogs,
|
|
|
|
supportsTable,
|
|
|
|
tableResult,
|
2019-01-11 11:26:56 -06:00
|
|
|
} = item;
|
2019-01-10 07:24:31 -06:00
|
|
|
return {
|
|
|
|
StartPage,
|
|
|
|
datasourceError,
|
|
|
|
datasourceInstance,
|
|
|
|
datasourceLoading,
|
|
|
|
datasourceMissing,
|
|
|
|
exploreDatasources,
|
|
|
|
graphResult,
|
|
|
|
initialDatasource,
|
|
|
|
initialQueries,
|
|
|
|
history,
|
|
|
|
logsHighlighterExpressions,
|
|
|
|
logsResult,
|
|
|
|
queryTransactions,
|
|
|
|
range,
|
|
|
|
scanning,
|
|
|
|
scanRange,
|
|
|
|
showingGraph,
|
|
|
|
showingLogs,
|
|
|
|
showingStartPage,
|
|
|
|
showingTable,
|
2019-01-11 11:26:56 -06:00
|
|
|
split,
|
2019-01-10 07:24:31 -06:00
|
|
|
supportsGraph,
|
|
|
|
supportsLogs,
|
|
|
|
supportsTable,
|
|
|
|
tableResult,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
addQueryRow,
|
|
|
|
changeDatasource,
|
|
|
|
changeQuery,
|
2019-01-11 11:26:56 -06:00
|
|
|
changeSize,
|
2019-01-10 07:24:31 -06:00
|
|
|
changeTime,
|
|
|
|
clickClear,
|
2019-01-11 11:26:56 -06:00
|
|
|
clickCloseSplit,
|
2019-01-10 07:24:31 -06:00
|
|
|
clickExample,
|
|
|
|
clickGraphButton,
|
|
|
|
clickLogsButton,
|
2019-01-11 11:26:56 -06:00
|
|
|
clickSplit,
|
2019-01-10 07:24:31 -06:00
|
|
|
clickTableButton,
|
|
|
|
highlightLogsExpression,
|
|
|
|
initializeExplore,
|
|
|
|
modifyQueries,
|
|
|
|
removeQueryRow,
|
|
|
|
runQueries,
|
|
|
|
scanStart,
|
|
|
|
scanStop,
|
|
|
|
};
|
|
|
|
|
2019-01-11 11:26:56 -06:00
|
|
|
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(Explore));
|