|
@@ -1,4 +1,3 @@
|
|
-import { reduce } from 'lodash';
|
|
|
|
import {
|
|
import {
|
|
TopicName,
|
|
TopicName,
|
|
Topic,
|
|
Topic,
|
|
@@ -8,10 +7,21 @@ 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';
|
|
|
|
+
|
|
|
|
+const flattenCustomParams = (customParams: {
|
|
|
|
+ [key: string]: TopicFormCustomParam;
|
|
|
|
+}): FlattenedCustomParams => {
|
|
|
|
+ return Object.values(customParams || {}).reduce(
|
|
|
|
+ (result: FlattenedCustomParams, customParam: TopicFormCustomParam) => {
|
|
|
|
+ return {
|
|
|
|
+ ...result,
|
|
|
|
+ [customParam.name]: customParam.value,
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ {} as FlattenedCustomParams
|
|
|
|
+ );
|
|
|
|
+};
|
|
|
|
|
|
export const getTopicConfig = (
|
|
export const getTopicConfig = (
|
|
clusterName: ClusterName,
|
|
clusterName: ClusterName,
|
|
@@ -34,7 +44,7 @@ export const getTopics = (clusterName: ClusterName): Promise<Topic[]> =>
|
|
...BASE_PARAMS,
|
|
...BASE_PARAMS,
|
|
}).then((res) => res.json());
|
|
}).then((res) => res.json());
|
|
|
|
|
|
-interface Result {
|
|
|
|
|
|
+interface FlattenedCustomParams {
|
|
[index: string]: string;
|
|
[index: string]: string;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -53,18 +63,6 @@ export const postTopic = (
|
|
minInSyncReplicas,
|
|
minInSyncReplicas,
|
|
} = form;
|
|
} = form;
|
|
|
|
|
|
- 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,
|
|
partitions,
|
|
partitions,
|
|
@@ -75,15 +73,15 @@ export const postTopic = (
|
|
'retention.bytes': retentionBytes,
|
|
'retention.bytes': retentionBytes,
|
|
'max.message.bytes': maxMessageBytes,
|
|
'max.message.bytes': maxMessageBytes,
|
|
'min.insync.replicas': minInSyncReplicas,
|
|
'min.insync.replicas': minInSyncReplicas,
|
|
- ...customParams,
|
|
|
|
- }
|
|
|
|
|
|
+ ...flattenCustomParams(form.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());
|
|
};
|
|
};
|
|
|
|
|
|
export const patchTopic = (
|
|
export const patchTopic = (
|
|
@@ -109,7 +107,7 @@ export const patchTopic = (
|
|
'retention.bytes': retentionBytes,
|
|
'retention.bytes': retentionBytes,
|
|
'max.message.bytes': maxMessageBytes,
|
|
'max.message.bytes': maxMessageBytes,
|
|
'min.insync.replicas': minInSyncReplicas,
|
|
'min.insync.replicas': minInSyncReplicas,
|
|
- ...customParams,
|
|
|
|
|
|
+ ...flattenCustomParams(customParams),
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
|