Skip to content

Commit 99bbff4

Browse files
authored
Show the server display string that the user is going to connect to after selecting a compute instance and reloading the window. (#13600)
1 parent 2a58d26 commit 99bbff4

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

news/2 Fixes/13551.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Show the server display string that the user is going to connect to after selecting a compute instance and reloading the window.

src/datascience-ui/history-react/interactivePanel.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ ${buildSettingsCss(this.props.settings)}`}</style>
237237
selectServer={this.props.selectServer}
238238
selectKernel={this.props.selectKernel}
239239
shouldShowTrustMessage={false}
240+
settings={this.props.settings}
240241
/>
241242
);
242243
} else if (this.props.kernel.localizedUri === getLocString('DataScience.localJupyterServer', 'local')) {
@@ -252,6 +253,7 @@ ${buildSettingsCss(this.props.settings)}`}</style>
252253
selectServer={this.props.selectServer}
253254
selectKernel={this.props.selectKernel}
254255
shouldShowTrustMessage={false}
256+
settings={this.props.settings}
255257
/>
256258
);
257259
}

src/datascience-ui/interactive-common/jupyterInfo.tsx

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33
'use strict';
4+
import { isEmpty, isNil } from 'lodash';
45
import * as React from 'react';
6+
import { IDataScienceExtraSettings } from '../../client/datascience/types';
57
import { Image, ImageName } from '../react-common/image';
68
import { getLocString } from '../react-common/locReactSide';
79
import { IFont, IServerState, ServerStatus } from './mainState';
@@ -14,6 +16,7 @@ export interface IJupyterInfoProps {
1416
kernel: IServerState;
1517
isNotebookTrusted?: boolean;
1618
shouldShowTrustMessage: boolean;
19+
settings?: IDataScienceExtraSettings | undefined;
1720
selectServer(): void;
1821
launchNotebookTrustPrompt?(): void; // Native editor-specific
1922
selectKernel(): void;
@@ -33,10 +36,16 @@ export class JupyterInfo extends React.Component<IJupyterInfoProps> {
3336
}
3437

3538
public render() {
39+
let jupyterServerDisplayName: string = this.props.kernel.localizedUri;
40+
if (!isNil(this.props.settings) && isEmpty(jupyterServerDisplayName)) {
41+
const jupyterServerUriSetting: string = this.props.settings.jupyterServerURI;
42+
if (!isEmpty(jupyterServerUriSetting) && this.isUriOfComputeInstance(jupyterServerUriSetting)) {
43+
jupyterServerDisplayName = this.getComputeInstanceNameFromId(jupyterServerUriSetting);
44+
}
45+
}
46+
3647
const serverTextSize =
37-
getLocString('DataScience.jupyterServer', 'Jupyter Server').length +
38-
this.props.kernel.localizedUri.length +
39-
4; // plus 4 for the icon
48+
getLocString('DataScience.jupyterServer', 'Jupyter Server').length + jupyterServerDisplayName.length + 4; // plus 4 for the icon
4049
const displayNameTextSize = this.props.kernel.displayName.length + this.props.kernel.jupyterServerStatus.length;
4150
const dynamicFont: React.CSSProperties = {
4251
fontSize: 'var(--vscode-font-size)', // Use the same font and size as the menu
@@ -54,8 +63,8 @@ export class JupyterInfo extends React.Component<IJupyterInfoProps> {
5463
<div className="kernel-status" style={dynamicFont}>
5564
{this.renderTrustMessage()}
5665
<div className="kernel-status-section kernel-status-server" style={serverTextWidth} role="button">
57-
<div className="kernel-status-text" title={this.props.kernel.localizedUri}>
58-
{getLocString('DataScience.jupyterServer', 'Jupyter Server')}: {this.props.kernel.localizedUri}
66+
<div className="kernel-status-text" title={jupyterServerDisplayName}>
67+
{getLocString('DataScience.jupyterServer', 'Jupyter Server')}: {jupyterServerDisplayName}
5968
</div>
6069
<Image
6170
baseTheme={this.props.baseTheme}
@@ -120,4 +129,28 @@ export class JupyterInfo extends React.Component<IJupyterInfoProps> {
120129
? getLocString('DataScience.disconnected', 'Disconnected')
121130
: getLocString('DataScience.connected', 'Connected');
122131
}
132+
133+
private isUriOfComputeInstance(uri: string): boolean {
134+
try {
135+
const parsedUrl: URL = new URL(uri);
136+
return parsedUrl.searchParams.get('id') === 'azureml_compute_instances';
137+
} catch (e) {
138+
return false;
139+
}
140+
}
141+
142+
private getComputeInstanceNameFromId(id: string | undefined): string {
143+
if (isNil(id)) {
144+
return '';
145+
}
146+
147+
const res: string[] | null = id.match(
148+
/\/providers\/Microsoft.MachineLearningServices\/workspaces\/[^\/]+\/computes\/([^\/]+)(\/)?/
149+
);
150+
if (isNil(res) || res.length < 2) {
151+
return '';
152+
}
153+
154+
return res[1];
155+
}
123156
}

src/datascience-ui/native-editor/toolbar.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import * as React from 'react';
55
import { connect } from 'react-redux';
66
import { NativeMouseCommandTelemetry } from '../../client/datascience/constants';
7+
import { IDataScienceExtraSettings } from '../../client/datascience/types';
78
import { JupyterInfo } from '../interactive-common/jupyterInfo';
89
import {
910
getSelectedAndFocusedInfo,
@@ -28,6 +29,7 @@ type INativeEditorDataProps = {
2829
kernel: IServerState;
2930
selectionFocusedInfo: SelectionAndFocusedInfo;
3031
variablesVisible: boolean;
32+
settings?: IDataScienceExtraSettings;
3133
};
3234
export type INativeEditorToolbarProps = INativeEditorDataProps & {
3335
sendCommand: typeof actionCreators.sendCommand;
@@ -266,6 +268,7 @@ export class Toolbar extends React.PureComponent<INativeEditorToolbarProps> {
266268
shouldShowTrustMessage={true}
267269
isNotebookTrusted={this.props.isNotebookTrusted}
268270
launchNotebookTrustPrompt={launchNotebookTrustPrompt}
271+
settings={this.props.settings}
269272
/>
270273
</div>
271274
<div className="toolbar-divider" />

0 commit comments

Comments
 (0)