From 2d45c488f925f9d2f2bfdfcffab41b466b049ab6 Mon Sep 17 00:00:00 2001 From: Azat Gataullin Date: Tue, 28 Apr 2020 14:21:36 +0300 Subject: [PATCH] Enhancement/improve time to retain usability v2 (#35) * enhancement/improve-time-to-retain-usability * add-btn-controls-for-time-to-retain-for-topics --- .../src/components/Topics/New/New.tsx | 161 +++++++++--------- .../components/Topics/New/TimeToRetain.tsx | 43 +++-- .../components/Topics/New/TimeToRetainBtn.tsx | 29 ++++ .../Topics/New/TimeToRetainBtns.tsx | 36 ++++ kafka-ui-react-app/src/lib/constants.ts | 2 + 5 files changed, 168 insertions(+), 103 deletions(-) create mode 100644 kafka-ui-react-app/src/components/Topics/New/TimeToRetainBtn.tsx create mode 100644 kafka-ui-react-app/src/components/Topics/New/TimeToRetainBtns.tsx diff --git a/kafka-ui-react-app/src/components/Topics/New/New.tsx b/kafka-ui-react-app/src/components/Topics/New/New.tsx index c782ca75b8..34def6a1a1 100644 --- a/kafka-ui-react-app/src/components/Topics/New/New.tsx +++ b/kafka-ui-react-app/src/components/Topics/New/New.tsx @@ -1,16 +1,17 @@ import React from 'react'; -import { ClusterName, CleanupPolicy, TopicFormData, TopicName } from 'redux/interfaces'; +import { + ClusterName, + CleanupPolicy, + TopicFormData, + TopicName, +} from 'redux/interfaces'; import { useForm, FormContext, ErrorMessage } from 'react-hook-form'; import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb'; -import CustomParamsContainer from "./CustomParams/CustomParamsContainer"; -import TimeToRetain from './TimeToRetain'; import { clusterTopicsPath } from 'lib/paths'; -import { - TOPIC_NAME_VALIDATION_PATTERN, - BYTES_IN_GB, -} from 'lib/constants'; - +import { TOPIC_NAME_VALIDATION_PATTERN, BYTES_IN_GB } from 'lib/constants'; +import CustomParamsContainer from './CustomParams/CustomParamsContainer'; +import TimeToRetain from './TimeToRetain'; interface Props { clusterName: ClusterName; @@ -21,29 +22,32 @@ interface Props { } const New: React.FC = ({ - clusterName, - isTopicCreated, - createTopic, - redirectToTopicPath, - resetUploadedState - }) => { + clusterName, + isTopicCreated, + createTopic, + redirectToTopicPath, + resetUploadedState, +}) => { const methods = useForm(); const [isSubmitting, setIsSubmitting] = React.useState(false); - React.useEffect( - () => { - if (isSubmitting && isTopicCreated) { - const {name} = methods.getValues(); - redirectToTopicPath(clusterName, name); - } - }, - [isSubmitting, isTopicCreated, redirectToTopicPath, clusterName, methods.getValues], - ); + React.useEffect(() => { + if (isSubmitting && isTopicCreated) { + const { name } = methods.getValues(); + redirectToTopicPath(clusterName, name); + } + }, [ + isSubmitting, + isTopicCreated, + redirectToTopicPath, + clusterName, + methods.getValues, + ]); const onSubmit = async (data: TopicFormData) => { - //TODO: need to fix loader. After success loading the first time, we won't wait for creation any more, because state is - //loaded, and we will try to get entity immediately after pressing the button, and we will receive null - //going to object page on the second creation. Resetting loaded state is workaround, need to tweak loader logic + // TODO: need to fix loader. After success loading the first time, we won't wait for creation any more, because state is + // loaded, and we will try to get entity immediately after pressing the button, and we will receive null + // going to object page on the second creation. Resetting loaded state is workaround, need to tweak loader logic resetUploadedState(); setIsSubmitting(true); createTopic(clusterName, data); @@ -53,9 +57,11 @@ const New: React.FC = ({
- + New Topic
@@ -66,9 +72,7 @@ const New: React.FC = ({
- + = ({ disabled={isSubmitting} />

- +

- +

- +

- +

- +

- +

- +

- +
@@ -172,9 +176,7 @@ const New: React.FC = ({
- +
@@ -204,26 +196,33 @@ const New: React.FC = ({
- +

- +

- +
diff --git a/kafka-ui-react-app/src/components/Topics/New/TimeToRetain.tsx b/kafka-ui-react-app/src/components/Topics/New/TimeToRetain.tsx index 871ce4c3d4..5e4494001d 100644 --- a/kafka-ui-react-app/src/components/Topics/New/TimeToRetain.tsx +++ b/kafka-ui-react-app/src/components/Topics/New/TimeToRetain.tsx @@ -1,53 +1,52 @@ import React from 'react'; import prettyMilliseconds from 'pretty-ms'; import { useFormContext, ErrorMessage } from 'react-hook-form'; -import { MILLISECONDS_IN_WEEK } from 'lib/constants'; - -const MILLISECONDS_IN_SECOND = 1000; +import { MILLISECONDS_IN_WEEK, MILLISECONDS_IN_SECOND } from 'lib/constants'; +import TimeToRetainBtns from './TimeToRetainBtns'; interface Props { isSubmitting: boolean; } -const TimeToRetain: React.FC = ({ - isSubmitting, -}) => { +const TimeToRetain: React.FC = ({ isSubmitting }) => { const { register, errors, watch } = useFormContext(); const defaultValue = MILLISECONDS_IN_WEEK; - const name: string = 'retentionMs'; - const watchedValue: any = watch(name, defaultValue.toString()); + const name = 'retentionMs'; + const watchedValue = watch(name, defaultValue.toString()); const valueHint = React.useMemo(() => { const value = parseInt(watchedValue, 10); return value >= MILLISECONDS_IN_SECOND ? prettyMilliseconds(value) : false; - }, [watchedValue]) + }, [watchedValue]); return ( <> -