@@ -232,10 +232,10 @@ export class Cluster extends OpenShiftItem {
232232 const prompt = 'Provide new Cluster URL to connect' ;
233233 const validateInput = ( value : string ) => NameValidator . validateUrl ( 'Invalid URL provided' , value ) ;
234234 const newURL = await this . enterValue ( prompt , '' , false , validateInput ) ;
235- if ( ! newURL ) {
236- resolve ( await Cluster . showQuickPick ( clusterURl ) ) ; // Back
237- } else if ( newURL === null ) {
235+ if ( newURL === null ) {
238236 return null ; // Cancel
237+ } else if ( ! newURL ) {
238+ resolve ( await Cluster . showQuickPick ( clusterURl ) ) ; // Back
239239 } else {
240240 resolve ( newURL ) ;
241241 }
@@ -395,8 +395,13 @@ export class Cluster extends OpenShiftItem {
395395 // so it's running
396396 clusterIsUp = true ;
397397 } catch ( e ) {
398- const clusterURLObj = new URL ( clusterURL ) ;
399- if ( clusterURLObj . hostname === 'api.crc.testing' ) {
398+ let clusterURLObj : any = undefined ;
399+ try {
400+ clusterURLObj = new URL ( clusterURL ) ;
401+ } catch ( _ ) {
402+ // Ignore
403+ }
404+ if ( clusterURLObj && clusterURLObj . hostname === 'api.crc.testing' ) {
400405 const startCrc = 'Start OpenShift Local' ;
401406 const promptResponse = await window . showWarningMessage (
402407 'The cluster appears to be a OpenShift Local cluster, but it isn\'t running' ,
@@ -409,7 +414,7 @@ export class Cluster extends OpenShiftItem {
409414 // it will take the cluster a few minutes to stabilize
410415 return null ;
411416 }
412- } else if ( / a p i \. s a n d b o x - .* o p e n s h i f t a p p s \. c o m / . test ( clusterURLObj . hostname ) ) {
417+ } else if ( clusterURLObj && / a p i \. s a n d b o x - .* o p e n s h i f t a p p s \. c o m / . test ( clusterURLObj . hostname ) ) {
413418 const devSandboxSignup = 'Sign up for OpenShift Dev Sandbox' ;
414419 const promptResponse = await window . showWarningMessage (
415420 'The cluster appears to be a OpenShift Dev Sandbox cluster, but it isn\'t running' ,
@@ -435,10 +440,10 @@ export class Cluster extends OpenShiftItem {
435440 }
436441 case Step . selectLoginMethod : {
437442 const result = await Cluster . getLoginMethod ( ) ;
438- if ( ! result ) { // Back Button is hit
439- step = Step . selectCluster ;
440- } if ( result === null ) { // User cancelled the operation
443+ if ( result == null ) { // User cancelled the operation
441444 return null ;
445+ } else if ( ! result ) { // Back button is hit
446+ step = Step . selectCluster ;
442447 } else if ( result === 'Credentials' ) {
443448 step = Step . loginUsingCredentials ;
444449 } else if ( result === 'Token' ) {
@@ -451,10 +456,11 @@ export class Cluster extends OpenShiftItem {
451456 const clusterVersions : string = step === Step . loginUsingCredentials
452457 ? await Cluster . credentialsLogin ( true , clusterURL )
453458 : await Cluster . tokenLogin ( clusterURL , true ) ;
454- if ( ! clusterVersions ) { // Back Button is hit
455- step = Step . selectLoginMethod ;
456- } else if ( clusterVersions === null ) { // User cancelled the operation
459+
460+ if ( clusterVersions === null ) { // User cancelled the operation
457461 return null ;
462+ } else if ( ! clusterVersions ) { // Back button is hit
463+ step = Step . selectLoginMethod ;
458464 } else {
459465 // login successful
460466 return null ;
@@ -545,14 +551,15 @@ export class Cluster extends OpenShiftItem {
545551 input . value = initialValue ;
546552 input . prompt = prompt ;
547553 input . password = password ;
548- input . buttons = [ QuickInputButtons . Back ] ;
549- const validationMessage : string = validate ( input . value ) ;
554+ const enterBtn = new quickBtn ( new ThemeIcon ( 'check' ) , 'Enter' ) ;
555+ const cancelBtn = new quickBtn ( new ThemeIcon ( 'close' ) , 'Cancel' ) ;
556+ input . buttons = [ QuickInputButtons . Back , enterBtn , cancelBtn ] ;
557+ const validationMessage : string = validate ( input . value ? input . value : '' ) ;
550558 input . ignoreFocusOut = true ;
551559 if ( validationMessage ) {
552560 input . validationMessage = validationMessage ;
553561 }
554-
555- input . onDidAccept ( async ( ) => {
562+ const acceptInput = async ( ) => {
556563 const value = input . value ;
557564 input . enabled = false ;
558565 input . busy = true ;
@@ -562,21 +569,27 @@ export class Cluster extends OpenShiftItem {
562569 }
563570 input . enabled = true ;
564571 input . busy = false ;
565- } ) ;
572+ } ;
573+ input . onDidAccept ( acceptInput ) ;
566574 input . onDidChangeValue ( async text => {
567575 const current = validate ( text ) ;
568576 const validating = current ;
569577 const validationMessage = await current ;
570578 if ( current === validating ) {
571- input . validationMessage = validationMessage ;
579+ input . validationMessage = validationMessage ;
572580 }
573581 } ) ;
574582 input . onDidHide ( ( ) => {
575583 input . dispose ( ) ;
576584 } )
577- input . onDidTriggerButton ( ( event ) => {
585+ input . onDidTriggerButton ( async ( event ) => {
578586 if ( event === QuickInputButtons . Back ) {
579587 resolve ( undefined ) ;
588+ } else if ( event === enterBtn ) {
589+ await acceptInput ( ) ;
590+ } else if ( event === cancelBtn ) {
591+ resolve ( null ) ;
592+ input . dispose ( ) ;
580593 }
581594 } ) ;
582595 input . show ( ) ;
@@ -614,8 +627,7 @@ export class Cluster extends OpenShiftItem {
614627 if ( ! username ) {
615628 const addUserLabel = '$(plus) Add new user...' ;
616629 const choice = await this . getUserName ( clusterURL , addUserLabel ) ;
617- if ( ! choice || choice === null ) return choice ; // Back or Cancel
618-
630+ if ( ! choice ) return choice ; // Back or Cancel
619631 if ( choice === addUserLabel ) {
620632 step = Step . enterUserName ;
621633 } else {
@@ -629,11 +641,12 @@ export class Cluster extends OpenShiftItem {
629641 const prompt = 'Provide Username for basic authentication to the API server' ;
630642 const validateInput = ( value : string ) => NameValidator . emptyName ( 'User name cannot be empty' , value ) ;
631643 const newUsername = await this . enterValue ( prompt , '' , false , validateInput ) ;
632- if ( ! newUsername ) {
644+
645+ if ( newUsername === null ) {
646+ return null ; // Cancel
647+ } else if ( ! newUsername ) {
633648 username = undefined ;
634649 step = Step . getUserName ; // Back
635- } else if ( newUsername === null ) {
636- return null ; // Cancel
637650 } else {
638651 username = newUsername ;
639652 step = Step . enterPassword ;
@@ -646,11 +659,12 @@ export class Cluster extends OpenShiftItem {
646659 const prompt = 'Provide Password for basic authentication to the API server' ;
647660 const validateInput = ( value : string ) => NameValidator . emptyName ( 'Password cannot be empty' , value ) ;
648661 const newPassword = await this . enterValue ( prompt , password , true , validateInput ) ;
649- if ( ! newPassword ) {
662+
663+ if ( newPassword === null ) {
664+ return null ; // Cancel
665+ } else if ( ! newPassword ) {
650666 username = undefined ;
651667 step = Step . getUserName ; // Back
652- } else if ( newPassword === null ) {
653- return null ; // Cancel
654668 } else {
655669 passwd = newPassword ;
656670 step = undefined ;
@@ -743,10 +757,10 @@ export class Cluster extends OpenShiftItem {
743757 const validateInput = ( value : string ) => NameValidator . emptyName ( 'Bearer token cannot be empty' , value ) ;
744758 const initialValue = token ? token : '' ;
745759 ocToken = await this . enterValue ( prompt , initialValue , true , validateInput ) ;
746- if ( ! ocToken ) {
747- return undefined ; // Back
748- } else if ( ocToken === null ) {
760+ if ( ocToken === null ) {
749761 return null ; // Cancel
762+ } else if ( ! ocToken ) {
763+ return undefined ; // Back
750764 }
751765 } else {
752766 ocToken = userToken ;
0 commit comments