Skip to content

Commit ddc7845

Browse files
authored
Get rid of redundant enums (#186)
* [CHORE] Get rid of redundant ActionType enum * [CHORE] Get rid of redundant FetchStatus enum * [CHORE] Get rid of redundant CustomParamButtonType enum
1 parent ba4e174 commit ddc7845

File tree

18 files changed

+77
-155
lines changed

18 files changed

+77
-155
lines changed

kafka-ui-react-app/src/components/Topics/Details/Messages/MessagesTable.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
22
import { TopicMessage } from 'generated-sources';
3-
import CustomParamButton, {
4-
CustomParamButtonType,
5-
} from '../../shared/Form/CustomParams/CustomParamButton';
3+
import CustomParamButton from 'components/Topics/shared/Form/CustomParams/CustomParamButton';
64
import MessageItem from './MessageItem';
75

86
interface MessagesTableProp {
@@ -44,7 +42,7 @@ const MessagesTable: React.FC<MessagesTableProp> = ({ messages, onNext }) => {
4442
<div className="column is-full">
4543
<CustomParamButton
4644
className="is-link is-pulled-right"
47-
type={CustomParamButtonType.chevronRight}
45+
type="fa-chevron-right"
4846
onClick={onNext}
4947
btnText="Next"
5048
/>

kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParamAction.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import CustomParamButton, { CustomParamButtonType } from './CustomParamButton';
2+
import CustomParamButton from './CustomParamButton';
33

44
interface Props {
55
index: string;
@@ -11,7 +11,7 @@ const CustomParamAction: React.FC<Props> = ({ index, onRemove }) => (
1111
<label className="label">&nbsp;</label>
1212
<CustomParamButton
1313
className="is-danger"
14-
type={CustomParamButtonType.minus}
14+
type="fa-minus"
1515
onClick={() => onRemove(index)}
1616
/>
1717
</>

kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParamButton.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import React from 'react';
22

3-
export enum CustomParamButtonType {
4-
plus = 'fa-plus',
5-
minus = 'fa-minus',
6-
chevronRight = 'fa-chevron-right',
7-
}
8-
93
interface Props {
104
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
115
className: string;
12-
type: CustomParamButtonType;
6+
type: 'fa-plus' | 'fa-minus' | 'fa-chevron-right';
137
btnText?: string;
148
}
159

kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParams.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
TopicConfigByName,
88
TopicConfigParams,
99
} from 'redux/interfaces';
10-
import CustomParamButton, { CustomParamButtonType } from './CustomParamButton';
10+
import CustomParamButton from './CustomParamButton';
1111
import CustomParamField from './CustomParamField';
1212

1313
export const INDEX_PREFIX = 'customParams';
@@ -79,7 +79,7 @@ const CustomParams: React.FC<Props> = ({ isSubmitting, config }) => {
7979
<div className="column">
8080
<CustomParamButton
8181
className="is-success"
82-
type={CustomParamButtonType.plus}
82+
type="fa-plus"
8383
onClick={onAdd}
8484
btnText="Add Custom Parameter"
8585
/>

kafka-ui-react-app/src/redux/actionType.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

kafka-ui-react-app/src/redux/actions/actions.ts

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createAsyncAction } from 'typesafe-actions';
2-
import ActionType from 'redux/actionType';
32
import { TopicName, ConsumerGroupID } from 'redux/interfaces';
43

54
import {
@@ -17,81 +16,81 @@ import {
1716
} from 'generated-sources';
1817

1918
export const fetchClusterStatsAction = createAsyncAction(
20-
ActionType.GET_CLUSTER_STATS__REQUEST,
21-
ActionType.GET_CLUSTER_STATS__SUCCESS,
22-
ActionType.GET_CLUSTER_STATS__FAILURE
19+
'GET_CLUSTER_STATUS__REQUEST',
20+
'GET_CLUSTER_STATUS__SUCCESS',
21+
'GET_CLUSTER_STATUS__FAILURE'
2322
)<undefined, ClusterStats, undefined>();
2423

2524
export const fetchClusterMetricsAction = createAsyncAction(
26-
ActionType.GET_CLUSTER_METRICS__REQUEST,
27-
ActionType.GET_CLUSTER_METRICS__SUCCESS,
28-
ActionType.GET_CLUSTER_METRICS__FAILURE
25+
'GET_CLUSTER_METRICS__REQUEST',
26+
'GET_CLUSTER_METRICS__SUCCESS',
27+
'GET_CLUSTER_METRICS__FAILURE'
2928
)<undefined, ClusterMetrics, undefined>();
3029

3130
export const fetchBrokersAction = createAsyncAction(
32-
ActionType.GET_BROKERS__REQUEST,
33-
ActionType.GET_BROKERS__SUCCESS,
34-
ActionType.GET_BROKERS__FAILURE
31+
'GET_BROKERS__REQUEST',
32+
'GET_BROKERS__SUCCESS',
33+
'GET_BROKERS__FAILURE'
3534
)<undefined, Broker[], undefined>();
3635

3736
export const fetchBrokerMetricsAction = createAsyncAction(
38-
ActionType.GET_BROKER_METRICS__REQUEST,
39-
ActionType.GET_BROKER_METRICS__SUCCESS,
40-
ActionType.GET_BROKER_METRICS__FAILURE
37+
'GET_BROKER_METRICS__REQUEST',
38+
'GET_BROKER_METRICS__SUCCESS',
39+
'GET_BROKER_METRICS__FAILURE'
4140
)<undefined, BrokerMetrics, undefined>();
4241

4342
export const fetchClusterListAction = createAsyncAction(
44-
ActionType.GET_CLUSTERS__REQUEST,
45-
ActionType.GET_CLUSTERS__SUCCESS,
46-
ActionType.GET_CLUSTERS__FAILURE
43+
'GET_CLUSTERS__REQUEST',
44+
'GET_CLUSTERS__SUCCESS',
45+
'GET_CLUSTERS__FAILURE'
4746
)<undefined, Cluster[], undefined>();
4847

4948
export const fetchTopicsListAction = createAsyncAction(
50-
ActionType.GET_TOPICS__REQUEST,
51-
ActionType.GET_TOPICS__SUCCESS,
52-
ActionType.GET_TOPICS__FAILURE
49+
'GET_TOPICS__REQUEST',
50+
'GET_TOPICS__SUCCESS',
51+
'GET_TOPICS__FAILURE'
5352
)<undefined, Topic[], undefined>();
5453

5554
export const fetchTopicMessagesAction = createAsyncAction(
56-
ActionType.GET_TOPIC_MESSAGES__REQUEST,
57-
ActionType.GET_TOPIC_MESSAGES__SUCCESS,
58-
ActionType.GET_TOPIC_MESSAGES__FAILURE
55+
'GET_TOPIC_MESSAGES__REQUEST',
56+
'GET_TOPIC_MESSAGES__SUCCESS',
57+
'GET_TOPIC_MESSAGES__FAILURE'
5958
)<undefined, TopicMessage[], undefined>();
6059

6160
export const fetchTopicDetailsAction = createAsyncAction(
62-
ActionType.GET_TOPIC_DETAILS__REQUEST,
63-
ActionType.GET_TOPIC_DETAILS__SUCCESS,
64-
ActionType.GET_TOPIC_DETAILS__FAILURE
61+
'GET_TOPIC_DETAILS__REQUEST',
62+
'GET_TOPIC_DETAILS__SUCCESS',
63+
'GET_TOPIC_DETAILS__FAILURE'
6564
)<undefined, { topicName: TopicName; details: TopicDetails }, undefined>();
6665

6766
export const fetchTopicConfigAction = createAsyncAction(
68-
ActionType.GET_TOPIC_CONFIG__REQUEST,
69-
ActionType.GET_TOPIC_CONFIG__SUCCESS,
70-
ActionType.GET_TOPIC_CONFIG__FAILURE
67+
'GET_TOPIC_CONFIG__REQUEST',
68+
'GET_TOPIC_CONFIG__SUCCESS',
69+
'GET_TOPIC_CONFIG__FAILURE'
7170
)<undefined, { topicName: TopicName; config: TopicConfig[] }, undefined>();
7271

7372
export const createTopicAction = createAsyncAction(
74-
ActionType.POST_TOPIC__REQUEST,
75-
ActionType.POST_TOPIC__SUCCESS,
76-
ActionType.POST_TOPIC__FAILURE
73+
'POST_TOPIC__REQUEST',
74+
'POST_TOPIC__SUCCESS',
75+
'POST_TOPIC__FAILURE'
7776
)<undefined, Topic, undefined>();
7877

7978
export const updateTopicAction = createAsyncAction(
80-
ActionType.PATCH_TOPIC__REQUEST,
81-
ActionType.PATCH_TOPIC__SUCCESS,
82-
ActionType.PATCH_TOPIC__FAILURE
79+
'PATCH_TOPIC__REQUEST',
80+
'PATCH_TOPIC__SUCCESS',
81+
'PATCH_TOPIC__FAILURE'
8382
)<undefined, Topic, undefined>();
8483

8584
export const fetchConsumerGroupsAction = createAsyncAction(
86-
ActionType.GET_CONSUMER_GROUPS__REQUEST,
87-
ActionType.GET_CONSUMER_GROUPS__SUCCESS,
88-
ActionType.GET_CONSUMER_GROUPS__FAILURE
85+
'GET_CONSUMER_GROUPS__REQUEST',
86+
'GET_CONSUMER_GROUPS__SUCCESS',
87+
'GET_CONSUMER_GROUPS__FAILURE'
8988
)<undefined, ConsumerGroup[], undefined>();
9089

9190
export const fetchConsumerGroupDetailsAction = createAsyncAction(
92-
ActionType.GET_CONSUMER_GROUP_DETAILS__REQUEST,
93-
ActionType.GET_CONSUMER_GROUP_DETAILS__SUCCESS,
94-
ActionType.GET_CONSUMER_GROUP_DETAILS__FAILURE
91+
'GET_CONSUMER_GROUP_DETAILS__REQUEST',
92+
'GET_CONSUMER_GROUP_DETAILS__SUCCESS',
93+
'GET_CONSUMER_GROUP_DETAILS__FAILURE'
9594
)<
9695
undefined,
9796
{ consumerGroupID: ConsumerGroupID; details: ConsumerGroupDetails },

kafka-ui-react-app/src/redux/interfaces/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ export * from './broker';
1616
export * from './consumerGroup';
1717
export * from './loader';
1818

19-
export enum FetchStatus {
20-
notFetched = 'notFetched',
21-
fetching = 'fetching',
22-
fetched = 'fetched',
23-
errorFetching = 'errorFetching',
24-
}
25-
2619
export interface RootState {
2720
topics: TopicsState;
2821
clusters: ClusterState;
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { FetchStatus } from 'redux/interfaces/index';
2-
31
export interface LoaderState {
4-
[key: string]: FetchStatus;
2+
[key: string]: 'notFetched' | 'fetching' | 'fetched' | 'errorFetching';
53
}

kafka-ui-react-app/src/redux/reducers/brokers/reducer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Action, BrokersState, ZooKeeperStatus } from 'redux/interfaces';
22
import { ClusterStats } from 'generated-sources';
3-
import ActionType from 'redux/actionType';
43

54
export const initialState: BrokersState = {
65
items: [],
@@ -36,14 +35,14 @@ const updateBrokerSegmentSize = (
3635

3736
const reducer = (state = initialState, action: Action): BrokersState => {
3837
switch (action.type) {
39-
case ActionType.GET_BROKERS__REQUEST:
38+
case 'GET_BROKERS__REQUEST':
4039
return initialState;
41-
case ActionType.GET_BROKERS__SUCCESS:
40+
case 'GET_BROKERS__SUCCESS':
4241
return {
4342
...state,
4443
items: action.payload,
4544
};
46-
case ActionType.GET_CLUSTER_STATS__SUCCESS:
45+
case 'GET_CLUSTER_STATUS__SUCCESS':
4746
return updateBrokerSegmentSize(state, action.payload);
4847
default:
4948
return state;

kafka-ui-react-app/src/redux/reducers/brokers/selectors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createSelector } from 'reselect';
2-
import { RootState, FetchStatus, BrokersState } from 'redux/interfaces';
2+
import { RootState, BrokersState } from 'redux/interfaces';
33
import { createFetchingSelector } from 'redux/reducers/loader/selectors';
44

55
const brokersState = ({ brokers }: RootState): BrokersState => brokers;
@@ -8,7 +8,7 @@ const getBrokerListFetchingStatus = createFetchingSelector('GET_BROKERS');
88

99
export const getIsBrokerListFetched = createSelector(
1010
getBrokerListFetchingStatus,
11-
(status) => status === FetchStatus.fetched
11+
(status) => status === 'fetched'
1212
);
1313

1414
export const getBrokerCount = createSelector(

0 commit comments

Comments
 (0)