Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE: Wizard: Fix sections collapsing #399

Merged
merged 7 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
<>
<SectionHeader
title="Authentication"
adding={!hasAuth}
adding={!configOpen}
addButtonText="Configure Authentication"
onClick={toggle}
/>
{hasAuth && (
{configOpen && (
<>
<ControlledSelect
name="auth.method"
Expand Down
22 changes: 14 additions & 8 deletions frontend/src/widgets/ClusterConfigForm/Sections/KSQL.tsx
Original file line number Diff line number Diff line change
@@ -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 SectionHeader from 'widgets/ClusterConfigForm/common/SectionHeader';
Expand All @@ -8,22 +8,28 @@ import Credentials from 'widgets/ClusterConfigForm/common/Credentials';
const KSQL = () => {
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 (
<>
<SectionHeader
title="KSQL DB"
adding={!ksql}
adding={!configOpen}
addButtonText="Configure KSQL DB"
onClick={toggleConfig}
/>
{ksql && (
{configOpen && (
<>
<Input
label="URL *"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import Input from 'components/common/Input/Input';
import { useFieldArray, useFormContext } from 'react-hook-form';
import { FormError, InputHint } from 'components/common/Input/Input.styled';
Expand All @@ -21,19 +21,22 @@ const KafkaCluster: React.FC = () => {
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 (
<>
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/widgets/ClusterConfigForm/Sections/Metrics.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 (
<>
<SectionHeader
title="Metrics"
adding={!visibleMetrics}
adding={!configOpen}
addButtonText="Configure Metrics"
onClick={toggleMetrics}
/>
{visibleMetrics && (
{configOpen && (
<>
<ControlledSelect
name="metrics.type"
Expand Down
Original file line number Diff line number Diff line change
@@ -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 SectionHeader from 'widgets/ClusterConfigForm/common/SectionHeader';
Expand All @@ -8,22 +8,30 @@ import Credentials from 'widgets/ClusterConfigForm/common/Credentials';
const SchemaRegistry = () => {
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 (
<>
<SectionHeader
title="Schema Registry"
adding={!schemaRegistry}
adding={!configOpen}
addButtonText="Configure Schema Registry"
onClick={toggleConfig}
/>
{schemaRegistry && (
{configOpen && (
<>
<Input
label="URL *"
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/widgets/ClusterConfigForm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type WithAuth = {
type URLWithAuth = WithAuth &
WithKeystore & {
url?: string;
isActive?: string;
};

type KafkaConnect = WithAuth &
Expand All @@ -30,6 +31,7 @@ type KafkaConnect = WithAuth &

type Metrics = WithAuth &
WithKeystore & {
isActive?: string;
type: string;
port: string;
};
Expand All @@ -43,6 +45,7 @@ export type ClusterConfigFormValues = {
password: string;
};
auth?: WithKeystore & {
isActive?: string;
method: string;
securityProtocol: SecurityProtocol;
props: Record<string, string>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -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':
Expand Down
Loading