|
@@ -32,136 +32,138 @@ export interface FetchTopicsListParams {
|
|
|
perPage?: number;
|
|
|
}
|
|
|
|
|
|
-export const fetchTopicsList = (
|
|
|
- params: FetchTopicsListParams
|
|
|
-): PromiseThunkResult => async (dispatch, getState) => {
|
|
|
- dispatch(actions.fetchTopicsListAction.request());
|
|
|
- try {
|
|
|
- const { topics, pageCount } = await topicsApiClient.getTopics(params);
|
|
|
- const newState = (topics || []).reduce(
|
|
|
- (memo: TopicsState, topic) => ({
|
|
|
- ...memo,
|
|
|
- byName: {
|
|
|
- ...memo.byName,
|
|
|
- [topic.name]: {
|
|
|
- ...memo.byName[topic.name],
|
|
|
- ...topic,
|
|
|
- id: v4(),
|
|
|
+export const fetchTopicsList =
|
|
|
+ (params: FetchTopicsListParams): PromiseThunkResult =>
|
|
|
+ async (dispatch, getState) => {
|
|
|
+ dispatch(actions.fetchTopicsListAction.request());
|
|
|
+ try {
|
|
|
+ const { topics, pageCount } = await topicsApiClient.getTopics(params);
|
|
|
+ const newState = (topics || []).reduce(
|
|
|
+ (memo: TopicsState, topic) => ({
|
|
|
+ ...memo,
|
|
|
+ byName: {
|
|
|
+ ...memo.byName,
|
|
|
+ [topic.name]: {
|
|
|
+ ...memo.byName[topic.name],
|
|
|
+ ...topic,
|
|
|
+ id: v4(),
|
|
|
+ },
|
|
|
},
|
|
|
- },
|
|
|
- allNames: [...memo.allNames, topic.name],
|
|
|
- }),
|
|
|
- {
|
|
|
- ...getState().topics,
|
|
|
- allNames: [],
|
|
|
- totalPages: pageCount || 1,
|
|
|
- }
|
|
|
- );
|
|
|
- dispatch(actions.fetchTopicsListAction.success(newState));
|
|
|
- } catch (e) {
|
|
|
- dispatch(actions.fetchTopicsListAction.failure());
|
|
|
- }
|
|
|
-};
|
|
|
+ allNames: [...memo.allNames, topic.name],
|
|
|
+ }),
|
|
|
+ {
|
|
|
+ ...getState().topics,
|
|
|
+ allNames: [],
|
|
|
+ totalPages: pageCount || 1,
|
|
|
+ }
|
|
|
+ );
|
|
|
+ dispatch(actions.fetchTopicsListAction.success(newState));
|
|
|
+ } catch (e) {
|
|
|
+ dispatch(actions.fetchTopicsListAction.failure());
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
-export const fetchTopicMessages = (
|
|
|
- clusterName: ClusterName,
|
|
|
- topicName: TopicName,
|
|
|
- queryParams: Partial<TopicMessageQueryParams>
|
|
|
-): PromiseThunkResult => async (dispatch) => {
|
|
|
- dispatch(actions.fetchTopicMessagesAction.request());
|
|
|
- try {
|
|
|
- const messages = await messagesApiClient.getTopicMessages({
|
|
|
- clusterName,
|
|
|
- topicName,
|
|
|
- ...queryParams,
|
|
|
- });
|
|
|
- dispatch(actions.fetchTopicMessagesAction.success(messages));
|
|
|
- } catch (e) {
|
|
|
- dispatch(actions.fetchTopicMessagesAction.failure());
|
|
|
- }
|
|
|
-};
|
|
|
+export const fetchTopicMessages =
|
|
|
+ (
|
|
|
+ clusterName: ClusterName,
|
|
|
+ topicName: TopicName,
|
|
|
+ queryParams: Partial<TopicMessageQueryParams>
|
|
|
+ ): PromiseThunkResult =>
|
|
|
+ async (dispatch) => {
|
|
|
+ dispatch(actions.fetchTopicMessagesAction.request());
|
|
|
+ try {
|
|
|
+ const messages = await messagesApiClient.getTopicMessages({
|
|
|
+ clusterName,
|
|
|
+ topicName,
|
|
|
+ ...queryParams,
|
|
|
+ });
|
|
|
+ dispatch(actions.fetchTopicMessagesAction.success(messages));
|
|
|
+ } catch (e) {
|
|
|
+ dispatch(actions.fetchTopicMessagesAction.failure());
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
-export const clearTopicMessages = (
|
|
|
- clusterName: ClusterName,
|
|
|
- topicName: TopicName,
|
|
|
- partitions?: number[]
|
|
|
-): PromiseThunkResult => async (dispatch) => {
|
|
|
- dispatch(actions.clearMessagesTopicAction.request());
|
|
|
- try {
|
|
|
- await messagesApiClient.deleteTopicMessages({
|
|
|
- clusterName,
|
|
|
- topicName,
|
|
|
- partitions,
|
|
|
- });
|
|
|
- dispatch(actions.clearMessagesTopicAction.success(topicName));
|
|
|
- } catch (e) {
|
|
|
- const response = await getResponse(e);
|
|
|
- const alert: FailurePayload = {
|
|
|
- subject: [clusterName, topicName, partitions].join('-'),
|
|
|
- title: `Clear Topic Messages`,
|
|
|
- response,
|
|
|
- };
|
|
|
- dispatch(actions.clearMessagesTopicAction.failure({ alert }));
|
|
|
- }
|
|
|
-};
|
|
|
+export const clearTopicMessages =
|
|
|
+ (
|
|
|
+ clusterName: ClusterName,
|
|
|
+ topicName: TopicName,
|
|
|
+ partitions?: number[]
|
|
|
+ ): PromiseThunkResult =>
|
|
|
+ async (dispatch) => {
|
|
|
+ dispatch(actions.clearMessagesTopicAction.request());
|
|
|
+ try {
|
|
|
+ await messagesApiClient.deleteTopicMessages({
|
|
|
+ clusterName,
|
|
|
+ topicName,
|
|
|
+ partitions,
|
|
|
+ });
|
|
|
+ dispatch(actions.clearMessagesTopicAction.success(topicName));
|
|
|
+ } catch (e) {
|
|
|
+ const response = await getResponse(e);
|
|
|
+ const alert: FailurePayload = {
|
|
|
+ subject: [clusterName, topicName, partitions].join('-'),
|
|
|
+ title: `Clear Topic Messages`,
|
|
|
+ response,
|
|
|
+ };
|
|
|
+ dispatch(actions.clearMessagesTopicAction.failure({ alert }));
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
-export const fetchTopicDetails = (
|
|
|
- clusterName: ClusterName,
|
|
|
- topicName: TopicName
|
|
|
-): PromiseThunkResult => async (dispatch, getState) => {
|
|
|
- dispatch(actions.fetchTopicDetailsAction.request());
|
|
|
- try {
|
|
|
- const topicDetails = await topicsApiClient.getTopicDetails({
|
|
|
- clusterName,
|
|
|
- topicName,
|
|
|
- });
|
|
|
- const state = getState().topics;
|
|
|
- const newState = {
|
|
|
- ...state,
|
|
|
- byName: {
|
|
|
- ...state.byName,
|
|
|
- [topicName]: {
|
|
|
- ...state.byName[topicName],
|
|
|
- ...topicDetails,
|
|
|
+export const fetchTopicDetails =
|
|
|
+ (clusterName: ClusterName, topicName: TopicName): PromiseThunkResult =>
|
|
|
+ async (dispatch, getState) => {
|
|
|
+ dispatch(actions.fetchTopicDetailsAction.request());
|
|
|
+ try {
|
|
|
+ const topicDetails = await topicsApiClient.getTopicDetails({
|
|
|
+ clusterName,
|
|
|
+ topicName,
|
|
|
+ });
|
|
|
+ const state = getState().topics;
|
|
|
+ const newState = {
|
|
|
+ ...state,
|
|
|
+ byName: {
|
|
|
+ ...state.byName,
|
|
|
+ [topicName]: {
|
|
|
+ ...state.byName[topicName],
|
|
|
+ ...topicDetails,
|
|
|
+ },
|
|
|
},
|
|
|
- },
|
|
|
- };
|
|
|
- dispatch(actions.fetchTopicDetailsAction.success(newState));
|
|
|
- } catch (e) {
|
|
|
- dispatch(actions.fetchTopicDetailsAction.failure());
|
|
|
- }
|
|
|
-};
|
|
|
+ };
|
|
|
+ dispatch(actions.fetchTopicDetailsAction.success(newState));
|
|
|
+ } catch (e) {
|
|
|
+ dispatch(actions.fetchTopicDetailsAction.failure());
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
-export const fetchTopicConfig = (
|
|
|
- clusterName: ClusterName,
|
|
|
- topicName: TopicName
|
|
|
-): PromiseThunkResult => async (dispatch, getState) => {
|
|
|
- dispatch(actions.fetchTopicConfigAction.request());
|
|
|
- try {
|
|
|
- const config = await topicsApiClient.getTopicConfigs({
|
|
|
- clusterName,
|
|
|
- topicName,
|
|
|
- });
|
|
|
+export const fetchTopicConfig =
|
|
|
+ (clusterName: ClusterName, topicName: TopicName): PromiseThunkResult =>
|
|
|
+ async (dispatch, getState) => {
|
|
|
+ dispatch(actions.fetchTopicConfigAction.request());
|
|
|
+ try {
|
|
|
+ const config = await topicsApiClient.getTopicConfigs({
|
|
|
+ clusterName,
|
|
|
+ topicName,
|
|
|
+ });
|
|
|
|
|
|
- const state = getState().topics;
|
|
|
- const newState = {
|
|
|
- ...state,
|
|
|
- byName: {
|
|
|
- ...state.byName,
|
|
|
- [topicName]: {
|
|
|
- ...state.byName[topicName],
|
|
|
- config: config.map((inputConfig) => ({
|
|
|
- ...inputConfig,
|
|
|
- })),
|
|
|
+ const state = getState().topics;
|
|
|
+ const newState = {
|
|
|
+ ...state,
|
|
|
+ byName: {
|
|
|
+ ...state.byName,
|
|
|
+ [topicName]: {
|
|
|
+ ...state.byName[topicName],
|
|
|
+ config: config.map((inputConfig) => ({
|
|
|
+ ...inputConfig,
|
|
|
+ })),
|
|
|
+ },
|
|
|
},
|
|
|
- },
|
|
|
- };
|
|
|
+ };
|
|
|
|
|
|
- dispatch(actions.fetchTopicConfigAction.success(newState));
|
|
|
- } catch (e) {
|
|
|
- dispatch(actions.fetchTopicConfigAction.failure());
|
|
|
- }
|
|
|
-};
|
|
|
+ dispatch(actions.fetchTopicConfigAction.success(newState));
|
|
|
+ } catch (e) {
|
|
|
+ dispatch(actions.fetchTopicConfigAction.failure());
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
const formatTopicCreation = (form: TopicFormDataRaw): TopicCreation => {
|
|
|
const {
|
|
@@ -229,84 +231,84 @@ const formatTopicUpdate = (form: TopicFormDataRaw): TopicUpdate => {
|
|
|
};
|
|
|
};
|
|
|
|
|
|
-export const createTopic = (
|
|
|
- clusterName: ClusterName,
|
|
|
- form: TopicFormDataRaw
|
|
|
-): PromiseThunkResult => async (dispatch, getState) => {
|
|
|
- dispatch(actions.createTopicAction.request());
|
|
|
- try {
|
|
|
- const topic: Topic = await topicsApiClient.createTopic({
|
|
|
- clusterName,
|
|
|
- topicCreation: formatTopicCreation(form),
|
|
|
- });
|
|
|
+export const createTopic =
|
|
|
+ (clusterName: ClusterName, form: TopicFormDataRaw): PromiseThunkResult =>
|
|
|
+ async (dispatch, getState) => {
|
|
|
+ dispatch(actions.createTopicAction.request());
|
|
|
+ try {
|
|
|
+ const topic: Topic = await topicsApiClient.createTopic({
|
|
|
+ clusterName,
|
|
|
+ topicCreation: formatTopicCreation(form),
|
|
|
+ });
|
|
|
|
|
|
- const state = getState().topics;
|
|
|
- const newState = {
|
|
|
- ...state,
|
|
|
- byName: {
|
|
|
- ...state.byName,
|
|
|
- [topic.name]: {
|
|
|
- ...topic,
|
|
|
+ const state = getState().topics;
|
|
|
+ const newState = {
|
|
|
+ ...state,
|
|
|
+ byName: {
|
|
|
+ ...state.byName,
|
|
|
+ [topic.name]: {
|
|
|
+ ...topic,
|
|
|
+ },
|
|
|
},
|
|
|
- },
|
|
|
- allNames: [...state.allNames, topic.name],
|
|
|
- };
|
|
|
+ allNames: [...state.allNames, topic.name],
|
|
|
+ };
|
|
|
|
|
|
- dispatch(actions.createTopicAction.success(newState));
|
|
|
- } catch (error) {
|
|
|
- const response = await getResponse(error);
|
|
|
- const alert: FailurePayload = {
|
|
|
- subject: ['schema', form.name].join('-'),
|
|
|
- title: `Schema ${form.name}`,
|
|
|
- response,
|
|
|
- };
|
|
|
- dispatch(actions.createTopicAction.failure({ alert }));
|
|
|
- }
|
|
|
-};
|
|
|
+ dispatch(actions.createTopicAction.success(newState));
|
|
|
+ } catch (error) {
|
|
|
+ const response = await getResponse(error);
|
|
|
+ const alert: FailurePayload = {
|
|
|
+ subject: ['schema', form.name].join('-'),
|
|
|
+ title: `Schema ${form.name}`,
|
|
|
+ response,
|
|
|
+ };
|
|
|
+ dispatch(actions.createTopicAction.failure({ alert }));
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
-export const updateTopic = (
|
|
|
- clusterName: ClusterName,
|
|
|
- topicName: TopicName,
|
|
|
- form: TopicFormDataRaw
|
|
|
-): PromiseThunkResult => async (dispatch, getState) => {
|
|
|
- dispatch(actions.updateTopicAction.request());
|
|
|
- try {
|
|
|
- const topic: Topic = await topicsApiClient.updateTopic({
|
|
|
- clusterName,
|
|
|
- topicName,
|
|
|
- topicUpdate: formatTopicUpdate(form),
|
|
|
- });
|
|
|
+export const updateTopic =
|
|
|
+ (
|
|
|
+ clusterName: ClusterName,
|
|
|
+ topicName: TopicName,
|
|
|
+ form: TopicFormDataRaw
|
|
|
+ ): PromiseThunkResult =>
|
|
|
+ async (dispatch, getState) => {
|
|
|
+ dispatch(actions.updateTopicAction.request());
|
|
|
+ try {
|
|
|
+ const topic: Topic = await topicsApiClient.updateTopic({
|
|
|
+ clusterName,
|
|
|
+ topicName,
|
|
|
+ topicUpdate: formatTopicUpdate(form),
|
|
|
+ });
|
|
|
|
|
|
- const state = getState().topics;
|
|
|
- const newState = {
|
|
|
- ...state,
|
|
|
- byName: {
|
|
|
- ...state.byName,
|
|
|
- [topic.name]: {
|
|
|
- ...state.byName[topic.name],
|
|
|
- ...topic,
|
|
|
+ const state = getState().topics;
|
|
|
+ const newState = {
|
|
|
+ ...state,
|
|
|
+ byName: {
|
|
|
+ ...state.byName,
|
|
|
+ [topic.name]: {
|
|
|
+ ...state.byName[topic.name],
|
|
|
+ ...topic,
|
|
|
+ },
|
|
|
},
|
|
|
- },
|
|
|
- };
|
|
|
+ };
|
|
|
|
|
|
- dispatch(actions.updateTopicAction.success(newState));
|
|
|
- } catch (e) {
|
|
|
- dispatch(actions.updateTopicAction.failure());
|
|
|
- }
|
|
|
-};
|
|
|
+ dispatch(actions.updateTopicAction.success(newState));
|
|
|
+ } catch (e) {
|
|
|
+ dispatch(actions.updateTopicAction.failure());
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
-export const deleteTopic = (
|
|
|
- clusterName: ClusterName,
|
|
|
- topicName: TopicName
|
|
|
-): PromiseThunkResult => async (dispatch) => {
|
|
|
- dispatch(actions.deleteTopicAction.request());
|
|
|
- try {
|
|
|
- await topicsApiClient.deleteTopic({
|
|
|
- clusterName,
|
|
|
- topicName,
|
|
|
- });
|
|
|
- dispatch(actions.deleteTopicAction.success(topicName));
|
|
|
- } catch (e) {
|
|
|
- dispatch(actions.deleteTopicAction.failure());
|
|
|
- }
|
|
|
-};
|
|
|
+export const deleteTopic =
|
|
|
+ (clusterName: ClusterName, topicName: TopicName): PromiseThunkResult =>
|
|
|
+ async (dispatch) => {
|
|
|
+ dispatch(actions.deleteTopicAction.request());
|
|
|
+ try {
|
|
|
+ await topicsApiClient.deleteTopic({
|
|
|
+ clusterName,
|
|
|
+ topicName,
|
|
|
+ });
|
|
|
+ dispatch(actions.deleteTopicAction.success(topicName));
|
|
|
+ } catch (e) {
|
|
|
+ dispatch(actions.deleteTopicAction.failure());
|
|
|
+ }
|
|
|
+ };
|