Skip to content

Commit 1196f9f

Browse files
FE: Wizard: Fix sections collapsing (#399)
Co-authored-by: Roman Zabaluev <[email protected]>
1 parent 1405952 commit 1196f9f

File tree

7 files changed

+58
-31
lines changed

7 files changed

+58
-31
lines changed

frontend/src/widgets/ClusterConfigForm/Sections/Authentication/Authentication.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import { useFormContext } from 'react-hook-form';
33
import { AUTH_OPTIONS, SECURITY_PROTOCOL_OPTIONS } from 'lib/constants';
44
import ControlledSelect from 'components/common/Select/ControlledSelect';
@@ -10,25 +10,28 @@ const Authentication: React.FC = () => {
1010
const { watch, setValue } = useFormContext();
1111
const hasAuth = !!watch('auth');
1212
const authMethod = watch('auth.method');
13+
const [configOpen, setConfigOpen] = useState(false);
1314
const hasSecurityProtocolField =
1415
authMethod && !['Delegation tokens', 'mTLS'].includes(authMethod);
1516

16-
const toggle = () =>
17-
setValue('auth', hasAuth ? undefined : {}, {
17+
const toggle = () => {
18+
setConfigOpen((prevConfigOpen) => !prevConfigOpen);
19+
setValue('auth', hasAuth ? { isActive: false } : { isActive: true }, {
1820
shouldValidate: true,
1921
shouldDirty: true,
2022
shouldTouch: true,
2123
});
24+
};
2225

2326
return (
2427
<>
2528
<SectionHeader
2629
title="Authentication"
27-
adding={!hasAuth}
30+
adding={!configOpen}
2831
addButtonText="Configure Authentication"
2932
onClick={toggle}
3033
/>
31-
{hasAuth && (
34+
{configOpen && (
3235
<>
3336
<ControlledSelect
3437
name="auth.method"

frontend/src/widgets/ClusterConfigForm/Sections/KSQL.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import Input from 'components/common/Input/Input';
33
import { useFormContext } from 'react-hook-form';
44
import SectionHeader from 'widgets/ClusterConfigForm/common/SectionHeader';
@@ -8,22 +8,28 @@ import Credentials from 'widgets/ClusterConfigForm/common/Credentials';
88
const KSQL = () => {
99
const { setValue, watch } = useFormContext();
1010
const ksql = watch('ksql');
11+
const [configOpen, setConfigOpen] = useState(false);
1112
const toggleConfig = () => {
12-
setValue('ksql', ksql ? undefined : { url: '', isAuth: false }, {
13-
shouldValidate: true,
14-
shouldDirty: true,
15-
shouldTouch: true,
16-
});
13+
setConfigOpen((prevConfigOpen) => !prevConfigOpen);
14+
setValue(
15+
'ksql',
16+
ksql ? { isActive: false } : { isActive: false, url: '', isAuth: false },
17+
{
18+
shouldValidate: true,
19+
shouldDirty: true,
20+
shouldTouch: true,
21+
}
22+
);
1723
};
1824
return (
1925
<>
2026
<SectionHeader
2127
title="KSQL DB"
22-
adding={!ksql}
28+
adding={!configOpen}
2329
addButtonText="Configure KSQL DB"
2430
onClick={toggleConfig}
2531
/>
26-
{ksql && (
32+
{configOpen && (
2733
<>
2834
<Input
2935
label="URL *"

frontend/src/widgets/ClusterConfigForm/Sections/KafkaCluster.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import Input from 'components/common/Input/Input';
33
import { useFieldArray, useFormContext } from 'react-hook-form';
44
import { FormError, InputHint } from 'components/common/Input/Input.styled';
@@ -21,19 +21,22 @@ const KafkaCluster: React.FC = () => {
2121
name: 'bootstrapServers',
2222
});
2323

24-
const hasTrustStore = !!watch('truststore');
24+
const [hasTrustStore, setHasTrustStore] = useState(false);
2525

26-
const toggleSection = (section: string) => () =>
26+
const toggleSection = (section: string) => () => {
27+
setHasTrustStore((prevConfigOpen) => !prevConfigOpen);
2728
setValue(
2829
section,
2930
watch(section)
30-
? undefined
31+
? { isActive: false }
3132
: {
33+
isActive: true,
3234
location: '',
3335
password: '',
3436
},
3537
{ shouldValidate: true, shouldDirty: true, shouldTouch: true }
3638
);
39+
};
3740

3841
return (
3942
<>

frontend/src/widgets/ClusterConfigForm/Sections/Metrics.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import Input from 'components/common/Input/Input';
33
import { useFormContext } from 'react-hook-form';
44
import ControlledSelect from 'components/common/Select/ControlledSelect';
@@ -11,28 +11,32 @@ import Credentials from 'widgets/ClusterConfigForm/common/Credentials';
1111
const Metrics = () => {
1212
const { setValue, watch } = useFormContext();
1313
const visibleMetrics = !!watch('metrics');
14-
const toggleMetrics = () =>
14+
const [configOpen, setConfigOpen] = useState(false);
15+
const toggleMetrics = () => {
16+
setConfigOpen((prevConfigOpen) => !prevConfigOpen);
1517
setValue(
1618
'metrics',
1719
visibleMetrics
18-
? undefined
20+
? { isActive: false }
1921
: {
22+
isActive: true,
2023
type: '',
2124
port: 0,
2225
isAuth: false,
2326
},
2427
{ shouldValidate: true, shouldDirty: true, shouldTouch: true }
2528
);
29+
};
2630

2731
return (
2832
<>
2933
<SectionHeader
3034
title="Metrics"
31-
adding={!visibleMetrics}
35+
adding={!configOpen}
3236
addButtonText="Configure Metrics"
3337
onClick={toggleMetrics}
3438
/>
35-
{visibleMetrics && (
39+
{configOpen && (
3640
<>
3741
<ControlledSelect
3842
name="metrics.type"

frontend/src/widgets/ClusterConfigForm/Sections/SchemaRegistry.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useState } from 'react';
22
import Input from 'components/common/Input/Input';
33
import { useFormContext } from 'react-hook-form';
44
import SectionHeader from 'widgets/ClusterConfigForm/common/SectionHeader';
@@ -8,22 +8,30 @@ import Credentials from 'widgets/ClusterConfigForm/common/Credentials';
88
const SchemaRegistry = () => {
99
const { setValue, watch } = useFormContext();
1010
const schemaRegistry = watch('schemaRegistry');
11+
const [configOpen, setConfigOpen] = useState(false);
1112
const toggleConfig = () => {
13+
setConfigOpen((prevConfigOpen) => !prevConfigOpen);
1214
setValue(
1315
'schemaRegistry',
14-
schemaRegistry ? undefined : { url: '', isAuth: false },
15-
{ shouldValidate: true, shouldDirty: true, shouldTouch: true }
16+
schemaRegistry
17+
? { isActive: false }
18+
: { isActive: true, url: '', isAuth: false },
19+
{
20+
shouldValidate: true,
21+
shouldDirty: true,
22+
shouldTouch: true,
23+
}
1624
);
1725
};
1826
return (
1927
<>
2028
<SectionHeader
2129
title="Schema Registry"
22-
adding={!schemaRegistry}
30+
adding={!configOpen}
2331
addButtonText="Configure Schema Registry"
2432
onClick={toggleConfig}
2533
/>
26-
{schemaRegistry && (
34+
{configOpen && (
2735
<>
2836
<Input
2937
label="URL *"

frontend/src/widgets/ClusterConfigForm/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type WithAuth = {
2020
type URLWithAuth = WithAuth &
2121
WithKeystore & {
2222
url?: string;
23+
isActive?: string;
2324
};
2425

2526
type KafkaConnect = WithAuth &
@@ -30,6 +31,7 @@ type KafkaConnect = WithAuth &
3031

3132
type Metrics = WithAuth &
3233
WithKeystore & {
34+
isActive?: string;
3335
type: string;
3436
port: string;
3537
};
@@ -43,6 +45,7 @@ export type ClusterConfigFormValues = {
4345
password: string;
4446
};
4547
auth?: WithKeystore & {
48+
isActive?: string;
4649
method: string;
4750
securityProtocol: SecurityProtocol;
4851
props: Record<string, string>;

frontend/src/widgets/ClusterConfigForm/utils/transformFormDataToPayload.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const transformFormDataToPayload = (data: ClusterConfigFormValues) => {
5252
}
5353

5454
// Schema Registry
55-
if (data.schemaRegistry) {
55+
if (data.schemaRegistry?.isActive) {
5656
config.schemaRegistry = data.schemaRegistry.url;
5757
config.schemaRegistryAuth = transformToCredentials(
5858
data.schemaRegistry.isAuth,
@@ -65,7 +65,7 @@ export const transformFormDataToPayload = (data: ClusterConfigFormValues) => {
6565
}
6666

6767
// KSQL
68-
if (data.ksql) {
68+
if (data.ksql?.isActive) {
6969
config.ksqldbServer = data.ksql.url;
7070
config.ksqldbServerAuth = transformToCredentials(
7171
data.ksql.isAuth,
@@ -88,7 +88,7 @@ export const transformFormDataToPayload = (data: ClusterConfigFormValues) => {
8888
}
8989

9090
// Metrics
91-
if (data.metrics) {
91+
if (data.metrics?.isActive) {
9292
config.metrics = {
9393
type: data.metrics.type,
9494
port: Number(data.metrics.port),
@@ -106,7 +106,7 @@ export const transformFormDataToPayload = (data: ClusterConfigFormValues) => {
106106
};
107107

108108
// Authentication
109-
if (data.auth) {
109+
if (data.auth?.isActive) {
110110
const { method, props, securityProtocol, keystore } = data.auth;
111111
switch (method) {
112112
case 'SASL/JAAS':

0 commit comments

Comments
 (0)