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