@@ -15,15 +15,20 @@ export const useUsernameField = (isEditField, fields, connections, hasSelectedCo
1515 const type = isEditField ? 'edit' : 'create' ;
1616 const selectedConnection = _ . find ( connections , ( conn ) => conn . name === hasSelectedConnection ) ;
1717 const requireUsername = selectedConnection && selectedConnection . options ? selectedConnection . options . requires_username : false ;
18- const noUsername = ! requireUsername && ( ! initialValues || ! initialValues . username ) ;
18+ const noUsername = connections . length > 0
19+ ? ! requireUsername && ( ! initialValues || ! initialValues . username )
20+ // if we have no connections, we *might* need a username field, we don't know -
21+ // because we don't have the connections to check
22+ : false ;
1923
2024 const defaults = {
2125 property : 'username' ,
2226 label : 'Username' ,
2327 disable : noUsername ,
2428 [ type ] : {
2529 type : 'text' ,
26- required : true
30+ // if we have no connections we should show the field but not require it
31+ required : connections . length > 0
2732 }
2833 } ;
2934
@@ -57,18 +62,22 @@ export const useMembershipsField = (isEditField, fields, hasMembership, membersh
5762
5863export const useConnectionsField = ( isEditField , fields , connections , onConnectionChange ) => {
5964 const type = isEditField ? 'edit' : 'create' ;
60- if ( ! connections || connections . length <= 1 ) {
65+ // if we have exactly one connection then don't show this field and use that connection
66+ // however if we have zero connections, we should show the free text connections field
67+ if ( ! connections || connections . length === 1 ) {
6168 return _ . remove ( fields , { property : 'connection' } ) ;
6269 }
6370
71+ const isConnectionLimitExceeded = connections . length === 0 ;
72+
6473 const defaults = {
6574 property : 'connection' ,
66- label : 'Connection' ,
75+ label : isConnectionLimitExceeded ? 'Connection Name' : 'Connection' ,
6776 [ type ] : {
6877 required : true ,
69- type : 'select' ,
70- component : 'InputCombo' ,
71- options : connections . map ( conn => ( { value : conn . name , label : conn . name } ) ) ,
78+ type : isConnectionLimitExceeded ? 'text' : 'select' ,
79+ component : isConnectionLimitExceeded ? 'InputText' : 'InputCombo' ,
80+ options : isConnectionLimitExceeded ? undefined : connections . map ( conn => ( { value : conn . name , label : conn . name } ) ) ,
7281 onChange : onConnectionChange
7382 }
7483 } ;
0 commit comments