Skip to content
This repository was archived by the owner on Dec 11, 2022. It is now read-only.

Commit 51b8e59

Browse files
committed
Fixes #51
1 parent 9d5d655 commit 51b8e59

File tree

4 files changed

+65
-34
lines changed

4 files changed

+65
-34
lines changed

dist/module.js

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34079,6 +34079,7 @@ function () {
3407934079
key: "gce",
3408034080
value: "GCE Default Service Account"
3408134081
}];
34082+
console.log("current", this.current);
3408234083
}
3408334084

3408434085
BigQueryConfigCtrl.prototype.onUpload = function (json) {
@@ -34201,6 +34202,8 @@ var BigQueryDatasource =
3420134202
function () {
3420234203
/** @ngInject */
3420334204
function BigQueryDatasource(instanceSettings, backendSrv, $q, templateSrv) {
34205+
var _this = this;
34206+
3420434207
this.backendSrv = backendSrv;
3420534208
this.$q = $q;
3420634209
this.templateSrv = templateSrv;
@@ -34234,7 +34237,11 @@ function () {
3423434237
this.url = instanceSettings.url;
3423534238
this.interval = (instanceSettings.jsonData || {}).timeInterval || "1m";
3423634239
this.authenticationType = instanceSettings.jsonData.authenticationType || "jwt";
34237-
this.projectName = instanceSettings.jsonData.defaultProject || this.getDefaultProject();
34240+
var prj = "";
34241+
this.getDefaultProject().then(function (res) {
34242+
prj = res;
34243+
_this.projectName = instanceSettings.jsonData.defaultProject || prj;
34244+
});
3423834245
}
3423934246

3424034247
BigQueryDatasource.formatBigqueryError = function (error) {
@@ -34340,7 +34347,7 @@ function () {
3434034347

3434134348
BigQueryDatasource.prototype.testDatasource = function () {
3434234349
return tslib_1.__awaiter(this, void 0, void 0, function () {
34343-
var status, message, defaultErrorMessage, projectName, path, response, error_1;
34350+
var status, message, defaultErrorMessage, path, response, error_1;
3434434351
return tslib_1.__generator(this, function (_a) {
3434534352
switch (_a.label) {
3434634353
case 0:
@@ -34352,8 +34359,7 @@ function () {
3435234359
case 1:
3435334360
_a.trys.push([1, 3,, 4]);
3435434361

34355-
projectName = this.getDefaultProject();
34356-
path = "v2/projects/" + projectName + "/datasets";
34362+
path = "v2/projects/" + this.projectName + "/datasets";
3435734363
return [4
3435834364
/*yield*/
3435934365
, this.doRequest("" + this.baseUrl + path)];
@@ -34474,24 +34480,51 @@ function () {
3447434480
};
3447534481

3447634482
BigQueryDatasource.prototype.getDefaultProject = function () {
34477-
var _this = this;
34483+
return tslib_1.__awaiter(this, void 0, void 0, function () {
34484+
var data, error_2;
34485+
return tslib_1.__generator(this, function (_a) {
34486+
switch (_a.label) {
34487+
case 0:
34488+
_a.trys.push([0, 4,, 5]);
3447834489

34479-
try {
34480-
if (this.authenticationType === "gce" || !this.projectName) {
34481-
var data_1;
34482-
this.getProjects().then(function (results) {
34483-
data_1 = results;
34484-
}).catch(function (err) {
34485-
return _this.projectName = "";
34486-
});
34487-
this.projectName = data_1[0].value;
34488-
return this.projectName;
34489-
} else {
34490-
return this.projectName;
34491-
}
34492-
} catch (error) {
34493-
return this.projectName = "";
34494-
}
34490+
if (!(this.authenticationType === "gce" || !this.projectName)) return [3
34491+
/*break*/
34492+
, 2];
34493+
data = void 0;
34494+
return [4
34495+
/*yield*/
34496+
, this.getProjects()];
34497+
34498+
case 1:
34499+
data = _a.sent();
34500+
this.projectName = data[0].value;
34501+
return [2
34502+
/*return*/
34503+
, this.projectName];
34504+
34505+
case 2:
34506+
return [2
34507+
/*return*/
34508+
, this.projectName];
34509+
34510+
case 3:
34511+
return [3
34512+
/*break*/
34513+
, 5];
34514+
34515+
case 4:
34516+
error_2 = _a.sent();
34517+
return [2
34518+
/*return*/
34519+
, this.projectName = ""];
34520+
34521+
case 5:
34522+
return [2
34523+
/*return*/
34524+
];
34525+
}
34526+
});
34527+
});
3449534528
};
3449634529

3449734530
BigQueryDatasource.prototype.annotationQuery = function (options) {

dist/module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config_ctrl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class BigQueryConfigCtrl {
2525
{ key: this.defaultAuthenticationType, value: "Google JWT File" },
2626
{ key: "gce", value: "GCE Default Service Account" }
2727
];
28+
console.log("current", this.current)
2829
}
2930

3031
public onUpload(json) {

src/datasource.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import _ from "lodash";
22
import BigQueryQuery from "./bigquery_query";
33
import ResponseParser, { IResultFormat } from "./response_parser";
4+
import {countBy} from "lodash-es";
45

56
function sleep(ms) {
67
return new Promise(resolve => {
@@ -68,8 +69,11 @@ export class BigQueryDatasource {
6869
this.interval = (instanceSettings.jsonData || {}).timeInterval || "1m";
6970
this.authenticationType =
7071
instanceSettings.jsonData.authenticationType || "jwt";
71-
this.projectName =
72-
instanceSettings.jsonData.defaultProject || this.getDefaultProject();
72+
let prj = "";
73+
this.getDefaultProject().then(res => {
74+
prj = res;
75+
this.projectName = instanceSettings.jsonData.defaultProject || prj;
76+
});
7377
}
7478

7579
public async query(options) {
@@ -126,8 +130,7 @@ export class BigQueryDatasource {
126130
let message = "Successfully queried the BigQuery API.";
127131
const defaultErrorMessage = "Cannot connect to BigQuery API";
128132
try {
129-
const projectName = this.getDefaultProject();
130-
const path = `v2/projects/${projectName}/datasets`;
133+
const path = `v2/projects/${this.projectName}/datasets`;
131134
const response = await this.doRequest(`${this.baseUrl}${path}`);
132135
if (response.status !== 200) {
133136
status = "error";
@@ -176,17 +179,11 @@ export class BigQueryDatasource {
176179
return ResponseParser.parseTableFields(data, filter);
177180
}
178181

179-
public getDefaultProject() {
182+
public async getDefaultProject() {
180183
try {
181184
if (this.authenticationType === "gce" || !this.projectName) {
182185
let data;
183-
this.getProjects()
184-
.then(results => {
185-
data = results;
186-
})
187-
.catch(err => {
188-
return (this.projectName = "");
189-
});
186+
data = await this.getProjects();
190187
this.projectName = data[0].value;
191188
return this.projectName;
192189
} else {

0 commit comments

Comments
 (0)