Merge branch 'master' into apply-function-ui-fix

pull/10616/head
Alex P 2016-12-07 12:49:51 -08:00
commit da89c14b02
5 changed files with 53 additions and 36 deletions

View File

@ -148,8 +148,8 @@ func getEmail(ctx context.Context) (string, error) {
func (h *Service) Me(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
if !h.UseAuth {
Error(w, http.StatusTeapot, fmt.Sprintf("%v", "Go to line 151 users.go. Look for Arnold"), h.Logger)
_ = 42 // did you mean to learn the answer? if so go to line aslfjasdlfja; (gee willickers.... tbc)
// Using status code to signal no need for authentication
w.WriteHeader(http.StatusTeapot)
return
}
email, err := getEmail(ctx)

View File

@ -34,6 +34,7 @@ export const DataSection = React.createClass({
groupByTime: PropTypes.func.isRequired,
toggleTagAcceptance: PropTypes.func.isRequired,
}).isRequired,
timeRange: PropTypes.shape({}).isRequired,
},
childContextTypes: {
@ -96,9 +97,8 @@ export const DataSection = React.createClass({
},
render() {
const {query} = this.props;
const timeRange = {lower: 'now() - 15m', upper: null};
const statement = query.rawText || selectStatement(timeRange, query) || `SELECT "fields" FROM "db"."rp"."measurement"`;
const {query, timeRange} = this.props;
const statement = query.rawText || selectStatement({lower: timeRange.queryValue}, query) || `SELECT "fields" FROM "db"."rp"."measurement"`;
return (
<div className="kapacitor-rule-section">

View File

@ -6,6 +6,7 @@ import RuleGraph from 'src/kapacitor/components/RuleGraph';
import RuleMessage from 'src/kapacitor/components/RuleMessage';
import {createRule, editRule} from 'src/kapacitor/apis';
import selectStatement from '../../chronograf/utils/influxql/select';
import timeRanges from 'hson!../../shared/data/timeRanges.hson';
export const KapacitorRule = React.createClass({
propTypes: {
@ -24,10 +25,18 @@ export const KapacitorRule = React.createClass({
kapacitor: PropTypes.shape({}).isRequired,
},
getInitialState() {
const fifteenMinutesIndex = 1;
return {
timeRange: timeRanges[fifteenMinutesIndex],
};
},
render() {
const {queryActions, source, enabledAlerts, queryConfigs, query,
rule, kapacitorActions, isEditing} = this.props;
const {chooseTrigger, updateRuleValues} = kapacitorActions;
const {timeRange} = this.state;
return (
<div className="page">
@ -35,21 +44,23 @@ export const KapacitorRule = React.createClass({
rule={rule}
actions={kapacitorActions}
onSave={isEditing ? this.handleEdit : this.handleCreate}
onChooseTimeRange={this.handleChooseTimeRange}
validationError={this.validationError()}
timeRange={timeRange}
/>
<div className="page-contents page-contents--green-scrollbar">
<div className="container-fluid">
<div className="row">
<div className="col-xs-12">
<div className="rule-builder">
<DataSection source={source} query={query} actions={queryActions} />
<DataSection timeRange={timeRange} source={source} query={query} actions={queryActions} />
<ValuesSection
rule={rule}
query={queryConfigs[rule.queryID]}
onChooseTrigger={chooseTrigger}
onUpdateValues={updateRuleValues}
/>
<RuleGraph source={source} query={query} rule={rule} />
<RuleGraph timeRange={timeRange} source={source} query={query} rule={rule} />
<RuleMessage rule={rule} actions={kapacitorActions} enabledAlerts={enabledAlerts} />
</div>
</div>
@ -60,6 +71,11 @@ export const KapacitorRule = React.createClass({
);
},
handleChooseTimeRange({lower}) {
const timeRange = timeRanges.find((range) => range.queryValue === lower);
this.setState({timeRange});
},
handleCreate() {
const {addFlashMessage, queryConfigs, rule, source, router, kapacitor} = this.props;

View File

@ -13,6 +13,7 @@ export const RuleGraph = React.createClass({
}).isRequired,
query: PropTypes.shape({}).isRequired,
rule: PropTypes.shape({}).isRequired,
timeRange: PropTypes.shape({}).isRequired,
},
render() {
@ -24,9 +25,9 @@ export const RuleGraph = React.createClass({
},
renderGraph() {
const {query, source} = this.props;
const {query, source, timeRange} = this.props;
const autoRefreshMs = 30000;
const queryText = selectStatement({lower: 'now() - 15m'}, query);
const queryText = selectStatement({lower: timeRange.queryValue}, query);
const queries = [{host: source.links.proxy, text: queryText}];
const kapacitorLineColors = ["#4ED8A0"];

View File

@ -1,5 +1,6 @@
import React, {PropTypes} from 'react';
import ReactTooltip from 'react-tooltip';
import TimeRangeDropdown from '../../shared/components/TimeRangeDropdown';
export const RuleHeader = React.createClass({
propTypes: {
@ -9,6 +10,8 @@ export const RuleHeader = React.createClass({
updateRuleName: PropTypes.func.isRequired,
}).isRequired,
validationError: PropTypes.string.isRequired,
onChooseTimeRange: PropTypes.func.isRequired,
timeRange: PropTypes.shape({}).isRequired,
},
getInitialState() {
@ -41,33 +44,29 @@ export const RuleHeader = React.createClass({
this.setState({isEditingName: !this.state.isEditingName});
},
render() {
return (
<div className="page-header">
<div className="page-header__container">
<div className="page-header__left">
{this.renderEditName()}
</div>
<div className="page-header__right">
{this.renderSave()}
</div>
</div>
</div>
);
},
renderSave() {
const {validationError, onSave} = this.props;
if (!validationError) {
return <button className="btn btn-success btn-sm" onClick={onSave}>Save Rule</button>;
}
return (
<div>
const {validationError, onSave, timeRange, onChooseTimeRange} = this.props;
const saveButton = validationError ?
<button className="btn btn-sm btn-default disabled" data-for="save-kapacitor-tooltip" data-tip={validationError}>
Save Rule
</button>
</button> :
<button className="btn btn-success btn-sm" onClick={onSave}>Save Rule</button>;
return (
<div className="page-header__right">
<TimeRangeDropdown onChooseTimeRange={onChooseTimeRange} selected={timeRange.inputValue} />
{saveButton}
<ReactTooltip id="save-kapacitor-tooltip" effect="solid" html={true} offset={{top: 2}} place="bottom" class="influx-tooltip kapacitor-tooltip place-bottom" />
</div>
);
@ -75,18 +74,9 @@ export const RuleHeader = React.createClass({
renderEditName() {
const {rule} = this.props;
const {isEditingName} = this.state;
if (!this.state.isEditingName) {
return (
<h1 className="chronograf-header__editable" onClick={this.toggleEditName} data-for="rename-kapacitor-tooltip" data-tip="Click to Rename">
{rule.name}
<span className="icon pencil"></span>
<ReactTooltip id="rename-kapacitor-tooltip" delayShow="200" effect="solid" html={true} offset={{top: 2}} place="bottom" class="influx-tooltip kapacitor-tooltip place-bottom" />
</h1>
);
}
return (
const name = isEditingName ?
<input
className="chronograf-header__editing"
autoFocus={true}
@ -95,7 +85,17 @@ export const RuleHeader = React.createClass({
onKeyDown={(e) => this.handleEditName(e, rule)}
onBlur={() => this.handleEditNameBlur(rule)}
placeholder="Name your rule"
/>
/> :
<h1 className="chronograf-header__editable" onClick={this.toggleEditName} data-for="rename-kapacitor-tooltip" data-tip="Click to Rename">
{rule.name}
<span className="icon pencil"></span>
<ReactTooltip id="rename-kapacitor-tooltip" delayShow={200} effect="solid" html={true} offset={{top: 2}} place="bottom" class="influx-tooltip kapacitor-tooltip place-bottom" />
</h1>;
return (
<div className="page-header__left">
{name}
</div>
);
},