Skip to content

Cherry pick history bug for Azure ML CI && Make Jupyter server clickable #13712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1 Enhancements/13656.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make Jupyter Server name clickable to select Jupyter server
1 change: 1 addition & 0 deletions news/2 Fixes/13387.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed connection to a Compute Instance from the quickpicks history options
10 changes: 6 additions & 4 deletions src/client/datascience/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,23 @@ const AllowedKeys = {
['execute_result']: new Set(Object.keys(dummyExecuteResultObj))
};

export function getSavedUriList(globalState: Memento): { uri: string; time: number }[] {
const uriList = globalState.get<{ uri: string; time: number }[]>(Settings.JupyterServerUriList);
export function getSavedUriList(globalState: Memento): { uri: string; time: number; displayName?: string }[] {
const uriList = globalState.get<{ uri: string; time: number; displayName?: string }[]>(
Settings.JupyterServerUriList
);
return uriList
? uriList.sort((a, b) => {
return b.time - a.time;
})
: [];
}
export function addToUriList(globalState: Memento, uri: string, time: number) {
export function addToUriList(globalState: Memento, uri: string, time: number, displayName: string) {
const uriList = getSavedUriList(globalState);

const editList = uriList.filter((f, i) => {
return f.uri !== uri && i < Settings.JupyterServerUriListMax - 1;
});
editList.splice(0, 0, { uri, time });
editList.splice(0, 0, { uri, time, displayName });

globalState.update(Settings.JupyterServerUriList, editList).then(noop, noop);
}
Expand Down
10 changes: 7 additions & 3 deletions src/client/datascience/interactive-common/interactiveBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { EXTENSION_ROOT_DIR, isTestExecution, PYTHON_LANGUAGE } from '../../comm
import { RemoveKernelToolbarInInteractiveWindow, RunByLine } from '../../common/experiments/groups';
import { traceError, traceInfo, traceWarning } from '../../common/logger';

import { isNil } from 'lodash';
import {
IConfigurationService,
IDisposableRegistry,
Expand Down Expand Up @@ -1162,10 +1163,13 @@ export abstract class InteractiveBase extends WebViewHost<IInteractiveWindowMapp
if (serverConnection.localLaunch) {
localizedUri = localize.DataScience.localJupyterServer();
} else {
localizedUri = serverConnection.displayName;

// Log this remote URI into our MRU list
addToUriList(this.globalStorage, localizedUri, Date.now());
addToUriList(
this.globalStorage,
!isNil(serverConnection.url) ? serverConnection.url : serverConnection.displayName,
Date.now(),
serverConnection.displayName
);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/client/datascience/jupyter/jupyterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function createRemoteConnectionInfo(
return { dispose: noop };
},
dispose: noop,
getAuthHeader: serverUri ? () => getJupyterServerUri(uri)?.authorizationHeader : undefined
getAuthHeader: serverUri ? () => getJupyterServerUri(uri)?.authorizationHeader : undefined,
url: uri
};
}
9 changes: 6 additions & 3 deletions src/client/datascience/jupyter/serverSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'use strict';

import { inject, injectable, named } from 'inversify';
import { isNil } from 'lodash';
import { ConfigurationTarget, Memento, QuickPickItem, Uri } from 'vscode';
import { IClipboard, ICommandManager } from '../../common/application/types';
import { GLOBAL_MEMENTO, IConfigurationService, IMemento } from '../../common/types';
Expand All @@ -26,6 +27,7 @@ const defaultUri = 'https://hostname:8080/?token=849d61a414abafab97bc4aab1f35477
interface ISelectUriQuickPickItem extends QuickPickItem {
newChoice: boolean;
provider?: IJupyterUriProvider;
url?: string;
}

@injectable()
Expand Down Expand Up @@ -66,7 +68,7 @@ export class JupyterServerSelector {
if (item.label === this.localLabel) {
await this.setJupyterURIToLocal();
} else if (!item.newChoice && !item.provider) {
await this.setJupyterURIToRemote(item.label);
await this.setJupyterURIToRemote(!isNil(item.url) ? item.url : item.label);
} else if (!item.provider) {
return this.selectRemoteURI.bind(this);
} else {
Expand Down Expand Up @@ -208,9 +210,10 @@ export class JupyterServerSelector {
if (uriItem.uri) {
const uriDate = new Date(uriItem.time);
items.push({
label: uriItem.uri,
label: !isNil(uriItem.displayName) ? uriItem.displayName : uriItem.uri,
detail: DataScience.jupyterSelectURIMRUDetail().format(uriDate.toLocaleString()),
newChoice: false
newChoice: false,
url: uriItem.uri
});
}
});
Expand Down
1 change: 1 addition & 0 deletions src/client/datascience/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface IJupyterConnection extends Disposable {
readonly token: string;
readonly hostName: string;
localProcExitCode: number | undefined;
readonly url?: string;
// tslint:disable-next-line: no-any
getAuthHeader?(): any; // Snould be a json object
}
Expand Down
16 changes: 14 additions & 2 deletions src/datascience-ui/interactive-common/jupyterInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class JupyterInfo extends React.Component<IJupyterInfoProps> {
constructor(prop: IJupyterInfoProps) {
super(prop);
this.selectKernel = this.selectKernel.bind(this);
this.selectServer = this.selectServer.bind(this);
}

public render() {
Expand All @@ -59,11 +60,18 @@ export class JupyterInfo extends React.Component<IJupyterInfoProps> {
maxWidth: getMaxWidth(displayNameTextSize)
};

const ariaDisabled = this.props.isNotebookTrusted === undefined ? false : this.props.isNotebookTrusted;
return (
<div className="kernel-status" style={dynamicFont}>
{this.renderTrustMessage()}
<div className="kernel-status-section kernel-status-server" style={serverTextWidth} role="button">
<div className="kernel-status-text" title={jupyterServerDisplayName}>
<div className="kernel-status-section kernel-status-server" style={serverTextWidth}>
<div
className="kernel-status-text kernel-status-section-hoverable"
style={serverTextWidth}
onClick={this.selectServer}
role="button"
aria-disabled={ariaDisabled}
>
{getLocString('DataScience.jupyterServer', 'Jupyter Server')}: {jupyterServerDisplayName}
</div>
<Image
Expand Down Expand Up @@ -153,4 +161,8 @@ export class JupyterInfo extends React.Component<IJupyterInfoProps> {

return res[1];
}

private selectServer(): void {
this.props.selectServer();
}
}
8 changes: 4 additions & 4 deletions src/test/datascience/jupyter/serverSelector.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,31 @@ suite('DataScience - Jupyter Server URI Selector', () => {

// Add in a new server
const serverA1 = { uri: 'ServerA', time: 1, date: new Date(1) };
addToUriList(mockStorage, serverA1.uri, serverA1.time);
addToUriList(mockStorage, serverA1.uri, serverA1.time, serverA1.uri);

await ds.selectJupyterURI(true);
assert.equal(quickPick?.items.length, 3, 'Wrong number of items in the quick pick');
quickPickCheck(quickPick?.items[2], serverA1);

// Add in a second server, the newer server should be higher in the list due to newer time
const serverB1 = { uri: 'ServerB', time: 2, date: new Date(2) };
addToUriList(mockStorage, serverB1.uri, serverB1.time);
addToUriList(mockStorage, serverB1.uri, serverB1.time, serverB1.uri);
await ds.selectJupyterURI(true);
assert.equal(quickPick?.items.length, 4, 'Wrong number of items in the quick pick');
quickPickCheck(quickPick?.items[2], serverB1);
quickPickCheck(quickPick?.items[3], serverA1);

// Reconnect to server A with a new time, it should now be higher in the list
const serverA3 = { uri: 'ServerA', time: 3, date: new Date(3) };
addToUriList(mockStorage, serverA3.uri, serverA3.time);
addToUriList(mockStorage, serverA3.uri, serverA3.time, serverA3.uri);
await ds.selectJupyterURI(true);
assert.equal(quickPick?.items.length, 4, 'Wrong number of items in the quick pick');
quickPickCheck(quickPick?.items[3], serverB1);
quickPickCheck(quickPick?.items[2], serverA1);

// Verify that we stick to our settings limit
for (let i = 0; i < Settings.JupyterServerUriListMax + 10; i = i + 1) {
addToUriList(mockStorage, i.toString(), i);
addToUriList(mockStorage, i.toString(), i, i.toString());
}

await ds.selectJupyterURI(true);
Expand Down