|
@@ -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<Props> = ({
|
|
|
- clusterName,
|
|
|
- isTopicCreated,
|
|
|
- createTopic,
|
|
|
- redirectToTopicPath,
|
|
|
- resetUploadedState
|
|
|
- }) => {
|
|
|
+ clusterName,
|
|
|
+ isTopicCreated,
|
|
|
+ createTopic,
|
|
|
+ redirectToTopicPath,
|
|
|
+ resetUploadedState,
|
|
|
+}) => {
|
|
|
const methods = useForm<TopicFormData>();
|
|
|
const [isSubmitting, setIsSubmitting] = React.useState<boolean>(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<Props> = ({
|
|
|
<div className="section">
|
|
|
<div className="level">
|
|
|
<div className="level-item level-left">
|
|
|
- <Breadcrumb links={[
|
|
|
- {href: clusterTopicsPath(clusterName), label: 'All Topics'},
|
|
|
- ]}>
|
|
|
+ <Breadcrumb
|
|
|
+ links={[
|
|
|
+ { href: clusterTopicsPath(clusterName), label: 'All Topics' },
|
|
|
+ ]}
|
|
|
+ >
|
|
|
New Topic
|
|
|
</Breadcrumb>
|
|
|
</div>
|
|
@@ -66,9 +72,7 @@ const New: React.FC<Props> = ({
|
|
|
<form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
|
<div className="columns">
|
|
|
<div className="column is-three-quarters">
|
|
|
- <label className="label">
|
|
|
- Topic Name *
|
|
|
- </label>
|
|
|
+ <label className="label">Topic Name *</label>
|
|
|
<input
|
|
|
className="input"
|
|
|
placeholder="Topic Name"
|
|
@@ -84,72 +88,76 @@ const New: React.FC<Props> = ({
|
|
|
disabled={isSubmitting}
|
|
|
/>
|
|
|
<p className="help is-danger">
|
|
|
- <ErrorMessage errors={methods.errors} name="name"/>
|
|
|
+ <ErrorMessage errors={methods.errors} name="name" />
|
|
|
</p>
|
|
|
</div>
|
|
|
|
|
|
<div className="column">
|
|
|
- <label className="label">
|
|
|
- Number of partitions *
|
|
|
- </label>
|
|
|
+ <label className="label">Number of partitions *</label>
|
|
|
<input
|
|
|
className="input"
|
|
|
type="number"
|
|
|
placeholder="Number of partitions"
|
|
|
defaultValue="1"
|
|
|
- ref={methods.register({required: 'Number of partitions is required.'})}
|
|
|
+ ref={methods.register({
|
|
|
+ required: 'Number of partitions is required.',
|
|
|
+ })}
|
|
|
name="partitions"
|
|
|
disabled={isSubmitting}
|
|
|
/>
|
|
|
<p className="help is-danger">
|
|
|
- <ErrorMessage errors={methods.errors} name="partitions"/>
|
|
|
+ <ErrorMessage errors={methods.errors} name="partitions" />
|
|
|
</p>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div className="columns">
|
|
|
<div className="column">
|
|
|
- <label className="label">
|
|
|
- Replication Factor *
|
|
|
- </label>
|
|
|
+ <label className="label">Replication Factor *</label>
|
|
|
<input
|
|
|
className="input"
|
|
|
type="number"
|
|
|
placeholder="Replication Factor"
|
|
|
defaultValue="1"
|
|
|
- ref={methods.register({required: 'Replication Factor is required.'})}
|
|
|
+ ref={methods.register({
|
|
|
+ required: 'Replication Factor is required.',
|
|
|
+ })}
|
|
|
name="replicationFactor"
|
|
|
disabled={isSubmitting}
|
|
|
/>
|
|
|
<p className="help is-danger">
|
|
|
- <ErrorMessage errors={methods.errors} name="replicationFactor"/>
|
|
|
+ <ErrorMessage
|
|
|
+ errors={methods.errors}
|
|
|
+ name="replicationFactor"
|
|
|
+ />
|
|
|
</p>
|
|
|
</div>
|
|
|
|
|
|
<div className="column">
|
|
|
- <label className="label">
|
|
|
- Min In Sync Replicas *
|
|
|
- </label>
|
|
|
+ <label className="label">Min In Sync Replicas *</label>
|
|
|
<input
|
|
|
className="input"
|
|
|
type="number"
|
|
|
placeholder="Replication Factor"
|
|
|
defaultValue="1"
|
|
|
- ref={methods.register({required: 'Min In Sync Replicas is required.'})}
|
|
|
+ ref={methods.register({
|
|
|
+ required: 'Min In Sync Replicas is required.',
|
|
|
+ })}
|
|
|
name="minInSyncReplicas"
|
|
|
disabled={isSubmitting}
|
|
|
/>
|
|
|
<p className="help is-danger">
|
|
|
- <ErrorMessage errors={methods.errors} name="minInSyncReplicas"/>
|
|
|
+ <ErrorMessage
|
|
|
+ errors={methods.errors}
|
|
|
+ name="minInSyncReplicas"
|
|
|
+ />
|
|
|
</p>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div className="columns">
|
|
|
<div className="column is-one-third">
|
|
|
- <label className="label">
|
|
|
- Cleanup policy
|
|
|
- </label>
|
|
|
+ <label className="label">Cleanup policy</label>
|
|
|
<div className="select is-block">
|
|
|
<select
|
|
|
defaultValue={CleanupPolicy.Delete}
|
|
@@ -157,12 +165,8 @@ const New: React.FC<Props> = ({
|
|
|
ref={methods.register}
|
|
|
disabled={isSubmitting}
|
|
|
>
|
|
|
- <option value={CleanupPolicy.Delete}>
|
|
|
- Delete
|
|
|
- </option>
|
|
|
- <option value={CleanupPolicy.Compact}>
|
|
|
- Compact
|
|
|
- </option>
|
|
|
+ <option value={CleanupPolicy.Delete}>Delete</option>
|
|
|
+ <option value={CleanupPolicy.Compact}>Compact</option>
|
|
|
</select>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -172,9 +176,7 @@ const New: React.FC<Props> = ({
|
|
|
</div>
|
|
|
|
|
|
<div className="column is-one-third">
|
|
|
- <label className="label">
|
|
|
- Max size on disk in GB
|
|
|
- </label>
|
|
|
+ <label className="label">Max size on disk in GB</label>
|
|
|
<div className="select is-block">
|
|
|
<select
|
|
|
defaultValue={-1}
|
|
@@ -182,21 +184,11 @@ const New: React.FC<Props> = ({
|
|
|
ref={methods.register}
|
|
|
disabled={isSubmitting}
|
|
|
>
|
|
|
- <option value={-1}>
|
|
|
- Not Set
|
|
|
- </option>
|
|
|
- <option value={BYTES_IN_GB}>
|
|
|
- 1 GB
|
|
|
- </option>
|
|
|
- <option value={BYTES_IN_GB * 10}>
|
|
|
- 10 GB
|
|
|
- </option>
|
|
|
- <option value={BYTES_IN_GB * 20}>
|
|
|
- 20 GB
|
|
|
- </option>
|
|
|
- <option value={BYTES_IN_GB * 50}>
|
|
|
- 50 GB
|
|
|
- </option>
|
|
|
+ <option value={-1}>Not Set</option>
|
|
|
+ <option value={BYTES_IN_GB}>1 GB</option>
|
|
|
+ <option value={BYTES_IN_GB * 10}>10 GB</option>
|
|
|
+ <option value={BYTES_IN_GB * 20}>20 GB</option>
|
|
|
+ <option value={BYTES_IN_GB * 50}>50 GB</option>
|
|
|
</select>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -204,26 +196,33 @@ const New: React.FC<Props> = ({
|
|
|
|
|
|
<div className="columns">
|
|
|
<div className="column">
|
|
|
- <label className="label">
|
|
|
- Maximum message size in bytes *
|
|
|
- </label>
|
|
|
+ <label className="label">Maximum message size in bytes *</label>
|
|
|
<input
|
|
|
className="input"
|
|
|
type="number"
|
|
|
defaultValue="1000012"
|
|
|
- ref={methods.register({required: 'Maximum message size in bytes is required'})}
|
|
|
+ ref={methods.register({
|
|
|
+ required: 'Maximum message size in bytes is required',
|
|
|
+ })}
|
|
|
name="maxMessageBytes"
|
|
|
disabled={isSubmitting}
|
|
|
/>
|
|
|
<p className="help is-danger">
|
|
|
- <ErrorMessage errors={methods.errors} name="maxMessageBytes"/>
|
|
|
+ <ErrorMessage
|
|
|
+ errors={methods.errors}
|
|
|
+ name="maxMessageBytes"
|
|
|
+ />
|
|
|
</p>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<CustomParamsContainer isSubmitting={isSubmitting} />
|
|
|
|
|
|
- <input type="submit" className="button is-primary" disabled={isSubmitting}/>
|
|
|
+ <input
|
|
|
+ type="submit"
|
|
|
+ className="button is-primary"
|
|
|
+ disabled={isSubmitting}
|
|
|
+ />
|
|
|
</form>
|
|
|
</FormContext>
|
|
|
</div>
|