Просмотр исходного кода

Merge pull request #27 from provectus/issue-14/update-custom-params-key-to-work-as-object-not-array

issue-14/update-custom-params-key-to-work-as-object-not-array
Azat Gataullin 5 лет назад
Родитель
Сommit
ef1edba34b

+ 1 - 1
kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParams.tsx

@@ -24,7 +24,7 @@ const CustomParams: React.FC<Props> = ({ isSubmitting }) => {
   const onAdd = (event: React.MouseEvent<HTMLButtonElement>) => {
   const onAdd = (event: React.MouseEvent<HTMLButtonElement>) => {
     event.preventDefault();
     event.preventDefault();
 
 
-    const newIndex = `${INDEX_PREFIX}.${new Date().getTime()}`;
+    const newIndex = `${INDEX_PREFIX}.${new Date().getTime()}ts`;
 
 
     setFormCustomParams({
     setFormCustomParams({
       ...formCustomParams,
       ...formCustomParams,

+ 14 - 0
kafka-ui-react-app/src/redux/api/topics.ts

@@ -1,3 +1,4 @@
+import { reduce } from 'lodash';
 import {
 import {
   TopicName,
   TopicName,
   Topic,
   Topic,
@@ -5,6 +6,7 @@ import {
   TopicDetails,
   TopicDetails,
   TopicConfig,
   TopicConfig,
   TopicFormData,
   TopicFormData,
+  TopicFormCustomParam,
 } from 'redux/interfaces';
 } from 'redux/interfaces';
 import {
 import {
   BASE_URL,
   BASE_URL,
@@ -23,6 +25,10 @@ export const getTopics = (clusterName: ClusterName): Promise<Topic[]> =>
   fetch(`${BASE_URL}/clusters/${clusterName}/topics`, { ...BASE_PARAMS })
   fetch(`${BASE_URL}/clusters/${clusterName}/topics`, { ...BASE_PARAMS })
     .then(res => res.json());
     .then(res => res.json());
 
 
+interface Result {
+  [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,
@@ -34,6 +40,12 @@ export const postTopic = (clusterName: ClusterName, form: TopicFormData): Promis
     maxMessageBytes,
     maxMessageBytes,
     minInSyncReplicas,
     minInSyncReplicas,
   } = form;
   } = form;
+
+  const 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,
     partitions,
     partitions,
@@ -44,8 +56,10 @@ export const postTopic = (clusterName: ClusterName, form: TopicFormData): Promis
       'retention.bytes': retentionBytes,
       'retention.bytes': retentionBytes,
       'max.message.bytes': maxMessageBytes,
       'max.message.bytes': maxMessageBytes,
       'min.insync.replicas': minInSyncReplicas,
       'min.insync.replicas': minInSyncReplicas,
+      ...customParams,
     }
     }
   });
   });
+
   return fetch(`${BASE_URL}/clusters/${clusterName}/topics`, {
   return fetch(`${BASE_URL}/clusters/${clusterName}/topics`, {
     ...BASE_PARAMS,
     ...BASE_PARAMS,
     method: 'POST',
     method: 'POST',