diff --git a/src/sql/workbench/parts/notebook/browser/notebook.contribution.ts b/src/sql/workbench/parts/notebook/browser/notebook.contribution.ts index 78376bd1bf..d38d1bfddc 100644 --- a/src/sql/workbench/parts/notebook/browser/notebook.contribution.ts +++ b/src/sql/workbench/parts/notebook/browser/notebook.contribution.ts @@ -70,7 +70,7 @@ CommandsRegistry.registerCommand({ handler: (accessor, args: TreeViewItemHandleArg) => { const instantiationService = accessor.get(IInstantiationService); const connectedContext: ConnectedContext = { connectionProfile: args.$treeItem.payload }; - return instantiationService.createInstance(NewNotebookAction, NewNotebookAction.ID, NewNotebookAction.LABEL).run(connectedContext); + return instantiationService.createInstance(NewNotebookAction, NewNotebookAction.ID, NewNotebookAction.LABEL).run({ connectionProfile: connectedContext.connectionProfile, isConnectionNode: false, nodeInfo: undefined }); } }); @@ -91,10 +91,9 @@ const OE_NEW_NOTEBOOK_COMMAND_ID = 'objectExplorer.newNotebook'; // New Notebook CommandsRegistry.registerCommand({ id: OE_NEW_NOTEBOOK_COMMAND_ID, - handler: (accessor, args: ObjectExplorerActionsContext) => { + handler: (accessor, actionContext: ObjectExplorerActionsContext) => { const instantiationService = accessor.get(IInstantiationService); - const connectedContext: ConnectedContext = { connectionProfile: args.connectionProfile }; - return instantiationService.createInstance(NewNotebookAction, NewNotebookAction.ID, NewNotebookAction.LABEL).run(connectedContext); + return instantiationService.createInstance(NewNotebookAction, NewNotebookAction.ID, NewNotebookAction.LABEL).run(actionContext); } }); @@ -112,7 +111,7 @@ const ExplorerNotebookActionID = 'explorer.notebook'; CommandsRegistry.registerCommand(ExplorerNotebookActionID, (accessor, context: ManageActionContext) => { const instantiationService = accessor.get(IInstantiationService); const connectedContext: ConnectedContext = { connectionProfile: context.profile }; - instantiationService.createInstance(NewNotebookAction, NewNotebookAction.ID, NewNotebookAction.LABEL).run(connectedContext); + instantiationService.createInstance(NewNotebookAction, NewNotebookAction.ID, NewNotebookAction.LABEL).run({ connectionProfile: connectedContext.connectionProfile, isConnectionNode: false, nodeInfo: undefined }); }); MenuRegistry.appendMenuItem(MenuId.ExplorerWidgetContext, { diff --git a/src/sql/workbench/parts/notebook/browser/notebookActions.ts b/src/sql/workbench/parts/notebook/browser/notebookActions.ts index 962d9711f2..115bdd3610 100644 --- a/src/sql/workbench/parts/notebook/browser/notebookActions.ts +++ b/src/sql/workbench/parts/notebook/browser/notebookActions.ts @@ -25,6 +25,8 @@ import { CellType } from 'sql/workbench/parts/notebook/common/models/contracts'; import { NotebookComponent } from 'sql/workbench/parts/notebook/browser/notebook.component'; import { getErrorMessage } from 'vs/base/common/errors'; import { INotebookModel } from 'sql/workbench/parts/notebook/browser/models/modelInterfaces'; +import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService'; +import { TreeUpdateUtils } from 'sql/workbench/parts/objectExplorer/browser/treeUpdateUtils'; const msgLoading = localize('loading', "Loading kernels..."); const msgChanging = localize('changing', "Changing kernel..."); @@ -591,14 +593,22 @@ export class NewNotebookAction extends Action { constructor( id: string, label: string, - @ICommandService private commandService: ICommandService + @ICommandService private commandService: ICommandService, + @IObjectExplorerService private objectExplorerService: IObjectExplorerService ) { super(id, label); this.class = 'notebook-action new-notebook'; } - run(context?: azdata.ConnectedContext): Promise { - return this.commandService.executeCommand(NewNotebookAction.INTERNAL_NEW_NOTEBOOK_CMD_ID, context); + async run(context?: azdata.ObjectExplorerContext): Promise { + let connProfile: azdata.IConnectionProfile; + if (context && context.nodeInfo) { + let node = await this.objectExplorerService.getTreeNode(context.connectionProfile.id, context.nodeInfo.nodePath); + connProfile = TreeUpdateUtils.getConnectionProfile(node).toIConnectionProfile(); + } else if (context && context.connectionProfile) { + connProfile = context.connectionProfile; + } + return this.commandService.executeCommand(NewNotebookAction.INTERNAL_NEW_NOTEBOOK_CMD_ID, { connectionProfile: connProfile }); } }