From 1ab9fc871c847adc5ffc924796ed5af476f1ff67 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Wed, 2 Jan 2019 15:35:36 +0100 Subject: [PATCH] cleanup. remove comments, not used files etc --- .../stackdriver/angular_wrappers.ts | 1 + .../stackdriver/annotations_query_ctrl.ts | 11 ++- .../stackdriver/components/Aggregations.tsx | 2 +- .../components/AnnotationQueryEditor.tsx | 1 - .../stackdriver/components/Metrics.tsx | 3 +- .../stackdriver/components/Segment.tsx | 44 --------- .../components/StackdriverPicker.tsx | 97 ------------------- .../partials/annotations.editor.html | 2 +- .../stackdriver/partials/query.filter.html | 30 ------ .../datasource/stackdriver/query_ctrl.ts | 14 ++- 10 files changed, 25 insertions(+), 180 deletions(-) delete mode 100644 public/app/plugins/datasource/stackdriver/components/Segment.tsx delete mode 100644 public/app/plugins/datasource/stackdriver/components/StackdriverPicker.tsx diff --git a/public/app/plugins/datasource/stackdriver/angular_wrappers.ts b/public/app/plugins/datasource/stackdriver/angular_wrappers.ts index 513d7d3f623..ff469b96535 100644 --- a/public/app/plugins/datasource/stackdriver/angular_wrappers.ts +++ b/public/app/plugins/datasource/stackdriver/angular_wrappers.ts @@ -2,6 +2,7 @@ import { react2AngularDirective } from 'app/core/utils/react2angular'; import { QueryEditor } from './components/QueryEditor'; import { AnnotationQueryEditor } from './components/AnnotationQueryEditor'; +//This should be removed when the plugin is fully reactified export function registerAngularDirectives() { react2AngularDirective('queryEditor', QueryEditor, [ 'target', diff --git a/public/app/plugins/datasource/stackdriver/annotations_query_ctrl.ts b/public/app/plugins/datasource/stackdriver/annotations_query_ctrl.ts index 1975c75d5a6..0f8a32d254c 100644 --- a/public/app/plugins/datasource/stackdriver/annotations_query_ctrl.ts +++ b/public/app/plugins/datasource/stackdriver/annotations_query_ctrl.ts @@ -1,6 +1,7 @@ import _ from 'lodash'; import './query_filter_ctrl'; -import { registerAngularDirectives } from './angular_wrappers'; +import { react2AngularDirective } from 'app/core/utils/react2angular'; +import { AnnotationQueryEditor } from './components/AnnotationQueryEditor'; export class StackdriverAnnotationsQueryCtrl { static templateUrl = 'partials/annotations.editor.html'; @@ -28,8 +29,14 @@ export class StackdriverAnnotationsQueryCtrl { this.annotation.target = this.annotation.target || {}; this.annotation.target.refId = 'annotationQuery'; _.defaultsDeep(this.annotation.target, this.defaults); - registerAngularDirectives(); this.handleQueryChange = this.handleQueryChange.bind(this); + + react2AngularDirective('annotationQueryEditor', AnnotationQueryEditor, [ + 'target', + 'onQueryChange', + 'onExecuteQuery', + ['datasource', { watchDepth: 'reference' }], + ]); } handleQueryChange(target) { diff --git a/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx b/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx index 7d963582552..d752d59261f 100644 --- a/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx +++ b/public/app/plugins/datasource/stackdriver/components/Aggregations.tsx @@ -1,8 +1,8 @@ import React from 'react'; import _ from 'lodash'; -import { getAggregationOptionsByMetric } from '../functions'; import { MetricSelect } from 'app/core/components/Select/MetricSelect'; +import { getAggregationOptionsByMetric } from '../functions'; export interface Props { onChange: (metricDescriptor) => void; diff --git a/public/app/plugins/datasource/stackdriver/components/AnnotationQueryEditor.tsx b/public/app/plugins/datasource/stackdriver/components/AnnotationQueryEditor.tsx index 057fd5fe35b..48add7d584d 100644 --- a/public/app/plugins/datasource/stackdriver/components/AnnotationQueryEditor.tsx +++ b/public/app/plugins/datasource/stackdriver/components/AnnotationQueryEditor.tsx @@ -109,7 +109,6 @@ export class AnnotationQueryEditor extends React.Component { - {/* */} ); } diff --git a/public/app/plugins/datasource/stackdriver/components/Metrics.tsx b/public/app/plugins/datasource/stackdriver/components/Metrics.tsx index 7d93e796384..4ea09245408 100644 --- a/public/app/plugins/datasource/stackdriver/components/Metrics.tsx +++ b/public/app/plugins/datasource/stackdriver/components/Metrics.tsx @@ -1,6 +1,7 @@ import React from 'react'; import _ from 'lodash'; +import appEvents from 'app/core/app_events'; import { MetricSelect } from 'app/core/components/Select/MetricSelect'; export interface Props { @@ -54,7 +55,7 @@ export class Metrics extends React.Component { } resolve(this.state.defaultProject); } catch (error) { - // appEvents.emit('ds-request-error', error); + appEvents.emit('ds-request-error', error); reject(); } }); diff --git a/public/app/plugins/datasource/stackdriver/components/Segment.tsx b/public/app/plugins/datasource/stackdriver/components/Segment.tsx deleted file mode 100644 index e330b1ab312..00000000000 --- a/public/app/plugins/datasource/stackdriver/components/Segment.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import React, { PureComponent } from 'react'; -import { getAngularLoader, AngularComponent } from 'app/core/services/AngularLoader'; -import 'app/core/directives/metric_segment'; - -interface QueryEditorProps { - segment: any; - getOptions: () => Promise; - onChange: (segment, index) => void; - key: number; -} - -export default class Segment extends PureComponent { - element: any; - component: AngularComponent; - - async componentDidMount() { - if (!this.element) { - return; - } - - const { segment, getOptions, onChange } = this.props; - const loader = getAngularLoader(); - const template = ' '; - - const scopeProps = { - segment, - onChange, - getOptions, - debounce: false, - }; - - this.component = loader.load(this.element, scopeProps, template); - } - - componentWillUnmount() { - if (this.component) { - this.component.destroy(); - } - } - - render() { - return
(this.element = element)} style={{ width: '100%' }} />; - } -} diff --git a/public/app/plugins/datasource/stackdriver/components/StackdriverPicker.tsx b/public/app/plugins/datasource/stackdriver/components/StackdriverPicker.tsx deleted file mode 100644 index 30c17e1f983..00000000000 --- a/public/app/plugins/datasource/stackdriver/components/StackdriverPicker.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import React from 'react'; -import _ from 'lodash'; -import Select from 'app/core/components/Select/Select'; - -export interface Props { - onChange: (value: string) => void; - options: any[]; - searchable: boolean; - selected: string; - placeholder?: string; - className?: string; - groupName?: string; - templateVariables?: any[]; -} - -interface State { - options: any[]; -} - -export class StackdriverPicker extends React.Component { - static defaultProps = { - templateVariables: [], - options: [], - groupName: 'Options', - }; - - constructor(props) { - super(props); - this.state = { options: [] }; - } - - componentDidMount() { - this.setState({ options: this.buildOptions(this.props) }); - } - - componentWillReceiveProps(nextProps: Props) { - if (nextProps.options.length > 0 || nextProps.templateVariables.length) { - this.setState({ options: this.buildOptions(nextProps) }); - } - } - - shouldComponentUpdate(nextProps: Props) { - const nextOptions = this.buildOptions(nextProps); - return nextProps.selected !== this.props.selected || !_.isEqual(nextOptions, this.state.options); - } - - buildOptions({ templateVariables = [], groupName = '', options }) { - return templateVariables.length > 0 - ? [ - this.getTemplateVariablesGroup(), - { - label: groupName, - expanded: true, - options, - }, - ] - : options; - } - - getTemplateVariablesGroup() { - return { - label: 'Template Variables', - options: this.props.templateVariables.map(v => ({ - label: `$${v.name}`, - value: `$${v.name}`, - })), - }; - } - - getSelectedOption() { - const { options } = this.state; - const allOptions = options.every(o => o.options) ? _.flatten(options.map(o => o.options)) : options; - return allOptions.find(option => option.value === this.props.selected); - } - - render() { - const { placeholder, className, searchable, onChange } = this.props; - const { options } = this.state; - const selectedOption = this.getSelectedOption(); - - return ( -