import React from 'react'; import { useFormContext, Controller } from 'react-hook-form'; import { NOT_SET, BYTES_IN_GB } from 'lib/constants'; import { TopicName } from 'redux/interfaces'; import { ErrorMessage } from '@hookform/error-message'; import Select, { SelectOption } from 'components/common/Select/Select'; import Input from 'components/common/Input/Input'; import { Button } from 'components/common/Button/Button'; import { InputLabel } from 'components/common/Input/InputLabel.styled'; import { FormError } from 'components/common/Input/Input.styled'; import { StyledForm } from 'components/common/Form/Form.styled'; import CustomParamsContainer from './CustomParams/CustomParamsContainer'; import TimeToRetain from './TimeToRetain'; import * as S from './TopicForm.styled'; export interface Props { topicName?: TopicName; partitionCount?: number; replicationFactor?: number; inSyncReplicas?: number; cleanUpPolicy?: string; isEditing?: boolean; isSubmitting: boolean; onSubmit: (e: React.BaseSyntheticEvent) => Promise; } const CleanupPolicyOptions: Array = [ { value: 'delete', label: 'Delete' }, { value: 'compact', label: 'Compact' }, { value: 'compact,delete', label: 'Compact,Delete' }, ]; const RetentionBytesOptions: Array = [ { value: NOT_SET, label: 'Not Set' }, { value: BYTES_IN_GB, label: '1 GB' }, { value: BYTES_IN_GB * 10, label: '10 GB' }, { value: BYTES_IN_GB * 20, label: '20 GB' }, { value: BYTES_IN_GB * 50, label: '50 GB' }, ]; const TopicForm: React.FC = ({ topicName, isEditing, isSubmitting, onSubmit, partitionCount, replicationFactor, inSyncReplicas, cleanUpPolicy, }) => { const { control, formState: { errors }, } = useFormContext(); const getCleanUpPolicy = CleanupPolicyOptions.find((option: SelectOption) => { return option.value === cleanUpPolicy?.toLowerCase(); })?.value || CleanupPolicyOptions[0].value; return (
Topic Name * {!isEditing && (
Number of partitions *
Replication Factor *
)}
Min In Sync Replicas *
Cleanup policy ( )} />
Maximum message size in bytes *
Custom parameters
); }; export default TopicForm;