From 33c9217cc987cf4aee124c623cebe0bd45cbb7fb Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Fri, 26 Oct 2018 09:44:36 +0200 Subject: [PATCH] stackdriver: refactoring - rename react components and file structure changes --- .../pluginTemplateQueryComponentLoader.tsx | 6 ++-- .../MetricTypeSelector.tsx} | 12 ++++---- .../ServiceSelector.tsx} | 4 +-- .../TemplateQueryComponent.tsx} | 30 ++++++++++--------- .../plugins/datasource/stackdriver/module.ts | 4 +-- public/app/types/plugins.ts | 2 +- 6 files changed, 30 insertions(+), 28 deletions(-) rename public/app/plugins/datasource/stackdriver/{metricTypes.tsx => components/MetricTypeSelector.tsx} (77%) rename public/app/plugins/datasource/stackdriver/{services.tsx => components/ServiceSelector.tsx} (90%) rename public/app/plugins/datasource/stackdriver/{templateQueryCtrl.tsx => components/TemplateQueryComponent.tsx} (69%) diff --git a/public/app/features/plugins/pluginTemplateQueryComponentLoader.tsx b/public/app/features/plugins/pluginTemplateQueryComponentLoader.tsx index 9a27643ace5..9db8fc97088 100644 --- a/public/app/features/plugins/pluginTemplateQueryComponentLoader.tsx +++ b/public/app/features/plugins/pluginTemplateQueryComponentLoader.tsx @@ -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; } } diff --git a/public/app/plugins/datasource/stackdriver/metricTypes.tsx b/public/app/plugins/datasource/stackdriver/components/MetricTypeSelector.tsx similarity index 77% rename from public/app/plugins/datasource/stackdriver/metricTypes.tsx rename to public/app/plugins/datasource/stackdriver/components/MetricTypeSelector.tsx index d4e82dbc380..cf25a100747 100644 --- a/public/app/plugins/datasource/stackdriver/metricTypes.tsx +++ b/public/app/plugins/datasource/stackdriver/components/MetricTypeSelector.tsx @@ -1,13 +1,13 @@ import React, { SFC } from 'react'; interface Props { - onMetricTypeChanged: any; + onMetricTypeChange: any; selectedService: string; metricDescriptors: any[]; } -const MetricTypes: SFC = props => { - const extractMetricTypes = () => { +const MetricTypeSelector: SFC = props => { + const filterMetricTypes = () => { if (!props.selectedService) { return []; } @@ -22,8 +22,8 @@ const MetricTypes: SFC = props => {
Metric Types
- + {filterMetricTypes().map((qt, i) => ( @@ -34,4 +34,4 @@ const MetricTypes: SFC = props => { ); }; -export default MetricTypes; +export default MetricTypeSelector; diff --git a/public/app/plugins/datasource/stackdriver/services.tsx b/public/app/plugins/datasource/stackdriver/components/ServiceSelector.tsx similarity index 90% rename from public/app/plugins/datasource/stackdriver/services.tsx rename to public/app/plugins/datasource/stackdriver/components/ServiceSelector.tsx index e8da82933d2..44cf6122ebf 100644 --- a/public/app/plugins/datasource/stackdriver/services.tsx +++ b/public/app/plugins/datasource/stackdriver/components/ServiceSelector.tsx @@ -6,7 +6,7 @@ interface Props { metricDescriptors: any[]; } -const Services: SFC = props => { +const ServiceSelector: SFC = props => { const extractServices = () => uniqBy(props.metricDescriptors, 'service').map(m => ({ value: m.service, @@ -29,4 +29,4 @@ const Services: SFC = props => { ); }; -export default Services; +export default ServiceSelector; diff --git a/public/app/plugins/datasource/stackdriver/templateQueryCtrl.tsx b/public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx similarity index 69% rename from public/app/plugins/datasource/stackdriver/templateQueryCtrl.tsx rename to public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx index 20a2cf28077..a0ca1ad422e 100644 --- a/public/app/plugins/datasource/stackdriver/templateQueryCtrl.tsx +++ b/public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx @@ -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 { +export class StackdriverTemplateQueryComponent extends PureComponent { queryTypes: Array<{ value: string; name: string }> = [ { value: 'services', name: 'Services' }, { value: 'metricTypes', name: 'Metric Types' }, @@ -18,9 +18,9 @@ export class StackdriverTemplateQueryCtrl extends PureComponent { 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 { this.setState({ metricDescriptors }); } - handleChange(event) { + handleQueryTypeChange(event) { this.setState({ queryType: event.target.value }); } @@ -37,22 +37,24 @@ export class StackdriverTemplateQueryCtrl extends PureComponent { this.setState({ service: event.target.value }); } - onMetricTypeChanged(event) { + onMetricTypeChange(event) { this.setState({ metricType: event.target.value }); } renderSwitch(queryType) { switch (queryType) { case 'metricTypes': - return ; + return ( + + ); case 'metricLabels': return ( - - + ); @@ -67,7 +69,7 @@ export class StackdriverTemplateQueryCtrl extends PureComponent {
Query Type
- {this.queryTypes.map((qt, i) => (