|
|
@@ -1,13 +1,18 @@
|
|
|
-import React, { PureComponent } from 'react';
|
|
|
+import React, { SFC, PureComponent } from 'react';
|
|
|
import DataSourceOption from './DataSourceOption';
|
|
|
import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader';
|
|
|
import { EditorTabBody } from './EditorTabBody';
|
|
|
import { DataSourcePicker } from './DataSourcePicker';
|
|
|
-
|
|
|
import { PanelModel } from '../panel_model';
|
|
|
import { DashboardModel } from '../dashboard_model';
|
|
|
import './../../panel/metrics_tab';
|
|
|
import config from 'app/core/config';
|
|
|
+import { QueryInspector } from './QueryInspector';
|
|
|
+import { Switch } from 'app/core/components/Switch/Switch';
|
|
|
+import { Input } from 'app/core/components/Form';
|
|
|
+import { InputStatus, EventsWithValidation } from 'app/core/components/Form/Input';
|
|
|
+import { isValidTimeSpan } from 'app/core/utils/rangeutil';
|
|
|
+import { ValidationEvents } from 'app/types';
|
|
|
|
|
|
// Services
|
|
|
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
|
|
@@ -29,8 +34,29 @@ interface Help {
|
|
|
interface State {
|
|
|
currentDatasource: DataSourceSelectItem;
|
|
|
help: Help;
|
|
|
+ hideTimeOverride: boolean;
|
|
|
+}
|
|
|
+
|
|
|
+interface LoadingPlaceholderProps {
|
|
|
+ text: string;
|
|
|
}
|
|
|
|
|
|
+const LoadingPlaceholder: SFC<LoadingPlaceholderProps> = ({ text }) => <h2>{text}</h2>;
|
|
|
+
|
|
|
+const timeRangeValidationEvents: ValidationEvents = {
|
|
|
+ [EventsWithValidation.onBlur]: [
|
|
|
+ {
|
|
|
+ rule: value => {
|
|
|
+ if (!value) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return isValidTimeSpan(value);
|
|
|
+ },
|
|
|
+ errorMessage: 'Not a valid timespan',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+};
|
|
|
+
|
|
|
export class QueriesTab extends PureComponent<Props, State> {
|
|
|
element: any;
|
|
|
component: AngularComponent;
|
|
|
@@ -47,6 +73,7 @@ export class QueriesTab extends PureComponent<Props, State> {
|
|
|
isLoading: false,
|
|
|
helpHtml: null,
|
|
|
},
|
|
|
+ hideTimeOverride: false,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -199,9 +226,50 @@ export class QueriesTab extends PureComponent<Props, State> {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ renderQueryInspector = () => {
|
|
|
+ const { panel } = this.props;
|
|
|
+ return <QueryInspector panel={panel} LoadingPlaceholder={LoadingPlaceholder} />;
|
|
|
+ };
|
|
|
+
|
|
|
+ renderHelp = () => {
|
|
|
+ const { helpHtml, isLoading } = this.state.help;
|
|
|
+ return isLoading ? <LoadingPlaceholder text="Loading help..." /> : helpHtml;
|
|
|
+ };
|
|
|
+
|
|
|
+ emptyToNull = (value: string) => {
|
|
|
+ return value === '' ? null : value;
|
|
|
+ };
|
|
|
+
|
|
|
+ onOverrideTime = (evt, status: InputStatus) => {
|
|
|
+ const { value } = evt.target;
|
|
|
+ const { panel } = this.props;
|
|
|
+ const emptyToNullValue = this.emptyToNull(value);
|
|
|
+ if (status === InputStatus.Valid && panel.timeFrom !== emptyToNullValue) {
|
|
|
+ panel.timeFrom = emptyToNullValue;
|
|
|
+ panel.refresh();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ onTimeShift = (evt, status: InputStatus) => {
|
|
|
+ const { value } = evt.target;
|
|
|
+ const { panel } = this.props;
|
|
|
+ const emptyToNullValue = this.emptyToNull(value);
|
|
|
+ if (status === InputStatus.Valid && panel.timeShift !== emptyToNullValue) {
|
|
|
+ panel.timeShift = emptyToNullValue;
|
|
|
+ panel.refresh();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ onToggleTimeOverride = () => {
|
|
|
+ const { panel } = this.props;
|
|
|
+ panel.hideTimeOverride = !panel.hideTimeOverride;
|
|
|
+ panel.refresh();
|
|
|
+ };
|
|
|
+
|
|
|
render() {
|
|
|
const { currentDatasource } = this.state;
|
|
|
- const { helpHtml } = this.state.help;
|
|
|
+ const hideTimeOverride = this.props.panel.hideTimeOverride;
|
|
|
+ console.log('hideTimeOverride', hideTimeOverride);
|
|
|
const { hasQueryHelp, queryOptions } = currentDatasource.meta;
|
|
|
const hasQueryOptions = !!queryOptions;
|
|
|
const dsInformation = {
|
|
|
@@ -220,7 +288,7 @@ export class QueriesTab extends PureComponent<Props, State> {
|
|
|
|
|
|
const queryInspector = {
|
|
|
title: 'Query Inspector',
|
|
|
- render: () => <h2>hello</h2>,
|
|
|
+ render: this.renderQueryInspector,
|
|
|
};
|
|
|
|
|
|
const dsHelp = {
|
|
|
@@ -228,18 +296,67 @@ export class QueriesTab extends PureComponent<Props, State> {
|
|
|
icon: 'fa fa-question',
|
|
|
disabled: !hasQueryHelp,
|
|
|
onClick: this.loadHelp,
|
|
|
- render: () => helpHtml,
|
|
|
+ render: this.renderHelp,
|
|
|
};
|
|
|
|
|
|
const options = {
|
|
|
- title: 'Options',
|
|
|
+ title: '',
|
|
|
+ icon: 'fa fa-cog',
|
|
|
disabled: !hasQueryOptions,
|
|
|
render: this.renderOptions,
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
<EditorTabBody heading="Queries" main={dsInformation} toolbarItems={[options, queryInspector, dsHelp]}>
|
|
|
- <div ref={element => (this.element = element)} style={{ width: '100%' }} />
|
|
|
+ <>
|
|
|
+ <div ref={element => (this.element = element)} style={{ width: '100%' }} />
|
|
|
+
|
|
|
+ <h5 className="section-heading">Time Range</h5>
|
|
|
+
|
|
|
+ <div className="gf-form-group">
|
|
|
+ <div className="gf-form">
|
|
|
+ <span className="gf-form-label">
|
|
|
+ <i className="fa fa-clock-o" />
|
|
|
+ </span>
|
|
|
+
|
|
|
+ <span className="gf-form-label width-12">Override relative time</span>
|
|
|
+ <span className="gf-form-label width-6">Last</span>
|
|
|
+ <Input
|
|
|
+ type="text"
|
|
|
+ className="gf-form-input max-width-8"
|
|
|
+ placeholder="1h"
|
|
|
+ onBlur={this.onOverrideTime}
|
|
|
+ validationEvents={timeRangeValidationEvents}
|
|
|
+ hideErrorMessage={true}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="gf-form">
|
|
|
+ <span className="gf-form-label">
|
|
|
+ <i className="fa fa-clock-o" />
|
|
|
+ </span>
|
|
|
+ <span className="gf-form-label width-12">Add time shift</span>
|
|
|
+ <span className="gf-form-label width-6">Amount</span>
|
|
|
+ <Input
|
|
|
+ type="text"
|
|
|
+ className="gf-form-input max-width-8"
|
|
|
+ placeholder="1h"
|
|
|
+ onBlur={this.onTimeShift}
|
|
|
+ validationEvents={timeRangeValidationEvents}
|
|
|
+ hideErrorMessage={true}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div className="gf-form-inline">
|
|
|
+ <div className="gf-form">
|
|
|
+ <span className="gf-form-label">
|
|
|
+ <i className="fa fa-clock-o" />
|
|
|
+ </span>
|
|
|
+ </div>
|
|
|
+ <Switch label="Hide time override info" checked={hideTimeOverride} onChange={this.onToggleTimeOverride} />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </>
|
|
|
</EditorTabBody>
|
|
|
);
|
|
|
}
|