Browse Source

fix-bug-topic-not-creatable-when-no-custom-params (#37)

* fix-bug-topic-not-creatable-when-no-custom-params

* remove-linter-changes-to-cleanup-PR
Azat Gataullin 5 years ago
parent
commit
3c5b46bd76
1 changed files with 36 additions and 20 deletions
  1. 36 20
      kafka-ui-react-app/src/redux/api/topics.ts

+ 36 - 20
kafka-ui-react-app/src/redux/api/topics.ts

@@ -8,28 +8,37 @@ import {
   TopicFormData,
   TopicFormData,
   TopicFormCustomParam,
   TopicFormCustomParam,
 } from 'redux/interfaces';
 } from 'redux/interfaces';
-import {
-  BASE_URL,
-  BASE_PARAMS,
-} from 'lib/constants';
+import { BASE_URL, BASE_PARAMS } from 'lib/constants';
 
 
-export const getTopicConfig = (clusterName: ClusterName, topicName: TopicName): Promise<TopicConfig[]> =>
-  fetch(`${BASE_URL}/clusters/${clusterName}/topics/${topicName}/config`, { ...BASE_PARAMS })
-    .then(res => res.json());
+export const getTopicConfig = (
+  clusterName: ClusterName,
+  topicName: TopicName
+): Promise<TopicConfig[]> =>
+  fetch(`${BASE_URL}/clusters/${clusterName}/topics/${topicName}/config`, {
+    ...BASE_PARAMS,
+  }).then((res) => res.json());
 
 
-export const getTopicDetails = (clusterName: ClusterName, topicName: TopicName): Promise<TopicDetails> =>
-  fetch(`${BASE_URL}/clusters/${clusterName}/topics/${topicName}`, { ...BASE_PARAMS })
-    .then(res => res.json());
+export const getTopicDetails = (
+  clusterName: ClusterName,
+  topicName: TopicName
+): Promise<TopicDetails> =>
+  fetch(`${BASE_URL}/clusters/${clusterName}/topics/${topicName}`, {
+    ...BASE_PARAMS,
+  }).then((res) => res.json());
 
 
 export const getTopics = (clusterName: ClusterName): Promise<Topic[]> =>
 export const getTopics = (clusterName: ClusterName): Promise<Topic[]> =>
-  fetch(`${BASE_URL}/clusters/${clusterName}/topics`, { ...BASE_PARAMS })
-    .then(res => res.json());
+  fetch(`${BASE_URL}/clusters/${clusterName}/topics`, {
+    ...BASE_PARAMS,
+  }).then((res) => res.json());
 
 
 interface Result {
 interface Result {
-  [index: string]: string,
+  [index: string]: string;
 }
 }
 
 
-export const postTopic = (clusterName: ClusterName, form: TopicFormData): Promise<Topic> => {
+export const postTopic = (
+  clusterName: ClusterName,
+  form: TopicFormData
+): Promise<Topic> => {
   const {
   const {
     name,
     name,
     partitions,
     partitions,
@@ -41,10 +50,17 @@ export const postTopic = (clusterName: ClusterName, form: TopicFormData): Promis
     minInSyncReplicas,
     minInSyncReplicas,
   } = form;
   } = form;
 
 
-  const customParams = reduce(Object.values(form.customParams), (result: Result, customParam: TopicFormCustomParam) => {
-    result[customParam.name] = customParam.value;
-    return result;
-  }, {});
+  const customParams =
+    (form.customParams &&
+      reduce(
+        Object.values(form.customParams),
+        (result: Result, customParam: TopicFormCustomParam) => {
+          result[customParam.name] = customParam.value;
+          return result;
+        },
+        {}
+      )) ||
+    {};
 
 
   const body = JSON.stringify({
   const body = JSON.stringify({
     name,
     name,
@@ -57,12 +73,12 @@ export const postTopic = (clusterName: ClusterName, form: TopicFormData): Promis
       'max.message.bytes': maxMessageBytes,
       'max.message.bytes': maxMessageBytes,
       'min.insync.replicas': minInSyncReplicas,
       'min.insync.replicas': minInSyncReplicas,
       ...customParams,
       ...customParams,
-    }
+    },
   });
   });
 
 
   return fetch(`${BASE_URL}/clusters/${clusterName}/topics`, {
   return fetch(`${BASE_URL}/clusters/${clusterName}/topics`, {
     ...BASE_PARAMS,
     ...BASE_PARAMS,
     method: 'POST',
     method: 'POST',
     body,
     body,
-  }).then(res => res.json());
+  }).then((res) => res.json());
 };
 };