use listdatabases for sqlondemand (#10398)

* use listdatabases for sqlondemand

* comments

* use enum
This commit is contained in:
Alan Ren
2020-05-14 14:25:29 -07:00
committed by GitHub
parent 8f7861deac
commit f934dea6ea
2 changed files with 49 additions and 36 deletions

View File

@@ -478,17 +478,7 @@
{ {
"displayName": "%databasesListProperties.name%", "displayName": "%databasesListProperties.name%",
"value": "name", "value": "name",
"widthWeight": 60 "widthWeight": 100
},
{
"displayName": "%databasesListProperties.status%",
"value": "state",
"widthWeight": 20
},
{
"displayName": "%databasesListProperties.size%",
"value": "sizeInMB",
"widthWeight": 20
} }
] ]
} }

View File

@@ -26,6 +26,8 @@ import { ILogService } from 'vs/platform/log/common/log';
import { IEditorProgressService } from 'vs/platform/progress/common/progress'; import { IEditorProgressService } from 'vs/platform/progress/common/progress';
import { attachInputBoxStyler } from 'vs/platform/theme/common/styler'; import { attachInputBoxStyler } from 'vs/platform/theme/common/styler';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService'; import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { DatabaseEngineEdition } from 'sql/workbench/api/common/sqlExtHostTypes';
@Component({ @Component({
selector: 'explorer-widget', selector: 'explorer-widget',
@@ -51,6 +53,7 @@ export class ExplorerWidget extends DashboardWidget implements IDashboardWidget,
@Inject(IMenuService) private readonly menuService: IMenuService, @Inject(IMenuService) private readonly menuService: IMenuService,
@Inject(IContextKeyService) private readonly contextKeyService: IContextKeyService, @Inject(IContextKeyService) private readonly contextKeyService: IContextKeyService,
@Inject(IEditorProgressService) private readonly progressService: IEditorProgressService, @Inject(IEditorProgressService) private readonly progressService: IEditorProgressService,
@Inject(IConnectionManagementService) private readonly connectionManagementService: IConnectionManagementService,
@Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef @Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef
) { ) {
super(changeRef); super(changeRef);
@@ -95,7 +98,6 @@ export class ExplorerWidget extends DashboardWidget implements IDashboardWidget,
this._register(subscriptionToDisposable(this._bootstrap.metadataService.metadata.subscribe( this._register(subscriptionToDisposable(this._bootstrap.metadataService.metadata.subscribe(
data => { data => {
if (data) { if (data) {
const objectData = ObjectMetadataWrapper.createFromObjectMetadata(data.objectMetadata); const objectData = ObjectMetadataWrapper.createFromObjectMetadata(data.objectMetadata);
objectData.sort(ObjectMetadataWrapper.sort); objectData.sort(ObjectMetadataWrapper.sort);
this.updateTable(objectData); this.updateTable(objectData);
@@ -106,8 +108,35 @@ export class ExplorerWidget extends DashboardWidget implements IDashboardWidget,
} }
))); )));
} else { } else {
// TODO: remove this ADS side workaround for SQL On-Demand and handle it in SQL Tools Service
if (this._bootstrap.connectionManagementService.connectionInfo.serverInfo.engineEditionId === DatabaseEngineEdition.SqlOnDemand) {
this.connectionManagementService.listDatabases(this._bootstrap.connectionManagementService.connectionInfo.ownerUri).then(
result => {
// Sort the databases: system databases first and then the sorted list of other databases
const sysDatabases = ['master', 'model', 'msdb', 'tempdb'];
const databaseNames = result.databaseNames.filter(db => sysDatabases.indexOf(db) !== -1).
concat(result.databaseNames.filter(db => sysDatabases.indexOf(db) === -1).sort());
this.handleServerContextResults(databaseNames);
},
error => {
this.showErrorMessage(nls.localize('dashboard.explorer.databaseError', "Unable to load databases"));
}
);
}
else {
this._register(subscriptionToDisposable(this._bootstrap.metadataService.databases.subscribe( this._register(subscriptionToDisposable(this._bootstrap.metadataService.databases.subscribe(
data => { data => {
this.handleServerContextResults(data);
},
error => {
this.showErrorMessage(nls.localize('dashboard.explorer.databaseError', "Unable to load databases"));
}
)));
}
}
}
private handleServerContextResults(data: string[] | DatabaseInfo[]): void {
// Handle the case where there is no metadata service // Handle the case where there is no metadata service
data = data || []; data = data || [];
if (isStringArray(data)) { if (isStringArray(data)) {
@@ -126,12 +155,6 @@ export class ExplorerWidget extends DashboardWidget implements IDashboardWidget,
item[ConnectionProfilePropertyName] = profile; item[ConnectionProfilePropertyName] = profile;
return item; return item;
})); }));
},
error => {
this.showErrorMessage(nls.localize('dashboard.explorer.databaseError', "Unable to load databases"));
}
)));
}
} }
private updateTable(data: Slick.SlickData[]) { private updateTable(data: Slick.SlickData[]) {