Azure Monitor: Use default from datasource if not saved on dashboard/query (#20899)

* use default from datasource if not saved on dash/query

* find datasource default workspace in returned workspace list

* don't need the find

* fix dropdown
This commit is contained in:
Shavonn Brown 2019-12-13 11:03:08 -05:00 committed by GitHub
parent c14398edc8
commit f65da93d72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -87,7 +87,11 @@ export default class AzureLogAnalyticsDatasource {
);
const generated = querystringBuilder.generate();
const workspace = this.templateSrv.replace(item.workspace, options.scopedVars);
let workspace = this.templateSrv.replace(item.workspace, options.scopedVars);
if (!workspace && this.defaultOrFirstWorkspace) {
workspace = this.defaultOrFirstWorkspace;
}
const url = `${this.baseUrl}/${workspace}/query?${generated.uriString}`;

View File

@ -118,7 +118,7 @@
<div class="gf-form">
<label class="gf-form-label query-keyword width-9">Workspace</label>
<gf-form-dropdown model="ctrl.target.azureLogAnalytics.workspace" allow-custom="true" lookup-text="true"
get-options="ctrl.workspaces" on-change="ctrl.refresh()" css-class="min-width-12">
get-options="ctrl.getWorkspaces()" on-change="ctrl.refresh()" css-class="min-width-12">
</gf-form-dropdown>
<div class="gf-form">
<div class="width-1"></div>

View File

@ -537,9 +537,18 @@ export class AzureMonitorQueryCtrl extends QueryCtrl {
.getWorkspaces(this.target.subscription)
.then((list: any[]) => {
this.workspaces = list;
if (list.length > 0 && !this.target.azureLogAnalytics.workspace) {
this.target.azureLogAnalytics.workspace = list[0].value;
if (this.datasource.azureLogAnalyticsDatasource.defaultOrFirstWorkspace) {
this.target.azureLogAnalytics.workspace = this.datasource.azureLogAnalyticsDatasource.defaultOrFirstWorkspace;
}
if (!this.target.azureLogAnalytics.workspace) {
this.target.azureLogAnalytics.workspace = list[0].value;
}
}
return this.workspaces;
})
.catch(this.handleQueryCtrlError.bind(this));
};