Skip to content

Commit 1eaf9e4

Browse files
Add url param to preselect in connect frame (#1755)
* Add url param to preselect in connect frame * Reset connecting state on failed connection
1 parent cacb60f commit 1eaf9e4

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/browser/modules/Stream/Auth/ConnectForm.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ interface ConnectFormProps {
7171
SSOProviders: SSOProvider[]
7272
SSOLoading?: boolean
7373
onSSOProviderClicked: () => void
74+
connecting: boolean
75+
setIsConnecting: (c: boolean) => void
7476
}
7577

7678
export default function ConnectForm(props: ConnectFormProps): JSX.Element {
77-
const [connecting, setConnecting] = useState(false)
7879
const [scheme, setScheme] = useState(
7980
props.allowedSchemes ? `${getScheme(props.host)}://` : ''
8081
)
@@ -113,8 +114,8 @@ export default function ConnectForm(props: ConnectFormProps): JSX.Element {
113114

114115
const onConnectClick = (e: React.FormEvent<HTMLFormElement>) => {
115116
e.preventDefault()
116-
setConnecting(true)
117-
props.onConnectClick(() => setConnecting(false))
117+
props.setIsConnecting(true)
118+
props.onConnectClick(() => props.setIsConnecting(false))
118119
}
119120

120121
const hasSecureSchemes = ['neo4j+s', 'bolt+s'].every(scheme =>
@@ -268,7 +269,7 @@ export default function ConnectForm(props: ConnectFormProps): JSX.Element {
268269
</StyledSSOError>
269270
)}
270271

271-
{connecting
272+
{props.connecting
272273
? 'Connecting...'
273274
: props.authenticationMethod !== SSO && (
274275
<FormButton

src/browser/modules/Stream/Auth/ConnectionForm.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ export class ConnectionForm extends Component<any, ConnectionFormState> {
8080
constructor(props: any) {
8181
super(props)
8282
const connection = this.getConnection()
83+
84+
const { searchParams } = new URL(window.location.href)
85+
const searchParamAuthMethod = searchParams.get('preselectAuthMethod')
8386
const authenticationMethod =
84-
(connection && connection.authenticationMethod) || NATIVE
87+
searchParamAuthMethod ??
88+
((connection && connection.authenticationMethod) || NATIVE)
8589

8690
const allowedSchemes = getAllowedSchemesForHost(
8791
connection.host,
@@ -94,13 +98,22 @@ export class ConnectionForm extends Component<any, ConnectionFormState> {
9498
host: generateBoltUrl(allowedSchemes, connection.host),
9599
authenticationMethod,
96100
isLoading: false,
101+
connecting: false,
97102
passwordChangeNeeded: props.passwordChangeNeeded || false,
98103
forcePasswordChange: props.forcePasswordChange || false,
99104
successCallback: props.onSuccess || (() => {}),
100105
used: props.isConnected
101106
}
102107
}
103108

109+
componentDidMount() {
110+
const { authenticationMethod } = this.state
111+
if (authenticationMethod === NO_AUTH) {
112+
this.connect(() => this.setState({ connecting: false }))
113+
this.setState({ connecting: true })
114+
}
115+
}
116+
104117
getConnection() {
105118
return this.props.discoveredData || this.props.frame.connectionData || {}
106119
}
@@ -395,6 +408,10 @@ export class ConnectionForm extends Component<any, ConnectionFormState> {
395408
onAuthenticationMethodChange={this.onAuthenticationMethodChange.bind(
396409
this
397410
)}
411+
connecting={this.state.connecting}
412+
setIsConnecting={(connecting: boolean) =>
413+
this.setState({ connecting })
414+
}
398415
host={host}
399416
SSOError={this.state.SSOError}
400417
SSOProviders={this.state.SSOProviders || []}

0 commit comments

Comments
 (0)