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
This commit is contained in:
Azat Gataullin 2020-04-28 14:18:22 +03:00 committed by GitHub
parent 5d0b783abb
commit 3c5b46bd76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -8,28 +8,37 @@ import {
TopicFormData,
TopicFormCustomParam,
} 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[]> =>
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 {
[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 {
name,
partitions,
@ -41,10 +50,17 @@ export const postTopic = (clusterName: ClusterName, form: TopicFormData): Promis
minInSyncReplicas,
} = 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({
name,
@ -57,12 +73,12 @@ export const postTopic = (clusterName: ClusterName, form: TopicFormData): Promis
'max.message.bytes': maxMessageBytes,
'min.insync.replicas': minInSyncReplicas,
...customParams,
}
},
});
return fetch(`${BASE_URL}/clusters/${clusterName}/topics`, {
...BASE_PARAMS,
method: 'POST',
body,
}).then(res => res.json());
}).then((res) => res.json());
};