cleanup. remove comments, not used files etc

This commit is contained in:
Erik Sundell
2019-01-02 15:35:36 +01:00
parent 0e49225d1d
commit 1ab9fc871c
10 changed files with 25 additions and 180 deletions

View File

@@ -2,6 +2,7 @@ import { react2AngularDirective } from 'app/core/utils/react2angular';
import { QueryEditor } from './components/QueryEditor'; import { QueryEditor } from './components/QueryEditor';
import { AnnotationQueryEditor } from './components/AnnotationQueryEditor'; import { AnnotationQueryEditor } from './components/AnnotationQueryEditor';
//This should be removed when the plugin is fully reactified
export function registerAngularDirectives() { export function registerAngularDirectives() {
react2AngularDirective('queryEditor', QueryEditor, [ react2AngularDirective('queryEditor', QueryEditor, [
'target', 'target',

View File

@@ -1,6 +1,7 @@
import _ from 'lodash'; import _ from 'lodash';
import './query_filter_ctrl'; import './query_filter_ctrl';
import { registerAngularDirectives } from './angular_wrappers'; import { react2AngularDirective } from 'app/core/utils/react2angular';
import { AnnotationQueryEditor } from './components/AnnotationQueryEditor';
export class StackdriverAnnotationsQueryCtrl { export class StackdriverAnnotationsQueryCtrl {
static templateUrl = 'partials/annotations.editor.html'; static templateUrl = 'partials/annotations.editor.html';
@@ -28,8 +29,14 @@ export class StackdriverAnnotationsQueryCtrl {
this.annotation.target = this.annotation.target || {}; this.annotation.target = this.annotation.target || {};
this.annotation.target.refId = 'annotationQuery'; this.annotation.target.refId = 'annotationQuery';
_.defaultsDeep(this.annotation.target, this.defaults); _.defaultsDeep(this.annotation.target, this.defaults);
registerAngularDirectives();
this.handleQueryChange = this.handleQueryChange.bind(this); this.handleQueryChange = this.handleQueryChange.bind(this);
react2AngularDirective('annotationQueryEditor', AnnotationQueryEditor, [
'target',
'onQueryChange',
'onExecuteQuery',
['datasource', { watchDepth: 'reference' }],
]);
} }
handleQueryChange(target) { handleQueryChange(target) {

View File

@@ -1,8 +1,8 @@
import React from 'react'; import React from 'react';
import _ from 'lodash'; import _ from 'lodash';
import { getAggregationOptionsByMetric } from '../functions';
import { MetricSelect } from 'app/core/components/Select/MetricSelect'; import { MetricSelect } from 'app/core/components/Select/MetricSelect';
import { getAggregationOptionsByMetric } from '../functions';
export interface Props { export interface Props {
onChange: (metricDescriptor) => void; onChange: (metricDescriptor) => void;

View File

@@ -109,7 +109,6 @@ export class AnnotationQueryEditor extends React.Component<Props, State> {
</div> </div>
<AnnotationsHelp /> <AnnotationsHelp />
{/* <Help datasource={datasource} rawQuery={lastQuery} lastQueryError={lastQueryError} /> */}
</React.Fragment> </React.Fragment>
); );
} }

View File

@@ -1,6 +1,7 @@
import React from 'react'; import React from 'react';
import _ from 'lodash'; import _ from 'lodash';
import appEvents from 'app/core/app_events';
import { MetricSelect } from 'app/core/components/Select/MetricSelect'; import { MetricSelect } from 'app/core/components/Select/MetricSelect';
export interface Props { export interface Props {
@@ -54,7 +55,7 @@ export class Metrics extends React.Component<Props, State> {
} }
resolve(this.state.defaultProject); resolve(this.state.defaultProject);
} catch (error) { } catch (error) {
// appEvents.emit('ds-request-error', error); appEvents.emit('ds-request-error', error);
reject(); reject();
} }
}); });

View File

@@ -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<any[]>;
onChange: (segment, index) => void;
key: number;
}
export default class Segment extends PureComponent<QueryEditorProps, any> {
element: any;
component: AngularComponent;
async componentDidMount() {
if (!this.element) {
return;
}
const { segment, getOptions, onChange } = this.props;
const loader = getAngularLoader();
const template = '<metric-segment> </metric-segment>';
const scopeProps = {
segment,
onChange,
getOptions,
debounce: false,
};
this.component = loader.load(this.element, scopeProps, template);
}
componentWillUnmount() {
if (this.component) {
this.component.destroy();
}
}
render() {
return <div ref={element => (this.element = element)} style={{ width: '100%' }} />;
}
}

View File

@@ -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<Props, State> {
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 (
<Select
className={className}
isMulti={false}
isClearable={false}
backspaceRemovesValue={false}
onChange={item => onChange(item.value)}
options={options}
isSearchable={searchable}
maxMenuHeight={500}
placeholder={placeholder}
noOptionsMessage={() => 'No options found'}
value={selectedOption}
/>
);
}
}

View File

@@ -1,5 +1,5 @@
<annotation-query-editor <annotation-query-editor
target="ctrl.annotation.target" target="ctrl.annotation.target"
datasource="ctrl.datasource"
on-query-change="(ctrl.handleQueryChange)" on-query-change="(ctrl.handleQueryChange)"
datasource="ctrl.datasource"
></annotation-query-editor> ></annotation-query-editor>

View File

@@ -1,33 +1,3 @@
<!--
<div class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label width-9 query-keyword">Service</span>
<stackdriver-picker
onChange="ctrl.handleServiceChange"
selected="ctrl.target.service"
options="ctrl.services"
searchable="false"
placeholder="'Select Services'"
className="'width-15'"
></stackdriver-picker>
</div>
<div class="gf-form gf-form--grow"><div class="gf-form-label gf-form-label--grow"></div></div>
</div>
<div class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label width-9 query-keyword">Metric</span>
<stackdriver-picker
onChange="ctrl.handleMetricTypeChange"
selected="ctrl.target.metricType"
options="ctrl.getMetricsList()"
template-variables="ctrl.templateSrv.variables"
group-name="'Metric Types'"
searchable="true"
placeholder="'Select Metric'"
className="'width-15'"
></stackdriver-picker>
</div>
-->
<div class="gf-form-inline"> <div class="gf-form-inline">
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label query-keyword width-9">Filter</span> <span class="gf-form-label query-keyword width-9">Filter</span>

View File

@@ -1,7 +1,9 @@
import _ from 'lodash'; import _ from 'lodash';
import { QueryCtrl } from 'app/plugins/sdk'; import { QueryCtrl } from 'app/plugins/sdk';
import './query_filter_ctrl'; import { react2AngularDirective } from 'app/core/utils/react2angular';
import { registerAngularDirectives } from './angular_wrappers';
import { QueryEditor } from './components/QueryEditor';
import { Target } from './types'; import { Target } from './types';
export class StackdriverQueryCtrl extends QueryCtrl { export class StackdriverQueryCtrl extends QueryCtrl {
@@ -10,9 +12,15 @@ export class StackdriverQueryCtrl extends QueryCtrl {
/** @ngInject */ /** @ngInject */
constructor($scope, $injector) { constructor($scope, $injector) {
super($scope, $injector); super($scope, $injector);
registerAngularDirectives();
this.handleQueryChange = this.handleQueryChange.bind(this); this.handleQueryChange = this.handleQueryChange.bind(this);
this.handleExecuteQuery = this.handleExecuteQuery.bind(this); this.handleExecuteQuery = this.handleExecuteQuery.bind(this);
react2AngularDirective('queryEditor', QueryEditor, [
'target',
'onQueryChange',
'onExecuteQuery',
['events', { watchDepth: 'reference' }],
['datasource', { watchDepth: 'reference' }],
]);
} }
handleQueryChange(target: Target) { handleQueryChange(target: Target) {