Use getType in reducers

This commit is contained in:
Azat Mutigullin 2021-02-19 15:06:43 +03:00 committed by Oleg Shur
parent 44cf449a8f
commit 715b0da3f8
4 changed files with 19 additions and 11 deletions

View file

@ -1,5 +1,7 @@
import { Action, BrokersState, ZooKeeperStatus } from 'redux/interfaces';
import { ClusterStats } from 'generated-sources';
import { getType } from 'typesafe-actions';
import * as actions from 'redux/actions';
export const initialState: BrokersState = {
items: [],
@ -35,14 +37,14 @@ const updateBrokerSegmentSize = (
const reducer = (state = initialState, action: Action): BrokersState => {
switch (action.type) {
case 'GET_BROKERS__REQUEST':
case getType(actions.fetchBrokersAction.request):
return initialState;
case 'GET_BROKERS__SUCCESS':
case getType(actions.fetchBrokersAction.success):
return {
...state,
items: action.payload,
};
case 'GET_CLUSTER_STATUS__SUCCESS':
case getType(actions.fetchClusterStatsAction.success):
return updateBrokerSegmentSize(state, action.payload);
default:
return state;

View file

@ -1,11 +1,13 @@
import { Action } from 'redux/interfaces';
import { Cluster } from 'generated-sources';
import { getType } from 'typesafe-actions';
import * as actions from 'redux/actions';
export const initialState: Cluster[] = [];
const reducer = (state = initialState, action: Action): Cluster[] => {
switch (action.type) {
case 'GET_CLUSTERS__SUCCESS':
case getType(actions.fetchClusterListAction.success):
return action.payload;
default:
return state;

View file

@ -1,5 +1,7 @@
import { Action, ConsumerGroupsState } from 'redux/interfaces';
import { ConsumerGroup } from 'generated-sources';
import { getType } from 'typesafe-actions';
import * as actions from 'redux/actions';
export const initialState: ConsumerGroupsState = {
byID: {},
@ -33,9 +35,9 @@ const updateConsumerGroupsList = (
const reducer = (state = initialState, action: Action): ConsumerGroupsState => {
switch (action.type) {
case 'GET_CONSUMER_GROUPS__SUCCESS':
case getType(actions.fetchConsumerGroupsAction.success):
return updateConsumerGroupsList(state, action.payload);
case 'GET_CONSUMER_GROUP_DETAILS__SUCCESS':
case getType(actions.fetchConsumerGroupDetailsAction.success):
return {
...state,
byID: {

View file

@ -1,6 +1,8 @@
import { v4 } from 'uuid';
import { Topic, TopicMessage } from 'generated-sources';
import { Action, TopicsState } from 'redux/interfaces';
import { getType } from 'typesafe-actions';
import * as actions from 'redux/actions';
export const initialState: TopicsState = {
byName: {},
@ -67,9 +69,9 @@ const transformTopicMessages = (
const reducer = (state = initialState, action: Action): TopicsState => {
switch (action.type) {
case 'GET_TOPICS__SUCCESS':
case getType(actions.fetchTopicsListAction.success):
return updateTopicList(state, action.payload);
case 'GET_TOPIC_DETAILS__SUCCESS':
case getType(actions.fetchTopicDetailsAction.success):
return {
...state,
byName: {
@ -80,9 +82,9 @@ const reducer = (state = initialState, action: Action): TopicsState => {
},
},
};
case 'GET_TOPIC_MESSAGES__SUCCESS':
case getType(actions.fetchTopicMessagesAction.success):
return transformTopicMessages(state, action.payload);
case 'GET_TOPIC_CONFIG__SUCCESS':
case getType(actions.fetchTopicConfigAction.success):
return {
...state,
byName: {
@ -96,7 +98,7 @@ const reducer = (state = initialState, action: Action): TopicsState => {
},
},
};
case 'POST_TOPIC__SUCCESS':
case getType(actions.createTopicAction.success):
return addToTopicList(state, action.payload);
default:
return state;