From 06f771afd39cf02d28303063503b0a936d7ac99c Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 20 Dec 2018 15:59:21 +0100 Subject: [PATCH] add alias by component --- .../stackdriver/components/AliasBy.tsx | 54 +++++++++++++++++++ .../stackdriver/components/QueryEditor.tsx | 10 ++++ .../stackdriver/partials/query.editor.html | 4 +- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 public/app/plugins/datasource/stackdriver/components/AliasBy.tsx diff --git a/public/app/plugins/datasource/stackdriver/components/AliasBy.tsx b/public/app/plugins/datasource/stackdriver/components/AliasBy.tsx new file mode 100644 index 00000000000..ae397a2c4d8 --- /dev/null +++ b/public/app/plugins/datasource/stackdriver/components/AliasBy.tsx @@ -0,0 +1,54 @@ +import React, { Component } from 'react'; +import { debounce } from 'lodash'; + +export interface Props { + onChange: (alignmentPeriod) => void; + value: string; +} + +export interface State { + value: string; +} + +export class AliasBy extends Component { + constructor(props) { + super(props); + this.handleChange = this.handleChange.bind(this); + this.onChange = debounce(this.onChange.bind(this), 500); + this.state = { value: '' }; + } + + componentDidMount() { + this.setState({ value: this.props.value }); + } + + handleChange(e) { + this.setState({ value: e.target.value }); + this.onChange(e.target.value); + } + + onChange(value) { + this.props.onChange(value); + } + + render() { + return ( + +
+
+ + +
+
+
+
+
+ + ); + } +} diff --git a/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx b/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx index fd985a353c9..a5a85760054 100644 --- a/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx +++ b/public/app/plugins/datasource/stackdriver/components/QueryEditor.tsx @@ -6,6 +6,7 @@ import { Filter } from './Filter'; import { Aggregations } from './Aggregations'; import { Alignments } from './Alignments'; import { AlignmentPeriods } from './AlignmentPeriods'; +import { AliasBy } from './AliasBy'; import { Target } from '../types'; import { getAlignmentPickerData } from '../functions'; @@ -117,6 +118,13 @@ export class QueryEditor extends React.Component { }); } + handleAliasByChange(value) { + this.setState({ aliasBy: value }, () => { + this.props.onQueryChange(this.state); + this.props.onExecuteQuery(); + }); + } + render() { const { defaultProject, @@ -126,6 +134,7 @@ export class QueryEditor extends React.Component { perSeriesAligner, alignOptions, alignmentPeriod, + aliasBy, } = this.state; const { templateSrv, datasource, uiSegmentSrv } = this.props; @@ -173,6 +182,7 @@ export class QueryEditor extends React.Component { alignmentPeriod={alignmentPeriod} onChange={value => this.handleAlignmentPeriodChange(value)} /> + this.handleAliasByChange(value)} /> )} diff --git a/public/app/plugins/datasource/stackdriver/partials/query.editor.html b/public/app/plugins/datasource/stackdriver/partials/query.editor.html index f87dda0f044..20b3a6634a5 100755 --- a/public/app/plugins/datasource/stackdriver/partials/query.editor.html +++ b/public/app/plugins/datasource/stackdriver/partials/query.editor.html @@ -9,7 +9,7 @@ -
+
Project