@@ -7,10 +7,11 @@ import * as vscode from 'vscode';
77import { vsCommand } from '../vscommand' ;
88import { createSandboxAPI , SBSignupResponse } from '../openshift/sandbox' ;
99import ClusterViewLoader from '../webview/cluster/clusterViewLoader' ;
10+ import path = require( 'path' ) ;
1011
1112const sandboxAPI = createSandboxAPI ( ) ;
1213
13- class RedHatCloudItem extends vscode . TreeItem {
14+ class RedHatCloudItem extends vscode . TreeItem {
1415
1516}
1617
@@ -23,7 +24,7 @@ class RedHatTreeDataProvier implements vscode.TreeDataProvider<RedHatCloudItem>
2324 }
2425
2526 getChildren ( element ?: RedHatCloudItem ) : vscode . ProviderResult < RedHatCloudItem [ ] > {
26- if ( ! element ) {
27+ if ( ! element ) {
2728 return this . getTopLevelItems ( ) ;
2829 }
2930 return [ ] ;
@@ -39,23 +40,17 @@ class RedHatTreeDataProvier implements vscode.TreeDataProvider<RedHatCloudItem>
3940
4041 private async getTopLevelItems ( ) : Promise < RedHatCloudItem [ ] > {
4142 const sessionCheck = await vscode . authentication . getSession ( 'redhat-account-auth' , [ 'openid' ] , { createIfNone : false } ) ;
42- if ( sessionCheck ) {
43- const sandboxItem = await this . buildSandboxItem ( ) ;
44- sandboxItem . iconPath
45- const openshiftLocal = new RedHatCloudItem ( 'OpenShift Local' ) ;
46- openshiftLocal . tooltip = 'OpenShift Local'
47- openshiftLocal . command = {
48- command :'openshift.local.open.setup' ,
49- title : 'Install OpenShift Local' ,
50- }
51- return [ sandboxItem , openshiftLocal ] ;
43+ if ( sessionCheck ) {
44+ const sandboxItem = await this . buildDevSandboxItem ( ) ;
45+ const openshiftLocalItem = this . buildOpenshiftLocalItem ( ) ;
46+ return [ sandboxItem , openshiftLocalItem ] ;
5247 }
5348 const loginItem = new RedHatCloudItem ( 'Sign in to Red Hat' ) ;
5449 loginItem . iconPath = new vscode . ThemeIcon ( 'account' ) ;
5550 loginItem . tooltip = 'Sign in to Red Hat' ;
5651 loginItem . command = {
57- command : 'cloud.redhat.login' ,
58- title : 'Sign in to Red Hat' ,
52+ command : 'cloud.redhat.login' ,
53+ title : 'Sign in to Red Hat' ,
5954 }
6055
6156 const signUpItem = new RedHatCloudItem ( 'Create Red Hat Account' ) ;
@@ -67,31 +62,45 @@ class RedHatTreeDataProvier implements vscode.TreeDataProvider<RedHatCloudItem>
6762 tooltip : 'Create Red Hat Account'
6863 }
6964 return [ loginItem , signUpItem ] ;
70-
7165 }
7266
73- private async buildSandboxItem ( ) {
74- const signupStatus = await RedHatTreeDataProvier . getSandboxSignupStatus ( )
67+ private async buildDevSandboxItem ( ) {
68+ const signupStatus = await RedHatTreeDataProvier . getSandboxSignupStatus ( ) ;
7569 const sandboxItem = new RedHatCloudItem ( 'Developer Sandbox' ) ;
76- sandboxItem . tooltip = 'Developer Sandbox'
77-
70+ sandboxItem . tooltip = 'Get 30-days free access to a shared OpenShift and Kubernetes cluster.' ;
71+ sandboxItem . iconPath = vscode . Uri . file ( path . join ( __dirname , '..' , '..' , '..' , 'images' , 'title' , 'logo.svg' ) ) ;
7872 if ( ! signupStatus ) {
7973 sandboxItem . contextValue = 'openshift.sandbox.status.none' ;
8074 }
8175 else if ( signupStatus . status . ready ) {
8276 sandboxItem . contextValue = 'openshift.sandbox.status.ready' ;
8377 }
78+ sandboxItem . command = {
79+ command : 'openshift.sandbox.open.setup' ,
80+ title : 'Set up Developer Sandbox' ,
81+ }
8482 return sandboxItem ;
8583 }
8684
85+ private buildOpenshiftLocalItem ( ) {
86+ const openshiftLocalItem = new RedHatCloudItem ( 'Openshift Local' ) ;
87+ openshiftLocalItem . tooltip = 'Provision OpenShift 4 cluster to your local computer.' ;
88+ openshiftLocalItem . iconPath = new vscode . ThemeIcon ( 'vm' ) ;
89+ openshiftLocalItem . command = {
90+ command : 'openshift.local.open.setup' ,
91+ title : 'Install OpenShift Local' ,
92+ }
93+ return openshiftLocalItem ;
94+ }
95+
8796 @vsCommand ( 'openshift.sandbox.signup' )
88- static async signupForSandbox ( ) : Promise < string > {
97+ static async signupForSandbox ( ) : Promise < string > {
8998 const authSession = await vscode . authentication . getSession ( 'redhat-account-auth' , [ 'openid' ] , { createIfNone : false } ) ;
90- if ( authSession ) {
99+ if ( authSession ) {
91100 // eslint-disable-next-line dot-notation
92101 const signupResponse = await sandboxAPI . signUp ( authSession [ 'idToken' ] as string ) ;
93- if ( ! signupResponse ) {
94- return 'Sign up request for OpenShift Sandbox failed, please try again.'
102+ if ( ! signupResponse ) {
103+ return 'Sign up request for OpenShift Sandbox failed, please try again.' ;
95104 }
96105 await RedHatTreeDataProvier . refreshView ( ) ;
97106
@@ -100,13 +109,20 @@ class RedHatTreeDataProvier implements vscode.TreeDataProvider<RedHatCloudItem>
100109
101110 @vsCommand ( 'openshift.local.open.setup' )
102111 static async openCrCWizard ( ) : Promise < void > {
103- await ClusterViewLoader . loadView ( 'Add OpenShift Cluster' , 'crc' ) ;
112+ const webViewPanel : vscode . WebviewPanel = await ClusterViewLoader . loadView ( 'Add OpenShift Cluster' ) ;
113+ await webViewPanel . webview . postMessage ( { action : 'openCluster' , param : 'crc' } ) ;
114+ }
115+
116+ @vsCommand ( 'openshift.sandbox.open.setup' )
117+ static async openSandboxWizard ( ) : Promise < void > {
118+ const webViewPanel : vscode . WebviewPanel = await ClusterViewLoader . loadView ( 'Add OpenShift Cluster' ) ;
119+ await webViewPanel . webview . postMessage ( { action : 'openCluster' , param : 'sandbox' } ) ;
104120 }
105121
106122 @vsCommand ( 'cloud.redhat.login' , false )
107123 static async loginToRedHatCloud ( ) : Promise < void > {
108- const session = await vscode . authentication . getSession ( 'redhat-account-auth' , [ 'openid' ] , { createIfNone : true } ) ;
109- if ( session ) {
124+ const session = await vscode . authentication . getSession ( 'redhat-account-auth' , [ 'openid' ] , { createIfNone : true } ) ;
125+ if ( session ) {
110126 await RedHatTreeDataProvier . refreshView ( ) ;
111127 }
112128 }
@@ -119,36 +135,33 @@ class RedHatTreeDataProvier implements vscode.TreeDataProvider<RedHatCloudItem>
119135 @vsCommand ( 'openshift.sandbox.open.dashboard' , false )
120136 static async openDashboard ( ) : Promise < void > {
121137 const sandboxStatus = await RedHatTreeDataProvier . getSandboxSignupStatus ( ) ;
122- if ( sandboxStatus )
123- {
138+ if ( sandboxStatus ) {
124139 return vscode . commands . executeCommand ( 'vscode.open' , sandboxStatus . consoleURL ) ;
125140 }
126141 }
127142
128- private static async getSandboxSignupStatus ( ) : Promise < SBSignupResponse | undefined > {
143+ private static async getSandboxSignupStatus ( ) : Promise < SBSignupResponse | undefined > {
129144 const authSession = await vscode . authentication . getSession ( 'redhat-account-auth' , [ 'openid' ] , { createIfNone : false } ) ;
130- if ( authSession ) {
145+ if ( authSession ) {
131146 // eslint-disable-next-line dot-notation
132147 return await sandboxAPI . getSignUpStatus ( authSession [ 'idToken' ] as string ) ;
133148 }
134- return undefined
149+ return undefined ;
135150 }
136151 private static async refreshView ( ) {
137152 const cloudExplorer = await k8s . extension . cloudExplorer . v1 ;
138153 if ( cloudExplorer . available ) {
139154 cloudExplorer . api . refresh ( ) ;
140155 }
141156 }
142-
143157}
144158
145159class RedHatCloudProvider implements k8s . CloudExplorerV1 . CloudProvider {
146160 getKubeconfigYaml ( cluster : any ) : Promise < string > {
147161 throw new Error ( 'Method not implemented.' ) ;
148162 }
149- readonly cloudName = 'Red Hat OpenShift'
163+ readonly cloudName = 'Red Hat OpenShift' ;
150164 readonly treeDataProvider = new RedHatTreeDataProvier ( ) ;
151-
152165}
153166
154167export const REDHAT_CLOUD_PROVIDER = new RedHatCloudProvider ( ) ;
0 commit comments