import React, { PureComponent } from 'react'; import { ExploreId } from 'app/types/explore'; import { DataSourceSelectItem, RawTimeRange, TimeRange } from '@grafana/ui'; import TimePicker from './TimePicker'; import { DataSourcePicker } from 'app/core/components/Select/DataSourcePicker'; 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(); 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 ( ); } createResponsiveButton(options: { title: string; onClick: () => void; buttonClassName?: string; iconClassName?: string; }) { const { splitted } = this.props; const { title, onClick, buttonClassName, iconClassName } = options; return ( <> ); } createSplittedClassName(className: string) { const { splitted } = this.props; return splitted ? `${className}-splitted` : className; } render() { 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'); return (
{exploreId === 'left' && ( Explore )}
{!datasourceMissing && !splitted ? this.createDatasourcePicker() : null}
{exploreId === 'right' && ( )}
{!datasourceMissing && splitted ? (
{this.createDatasourcePicker()}
) : null}
{!datasourceMissing && !splitted ? (
{this.createDatasourcePicker()}
) : null} {exploreId === 'left' && !splitted ? (
{this.createResponsiveButton({ title: 'Split', onClick: this.props.onSplit, iconClassName: 'fa fa-fw fa-columns', })}
) : null}
{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', })}
); } }