2019-01-17 10:59:47 -06:00
|
|
|
// Libraries
|
2019-02-04 04:25:07 -06:00
|
|
|
import React, { ComponentClass } from 'react';
|
2018-04-26 04:58:42 -05:00
|
|
|
import { hot } from 'react-hot-loader';
|
2019-09-20 06:00:11 -05:00
|
|
|
import { css } from 'emotion';
|
2019-01-10 07:24:31 -06:00
|
|
|
import { connect } from 'react-redux';
|
2019-01-11 11:26:56 -06:00
|
|
|
import { AutoSizer } from 'react-virtualized';
|
2019-08-29 06:41:45 -05:00
|
|
|
import memoizeOne from 'memoize-one';
|
2018-07-13 02:09:36 -05:00
|
|
|
|
2019-01-17 10:59:47 -06:00
|
|
|
// Services & Utils
|
2018-08-02 09:43:33 -05:00
|
|
|
import store from 'app/core/store';
|
2019-01-17 10:59:47 -06:00
|
|
|
// Components
|
2019-09-04 06:59:30 -05:00
|
|
|
import { Alert, ErrorBoundaryAlert, DataQuery, ExploreStartPageProps, DataSourceApi, PanelData } from '@grafana/ui';
|
2019-01-17 10:59:47 -06:00
|
|
|
import LogsContainer from './LogsContainer';
|
|
|
|
import QueryRows from './QueryRows';
|
|
|
|
import TableContainer from './TableContainer';
|
|
|
|
// Actions
|
2019-03-22 09:24:30 -05:00
|
|
|
import {
|
|
|
|
changeSize,
|
|
|
|
initializeExplore,
|
|
|
|
modifyQueries,
|
|
|
|
scanStart,
|
|
|
|
setQueries,
|
|
|
|
refreshExplore,
|
2019-04-01 00:38:00 -05:00
|
|
|
reconnectDatasource,
|
2019-06-25 07:44:19 -05:00
|
|
|
updateTimeRange,
|
2019-08-26 01:11:07 -05:00
|
|
|
toggleGraph,
|
2019-03-22 09:24:30 -05:00
|
|
|
} from './state/actions';
|
2019-01-17 10:59:47 -06:00
|
|
|
// Types
|
2019-09-03 02:55:20 -05:00
|
|
|
import { RawTimeRange, GraphSeriesXY, TimeZone, AbsoluteTimeRange } from '@grafana/data';
|
2019-04-29 11:28:41 -05:00
|
|
|
import {
|
|
|
|
ExploreItemState,
|
|
|
|
ExploreUrlState,
|
|
|
|
ExploreId,
|
|
|
|
ExploreUpdateState,
|
|
|
|
ExploreUIState,
|
2019-05-16 02:52:22 -05:00
|
|
|
ExploreMode,
|
2019-04-29 11:28:41 -05:00
|
|
|
} from 'app/types/explore';
|
2019-01-17 10:59:47 -06:00
|
|
|
import { StoreState } from 'app/types';
|
2019-04-29 11:28:41 -05:00
|
|
|
import {
|
|
|
|
ensureQueries,
|
|
|
|
DEFAULT_RANGE,
|
|
|
|
DEFAULT_UI_STATE,
|
|
|
|
getTimeRangeFromUrl,
|
2019-07-04 09:31:15 -05:00
|
|
|
lastUsedDatasourceKeyForOrgId,
|
2019-04-29 11:28:41 -05:00
|
|
|
} from 'app/core/utils/explore';
|
2019-01-17 10:59:47 -06:00
|
|
|
import { Emitter } from 'app/core/utils/emitter';
|
2019-01-22 07:50:19 -06:00
|
|
|
import { ExploreToolbar } from './ExploreToolbar';
|
2019-03-28 11:17:01 -05:00
|
|
|
import { NoDataSourceCallToAction } from './NoDataSourceCallToAction';
|
2019-04-01 00:38:00 -05:00
|
|
|
import { FadeIn } from 'app/core/components/Animations/FadeIn';
|
2019-04-29 11:28:41 -05:00
|
|
|
import { getTimeZone } from '../profile/state/selectors';
|
2019-05-10 07:00:39 -05:00
|
|
|
import { ErrorContainer } from './ErrorContainer';
|
2019-06-03 07:54:32 -05:00
|
|
|
import { scanStopAction } from './state/actionTypes';
|
2019-08-26 01:11:07 -05:00
|
|
|
import { ExploreGraphPanel } from './ExploreGraphPanel';
|
2018-12-31 12:30:32 -06:00
|
|
|
|
2019-09-20 06:00:11 -05:00
|
|
|
const getStyles = memoizeOne(() => {
|
|
|
|
return {
|
|
|
|
logsMain: css`
|
|
|
|
label: logsMain;
|
|
|
|
// Is needed for some transition animations to work.
|
|
|
|
position: relative;
|
|
|
|
`,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2018-09-28 09:44:07 -05:00
|
|
|
interface ExploreProps {
|
2019-02-04 04:25:07 -06:00
|
|
|
StartPage?: ComponentClass<ExploreStartPageProps>;
|
2019-01-11 11:26:56 -06:00
|
|
|
changeSize: typeof changeSize;
|
2019-01-10 07:24:31 -06:00
|
|
|
datasourceError: string;
|
2019-06-04 03:30:07 -05:00
|
|
|
datasourceInstance: DataSourceApi;
|
2019-01-10 07:24:31 -06:00
|
|
|
datasourceMissing: boolean;
|
2019-01-11 11:26:56 -06:00
|
|
|
exploreId: ExploreId;
|
2019-01-10 07:24:31 -06:00
|
|
|
initializeExplore: typeof initializeExplore;
|
2019-01-12 16:22:28 -06:00
|
|
|
initialized: boolean;
|
2019-01-10 07:24:31 -06:00
|
|
|
modifyQueries: typeof modifyQueries;
|
2019-03-22 09:24:30 -05:00
|
|
|
update: ExploreUpdateState;
|
2019-04-01 00:38:00 -05:00
|
|
|
reconnectDatasource: typeof reconnectDatasource;
|
2019-03-22 09:24:30 -05:00
|
|
|
refreshExplore: typeof refreshExplore;
|
2019-01-10 07:24:31 -06:00
|
|
|
scanning?: boolean;
|
|
|
|
scanRange?: RawTimeRange;
|
|
|
|
scanStart: typeof scanStart;
|
2019-02-04 00:47:10 -06:00
|
|
|
scanStopAction: typeof scanStopAction;
|
2019-01-15 12:52:53 -06:00
|
|
|
setQueries: typeof setQueries;
|
2018-09-28 09:44:07 -05:00
|
|
|
split: boolean;
|
2019-01-10 07:24:31 -06:00
|
|
|
showingStartPage?: boolean;
|
2019-02-04 06:41:29 -06:00
|
|
|
queryKeys: string[];
|
2019-04-29 11:28:41 -05:00
|
|
|
initialDatasource: string;
|
|
|
|
initialQueries: DataQuery[];
|
|
|
|
initialRange: RawTimeRange;
|
2019-06-27 04:11:49 -05:00
|
|
|
mode: ExploreMode;
|
2019-04-29 11:28:41 -05:00
|
|
|
initialUI: ExploreUIState;
|
2019-05-20 06:28:23 -05:00
|
|
|
isLive: boolean;
|
2019-10-08 11:55:53 -05:00
|
|
|
syncedTimes: boolean;
|
2019-06-25 07:44:19 -05:00
|
|
|
updateTimeRange: typeof updateTimeRange;
|
2019-08-13 00:32:43 -05:00
|
|
|
graphResult?: GraphSeriesXY[];
|
2019-08-26 01:11:07 -05:00
|
|
|
loading?: boolean;
|
|
|
|
absoluteRange: AbsoluteTimeRange;
|
|
|
|
showingGraph?: boolean;
|
|
|
|
showingTable?: boolean;
|
|
|
|
timeZone?: TimeZone;
|
|
|
|
onHiddenSeriesChanged?: (hiddenSeries: string[]) => void;
|
|
|
|
toggleGraph: typeof toggleGraph;
|
2019-09-03 02:55:20 -05:00
|
|
|
queryResponse: PanelData;
|
2019-09-05 07:44:37 -05:00
|
|
|
originPanelId: number;
|
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
|
2019-01-12 16:44:24 -06:00
|
|
|
* of results viewers it supports. The state is managed entirely in Redux.
|
2018-11-22 05:00:41 -06:00
|
|
|
*
|
2019-01-12 16:44:24 -06:00
|
|
|
* SPLIT VIEW
|
2018-11-22 05:00:41 -06:00
|
|
|
*
|
2019-01-12 16:44:24 -06:00
|
|
|
* Explore can have two Explore areas side-by-side. This is handled in `Wrapper.tsx`.
|
|
|
|
* Since there can be multiple Explores (e.g., left and right) each action needs
|
|
|
|
* the `exploreId` as first parameter so that the reducer knows which Explore state
|
|
|
|
* is affected.
|
2018-11-22 05:00:41 -06:00
|
|
|
*
|
|
|
|
* 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-07-17 08:13:44 -05:00
|
|
|
|
2019-03-22 09:24:30 -05:00
|
|
|
constructor(props: ExploreProps) {
|
2018-04-26 04:58:42 -05:00
|
|
|
super(props);
|
2018-11-23 08:12:20 -06:00
|
|
|
this.exploreEvents = new Emitter();
|
2018-04-26 04:58:42 -05:00
|
|
|
}
|
|
|
|
|
2019-03-22 09:24:30 -05:00
|
|
|
componentDidMount() {
|
2019-09-05 07:44:37 -05:00
|
|
|
const {
|
|
|
|
initialized,
|
|
|
|
exploreId,
|
|
|
|
initialDatasource,
|
|
|
|
initialQueries,
|
|
|
|
initialRange,
|
|
|
|
mode,
|
|
|
|
initialUI,
|
|
|
|
originPanelId,
|
|
|
|
} = this.props;
|
2019-03-22 09:24:30 -05:00
|
|
|
const width = this.el ? this.el.offsetWidth : 0;
|
2019-04-29 11:28:41 -05:00
|
|
|
|
2019-03-22 09:24:30 -05:00
|
|
|
// initialize the whole explore first time we mount and if browser history contains a change in datasource
|
|
|
|
if (!initialized) {
|
2019-01-11 11:26:56 -06:00
|
|
|
this.props.initializeExplore(
|
|
|
|
exploreId,
|
|
|
|
initialDatasource,
|
|
|
|
initialQueries,
|
|
|
|
initialRange,
|
2019-06-27 04:11:49 -05:00
|
|
|
mode,
|
2019-01-11 11:26:56 -06:00
|
|
|
width,
|
2019-02-01 05:33:15 -06:00
|
|
|
this.exploreEvents,
|
2019-09-05 07:44:37 -05:00
|
|
|
initialUI,
|
|
|
|
originPanelId
|
2019-01-11 11:26:56 -06:00
|
|
|
);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2019-03-22 09:24:30 -05:00
|
|
|
componentDidUpdate(prevProps: ExploreProps) {
|
|
|
|
this.refreshExplore();
|
|
|
|
}
|
|
|
|
|
|
|
|
getRef = (el: any) => {
|
2018-07-17 08:13:44 -05:00
|
|
|
this.el = el;
|
|
|
|
};
|
|
|
|
|
2019-06-28 05:07:55 -05:00
|
|
|
onChangeTime = (rawRange: RawTimeRange) => {
|
|
|
|
const { updateTimeRange, exploreId } = this.props;
|
2019-06-25 07:44:19 -05:00
|
|
|
updateTimeRange({ exploreId, rawRange });
|
2018-04-30 10:25:25 -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-15 12:52:53 -06:00
|
|
|
this.props.setQueries(this.props.exploreId, [query]);
|
2018-10-09 12:46:31 -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
|
|
|
};
|
|
|
|
|
2019-03-22 09:24:30 -05:00
|
|
|
onModifyQueries = (action: any, index?: number) => {
|
2019-01-10 07:24:31 -06:00
|
|
|
const { datasourceInstance } = this.props;
|
|
|
|
if (datasourceInstance && datasourceInstance.modifyQuery) {
|
2019-01-15 12:52:53 -06:00
|
|
|
const modifier = (queries: DataQuery, modification: any) => datasourceInstance.modifyQuery(queries, modification);
|
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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-11 11:26:56 -06:00
|
|
|
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
|
2019-06-28 05:07:55 -05:00
|
|
|
this.props.scanStart(this.props.exploreId);
|
2018-11-23 10:53:16 -06:00
|
|
|
};
|
|
|
|
|
2018-11-27 09:35:37 -06:00
|
|
|
onStopScanning = () => {
|
2019-02-04 00:47:10 -06:00
|
|
|
this.props.scanStopAction({ exploreId: this.props.exploreId });
|
2018-11-23 10:53:16 -06:00
|
|
|
};
|
|
|
|
|
2019-08-26 01:11:07 -05:00
|
|
|
onToggleGraph = (showingGraph: boolean) => {
|
|
|
|
const { toggleGraph, exploreId } = this.props;
|
|
|
|
toggleGraph(exploreId, showingGraph);
|
|
|
|
};
|
|
|
|
|
|
|
|
onUpdateTimeRange = (absoluteRange: AbsoluteTimeRange) => {
|
2019-10-08 11:55:53 -05:00
|
|
|
const { exploreId, updateTimeRange } = this.props;
|
2019-08-26 01:11:07 -05:00
|
|
|
updateTimeRange({ exploreId, absoluteRange });
|
|
|
|
};
|
|
|
|
|
2019-03-22 09:24:30 -05:00
|
|
|
refreshExplore = () => {
|
|
|
|
const { exploreId, update } = this.props;
|
|
|
|
|
2019-08-13 00:32:43 -05:00
|
|
|
if (update.queries || update.ui || update.range || update.datasource || update.mode) {
|
2019-03-22 09:24:30 -05:00
|
|
|
this.props.refreshExplore(exploreId);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-28 11:17:01 -05:00
|
|
|
renderEmptyState = () => {
|
|
|
|
return (
|
|
|
|
<div className="explore-container">
|
|
|
|
<NoDataSourceCallToAction />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-04-01 00:38:00 -05:00
|
|
|
onReconnect = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
const { exploreId, reconnectDatasource } = this.props;
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
reconnectDatasource(exploreId);
|
|
|
|
};
|
|
|
|
|
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,
|
2018-07-13 02:09:36 -05:00
|
|
|
datasourceMissing,
|
2019-01-11 11:26:56 -06:00
|
|
|
exploreId,
|
2018-11-16 12:21:13 -06:00
|
|
|
showingStartPage,
|
2019-01-10 07:24:31 -06:00
|
|
|
split,
|
2019-02-04 06:41:29 -06:00
|
|
|
queryKeys,
|
2019-05-16 02:52:22 -05:00
|
|
|
mode,
|
2019-08-13 00:32:43 -05:00
|
|
|
graphResult,
|
2019-08-26 01:11:07 -05:00
|
|
|
loading,
|
|
|
|
absoluteRange,
|
|
|
|
showingGraph,
|
|
|
|
showingTable,
|
|
|
|
timeZone,
|
2019-09-03 02:55:20 -05:00
|
|
|
queryResponse,
|
2019-10-08 11:55:53 -05:00
|
|
|
syncedTimes,
|
2019-01-10 07:24:31 -06:00
|
|
|
} = this.props;
|
2018-05-15 10:07:38 -05:00
|
|
|
const exploreClass = split ? 'explore explore-split' : 'explore';
|
2019-09-20 06:00:11 -05:00
|
|
|
const styles = getStyles();
|
2019-01-24 02:03:26 -06:00
|
|
|
|
2018-04-26 04:58:42 -05:00
|
|
|
return (
|
2018-07-17 08:13:44 -05:00
|
|
|
<div className={exploreClass} ref={this.getRef}>
|
2019-06-28 05:07:55 -05:00
|
|
|
<ExploreToolbar exploreId={exploreId} onChangeTime={this.onChangeTime} />
|
2019-03-28 11:17:01 -05:00
|
|
|
{datasourceMissing ? this.renderEmptyState() : null}
|
2018-07-13 02:09:36 -05:00
|
|
|
|
2019-04-01 00:38:00 -05:00
|
|
|
<FadeIn duration={datasourceError ? 150 : 5} in={datasourceError ? true : false}>
|
2018-11-30 06:51:49 -06:00
|
|
|
<div className="explore-container">
|
2019-04-01 00:38:00 -05:00
|
|
|
<Alert
|
2019-09-02 13:45:18 -05:00
|
|
|
title={`Error connecting to datasource: ${datasourceError}`}
|
2019-09-20 06:41:00 -05:00
|
|
|
buttonText={'Reconnect'}
|
|
|
|
onButtonClick={this.onReconnect}
|
2019-04-01 00:38:00 -05:00
|
|
|
/>
|
2018-11-30 06:51:49 -06:00
|
|
|
</div>
|
2019-04-01 00:38:00 -05:00
|
|
|
</FadeIn>
|
2018-05-01 06:27:25 -05:00
|
|
|
|
2019-04-01 00:38:00 -05:00
|
|
|
{datasourceInstance && (
|
2019-02-19 08:41:35 -06:00
|
|
|
<div className="explore-container">
|
|
|
|
<QueryRows exploreEvents={this.exploreEvents} exploreId={exploreId} queryKeys={queryKeys} />
|
2019-09-03 02:55:20 -05:00
|
|
|
<ErrorContainer queryErrors={[queryResponse.error]} />
|
2019-02-19 08:41:35 -06:00
|
|
|
<AutoSizer onResize={this.onResize} disableHeight>
|
|
|
|
{({ width }) => {
|
|
|
|
if (width === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-02-07 11:20:16 -06:00
|
|
|
|
2019-02-19 08:41:35 -06:00
|
|
|
return (
|
2019-09-20 06:00:11 -05:00
|
|
|
<main className={`m-t-2 ${styles.logsMain}`} style={{ width }}>
|
2019-09-04 06:59:30 -05:00
|
|
|
<ErrorBoundaryAlert>
|
2019-09-16 00:17:34 -05:00
|
|
|
{showingStartPage && (
|
|
|
|
<div className="grafana-info-box grafana-info-box--max-lg">
|
|
|
|
<StartPage onClickExample={this.onClickExample} datasource={datasourceInstance} />
|
|
|
|
</div>
|
|
|
|
)}
|
2019-02-19 08:41:35 -06:00
|
|
|
{!showingStartPage && (
|
|
|
|
<>
|
2019-08-13 00:32:43 -05:00
|
|
|
{mode === ExploreMode.Metrics && (
|
2019-08-26 01:11:07 -05:00
|
|
|
<ExploreGraphPanel
|
|
|
|
series={graphResult}
|
|
|
|
width={width}
|
|
|
|
loading={loading}
|
|
|
|
absoluteRange={absoluteRange}
|
|
|
|
isStacked={false}
|
|
|
|
showPanel={true}
|
|
|
|
showingGraph={showingGraph}
|
|
|
|
showingTable={showingTable}
|
|
|
|
timeZone={timeZone}
|
|
|
|
onToggleGraph={this.onToggleGraph}
|
|
|
|
onUpdateTimeRange={this.onUpdateTimeRange}
|
|
|
|
showBars={false}
|
|
|
|
showLines={true}
|
|
|
|
/>
|
2019-08-13 00:32:43 -05:00
|
|
|
)}
|
2019-05-16 02:52:22 -05:00
|
|
|
{mode === ExploreMode.Metrics && (
|
|
|
|
<TableContainer exploreId={exploreId} onClickCell={this.onClickLabel} />
|
|
|
|
)}
|
|
|
|
{mode === ExploreMode.Logs && (
|
2019-02-19 08:41:35 -06:00
|
|
|
<LogsContainer
|
|
|
|
width={width}
|
|
|
|
exploreId={exploreId}
|
2019-10-08 11:55:53 -05:00
|
|
|
syncedTimes={syncedTimes}
|
2019-02-19 08:41:35 -06:00
|
|
|
onClickLabel={this.onClickLabel}
|
|
|
|
onStartScanning={this.onStartScanning}
|
|
|
|
onStopScanning={this.onStopScanning}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
)}
|
2019-09-04 06:59:30 -05:00
|
|
|
</ErrorBoundaryAlert>
|
2019-02-19 08:41:35 -06:00
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</AutoSizer>
|
|
|
|
</div>
|
|
|
|
)}
|
2018-04-26 04:58:42 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-29 06:41:45 -05:00
|
|
|
const ensureQueriesMemoized = memoizeOne(ensureQueries);
|
|
|
|
const getTimeRangeFromUrlMemoized = memoizeOne(getTimeRangeFromUrl);
|
|
|
|
|
2019-09-24 04:40:16 -05:00
|
|
|
function mapStateToProps(state: StoreState, { exploreId }: ExploreProps): Partial<ExploreProps> {
|
2019-01-11 11:26:56 -06:00
|
|
|
const explore = state.explore;
|
2019-10-08 11:55:53 -05:00
|
|
|
const { split, syncedTimes } = explore;
|
2019-01-11 11:26:56 -06:00
|
|
|
const item: ExploreItemState = explore[exploreId];
|
2019-04-29 11:28:41 -05:00
|
|
|
const timeZone = getTimeZone(state.user);
|
2019-01-10 07:24:31 -06:00
|
|
|
const {
|
|
|
|
StartPage,
|
|
|
|
datasourceError,
|
|
|
|
datasourceInstance,
|
|
|
|
datasourceMissing,
|
2019-01-12 16:22:28 -06:00
|
|
|
initialized,
|
2019-01-10 07:24:31 -06:00
|
|
|
showingStartPage,
|
2019-02-04 06:41:29 -06:00
|
|
|
queryKeys,
|
2019-03-22 09:24:30 -05:00
|
|
|
urlState,
|
|
|
|
update,
|
2019-05-20 06:28:23 -05:00
|
|
|
isLive,
|
2019-06-27 04:11:49 -05:00
|
|
|
supportedModes,
|
|
|
|
mode,
|
2019-08-13 00:32:43 -05:00
|
|
|
graphResult,
|
2019-09-03 02:55:20 -05:00
|
|
|
loading,
|
2019-08-26 01:11:07 -05:00
|
|
|
showingGraph,
|
|
|
|
showingTable,
|
|
|
|
absoluteRange,
|
2019-09-03 02:55:20 -05:00
|
|
|
queryResponse,
|
2019-01-11 11:26:56 -06:00
|
|
|
} = item;
|
2019-04-29 11:28:41 -05:00
|
|
|
|
2019-09-05 07:44:37 -05:00
|
|
|
const { datasource, queries, range: urlRange, mode: urlMode, ui, originPanelId } = (urlState ||
|
|
|
|
{}) as ExploreUrlState;
|
2019-07-04 09:31:15 -05:00
|
|
|
const initialDatasource = datasource || store.get(lastUsedDatasourceKeyForOrgId(state.user.orgId));
|
2019-08-29 06:41:45 -05:00
|
|
|
const initialQueries: DataQuery[] = ensureQueriesMemoized(queries);
|
|
|
|
const initialRange = urlRange ? getTimeRangeFromUrlMemoized(urlRange, timeZone).raw : DEFAULT_RANGE;
|
2019-06-27 04:11:49 -05:00
|
|
|
|
|
|
|
let newMode: ExploreMode;
|
|
|
|
if (supportedModes.length) {
|
|
|
|
const urlModeIsValid = supportedModes.includes(urlMode);
|
|
|
|
const modeStateIsValid = supportedModes.includes(mode);
|
|
|
|
|
2019-08-13 00:32:43 -05:00
|
|
|
if (modeStateIsValid) {
|
2019-06-27 04:11:49 -05:00
|
|
|
newMode = mode;
|
2019-08-13 00:32:43 -05:00
|
|
|
} else if (urlModeIsValid) {
|
|
|
|
newMode = urlMode;
|
2019-06-27 04:11:49 -05:00
|
|
|
} else {
|
|
|
|
newMode = supportedModes[0];
|
|
|
|
}
|
|
|
|
} else {
|
2019-08-13 00:32:43 -05:00
|
|
|
newMode = [ExploreMode.Metrics, ExploreMode.Logs].includes(mode) ? mode : ExploreMode.Metrics;
|
2019-06-27 04:11:49 -05:00
|
|
|
}
|
|
|
|
|
2019-04-29 11:28:41 -05:00
|
|
|
const initialUI = ui || DEFAULT_UI_STATE;
|
|
|
|
|
2019-01-10 07:24:31 -06:00
|
|
|
return {
|
|
|
|
StartPage,
|
|
|
|
datasourceError,
|
|
|
|
datasourceInstance,
|
|
|
|
datasourceMissing,
|
2019-01-12 16:22:28 -06:00
|
|
|
initialized,
|
2019-01-10 07:24:31 -06:00
|
|
|
showingStartPage,
|
2019-01-11 11:26:56 -06:00
|
|
|
split,
|
2019-02-04 06:41:29 -06:00
|
|
|
queryKeys,
|
2019-03-22 09:24:30 -05:00
|
|
|
update,
|
2019-04-29 11:28:41 -05:00
|
|
|
initialDatasource,
|
|
|
|
initialQueries,
|
|
|
|
initialRange,
|
2019-06-27 04:11:49 -05:00
|
|
|
mode: newMode,
|
2019-04-29 11:28:41 -05:00
|
|
|
initialUI,
|
2019-05-20 06:28:23 -05:00
|
|
|
isLive,
|
2019-08-13 00:32:43 -05:00
|
|
|
graphResult,
|
2019-08-26 01:11:07 -05:00
|
|
|
loading,
|
|
|
|
showingGraph,
|
|
|
|
showingTable,
|
|
|
|
absoluteRange,
|
2019-09-03 02:55:20 -05:00
|
|
|
queryResponse,
|
2019-09-05 07:44:37 -05:00
|
|
|
originPanelId,
|
2019-10-08 11:55:53 -05:00
|
|
|
syncedTimes,
|
2019-01-10 07:24:31 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-09-24 04:40:16 -05:00
|
|
|
const mapDispatchToProps: Partial<ExploreProps> = {
|
2019-01-11 11:26:56 -06:00
|
|
|
changeSize,
|
2019-01-10 07:24:31 -06:00
|
|
|
initializeExplore,
|
|
|
|
modifyQueries,
|
2019-04-01 00:38:00 -05:00
|
|
|
reconnectDatasource,
|
2019-03-22 09:24:30 -05:00
|
|
|
refreshExplore,
|
2019-01-10 07:24:31 -06:00
|
|
|
scanStart,
|
2019-02-04 00:47:10 -06:00
|
|
|
scanStopAction,
|
2019-01-15 12:52:53 -06:00
|
|
|
setQueries,
|
2019-06-25 07:44:19 -05:00
|
|
|
updateTimeRange,
|
2019-08-26 01:11:07 -05:00
|
|
|
toggleGraph,
|
2019-01-10 07:24:31 -06:00
|
|
|
};
|
|
|
|
|
2019-02-19 08:41:35 -06:00
|
|
|
export default hot(module)(
|
2019-09-24 04:40:16 -05:00
|
|
|
// @ts-ignore
|
2019-02-19 08:41:35 -06:00
|
|
|
connect(
|
|
|
|
mapStateToProps,
|
|
|
|
mapDispatchToProps
|
|
|
|
)(Explore)
|
2019-05-13 02:38:19 -05:00
|
|
|
) as React.ComponentType<{ exploreId: ExploreId }>;
|