@@ -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 ;
@@ -526,6 +532,11 @@ export class Cluster extends OpenShiftItem {
526532 quickPick . onDidTriggerButton ( ( button ) => {
527533 if ( button === QuickInputButtons . Back ) {
528534 resolve ( undefined ) ;
535+ // } else if (button === enterBtn) {
536+ // await acceptInput();
537+ // } else if (button === cancelBtn) {
538+ // resolve(null);
539+ // input.dispose();
529540 }
530541 } ) ;
531542 quickPick . show ( ) ;
@@ -545,14 +556,15 @@ export class Cluster extends OpenShiftItem {
545556 input . value = initialValue ;
546557 input . prompt = prompt ;
547558 input . password = password ;
548- input . buttons = [ QuickInputButtons . Back ] ;
549- const validationMessage : string = validate ( input . value ) ;
559+ const enterBtn = new quickBtn ( new ThemeIcon ( 'check' ) , 'Enter' ) ;
560+ const cancelBtn = new quickBtn ( new ThemeIcon ( 'close' ) , 'Cancel' ) ;
561+ input . buttons = [ QuickInputButtons . Back , enterBtn , cancelBtn ] ;
562+ const validationMessage : string = validate ( input . value ? input . value : '' ) ;
550563 input . ignoreFocusOut = true ;
551564 if ( validationMessage ) {
552565 input . validationMessage = validationMessage ;
553566 }
554-
555- input . onDidAccept ( async ( ) => {
567+ const acceptInput = async ( ) => {
556568 const value = input . value ;
557569 input . enabled = false ;
558570 input . busy = true ;
@@ -562,21 +574,27 @@ export class Cluster extends OpenShiftItem {
562574 }
563575 input . enabled = true ;
564576 input . busy = false ;
565- } ) ;
577+ } ;
578+ input . onDidAccept ( acceptInput ) ;
566579 input . onDidChangeValue ( async text => {
567580 const current = validate ( text ) ;
568581 const validating = current ;
569582 const validationMessage = await current ;
570583 if ( current === validating ) {
571- input . validationMessage = validationMessage ;
584+ input . validationMessage = validationMessage ;
572585 }
573586 } ) ;
574587 input . onDidHide ( ( ) => {
575588 input . dispose ( ) ;
576589 } )
577- input . onDidTriggerButton ( ( event ) => {
590+ input . onDidTriggerButton ( async ( event ) => {
578591 if ( event === QuickInputButtons . Back ) {
579592 resolve ( undefined ) ;
593+ } else if ( event === enterBtn ) {
594+ await acceptInput ( ) ;
595+ } else if ( event === cancelBtn ) {
596+ resolve ( null ) ;
597+ input . dispose ( ) ;
580598 }
581599 } ) ;
582600 input . show ( ) ;
@@ -614,8 +632,7 @@ export class Cluster extends OpenShiftItem {
614632 if ( ! username ) {
615633 const addUserLabel = '$(plus) Add new user...' ;
616634 const choice = await this . getUserName ( clusterURL , addUserLabel ) ;
617- if ( ! choice || choice === null ) return choice ; // Back or Cancel
618-
635+ if ( ! choice ) return choice ; // Back or Cancel
619636 if ( choice === addUserLabel ) {
620637 step = Step . enterUserName ;
621638 } else {
@@ -629,11 +646,12 @@ export class Cluster extends OpenShiftItem {
629646 const prompt = 'Provide Username for basic authentication to the API server' ;
630647 const validateInput = ( value : string ) => NameValidator . emptyName ( 'User name cannot be empty' , value ) ;
631648 const newUsername = await this . enterValue ( prompt , '' , false , validateInput ) ;
632- if ( ! newUsername ) {
649+
650+ if ( newUsername === null ) {
651+ return null ; // Cancel
652+ } else if ( ! newUsername ) {
633653 username = undefined ;
634654 step = Step . getUserName ; // Back
635- } else if ( newUsername === null ) {
636- return null ; // Cancel
637655 } else {
638656 username = newUsername ;
639657 step = Step . enterPassword ;
@@ -646,11 +664,12 @@ export class Cluster extends OpenShiftItem {
646664 const prompt = 'Provide Password for basic authentication to the API server' ;
647665 const validateInput = ( value : string ) => NameValidator . emptyName ( 'Password cannot be empty' , value ) ;
648666 const newPassword = await this . enterValue ( prompt , password , true , validateInput ) ;
649- if ( ! newPassword ) {
667+
668+ if ( newPassword === null ) {
669+ return null ; // Cancel
670+ } else if ( ! newPassword ) {
650671 username = undefined ;
651672 step = Step . getUserName ; // Back
652- } else if ( newPassword === null ) {
653- return null ; // Cancel
654673 } else {
655674 passwd = newPassword ;
656675 step = undefined ;
@@ -743,10 +762,10 @@ export class Cluster extends OpenShiftItem {
743762 const validateInput = ( value : string ) => NameValidator . emptyName ( 'Bearer token cannot be empty' , value ) ;
744763 const initialValue = token ? token : '' ;
745764 ocToken = await this . enterValue ( prompt , initialValue , true , validateInput ) ;
746- if ( ! ocToken ) {
747- return undefined ; // Back
748- } else if ( ocToken === null ) {
765+ if ( ocToken === null ) {
749766 return null ; // Cancel
767+ } else if ( ! ocToken ) {
768+ return undefined ; // Back
750769 }
751770 } else {
752771 ocToken = userToken ;
0 commit comments