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,34 +108,55 @@ export class ExplorerWidget extends DashboardWidget implements IDashboardWidget,
} }
))); )));
} else { } else {
this._register(subscriptionToDisposable(this._bootstrap.metadataService.databases.subscribe( // TODO: remove this ADS side workaround for SQL On-Demand and handle it in SQL Tools Service
data => { if (this._bootstrap.connectionManagementService.connectionInfo.serverInfo.engineEditionId === DatabaseEngineEdition.SqlOnDemand) {
// Handle the case where there is no metadata service this.connectionManagementService.listDatabases(this._bootstrap.connectionManagementService.connectionInfo.ownerUri).then(
data = data || []; result => {
if (isStringArray(data)) { // Sort the databases: system databases first and then the sorted list of other databases
data = data.map(item => { const sysDatabases = ['master', 'model', 'msdb', 'tempdb'];
const dbInfo: DatabaseInfo = { options: {} }; const databaseNames = result.databaseNames.filter(db => sysDatabases.indexOf(db) !== -1).
dbInfo.options[NameProperty] = item; concat(result.databaseNames.filter(db => sysDatabases.indexOf(db) === -1).sort());
return dbInfo; this.handleServerContextResults(databaseNames);
}); },
error => {
this.showErrorMessage(nls.localize('dashboard.explorer.databaseError', "Unable to load databases"));
} }
);
const currentProfile = this._bootstrap.connectionManagementService.connectionInfo.connectionProfile; }
this.updateTable(data.map(d => { else {
const item = assign({}, d.options); this._register(subscriptionToDisposable(this._bootstrap.metadataService.databases.subscribe(
const profile = currentProfile.toIConnectionProfile(); data => {
profile.databaseName = d.options[NameProperty]; this.handleServerContextResults(data);
item[ConnectionProfilePropertyName] = profile; },
return item; error => {
})); this.showErrorMessage(nls.localize('dashboard.explorer.databaseError', "Unable to load databases"));
}, }
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
data = data || [];
if (isStringArray(data)) {
data = data.map(item => {
const dbInfo: DatabaseInfo = { options: {} };
dbInfo.options[NameProperty] = item;
return dbInfo;
});
}
const currentProfile = this._bootstrap.connectionManagementService.connectionInfo.connectionProfile;
this.updateTable(data.map(d => {
const item = assign({}, d.options);
const profile = currentProfile.toIConnectionProfile();
profile.databaseName = d.options[NameProperty];
item[ConnectionProfilePropertyName] = profile;
return item;
}));
}
private updateTable(data: Slick.SlickData[]) { private updateTable(data: Slick.SlickData[]) {
this._table.setData(data); this._table.setData(data);
this.setLoadingStatus(false); this.setLoadingStatus(false);