11// Libraries
2- import React , { FC , useEffect , useState } from 'react'
2+ import React , { FC , useEffect , useRef , useState } from 'react'
3+ import { v4 as uuidv4 } from 'uuid'
34
45// Components
56import {
@@ -19,6 +20,9 @@ import {
1920 AlignItems ,
2021 FlexDirection ,
2122 ComponentStatus ,
23+ Toggle ,
24+ InputToggleType ,
25+ InputLabel ,
2226} from '@influxdata/clockface'
2327import UserInput from 'src/writeData/subscriptions/components/UserInput'
2428import CertificateInput from 'src/writeData/subscriptions/components/CertificateInput'
@@ -57,6 +61,10 @@ const BrokerFormContent: FC<Props> = ({
5761 const mqttProtocol = 'MQTT'
5862 const protocolList = [ mqttProtocol ]
5963 const [ protocol , setProtocol ] = useState ( mqttProtocol )
64+ const [ useCustomClientID , setUseCustomClientID ] = useState (
65+ ! ! formContent . clientID || false
66+ )
67+ const randomClientID = useRef ( uuidv4 ( ) )
6068
6169 useEffect ( ( ) => {
6270 updateForm ( { ...formContent , protocol : protocol . toLowerCase ( ) } )
@@ -293,6 +301,69 @@ const BrokerFormContent: FC<Props> = ({
293301 } `}
294302 </ Heading >
295303 ) }
304+ { isFlagEnabled ( 'subscriptionsClientId' ) && (
305+ < >
306+ < Form . ValidationElement
307+ label = "Client ID"
308+ value = { formContent . brokerHost }
309+ required = { useCustomClientID }
310+ validationFunc = { ( ) =>
311+ useCustomClientID &&
312+ handleValidation ( 'Client ID' , formContent . clientID )
313+ }
314+ helpText = "We will generate a Client ID for you, but some providers require you use their Client ID. If your provider requires a specific Client ID, the connection will fail without it. Check your provider’s documentation to verify whether you need to use their Client ID."
315+ className = "no-margin-bottom"
316+ >
317+ { status => (
318+ < Input
319+ type = { InputType . Text }
320+ placeholder = {
321+ useCustomClientID
322+ ? 'Enter a client id'
323+ : randomClientID . current
324+ }
325+ name = "clientid"
326+ autoFocus = { false }
327+ value = { formContent . clientID }
328+ onChange = { e => {
329+ updateForm ( {
330+ ...formContent ,
331+ clientID : e . target . value ,
332+ } )
333+ } }
334+ onBlur = { ( ) =>
335+ event (
336+ 'completed form field' ,
337+ { formField : 'clientid' , step : 'broker' } ,
338+ { feature : 'subscriptions' }
339+ )
340+ }
341+ status = {
342+ edit && useCustomClientID
343+ ? status
344+ : ComponentStatus . Disabled
345+ }
346+ testID = { `${ className } -broker-form--clientid` }
347+ maxLength = { 255 }
348+ />
349+ ) }
350+ </ Form . ValidationElement >
351+ < Toggle
352+ type = { InputToggleType . Checkbox }
353+ checked = { useCustomClientID }
354+ id = "clientid-toggle"
355+ size = { ComponentSize . Small }
356+ titleText = "Use Custom Client ID"
357+ onChange = { ( ) => {
358+ setUseCustomClientID ( ! useCustomClientID )
359+ updateForm ( { ...formContent , clientID : '' } )
360+ } }
361+ disabled = { ! edit }
362+ >
363+ < InputLabel > Use Custom Client ID</ InputLabel >
364+ </ Toggle >
365+ </ >
366+ ) }
296367 </ Grid . Column >
297368 < Grid . Column widthXS = { Columns . Twelve } >
298369 < Heading
0 commit comments