mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: refactoring - rename react components and file structure changes
This commit is contained in:
parent
4bcf3bf1ff
commit
33c9217cc9
@ -6,10 +6,10 @@ import DefaultTemplateQueryCtrl from '../templating/defaultTemplateQueryCtrl';
|
||||
|
||||
async function loadComponent(module) {
|
||||
const component = await importPluginModule(module);
|
||||
if (!component.TemplateQueryCtrl) {
|
||||
return DefaultTemplateQueryCtrl;
|
||||
if (component && component.TemplateQueryComponent) {
|
||||
return component.TemplateQueryComponent;
|
||||
} else {
|
||||
return component.TemplateQueryCtrl;
|
||||
return DefaultTemplateQueryCtrl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
import React, { SFC } from 'react';
|
||||
|
||||
interface Props {
|
||||
onMetricTypeChanged: any;
|
||||
onMetricTypeChange: any;
|
||||
selectedService: string;
|
||||
metricDescriptors: any[];
|
||||
}
|
||||
|
||||
const MetricTypes: SFC<Props> = props => {
|
||||
const extractMetricTypes = () => {
|
||||
const MetricTypeSelector: SFC<Props> = props => {
|
||||
const filterMetricTypes = () => {
|
||||
if (!props.selectedService) {
|
||||
return [];
|
||||
}
|
||||
@ -22,8 +22,8 @@ const MetricTypes: SFC<Props> = props => {
|
||||
<div className="gf-form max-width-21">
|
||||
<span className="gf-form-label width-7">Metric Types</span>
|
||||
<div className="gf-form-select-wrapper max-width-14">
|
||||
<select className="gf-form-input" required onChange={props.onMetricTypeChanged}>
|
||||
{extractMetricTypes().map((qt, i) => (
|
||||
<select className="gf-form-input" required onChange={props.onMetricTypeChange}>
|
||||
{filterMetricTypes().map((qt, i) => (
|
||||
<option key={i} value={qt.value} ng-if="false">
|
||||
{qt.name}
|
||||
</option>
|
||||
@ -34,4 +34,4 @@ const MetricTypes: SFC<Props> = props => {
|
||||
);
|
||||
};
|
||||
|
||||
export default MetricTypes;
|
||||
export default MetricTypeSelector;
|
@ -6,7 +6,7 @@ interface Props {
|
||||
metricDescriptors: any[];
|
||||
}
|
||||
|
||||
const Services: SFC<Props> = props => {
|
||||
const ServiceSelector: SFC<Props> = props => {
|
||||
const extractServices = () =>
|
||||
uniqBy(props.metricDescriptors, 'service').map(m => ({
|
||||
value: m.service,
|
||||
@ -29,4 +29,4 @@ const Services: SFC<Props> = props => {
|
||||
);
|
||||
};
|
||||
|
||||
export default Services;
|
||||
export default ServiceSelector;
|
@ -1,15 +1,15 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import StackdriverDatasource from './datasource';
|
||||
import Services from './services';
|
||||
import MetricTypes from './metricTypes';
|
||||
import StackdriverDatasource from '../datasource';
|
||||
import ServiceSelector from './ServiceSelector';
|
||||
import MetricTypeSelector from './MetricTypeSelector';
|
||||
|
||||
interface Props {
|
||||
datasource: StackdriverDatasource;
|
||||
query: string;
|
||||
query: any;
|
||||
onChange: (c: string) => void;
|
||||
}
|
||||
|
||||
export class StackdriverTemplateQueryCtrl extends PureComponent<Props, any> {
|
||||
export class StackdriverTemplateQueryComponent extends PureComponent<Props, any> {
|
||||
queryTypes: Array<{ value: string; name: string }> = [
|
||||
{ value: 'services', name: 'Services' },
|
||||
{ value: 'metricTypes', name: 'Metric Types' },
|
||||
@ -18,9 +18,9 @@ export class StackdriverTemplateQueryCtrl extends PureComponent<Props, any> {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
this.handleQueryTypeChange = this.handleQueryTypeChange.bind(this);
|
||||
this.onServiceChange = this.onServiceChange.bind(this);
|
||||
this.onMetricTypeChanged = this.onMetricTypeChanged.bind(this);
|
||||
this.onMetricTypeChange = this.onMetricTypeChange.bind(this);
|
||||
this.state = { queryType: undefined, metricDescriptors: [], service: undefined, metricType: undefined };
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ export class StackdriverTemplateQueryCtrl extends PureComponent<Props, any> {
|
||||
this.setState({ metricDescriptors });
|
||||
}
|
||||
|
||||
handleChange(event) {
|
||||
handleQueryTypeChange(event) {
|
||||
this.setState({ queryType: event.target.value });
|
||||
}
|
||||
|
||||
@ -37,22 +37,24 @@ export class StackdriverTemplateQueryCtrl extends PureComponent<Props, any> {
|
||||
this.setState({ service: event.target.value });
|
||||
}
|
||||
|
||||
onMetricTypeChanged(event) {
|
||||
onMetricTypeChange(event) {
|
||||
this.setState({ metricType: event.target.value });
|
||||
}
|
||||
|
||||
renderSwitch(queryType) {
|
||||
switch (queryType) {
|
||||
case 'metricTypes':
|
||||
return <Services metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />;
|
||||
return (
|
||||
<ServiceSelector metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />
|
||||
);
|
||||
case 'metricLabels':
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Services metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />
|
||||
<MetricTypes
|
||||
<ServiceSelector metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />
|
||||
<MetricTypeSelector
|
||||
selectedService={this.state.service}
|
||||
metricDescriptors={this.state.metricDescriptors}
|
||||
onMetricTypeChanged={this.onMetricTypeChanged}
|
||||
onMetricTypeChange={this.onMetricTypeChange}
|
||||
/>
|
||||
</React.Fragment>
|
||||
);
|
||||
@ -67,7 +69,7 @@ export class StackdriverTemplateQueryCtrl extends PureComponent<Props, any> {
|
||||
<div className="gf-form max-width-21">
|
||||
<span className="gf-form-label width-7">Query Type</span>
|
||||
<div className="gf-form-select-wrapper max-width-14">
|
||||
<select className="gf-form-input" required onChange={this.handleChange}>
|
||||
<select className="gf-form-input" required onChange={this.handleQueryTypeChange}>
|
||||
{this.queryTypes.map((qt, i) => (
|
||||
<option key={i} value={qt.value} ng-if="false">
|
||||
{qt.name}
|
@ -2,12 +2,12 @@ import StackdriverDatasource from './datasource';
|
||||
import { StackdriverQueryCtrl } from './query_ctrl';
|
||||
import { StackdriverConfigCtrl } from './config_ctrl';
|
||||
import { StackdriverAnnotationsQueryCtrl } from './annotations_query_ctrl';
|
||||
import { StackdriverTemplateQueryCtrl } from './templateQueryCtrl';
|
||||
import { StackdriverTemplateQueryComponent } from './components/TemplateQueryComponent';
|
||||
|
||||
export {
|
||||
StackdriverDatasource as Datasource,
|
||||
StackdriverQueryCtrl as QueryCtrl,
|
||||
StackdriverConfigCtrl as ConfigCtrl,
|
||||
StackdriverAnnotationsQueryCtrl as AnnotationsQueryCtrl,
|
||||
StackdriverTemplateQueryCtrl as TemplateQueryCtrl,
|
||||
StackdriverTemplateQueryComponent as TemplateQueryComponent,
|
||||
};
|
||||
|
@ -6,7 +6,7 @@ export interface PluginExports {
|
||||
QueryCtrl?: any;
|
||||
ConfigCtrl?: any;
|
||||
AnnotationsQueryCtrl?: any;
|
||||
TemplateQueryCtrl?: any;
|
||||
TemplateQueryComponent?: any;
|
||||
ExploreQueryField?: any;
|
||||
ExploreStartPage?: any;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user