stackdriver: refactor TemplateQueryComponent

This commit is contained in:
Erik Sundell
2018-11-09 13:55:10 +01:00
parent f0b4af9f6c
commit 727472a3cb
@@ -20,14 +20,14 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
]; ];
defaults = { defaults = {
type: undefined, type: '',
metricDescriptors: [], metricDescriptors: [],
service: undefined, service: '',
metricType: undefined, metricType: '',
metricLabels: [], metricLabels: [],
resourceLabels: [], resourceLabels: [],
metricLabelKey: undefined, metricLabelKey: '',
resourceLabelKey: undefined, resourceLabelKey: '',
}; };
constructor(props: TemplateQueryProps) { constructor(props: TemplateQueryProps) {
@@ -45,10 +45,6 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
this.setState({ metricDescriptors }); this.setState({ metricDescriptors });
} }
isLabelQuery(queryType) {
return [MetricFindQueryTypes.MetricLabels, MetricFindQueryTypes.ResourceLabels].indexOf(queryType) !== -1;
}
async loadTimeSeriesData() { async loadTimeSeriesData() {
const refId = 'StackdriverTemplateQueryComponent'; const refId = 'StackdriverTemplateQueryComponent';
const response = await this.props.datasource.getLabels(this.state.metricType, refId); const response = await this.props.datasource.getLabels(this.state.metricType, refId);
@@ -88,7 +84,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
this.props.onChange(queryModel); this.props.onChange(queryModel);
} }
switchMetaType(queryType) { getDropdown(queryType) {
switch (queryType) { switch (queryType) {
case MetricFindQueryTypes.ResourceLabels: case MetricFindQueryTypes.ResourceLabels:
return ( return (
@@ -113,7 +109,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
} }
} }
renderSwitch(queryType) { renderQueryTypeSwitch(queryType) {
switch (queryType) { switch (queryType) {
case MetricFindQueryTypes.MetricTypes: case MetricFindQueryTypes.MetricTypes:
return ( return (
@@ -122,7 +118,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
case MetricFindQueryTypes.MetricLabels: case MetricFindQueryTypes.MetricLabels:
case MetricFindQueryTypes.ResourceLabels: case MetricFindQueryTypes.ResourceLabels:
case MetricFindQueryTypes.ResourceTypes: case MetricFindQueryTypes.ResourceTypes:
const dropdown = this.switchMetaType(queryType); const dropdown = this.getDropdown(queryType);
return ( return (
<React.Fragment> <React.Fragment>
<ServiceSelector metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} /> <ServiceSelector metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />
@@ -151,6 +147,10 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
} }
} }
isLabelQuery(queryType) {
return [MetricFindQueryTypes.MetricLabels, MetricFindQueryTypes.ResourceLabels].indexOf(queryType) !== -1;
}
render() { render() {
return ( return (
<React.Fragment> <React.Fragment>
@@ -166,7 +166,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
</select> </select>
</div> </div>
</div> </div>
{this.renderSwitch(this.state.type)} {this.renderQueryTypeSwitch(this.state.type)}
</React.Fragment> </React.Fragment>
); );
} }