Use getType in reducers
This commit is contained in:
parent
44cf449a8f
commit
715b0da3f8
4 changed files with 19 additions and 11 deletions
|
@ -1,5 +1,7 @@
|
||||||
import { Action, BrokersState, ZooKeeperStatus } from 'redux/interfaces';
|
import { Action, BrokersState, ZooKeeperStatus } from 'redux/interfaces';
|
||||||
import { ClusterStats } from 'generated-sources';
|
import { ClusterStats } from 'generated-sources';
|
||||||
|
import { getType } from 'typesafe-actions';
|
||||||
|
import * as actions from 'redux/actions';
|
||||||
|
|
||||||
export const initialState: BrokersState = {
|
export const initialState: BrokersState = {
|
||||||
items: [],
|
items: [],
|
||||||
|
@ -35,14 +37,14 @@ const updateBrokerSegmentSize = (
|
||||||
|
|
||||||
const reducer = (state = initialState, action: Action): BrokersState => {
|
const reducer = (state = initialState, action: Action): BrokersState => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'GET_BROKERS__REQUEST':
|
case getType(actions.fetchBrokersAction.request):
|
||||||
return initialState;
|
return initialState;
|
||||||
case 'GET_BROKERS__SUCCESS':
|
case getType(actions.fetchBrokersAction.success):
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
items: action.payload,
|
items: action.payload,
|
||||||
};
|
};
|
||||||
case 'GET_CLUSTER_STATUS__SUCCESS':
|
case getType(actions.fetchClusterStatsAction.success):
|
||||||
return updateBrokerSegmentSize(state, action.payload);
|
return updateBrokerSegmentSize(state, action.payload);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import { Action } from 'redux/interfaces';
|
import { Action } from 'redux/interfaces';
|
||||||
import { Cluster } from 'generated-sources';
|
import { Cluster } from 'generated-sources';
|
||||||
|
import { getType } from 'typesafe-actions';
|
||||||
|
import * as actions from 'redux/actions';
|
||||||
|
|
||||||
export const initialState: Cluster[] = [];
|
export const initialState: Cluster[] = [];
|
||||||
|
|
||||||
const reducer = (state = initialState, action: Action): Cluster[] => {
|
const reducer = (state = initialState, action: Action): Cluster[] => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'GET_CLUSTERS__SUCCESS':
|
case getType(actions.fetchClusterListAction.success):
|
||||||
return action.payload;
|
return action.payload;
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { Action, ConsumerGroupsState } from 'redux/interfaces';
|
import { Action, ConsumerGroupsState } from 'redux/interfaces';
|
||||||
import { ConsumerGroup } from 'generated-sources';
|
import { ConsumerGroup } from 'generated-sources';
|
||||||
|
import { getType } from 'typesafe-actions';
|
||||||
|
import * as actions from 'redux/actions';
|
||||||
|
|
||||||
export const initialState: ConsumerGroupsState = {
|
export const initialState: ConsumerGroupsState = {
|
||||||
byID: {},
|
byID: {},
|
||||||
|
@ -33,9 +35,9 @@ const updateConsumerGroupsList = (
|
||||||
|
|
||||||
const reducer = (state = initialState, action: Action): ConsumerGroupsState => {
|
const reducer = (state = initialState, action: Action): ConsumerGroupsState => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'GET_CONSUMER_GROUPS__SUCCESS':
|
case getType(actions.fetchConsumerGroupsAction.success):
|
||||||
return updateConsumerGroupsList(state, action.payload);
|
return updateConsumerGroupsList(state, action.payload);
|
||||||
case 'GET_CONSUMER_GROUP_DETAILS__SUCCESS':
|
case getType(actions.fetchConsumerGroupDetailsAction.success):
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
byID: {
|
byID: {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import { Topic, TopicMessage } from 'generated-sources';
|
import { Topic, TopicMessage } from 'generated-sources';
|
||||||
import { Action, TopicsState } from 'redux/interfaces';
|
import { Action, TopicsState } from 'redux/interfaces';
|
||||||
|
import { getType } from 'typesafe-actions';
|
||||||
|
import * as actions from 'redux/actions';
|
||||||
|
|
||||||
export const initialState: TopicsState = {
|
export const initialState: TopicsState = {
|
||||||
byName: {},
|
byName: {},
|
||||||
|
@ -67,9 +69,9 @@ const transformTopicMessages = (
|
||||||
|
|
||||||
const reducer = (state = initialState, action: Action): TopicsState => {
|
const reducer = (state = initialState, action: Action): TopicsState => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'GET_TOPICS__SUCCESS':
|
case getType(actions.fetchTopicsListAction.success):
|
||||||
return updateTopicList(state, action.payload);
|
return updateTopicList(state, action.payload);
|
||||||
case 'GET_TOPIC_DETAILS__SUCCESS':
|
case getType(actions.fetchTopicDetailsAction.success):
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
byName: {
|
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);
|
return transformTopicMessages(state, action.payload);
|
||||||
case 'GET_TOPIC_CONFIG__SUCCESS':
|
case getType(actions.fetchTopicConfigAction.success):
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
byName: {
|
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);
|
return addToTopicList(state, action.payload);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
|
Loading…
Add table
Reference in a new issue