|
@@ -1,10 +1,9 @@
|
|
-import React from 'react';
|
|
|
|
|
|
+import React, { useEffect } from 'react';
|
|
import {
|
|
import {
|
|
ClusterName,
|
|
ClusterName,
|
|
TopicFormDataRaw,
|
|
TopicFormDataRaw,
|
|
TopicName,
|
|
TopicName,
|
|
TopicConfigByName,
|
|
TopicConfigByName,
|
|
- TopicWithDetailedInfo,
|
|
|
|
TopicFormData,
|
|
TopicFormData,
|
|
} from 'redux/interfaces';
|
|
} from 'redux/interfaces';
|
|
import { useForm, FormProvider } from 'react-hook-form';
|
|
import { useForm, FormProvider } from 'react-hook-form';
|
|
@@ -13,12 +12,13 @@ import { RouteParamsClusterTopic } from 'lib/paths';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { yupResolver } from '@hookform/resolvers/yup';
|
|
import { yupResolver } from '@hookform/resolvers/yup';
|
|
import { topicFormValidationSchema } from 'lib/yupExtended';
|
|
import { topicFormValidationSchema } from 'lib/yupExtended';
|
|
-import { TOPIC_CUSTOM_PARAMS_PREFIX, TOPIC_CUSTOM_PARAMS } from 'lib/constants';
|
|
|
|
import styled from 'styled-components';
|
|
import styled from 'styled-components';
|
|
import PageHeading from 'components/common/PageHeading/PageHeading';
|
|
import PageHeading from 'components/common/PageHeading/PageHeading';
|
|
import { useAppSelector } from 'lib/hooks/redux';
|
|
import { useAppSelector } from 'lib/hooks/redux';
|
|
import { getFullTopic } from 'redux/reducers/topics/selectors';
|
|
import { getFullTopic } from 'redux/reducers/topics/selectors';
|
|
import useAppParams from 'lib/hooks/useAppParams';
|
|
import useAppParams from 'lib/hooks/useAppParams';
|
|
|
|
+import topicParamsTransformer from 'components/Topics/Topic/Edit/topicParamsTransformer';
|
|
|
|
+import { MILLISECONDS_IN_WEEK } from 'lib/constants';
|
|
|
|
|
|
import DangerZoneContainer from './DangerZone/DangerZoneContainer';
|
|
import DangerZoneContainer from './DangerZone/DangerZoneContainer';
|
|
|
|
|
|
@@ -39,6 +39,7 @@ export interface Props {
|
|
const EditWrapperStyled = styled.div`
|
|
const EditWrapperStyled = styled.div`
|
|
display: flex;
|
|
display: flex;
|
|
justify-content: center;
|
|
justify-content: center;
|
|
|
|
+
|
|
& > * {
|
|
& > * {
|
|
width: 800px;
|
|
width: 800px;
|
|
}
|
|
}
|
|
@@ -50,29 +51,9 @@ export const DEFAULTS = {
|
|
minInSyncReplicas: 1,
|
|
minInSyncReplicas: 1,
|
|
cleanupPolicy: 'delete',
|
|
cleanupPolicy: 'delete',
|
|
retentionBytes: -1,
|
|
retentionBytes: -1,
|
|
|
|
+ retentionMs: MILLISECONDS_IN_WEEK,
|
|
maxMessageBytes: 1000012,
|
|
maxMessageBytes: 1000012,
|
|
-};
|
|
|
|
-
|
|
|
|
-const topicParams = (topic: TopicWithDetailedInfo | undefined) => {
|
|
|
|
- if (!topic) {
|
|
|
|
- return DEFAULTS;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const { name, replicationFactor } = topic;
|
|
|
|
-
|
|
|
|
- return {
|
|
|
|
- ...DEFAULTS,
|
|
|
|
- name,
|
|
|
|
- partitions: topic.partitionCount || DEFAULTS.partitions,
|
|
|
|
- replicationFactor,
|
|
|
|
- [TOPIC_CUSTOM_PARAMS_PREFIX]: topic.config
|
|
|
|
- ?.filter(
|
|
|
|
- (el) =>
|
|
|
|
- el.value !== el.defaultValue &&
|
|
|
|
- Object.keys(TOPIC_CUSTOM_PARAMS).includes(el.name)
|
|
|
|
- )
|
|
|
|
- .map((el) => ({ name: el.name, value: el.value })),
|
|
|
|
- };
|
|
|
|
|
|
+ customParams: [],
|
|
};
|
|
};
|
|
|
|
|
|
let formInit = false;
|
|
let formInit = false;
|
|
@@ -87,7 +68,7 @@ const Edit: React.FC<Props> = ({
|
|
|
|
|
|
const topic = useAppSelector((state) => getFullTopic(state, topicName));
|
|
const topic = useAppSelector((state) => getFullTopic(state, topicName));
|
|
|
|
|
|
- const defaultValues = React.useMemo(() => topicParams(topic), [topic]);
|
|
|
|
|
|
+ const defaultValues = topicParamsTransformer(topic);
|
|
|
|
|
|
const methods = useForm<TopicFormData>({
|
|
const methods = useForm<TopicFormData>({
|
|
defaultValues,
|
|
defaultValues,
|
|
@@ -95,12 +76,16 @@ const Edit: React.FC<Props> = ({
|
|
mode: 'onChange',
|
|
mode: 'onChange',
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ methods.reset(defaultValues);
|
|
|
|
+ }, [!topic]);
|
|
|
|
+
|
|
const [isSubmitting, setIsSubmitting] = React.useState<boolean>(false);
|
|
const [isSubmitting, setIsSubmitting] = React.useState<boolean>(false);
|
|
const navigate = useNavigate();
|
|
const navigate = useNavigate();
|
|
|
|
|
|
React.useEffect(() => {
|
|
React.useEffect(() => {
|
|
fetchTopicConfig({ clusterName, topicName });
|
|
fetchTopicConfig({ clusterName, topicName });
|
|
- }, [fetchTopicConfig, clusterName, topicName]);
|
|
|
|
|
|
+ }, [fetchTopicConfig, clusterName, topicName, isTopicUpdated]);
|
|
|
|
|
|
React.useEffect(() => {
|
|
React.useEffect(() => {
|
|
if (isSubmitting && isTopicUpdated) {
|
|
if (isSubmitting && isTopicUpdated) {
|
|
@@ -138,7 +123,10 @@ const Edit: React.FC<Props> = ({
|
|
<FormProvider {...methods}>
|
|
<FormProvider {...methods}>
|
|
<TopicForm
|
|
<TopicForm
|
|
topicName={topicName}
|
|
topicName={topicName}
|
|
|
|
+ retentionBytes={defaultValues.retentionBytes}
|
|
|
|
+ inSyncReplicas={Number(defaultValues.minInSyncReplicas)}
|
|
isSubmitting={isSubmitting}
|
|
isSubmitting={isSubmitting}
|
|
|
|
+ cleanUpPolicy={topic.cleanUpPolicy}
|
|
isEditing
|
|
isEditing
|
|
onSubmit={methods.handleSubmit(onSubmit)}
|
|
onSubmit={methods.handleSubmit(onSubmit)}
|
|
/>
|
|
/>
|