2019-01-22 07:50:19 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { ExploreId } from 'app/types/explore';
|
|
|
|
import { DataSourceSelectItem, RawTimeRange, TimeRange } from '@grafana/ui';
|
|
|
|
import TimePicker from './TimePicker';
|
2019-01-23 08:57:24 -06:00
|
|
|
import { DataSourcePicker } from 'app/core/components/Select/DataSourcePicker';
|
2019-01-22 07:50:19 -06:00
|
|
|
|
|
|
|
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<Props, {}> {
|
|
|
|
/**
|
|
|
|
* Timepicker to control scanning
|
|
|
|
*/
|
|
|
|
timepickerRef: React.RefObject<TimePicker>;
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.timepickerRef = React.createRef();
|
2019-01-23 08:57:24 -06:00
|
|
|
this.createResponsiveButton = this.createResponsiveButton.bind(this);
|
|
|
|
this.createDatasourcePicker = this.createDatasourcePicker.bind(this);
|
|
|
|
this.createSplittedClassName = this.createSplittedClassName.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
createDatasourcePicker() {
|
|
|
|
const { exploreDatasources, selectedDatasource } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DataSourcePicker
|
|
|
|
onChange={this.props.onChangeDatasource}
|
|
|
|
datasources={exploreDatasources}
|
|
|
|
current={selectedDatasource}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
createResponsiveButton(options: {
|
|
|
|
title: string;
|
|
|
|
onClick: () => void;
|
|
|
|
buttonClassName?: string;
|
|
|
|
iconClassName?: string;
|
|
|
|
}) {
|
|
|
|
const { splitted } = this.props;
|
|
|
|
const { title, onClick, buttonClassName, iconClassName } = options;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<button className={`btn navbar-button large-screens ${buttonClassName && buttonClassName}`} onClick={onClick}>
|
|
|
|
{!splitted ? title : ''}
|
|
|
|
{iconClassName && <i className={iconClassName} />}
|
|
|
|
</button>
|
|
|
|
<button className={`btn navbar-button small-screens ${buttonClassName && buttonClassName}`} onClick={onClick}>
|
|
|
|
{iconClassName && <i className={iconClassName} />}
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
createSplittedClassName(className: string) {
|
|
|
|
const { splitted } = this.props;
|
|
|
|
|
|
|
|
return splitted ? `${className}-splitted` : className;
|
2019-01-22 07:50:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-01-23 08:57:24 -06:00
|
|
|
const { datasourceMissing, exploreId, loading, range, splitted } = this.props;
|
|
|
|
const toolbar = this.createSplittedClassName('toolbar');
|
|
|
|
const toolbarItem = this.createSplittedClassName('toolbar-item');
|
|
|
|
const toolbarHeader = this.createSplittedClassName('toolbar-header');
|
|
|
|
const timepickerLarge = this.createSplittedClassName('toolbar-content-item timepicker-large-screens');
|
|
|
|
const timepickerSmall = this.createSplittedClassName('toolbar-content-item timepicker-small-screens');
|
2019-01-22 07:50:19 -06:00
|
|
|
|
|
|
|
return (
|
2019-01-23 08:57:24 -06:00
|
|
|
<div className={toolbar}>
|
|
|
|
<div className={toolbarItem}>
|
|
|
|
<div className={toolbarHeader}>
|
|
|
|
<div className="toolbar-header-title">
|
|
|
|
{exploreId === 'left' && (
|
2019-01-23 09:48:21 -06:00
|
|
|
<a>
|
2019-01-23 08:57:24 -06:00
|
|
|
<i className="fa fa-rocket fa-fw" />
|
|
|
|
Explore
|
|
|
|
</a>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<div className="toolbar-header-datasource large-screens">
|
|
|
|
<div className="datasource-picker">
|
|
|
|
{!datasourceMissing && !splitted ? this.createDatasourcePicker() : null}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="toolbar-header-close">
|
|
|
|
{exploreId === 'right' && (
|
2019-01-23 09:29:18 -06:00
|
|
|
<button className="btn navbar-button" onClick={this.props.onCloseSplit}>
|
|
|
|
Close Split
|
|
|
|
</button>
|
2019-01-23 08:57:24 -06:00
|
|
|
)}
|
|
|
|
</div>
|
2019-01-22 07:50:19 -06:00
|
|
|
</div>
|
2019-01-23 08:57:24 -06:00
|
|
|
</div>
|
|
|
|
<div className={toolbarItem}>
|
|
|
|
{!datasourceMissing && splitted ? (
|
|
|
|
<div className="datasource-picker">{this.createDatasourcePicker()}</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
<div className={toolbarItem}>
|
|
|
|
<div className="toolbar-content">
|
|
|
|
{!datasourceMissing && !splitted ? (
|
|
|
|
<div className="toolbar-content-item small-screens">
|
|
|
|
<div className="datasource-picker">{this.createDatasourcePicker()}</div>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
{exploreId === 'left' && !splitted ? (
|
|
|
|
<div className="toolbar-content-item">
|
|
|
|
{this.createResponsiveButton({
|
|
|
|
title: 'Split',
|
|
|
|
onClick: this.props.onSplit,
|
|
|
|
iconClassName: 'fa fa-fw fa-columns',
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
<div className={timepickerLarge}>
|
|
|
|
<TimePicker
|
|
|
|
ref={this.timepickerRef}
|
|
|
|
range={range}
|
|
|
|
onChangeTime={this.props.onChangeTime}
|
|
|
|
iconOnly={false}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className={timepickerSmall}>
|
|
|
|
<TimePicker
|
|
|
|
ref={this.timepickerRef}
|
|
|
|
range={range}
|
|
|
|
onChangeTime={this.props.onChangeTime}
|
|
|
|
iconOnly={true}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="toolbar-content-item">
|
|
|
|
<button className="btn navbar-button navbar-button--no-icon" onClick={this.props.onClearAll}>
|
|
|
|
Clear All
|
2019-01-22 07:50:19 -06:00
|
|
|
</button>
|
|
|
|
</div>
|
2019-01-23 08:57:24 -06:00
|
|
|
<div className="toolbar-content-item">
|
|
|
|
{this.createResponsiveButton({
|
|
|
|
title: 'Run Query',
|
|
|
|
onClick: this.props.onRunQuery,
|
|
|
|
buttonClassName: 'navbar-button--primary',
|
|
|
|
iconClassName: loading ? 'fa fa-spinner fa-fw fa-spin run-icon' : 'fa fa-level-down fa-fw run-icon',
|
|
|
|
})}
|
|
|
|
</div>
|
2019-01-22 07:50:19 -06:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|