diff --git a/frontend/src/widgets/ClusterConfigForm/Sections/Authentication/Authentication.tsx b/frontend/src/widgets/ClusterConfigForm/Sections/Authentication/Authentication.tsx index 0fad2cbf1..94113f8c8 100644 --- a/frontend/src/widgets/ClusterConfigForm/Sections/Authentication/Authentication.tsx +++ b/frontend/src/widgets/ClusterConfigForm/Sections/Authentication/Authentication.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { useFormContext } from 'react-hook-form'; import { AUTH_OPTIONS, SECURITY_PROTOCOL_OPTIONS } from 'lib/constants'; import ControlledSelect from 'components/common/Select/ControlledSelect'; @@ -10,25 +10,28 @@ const Authentication: React.FC = () => { const { watch, setValue } = useFormContext(); const hasAuth = !!watch('auth'); const authMethod = watch('auth.method'); + const [configOpen, setConfigOpen] = useState(false); const hasSecurityProtocolField = authMethod && !['Delegation tokens', 'mTLS'].includes(authMethod); - const toggle = () => - setValue('auth', hasAuth ? undefined : {}, { + const toggle = () => { + setConfigOpen((prevConfigOpen) => !prevConfigOpen); + setValue('auth', hasAuth ? { isActive: false } : { isActive: true }, { shouldValidate: true, shouldDirty: true, shouldTouch: true, }); + }; return ( <> - {hasAuth && ( + {configOpen && ( <> { const { setValue, watch } = useFormContext(); const ksql = watch('ksql'); + const [configOpen, setConfigOpen] = useState(false); const toggleConfig = () => { - setValue('ksql', ksql ? undefined : { url: '', isAuth: false }, { - shouldValidate: true, - shouldDirty: true, - shouldTouch: true, - }); + setConfigOpen((prevConfigOpen) => !prevConfigOpen); + setValue( + 'ksql', + ksql ? { isActive: false } : { isActive: false, url: '', isAuth: false }, + { + shouldValidate: true, + shouldDirty: true, + shouldTouch: true, + } + ); }; return ( <> - {ksql && ( + {configOpen && ( <> { name: 'bootstrapServers', }); - const hasTrustStore = !!watch('truststore'); + const [hasTrustStore, setHasTrustStore] = useState(false); - const toggleSection = (section: string) => () => + const toggleSection = (section: string) => () => { + setHasTrustStore((prevConfigOpen) => !prevConfigOpen); setValue( section, watch(section) - ? undefined + ? { isActive: false } : { + isActive: true, location: '', password: '', }, { shouldValidate: true, shouldDirty: true, shouldTouch: true } ); + }; return ( <> diff --git a/frontend/src/widgets/ClusterConfigForm/Sections/Metrics.tsx b/frontend/src/widgets/ClusterConfigForm/Sections/Metrics.tsx index e9d67f201..73b9d6d03 100644 --- a/frontend/src/widgets/ClusterConfigForm/Sections/Metrics.tsx +++ b/frontend/src/widgets/ClusterConfigForm/Sections/Metrics.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import Input from 'components/common/Input/Input'; import { useFormContext } from 'react-hook-form'; import ControlledSelect from 'components/common/Select/ControlledSelect'; @@ -11,28 +11,32 @@ import Credentials from 'widgets/ClusterConfigForm/common/Credentials'; const Metrics = () => { const { setValue, watch } = useFormContext(); const visibleMetrics = !!watch('metrics'); - const toggleMetrics = () => + const [configOpen, setConfigOpen] = useState(false); + const toggleMetrics = () => { + setConfigOpen((prevConfigOpen) => !prevConfigOpen); setValue( 'metrics', visibleMetrics - ? undefined + ? { isActive: false } : { + isActive: true, type: '', port: 0, isAuth: false, }, { shouldValidate: true, shouldDirty: true, shouldTouch: true } ); + }; return ( <> - {visibleMetrics && ( + {configOpen && ( <> { const { setValue, watch } = useFormContext(); const schemaRegistry = watch('schemaRegistry'); + const [configOpen, setConfigOpen] = useState(false); const toggleConfig = () => { + setConfigOpen((prevConfigOpen) => !prevConfigOpen); setValue( 'schemaRegistry', - schemaRegistry ? undefined : { url: '', isAuth: false }, - { shouldValidate: true, shouldDirty: true, shouldTouch: true } + schemaRegistry + ? { isActive: false } + : { isActive: true, url: '', isAuth: false }, + { + shouldValidate: true, + shouldDirty: true, + shouldTouch: true, + } ); }; return ( <> - {schemaRegistry && ( + {configOpen && ( <> ; diff --git a/frontend/src/widgets/ClusterConfigForm/utils/transformFormDataToPayload.ts b/frontend/src/widgets/ClusterConfigForm/utils/transformFormDataToPayload.ts index 91f9ad1e2..0dea696a1 100644 --- a/frontend/src/widgets/ClusterConfigForm/utils/transformFormDataToPayload.ts +++ b/frontend/src/widgets/ClusterConfigForm/utils/transformFormDataToPayload.ts @@ -52,7 +52,7 @@ export const transformFormDataToPayload = (data: ClusterConfigFormValues) => { } // Schema Registry - if (data.schemaRegistry) { + if (data.schemaRegistry?.isActive) { config.schemaRegistry = data.schemaRegistry.url; config.schemaRegistryAuth = transformToCredentials( data.schemaRegistry.isAuth, @@ -65,7 +65,7 @@ export const transformFormDataToPayload = (data: ClusterConfigFormValues) => { } // KSQL - if (data.ksql) { + if (data.ksql?.isActive) { config.ksqldbServer = data.ksql.url; config.ksqldbServerAuth = transformToCredentials( data.ksql.isAuth, @@ -88,7 +88,7 @@ export const transformFormDataToPayload = (data: ClusterConfigFormValues) => { } // Metrics - if (data.metrics) { + if (data.metrics?.isActive) { config.metrics = { type: data.metrics.type, port: Number(data.metrics.port), @@ -106,7 +106,7 @@ export const transformFormDataToPayload = (data: ClusterConfigFormValues) => { }; // Authentication - if (data.auth) { + if (data.auth?.isActive) { const { method, props, securityProtocol, keystore } = data.auth; switch (method) { case 'SASL/JAAS':