Isolate more features (#6854)

* working; new query and scripting

* working; removing manage from menus and combining data explorer contributions

* consolidate dashboard contributions; move manage action to dashboard contributions; make groupings the same

* fix notebook actions not firing

* fix notebook actions

* notebooks working

* move backup and restore entry points into their own file; move explorerwidget contribution into their respective files

* fix tests

* move extension actions to their own file

* fix tests

* change tests
This commit is contained in:
Anthony Dresser
2019-08-22 16:54:30 -07:00
committed by GitHub
parent 36244ed517
commit 82a8f09709
19 changed files with 616 additions and 589 deletions

View File

@@ -0,0 +1,80 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
import { ConnectedContext } from 'azdata';
import { TreeViewItemHandleArg } from 'sql/workbench/common/views';
import { BackupAction } from 'sql/workbench/parts/backup/browser/backupActions';
import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions';
import { ManageActionContext } from 'sql/workbench/common/actions';
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
import { ItemContextKey } from 'sql/workbench/parts/dashboard/browser/widgets/explorer/explorerTreeContext';
import { MssqlNodeContext } from 'sql/workbench/parts/dataExplorer/common/mssqlNodeContext';
import { NodeType } from 'sql/workbench/parts/objectExplorer/common/nodeType';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { localize } from 'vs/nls';
import { ObjectExplorerActionsContext } from 'sql/workbench/parts/objectExplorer/browser/objectExplorerActions';
import { TreeNodeContextKey } from 'sql/workbench/parts/objectExplorer/common/treeNodeContextKey';
import { ConnectionContextKey } from 'sql/workbench/parts/connection/common/connectionContextKey';
import { ServerInfoContextKey } from 'sql/workbench/parts/connection/common/serverInfoContextKey';
new BackupAction().registerTask();
// data explorer
const DE_BACKUP_COMMAND_ID = 'dataExplorer.backup';
CommandsRegistry.registerCommand({
id: DE_BACKUP_COMMAND_ID,
handler: (accessor, args: TreeViewItemHandleArg) => {
const commandService = accessor.get(ICommandService);
return commandService.executeCommand(BackupAction.ID, args.$treeItem.payload);
}
});
MenuRegistry.appendMenuItem(MenuId.DataExplorerContext, {
group: 'connection',
order: 4,
command: {
id: DE_BACKUP_COMMAND_ID,
title: localize('backup', "Backup")
},
when: ContextKeyExpr.and(MssqlNodeContext.NodeProvider.isEqualTo(mssqlProviderName),
MssqlNodeContext.NodeType.isEqualTo(NodeType.Database), MssqlNodeContext.IsCloud.toNegated())
});
// oe
const OE_BACKUP_COMMAND_ID = 'objectExplorer.backup';
CommandsRegistry.registerCommand({
id: OE_BACKUP_COMMAND_ID,
handler: (accessor, args: ObjectExplorerActionsContext) => {
const commandService = accessor.get(ICommandService);
return commandService.executeCommand(BackupAction.ID, args.connectionProfile);
}
});
MenuRegistry.appendMenuItem(MenuId.ObjectExplorerItemContext, {
group: 'connection',
order: 4,
command: {
id: OE_BACKUP_COMMAND_ID,
title: localize('backup', "Backup")
},
when: ContextKeyExpr.and(TreeNodeContextKey.NodeType.isEqualTo(NodeType.Database), ConnectionContextKey.Provider.isEqualTo(mssqlProviderName), ServerInfoContextKey.IsCloud.toNegated())
});
// dashboard explorer
const ExplorerBackUpActionID = 'explorer.backup';
CommandsRegistry.registerCommand(ExplorerBackUpActionID, (accessor, context: ManageActionContext) => {
const commandService = accessor.get(ICommandService);
return commandService.executeCommand(BackupAction.ID, context.profile);
});
MenuRegistry.appendMenuItem(MenuId.ExplorerWidgetContext, {
command: {
id: ExplorerBackUpActionID,
title: BackupAction.LABEL
},
when: ContextKeyExpr.and(ItemContextKey.ItemType.isEqualTo('database'), ItemContextKey.ConnectionProvider.isEqualTo('mssql'), ItemContextKey.IsCloud.toNegated()),
order: 2
});

View File

@@ -0,0 +1,70 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { localize } from 'vs/nls';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/common/objectExplorerService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { getCurrentGlobalConnection } from 'sql/workbench/browser/taskUtilities';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
import { IBackupUiService } from 'sql/workbench/services/backup/common/backupUiService';
import { Task } from 'sql/platform/tasks/browser/tasksRegistry';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
export const BackupFeatureName = 'backup';
export function showBackup(accessor: ServicesAccessor, connection: IConnectionProfile): Promise<void> {
const backupUiService = accessor.get(IBackupUiService);
return backupUiService.showBackup(connection).then();
}
export class BackupAction extends Task {
public static readonly ID = BackupFeatureName;
public static readonly LABEL = localize('backupAction.backup', "Backup");
public static readonly ICON = BackupFeatureName;
constructor() {
super({
id: BackupAction.ID,
title: BackupAction.LABEL,
iconPath: undefined,
iconClass: BackupAction.ICON
});
}
runTask(accessor: ServicesAccessor, profile: IConnectionProfile): void | Promise<void> {
const configurationService = accessor.get<IConfigurationService>(IConfigurationService);
const previewFeaturesEnabled: boolean = configurationService.getValue('workbench')['enablePreviewFeatures'];
if (!previewFeaturesEnabled) {
return accessor.get<INotificationService>(INotificationService).info(localize('backup.isPreviewFeature', "You must enable preview features in order to use backup"));
}
const connectionManagementService = accessor.get<IConnectionManagementService>(IConnectionManagementService);
if (!profile) {
const objectExplorerService = accessor.get<IObjectExplorerService>(IObjectExplorerService);
const workbenchEditorService = accessor.get<IEditorService>(IEditorService);
profile = getCurrentGlobalConnection(objectExplorerService, connectionManagementService, workbenchEditorService);
}
if (profile) {
const serverInfo = connectionManagementService.getServerInfo(profile.id);
if (serverInfo && serverInfo.isCloud && profile.providerName === mssqlProviderName) {
return accessor.get<INotificationService>(INotificationService).info(localize('backup.commandNotSupported', "Backup command is not supported for Azure SQL databases."));
}
if (!profile.databaseName && profile.providerName === mssqlProviderName) {
return accessor.get<INotificationService>(INotificationService).info(localize('backup.commandNotSupportedForServer', "Backup command is not supported in Server Context. Please select a Database and try again."));
}
}
const capabilitiesService = accessor.get(ICapabilitiesService);
const instantiationService = accessor.get(IInstantiationService);
return instantiationService.invokeFunction(showBackup, new ConnectionProfile(capabilitiesService, profile));
}
}