@@ -90,12 +90,19 @@ export default class OpenShiftItem {
9090 }
9191
9292 static async getApplicationNames ( project : OpenShiftObject , createCommand = false ) : Promise < Array < OpenShiftObject | QuickPickCommand > > {
93- return OpenShiftItem . odo . getApplications ( project ) . then ( ( applicationList ) => {
94- if ( applicationList . length === 0 && ! createCommand ) throw new VsCommandError ( errorMessage . Component ) ;
95- return createCommand ? [ new QuickPickCommand ( '$(plus) Create new Application...' , async ( ) => {
96- return OpenShiftItem . getName ( 'Application name' , Promise . resolve ( applicationList ) ) ;
97- } ) , ...applicationList ] : applicationList ;
98- } ) ;
93+ if ( project . getParent ( ) ) {
94+ return OpenShiftItem . odo . getApplications ( project ) . then ( ( applicationList ) => {
95+ if ( applicationList . length === 0 && ! createCommand ) throw new VsCommandError ( errorMessage . Component ) ;
96+ return createCommand ? [ new QuickPickCommand ( '$(plus) Create new Application...' , async ( ) => {
97+ return OpenShiftItem . getName ( 'Application name' , Promise . resolve ( applicationList ) ) ;
98+ } ) , ...applicationList ] : applicationList ;
99+ } ) ;
100+ }
101+ return [
102+ new QuickPickCommand ( '$(plus) Create new Application...' , async ( ) => {
103+ return OpenShiftItem . getName ( 'Application name' , Promise . resolve ( [ ] ) ) ;
104+ } )
105+ ] ;
99106 }
100107
101108 static async getComponentNames ( application : OpenShiftObject , condition ?: ( value : OpenShiftObject ) => boolean ) : Promise < OpenShiftObject [ ] > {
@@ -126,12 +133,23 @@ export default class OpenShiftItem {
126133 let context : OpenShiftObject | QuickPickCommand = treeItem ;
127134 let project : OpenShiftObject ;
128135 if ( ! context ) {
129- context = ( await this . odo . getProjects ( ) ) . find ( ( prj :OpenShiftProject ) => prj . active ) ;
130- if ( ! context ) {
131- throw new VsCommandError ( errorMessage . Project ) ;
136+ const clusters = await this . odo . getClusters ( ) ;
137+ if ( clusters . length ) { // connected to cluster because odo version printed out server url
138+ const projects = await this . odo . getProjects ( ) ;
139+ context = projects . find ( ( prj :OpenShiftProject ) => prj . active ) ;
140+ if ( ! context ) {
141+ throw new VsCommandError ( errorMessage . Project )
142+ }
143+ } else { // cluster is not accessible or user not logged in
144+ const projectName = await OpenShiftItem . getName ( 'Project Name' , Promise . resolve ( [ ] ) )
145+ if ( projectName ) {
146+ context = new OpenShiftProject ( undefined , projectName , true ) ;
147+ } else {
148+ context = null ;
149+ }
132150 }
133151 }
134- if ( context && context . contextValue === ContextType . PROJECT && appPlaceholder ) {
152+ if ( context && ! isCommand ( context ) && context . contextValue === ContextType . PROJECT && appPlaceholder ) {
135153 project = context ;
136154 const applicationList = await OpenShiftItem . getApplicationNames ( project , appPlaceholder . includes ( 'create' ) && compPlaceholder === undefined ) ;
137155 if ( applicationList . length === 1 && isCommand ( applicationList [ 0 ] ) ) {
0 commit comments