From 1aefc4cc2d47df02d4bd71ba53493cbcc4288664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Tue, 22 Jan 2019 14:50:19 +0100 Subject: [PATCH] Refactored out ExploreToolbar from Explore --- public/app/features/explore/Explore.tsx | 69 +++--------- .../app/features/explore/ExploreToolbar.tsx | 100 ++++++++++++++++++ 2 files changed, 116 insertions(+), 53 deletions(-) create mode 100644 public/app/features/explore/ExploreToolbar.tsx diff --git a/public/app/features/explore/Explore.tsx b/public/app/features/explore/Explore.tsx index b6f57a76004..25d868e3565 100644 --- a/public/app/features/explore/Explore.tsx +++ b/public/app/features/explore/Explore.tsx @@ -10,7 +10,6 @@ import store from 'app/core/store'; // Components import { DataSourceSelectItem } from '@grafana/ui/src/types'; -import { DataSourcePicker } from 'app/core/components/Select/DataSourcePicker'; import { Alert } from './Error'; import ErrorBoundary from './ErrorBoundary'; import GraphContainer from './GraphContainer'; @@ -41,6 +40,7 @@ import { ExploreItemState, ExploreUrlState, RangeScanner, ExploreId } from 'app/ import { StoreState } from 'app/types'; import { LAST_USED_DATASOURCE_KEY, ensureQueries, DEFAULT_RANGE } from 'app/core/utils/explore'; import { Emitter } from 'app/core/utils/emitter'; +import { ExploreToolbar } from './ExploreToolbar'; interface ExploreProps { StartPage?: any; @@ -233,58 +233,21 @@ export class Explore extends React.PureComponent { return (
-
- {exploreId === 'left' ? ( -
- - - Explore - -
- ) : ( - <> -
-
- -
- - )} - {!datasourceMissing ? ( -
- -
- ) : null} -
- {exploreId === 'left' && !split ? ( -
- -
- ) : null} - -
- -
-
- -
-
+ {datasourceLoading ?
Loading datasource...
: null} {datasourceMissing ? (
Please add a datasource that supports Explore (e.g., Prometheus).
diff --git a/public/app/features/explore/ExploreToolbar.tsx b/public/app/features/explore/ExploreToolbar.tsx new file mode 100644 index 00000000000..6b25b367039 --- /dev/null +++ b/public/app/features/explore/ExploreToolbar.tsx @@ -0,0 +1,100 @@ +import React, { PureComponent } from 'react'; +import { ExploreId } from 'app/types/explore'; +import { DataSourcePicker } from 'app/core/components/Select/DataSourcePicker'; +import { DataSourceSelectItem, RawTimeRange, TimeRange } from '@grafana/ui'; +import TimePicker from './TimePicker'; + +interface Props { + datasourceMissing: boolean; + exploreDatasources: DataSourceSelectItem[]; + exploreId: ExploreId; + loading: boolean; + range: RawTimeRange; + selectedDatasource: DataSourceSelectItem; + splitted: boolean; + onChangeDatasource: (option) => void; + onClearAll: () => void; + onCloseSplit: () => void; + onChangeTime: (range: TimeRange, changedByScanner?: boolean) => void; + onRunQuery: () => void; + onSplit: () => void; +} + +export class ExploreToolbar extends PureComponent { + /** + * Timepicker to control scanning + */ + timepickerRef: React.RefObject; + + constructor(props) { + super(props); + this.timepickerRef = React.createRef(); + } + + render() { + const { + datasourceMissing, + exploreDatasources, + exploreId, + loading, + range, + selectedDatasource, + splitted, + } = this.props; + + return ( +
+ {exploreId === 'left' ? ( + + ) : ( + <> +
+
+ +
+ + )} + {!datasourceMissing ? ( +
+ +
+ ) : null} +
+ {exploreId === 'left' && !splitted ? ( +
+ +
+ ) : null} + +
+ +
+
+ +
+
+ ); + } +}