1
1
// Copyright (c) Microsoft Corporation. All rights reserved.
2
2
// Licensed under the MIT License.
3
3
'use strict' ;
4
+ import { isEmpty , isNil } from 'lodash' ;
4
5
import * as React from 'react' ;
6
+ import { IDataScienceExtraSettings } from '../../client/datascience/types' ;
5
7
import { Image , ImageName } from '../react-common/image' ;
6
8
import { getLocString } from '../react-common/locReactSide' ;
7
9
import { IFont , IServerState , ServerStatus } from './mainState' ;
@@ -14,6 +16,7 @@ export interface IJupyterInfoProps {
14
16
kernel : IServerState ;
15
17
isNotebookTrusted ?: boolean ;
16
18
shouldShowTrustMessage : boolean ;
19
+ settings ?: IDataScienceExtraSettings | undefined ;
17
20
selectServer ( ) : void ;
18
21
launchNotebookTrustPrompt ?( ) : void ; // Native editor-specific
19
22
selectKernel ( ) : void ;
@@ -33,10 +36,16 @@ export class JupyterInfo extends React.Component<IJupyterInfoProps> {
33
36
}
34
37
35
38
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
+
36
47
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
40
49
const displayNameTextSize = this . props . kernel . displayName . length + this . props . kernel . jupyterServerStatus . length ;
41
50
const dynamicFont : React . CSSProperties = {
42
51
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> {
54
63
< div className = "kernel-status" style = { dynamicFont } >
55
64
{ this . renderTrustMessage ( ) }
56
65
< 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 }
59
68
</ div >
60
69
< Image
61
70
baseTheme = { this . props . baseTheme }
@@ -120,4 +129,28 @@ export class JupyterInfo extends React.Component<IJupyterInfoProps> {
120
129
? getLocString ( 'DataScience.disconnected' , 'Disconnected' )
121
130
: getLocString ( 'DataScience.connected' , 'Connected' ) ;
122
131
}
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
+ / \/ p r o v i d e r s \/ M i c r o s o f t .M a c h i n e L e a r n i n g S e r v i c e s \/ w o r k s p a c e s \/ [ ^ \/ ] + \/ c o m p u t e s \/ ( [ ^ \/ ] + ) ( \/ ) ? /
149
+ ) ;
150
+ if ( isNil ( res ) || res . length < 2 ) {
151
+ return '' ;
152
+ }
153
+
154
+ return res [ 1 ] ;
155
+ }
123
156
}
0 commit comments