stackdriver: use new naming convention for query editor all over

This commit is contained in:
Erik Sundell 2018-11-13 10:57:10 +01:00
parent 30f9a324ac
commit e698202fae
15 changed files with 51 additions and 34 deletions

View File

@ -249,7 +249,7 @@ signout_redirect_url =
#################################### Anonymous Auth ###################### #################################### Anonymous Auth ######################
[auth.anonymous] [auth.anonymous]
# enable anonymous access # enable anonymous access
enabled = false enabled = true
# specify organization name that should be used for unauthenticated users # specify organization name that should be used for unauthenticated users
org_name = Main Org. org_name = Main Org.

View File

@ -14,3 +14,4 @@ exports[`PickerOption renders correctly 1`] = `
</div> </div>
</div> </div>
`; `;

View File

@ -2,19 +2,19 @@ import coreModule from 'app/core/core_module';
import { importPluginModule } from './plugin_loader'; import { importPluginModule } from './plugin_loader';
import React from 'react'; import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import DefaultTemplateQueryComponent from '../templating/DefaultTemplateQueryComponent'; import DefaultVariableQueryEditor from '../templating/DefaultVariableQueryEditor';
async function loadComponent(module) { async function loadComponent(module) {
const component = await importPluginModule(module); const component = await importPluginModule(module);
if (component && component.TemplateQueryComponent) { if (component && component.VariableQueryEditor) {
return component.TemplateQueryComponent; return component.VariableQueryEditor;
} else { } else {
return DefaultTemplateQueryComponent; return DefaultVariableQueryEditor;
} }
} }
/** @ngInject */ /** @ngInject */
function templateQueryComponentLoader() { function variableQueryEditorLoader() {
return { return {
restrict: 'E', restrict: 'E',
link: async (scope, elem) => { link: async (scope, elem) => {
@ -32,4 +32,4 @@ function templateQueryComponentLoader() {
}; };
} }
coreModule.directive('templateQueryComponentLoader', templateQueryComponentLoader); coreModule.directive('variableQueryEditorLoader', variableQueryEditorLoader);

View File

@ -4,4 +4,4 @@ import './import_list/import_list';
import './ds_edit_ctrl'; import './ds_edit_ctrl';
import './datasource_srv'; import './datasource_srv';
import './plugin_component'; import './plugin_component';
import './TemplateQueryComponentLoader'; import './VariableQueryComponentLoader';

View File

@ -1,7 +1,7 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { TemplateQueryProps } from 'app/types/plugins'; import { VariableQueryProps } from 'app/types/plugins';
export default class DefaultTemplateQueryComponent extends PureComponent<TemplateQueryProps, any> { export default class DefaultVariableQueryEditor extends PureComponent<VariableQueryProps, any> {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { value: props.query }; this.state = { value: props.query };

View File

@ -200,8 +200,8 @@
</div> </div>
<rebuild-on-change property="currentDatasource"> <rebuild-on-change property="currentDatasource">
<template-query-component-loader> <variable-query-editor-loader>
</template-query-component-loader> </variable-query-editor-loader>
</rebuild-on-change> </rebuild-on-change>
<div class="gf-form"> <div class="gf-form">

View File

@ -1,14 +1,14 @@
import React from 'react'; import React from 'react';
import renderer from 'react-test-renderer'; import renderer from 'react-test-renderer';
import { StackdriverTemplateQueryComponent } from './TemplateQueryComponent'; import { StackdriverVariableQueryEditor } from './VariableQueryEditor';
import { TemplateQueryProps } from 'app/types/plugins'; import { VariableQueryProps } from 'app/types/plugins';
import { MetricFindQueryTypes } from '../types'; import { MetricFindQueryTypes } from '../types';
jest.mock('../functions', () => ({ jest.mock('../functions', () => ({
getMetricTypes: () => ({ metricTypes: [], selectedMetricType: '' }), getMetricTypes: () => ({ metricTypes: [], selectedMetricType: '' }),
})); }));
const props: TemplateQueryProps = { const props: VariableQueryProps = {
onChange: (query, definition) => {}, onChange: (query, definition) => {},
query: {}, query: {},
datasource: { datasource: {
@ -16,9 +16,9 @@ const props: TemplateQueryProps = {
}, },
}; };
describe('StackdriverTemplateQueryComponent', () => { describe('VariableQueryEditor', () => {
it('renders correctly', () => { it('renders correctly', () => {
const tree = renderer.create(<StackdriverTemplateQueryComponent {...props} />).toJSON(); const tree = renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
expect(tree).toMatchSnapshot(); expect(tree).toMatchSnapshot();
}); });
@ -28,7 +28,7 @@ describe('StackdriverTemplateQueryComponent', () => {
expect(definition).toBe('Stackdriver - Metric Types'); expect(definition).toBe('Stackdriver - Metric Types');
done(); done();
}; };
renderer.create(<StackdriverTemplateQueryComponent {...props} />).toJSON(); renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
}); });
}); });
@ -39,7 +39,7 @@ describe('StackdriverTemplateQueryComponent', () => {
expect(definition).toBe('Stackdriver - Metric Labels'); expect(definition).toBe('Stackdriver - Metric Labels');
done(); done();
}; };
renderer.create(<StackdriverTemplateQueryComponent {...props} />).toJSON(); renderer.create(<StackdriverVariableQueryEditor {...props} />).toJSON();
}); });
}); });
}); });

View File

@ -1,11 +1,11 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import uniqBy from 'lodash/uniqBy'; import uniqBy from 'lodash/uniqBy';
import { TemplateQueryProps } from 'app/types/plugins'; import { VariableQueryProps } from 'app/types/plugins';
import SimpleSelect from './SimpleSelect'; import SimpleSelect from './SimpleSelect';
import { getMetricTypes } from '../functions'; import { getMetricTypes } from '../functions';
import { MetricFindQueryTypes, TemplateQueryComponentData } from '../types'; import { MetricFindQueryTypes, VariableQueryData } from '../types';
export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQueryProps, TemplateQueryComponentData> { export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryProps, VariableQueryData> {
queryTypes: Array<{ value: string; name: string }> = [ queryTypes: Array<{ value: string; name: string }> = [
{ value: MetricFindQueryTypes.MetricTypes, name: 'Metric Types' }, { value: MetricFindQueryTypes.MetricTypes, name: 'Metric Types' },
{ value: MetricFindQueryTypes.MetricLabels, name: 'Metric Labels' }, { value: MetricFindQueryTypes.MetricLabels, name: 'Metric Labels' },
@ -16,7 +16,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
{ value: MetricFindQueryTypes.AlignmentPeriods, name: 'Alignment Periods' }, { value: MetricFindQueryTypes.AlignmentPeriods, name: 'Alignment Periods' },
]; ];
defaults: TemplateQueryComponentData = { defaults: VariableQueryData = {
selectedQueryType: this.queryTypes[0].value, selectedQueryType: this.queryTypes[0].value,
metricDescriptors: [], metricDescriptors: [],
selectedService: '', selectedService: '',
@ -27,7 +27,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
services: [], services: [],
}; };
constructor(props: TemplateQueryProps) { constructor(props: VariableQueryProps) {
super(props); super(props);
this.handleQueryTypeChange = this.handleQueryTypeChange.bind(this); this.handleQueryTypeChange = this.handleQueryTypeChange.bind(this);
this.onServiceChange = this.onServiceChange.bind(this); this.onServiceChange = this.onServiceChange.bind(this);
@ -111,7 +111,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
async getLabels(selectedMetricType, selectedQueryType = this.state.selectedQueryType) { async getLabels(selectedMetricType, selectedQueryType = this.state.selectedQueryType) {
let result = { labels: this.state.labels, labelKey: this.state.labelKey }; let result = { labels: this.state.labels, labelKey: this.state.labelKey };
if (selectedMetricType && this.isLabelQuery(selectedQueryType)) { if (selectedMetricType && this.isLabelQuery(selectedQueryType)) {
const refId = 'StackdriverTemplateQueryComponent'; const refId = 'StackdriverVariableQueryEditor';
const response = await this.props.datasource.getLabels(selectedMetricType, refId); const response = await this.props.datasource.getLabels(selectedMetricType, refId);
const labels = Object.keys(response.meta[selectedQueryType]); const labels = Object.keys(response.meta[selectedQueryType]);
const labelKey = labels.some(l => l === this.state.labelKey) ? this.state.labelKey : labels[0]; const labelKey = labels.some(l => l === this.state.labelKey) ? this.state.labelKey : labels[0];

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`StackdriverTemplateQueryComponent renders correctly 1`] = ` exports[`VariableQueryEditor renders correctly 1`] = `
Array [ Array [
<div <div
className="gf-form max-width-21" className="gf-form max-width-21"

View File

@ -111,6 +111,11 @@ export default class StackdriverDatasource {
return unit; return unit;
} }
async getProjects() {
const response = await this.doRequest(`/cloudresourcemanager/v1/projects`);
return response.data.projects.map(p => ({ value: p.projectId, name: p.name }));
}
async query(options) { async query(options) {
const result = []; const result = [];
const data = await this.getTimeSeries(options); const data = await this.getTimeSeries(options);

View File

@ -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 { StackdriverTemplateQueryComponent } from './components/TemplateQueryComponent'; import { StackdriverVariableQueryEditor } from './components/VariableQueryEditor';
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,
StackdriverTemplateQueryComponent as TemplateQueryComponent, StackdriverVariableQueryEditor as VariableQueryEditor,
}; };

View File

@ -13,9 +13,14 @@
</div> </div>
</div> </div>
<div class="gf-form-inline"> <div class="gf-form-inline">
<div class="gf-form"> <!-- <div class="gf-form">
<span class="gf-form-label width-9">Project</span> <span class="gf-form-label width-9">Project</span>
<input class="gf-form-input" disabled type="text" ng-model='ctrl.target.defaultProject' css-class="min-width-12" /> <input class="gf-form-input" disabled type="text" ng-model='ctrl.target.defaultProject' css-class="min-width-12" />
</div> -->
<div class="gf-form">
<span class="gf-form-label width-9">Project</span>
<gf-form-dropdown class="gf-form-input" type="text" ng-model='ctrl.target.defaultProject' get-options="ctrl.projects"
css-class="min-width-12"></gf-form-dropdown>
</div> </div>
<div class="gf-form"> <div class="gf-form">
<label class="gf-form-label query-keyword" ng-click="ctrl.showHelp = !ctrl.showHelp"> <label class="gf-form-label query-keyword" ng-click="ctrl.showHelp = !ctrl.showHelp">
@ -70,4 +75,4 @@
<div class="gf-form" ng-show="ctrl.lastQueryError"> <div class="gf-form" ng-show="ctrl.lastQueryError">
<pre class="gf-form-pre alert alert-error">{{ctrl.lastQueryError}}</pre> <pre class="gf-form-pre alert alert-error">{{ctrl.lastQueryError}}</pre>
</div> </div>
</query-editor-row> </query-editor-row>

View File

@ -52,6 +52,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
metricKind: '', metricKind: '',
valueType: '', valueType: '',
}; };
projects: any;
showHelp: boolean; showHelp: boolean;
showLastQuery: boolean; showLastQuery: boolean;
@ -62,11 +63,16 @@ export class StackdriverQueryCtrl extends QueryCtrl {
constructor($scope, $injector) { constructor($scope, $injector) {
super($scope, $injector); super($scope, $injector);
_.defaultsDeep(this.target, this.defaults); _.defaultsDeep(this.target, this.defaults);
this.setProjects($scope.ctrl.datasource);
this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope); this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope); this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
} }
async setProjects(ds) {
this.projects = await ds.getProjects();
console.log(this.projects);
}
onDataReceived(dataList) { onDataReceived(dataList) {
this.lastQueryError = null; this.lastQueryError = null;
this.lastQueryMeta = null; this.lastQueryMeta = null;

View File

@ -8,7 +8,7 @@ export enum MetricFindQueryTypes {
AlignmentPeriods = 'alignmentPeriods', AlignmentPeriods = 'alignmentPeriods',
} }
export interface TemplateQueryComponentData { export interface VariableQueryData {
selectedQueryType: string; selectedQueryType: string;
metricDescriptors: any[]; metricDescriptors: any[];
selectedService: string; selectedService: string;

View File

@ -6,7 +6,7 @@ export interface PluginExports {
QueryCtrl?: any; QueryCtrl?: any;
ConfigCtrl?: any; ConfigCtrl?: any;
AnnotationsQueryCtrl?: any; AnnotationsQueryCtrl?: any;
TemplateQueryComponent?: any; VariableQueryEditor?: any;
ExploreQueryField?: any; ExploreQueryField?: any;
ExploreStartPage?: any; ExploreStartPage?: any;
@ -100,7 +100,7 @@ export interface PluginsState {
dashboards: PluginDashboard[]; dashboards: PluginDashboard[];
} }
export interface TemplateQueryProps { export interface VariableQueryProps {
query: any; query: any;
onChange: (query: any, definition: string) => void; onChange: (query: any, definition: string) => void;
datasource: any; datasource: any;