From 83ce3f7f5ba6519575f024c14d02522dad3f23b9 Mon Sep 17 00:00:00 2001 From: Oleg Shuralev Date: Tue, 4 Feb 2020 09:23:53 +0300 Subject: [PATCH] Update the file structure --- src/components/AppContainer.tsx | 4 +- src/components/Brokers/Brokers.tsx | 2 +- src/components/Brokers/BrokersContainer.ts | 4 +- .../ClustersWidget/ClusterWidget.tsx | 2 +- .../ClustersWidget/ClustersWidget.tsx | 2 +- .../ClustersWidget/ClustersWidgetContainer.ts | 2 +- src/components/Nav/ClusterMenu.tsx | 2 +- src/components/Nav/Nav.tsx | 2 +- src/components/Nav/NavConatiner.ts | 2 +- src/components/Topics/Details/Details.tsx | 2 +- .../Topics/Details/DetailsContainer.ts | 2 +- .../Topics/Details/Messages/Messages.tsx | 2 +- .../Details/Messages/MessagesContainer.ts | 2 +- .../Topics/Details/Overview/Overview.tsx | 2 +- .../Details/Overview/OverviewContainer.ts | 4 +- .../Topics/Details/Settings/Settings.tsx | 2 +- .../Details/Settings/SettingsContainer.ts | 4 +- src/components/Topics/List/List.tsx | 2 +- src/components/Topics/List/ListContainer.ts | 2 +- src/components/Topics/List/ListItem.tsx | 2 +- src/components/Topics/New/New.tsx | 2 +- src/components/Topics/New/NewContainer.ts | 4 +- src/components/Topics/Topics.tsx | 2 +- src/components/Topics/TopicsContainer.ts | 4 +- src/lib/constants.ts | 2 + src/lib/paths.ts | 5 +- src/redux/{reducers/topics => }/actionType.ts | 18 ++++- .../{reducers/topics => actions}/actions.ts | 30 ++++++- src/redux/actions/index.ts | 2 + src/redux/actions/thunks.ts | 79 +++++++++++++++++++ src/{lib => redux}/api/brokers.ts | 2 +- src/{lib => redux}/api/clusters.ts | 2 +- src/{lib => redux}/api/index.ts | 0 src/{lib => redux}/api/topics.ts | 2 +- src/{lib => redux}/interfaces/broker.ts | 0 src/{lib => redux}/interfaces/cluster.ts | 0 src/{lib => redux}/interfaces/index.ts | 6 +- src/{lib => redux}/interfaces/loader.ts | 2 +- src/{lib => redux}/interfaces/topic.ts | 0 src/redux/reducers/actionType.ts | 9 --- src/redux/reducers/brokers/actionType.ts | 11 --- src/redux/reducers/brokers/actions.ts | 15 ---- src/redux/reducers/brokers/reducer.ts | 17 ++-- src/redux/reducers/brokers/selectors.ts | 4 +- src/redux/reducers/brokers/thunks.ts | 27 ------- src/redux/reducers/clusters/actionType.ts | 7 -- src/redux/reducers/clusters/actions.ts | 9 --- src/redux/reducers/clusters/reducer.ts | 6 +- src/redux/reducers/clusters/selectors.ts | 2 +- src/redux/reducers/clusters/thunks.ts | 19 ----- src/redux/reducers/index.ts | 2 +- src/redux/reducers/loader/reducer.ts | 8 +- src/redux/reducers/loader/selectors.ts | 2 +- src/redux/reducers/topics/reducer.ts | 10 +-- src/redux/reducers/topics/selectors.ts | 9 +-- src/redux/reducers/topics/thunks.ts | 54 ------------- 56 files changed, 199 insertions(+), 222 deletions(-) rename src/redux/{reducers/topics => }/actionType.ts (55%) rename src/redux/{reducers/topics => actions}/actions.ts (54%) create mode 100644 src/redux/actions/index.ts create mode 100644 src/redux/actions/thunks.ts rename src/{lib => redux}/api/brokers.ts (94%) rename src/{lib => redux}/api/clusters.ts (88%) rename src/{lib => redux}/api/index.ts (100%) rename src/{lib => redux}/api/topics.ts (98%) rename src/{lib => redux}/interfaces/broker.ts (100%) rename src/{lib => redux}/interfaces/cluster.ts (100%) rename src/{lib => redux}/interfaces/index.ts (71%) rename src/{lib => redux}/interfaces/loader.ts (57%) rename src/{lib => redux}/interfaces/topic.ts (100%) delete mode 100644 src/redux/reducers/actionType.ts delete mode 100644 src/redux/reducers/brokers/actionType.ts delete mode 100644 src/redux/reducers/brokers/actions.ts delete mode 100644 src/redux/reducers/brokers/thunks.ts delete mode 100644 src/redux/reducers/clusters/actionType.ts delete mode 100644 src/redux/reducers/clusters/actions.ts delete mode 100644 src/redux/reducers/clusters/thunks.ts delete mode 100644 src/redux/reducers/topics/thunks.ts diff --git a/src/components/AppContainer.tsx b/src/components/AppContainer.tsx index 0687f08320562335b5b8bb16fa4f98092637e66e..1206fceee1259dd560f53c5f56e476be2872d9a7 100644 --- a/src/components/AppContainer.tsx +++ b/src/components/AppContainer.tsx @@ -1,10 +1,10 @@ import { connect } from 'react-redux'; import { fetchClustersList, -} from 'redux/reducers/clusters/thunks'; +} from 'redux/actions'; import App from './App'; import { getIsClusterListFetched } from 'redux/reducers/clusters/selectors'; -import { RootState } from 'lib/interfaces'; +import { RootState } from 'redux/interfaces'; const mapStateToProps = (state: RootState) => ({ isClusterListFetched: getIsClusterListFetched(state), diff --git a/src/components/Brokers/Brokers.tsx b/src/components/Brokers/Brokers.tsx index bec64cc090356c19c50ee202863f1c7d672966a2..ddad0b610eee8d60547acc8436f1a3dad6401a53 100644 --- a/src/components/Brokers/Brokers.tsx +++ b/src/components/Brokers/Brokers.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { ClusterId, BrokerMetrics, ZooKeeperStatus } from 'lib/interfaces'; +import { ClusterId, BrokerMetrics, ZooKeeperStatus } from 'redux/interfaces'; import useInterval from 'lib/hooks/useInterval'; import formatBytes from 'lib/utils/formatBytes'; import cx from 'classnames'; diff --git a/src/components/Brokers/BrokersContainer.ts b/src/components/Brokers/BrokersContainer.ts index 88ee382893ca5ccc4d185a0520cd83752c49bed4..ec374ca0d392f07bfcc4f5462228897b8ca3558a 100644 --- a/src/components/Brokers/BrokersContainer.ts +++ b/src/components/Brokers/BrokersContainer.ts @@ -2,10 +2,10 @@ import { connect } from 'react-redux'; import { fetchBrokers, fetchBrokerMetrics, -} from 'redux/reducers/brokers/thunks'; +} from 'redux/actions'; import Brokers from './Brokers'; import * as brokerSelectors from 'redux/reducers/brokers/selectors'; -import { RootState, ClusterId } from 'lib/interfaces'; +import { RootState, ClusterId } from 'redux/interfaces'; import { RouteComponentProps } from 'react-router-dom'; interface RouteProps { diff --git a/src/components/Dashboard/ClustersWidget/ClusterWidget.tsx b/src/components/Dashboard/ClustersWidget/ClusterWidget.tsx index 1e0847daeb1b5d41353f9a2ace51a8bc4e7477ae..bc7e8d7851e7824cabd05461420facdb8a32259f 100644 --- a/src/components/Dashboard/ClustersWidget/ClusterWidget.tsx +++ b/src/components/Dashboard/ClustersWidget/ClusterWidget.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Cluster, ClusterStatus } from 'lib/interfaces'; +import { Cluster, ClusterStatus } from 'redux/interfaces'; import formatBytes from 'lib/utils/formatBytes'; import { NavLink } from 'react-router-dom'; import { clusterBrokersPath } from 'lib/paths'; diff --git a/src/components/Dashboard/ClustersWidget/ClustersWidget.tsx b/src/components/Dashboard/ClustersWidget/ClustersWidget.tsx index 0195ed92b5849d77d7f19eaff393e3ab02f0a424..c4f0a5750e810558db0179a3466d458dfd9cbc3a 100644 --- a/src/components/Dashboard/ClustersWidget/ClustersWidget.tsx +++ b/src/components/Dashboard/ClustersWidget/ClustersWidget.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { chunk } from 'lodash'; -import { Cluster } from 'lib/interfaces'; +import { Cluster } from 'redux/interfaces'; import MetricsWrapper from 'components/common/Dashboard/MetricsWrapper'; import Indicator from 'components/common/Dashboard/Indicator'; import ClusterWidget from './ClusterWidget'; diff --git a/src/components/Dashboard/ClustersWidget/ClustersWidgetContainer.ts b/src/components/Dashboard/ClustersWidget/ClustersWidgetContainer.ts index 7111ce4fc7c76aa254ad51c006ac022adab6d9ff..0d5db55eec531f8ba7f4973584f2f5f3c08d3913 100644 --- a/src/components/Dashboard/ClustersWidget/ClustersWidgetContainer.ts +++ b/src/components/Dashboard/ClustersWidget/ClustersWidgetContainer.ts @@ -5,7 +5,7 @@ import { getOnlineClusters, getOfflineClusters, } from 'redux/reducers/clusters/selectors'; -import { RootState } from 'lib/interfaces'; +import { RootState } from 'redux/interfaces'; const mapStateToProps = (state: RootState) => ({ clusters: getClusterList(state), diff --git a/src/components/Nav/ClusterMenu.tsx b/src/components/Nav/ClusterMenu.tsx index 880ceaa7f6c09b83280cca34f3a1de654c893b60..a56615046d1f7cd25f63bace1cf43f4874f9f55d 100644 --- a/src/components/Nav/ClusterMenu.tsx +++ b/src/components/Nav/ClusterMenu.tsx @@ -1,5 +1,5 @@ import React, { CSSProperties } from 'react'; -import { Cluster } from 'lib/interfaces'; +import { Cluster } from 'redux/interfaces'; import { NavLink } from 'react-router-dom'; import { clusterBrokersPath, clusterTopicsPath } from 'lib/paths'; diff --git a/src/components/Nav/Nav.tsx b/src/components/Nav/Nav.tsx index 1d1a2ad6b397c17c8e8f95bcca4a5048f5fc3c99..acd427bc6fa25a816894da0d28ad48cc2a7f05e9 100644 --- a/src/components/Nav/Nav.tsx +++ b/src/components/Nav/Nav.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Cluster } from 'lib/interfaces'; +import { Cluster } from 'redux/interfaces'; import { NavLink } from 'react-router-dom'; import cx from 'classnames'; import ClusterMenu from './ClusterMenu'; diff --git a/src/components/Nav/NavConatiner.ts b/src/components/Nav/NavConatiner.ts index 2ab2a365c38063c2e32f198e54d6f3aa75def566..6cb710ee9fdc4ffa7df763c0b7cc23232c3c4904 100644 --- a/src/components/Nav/NavConatiner.ts +++ b/src/components/Nav/NavConatiner.ts @@ -1,7 +1,7 @@ import { connect } from 'react-redux'; import Nav from './Nav'; import { getIsClusterListFetched, getClusterList } from 'redux/reducers/clusters/selectors'; -import { RootState } from 'lib/interfaces'; +import { RootState } from 'redux/interfaces'; const mapStateToProps = (state: RootState) => ({ isClusterListFetched: getIsClusterListFetched(state), diff --git a/src/components/Topics/Details/Details.tsx b/src/components/Topics/Details/Details.tsx index 1907477d003483dac9e7600f4dac8c57880ee6b9..9069fb49753d19e9b1e7463324ae69a7f5decbe5 100644 --- a/src/components/Topics/Details/Details.tsx +++ b/src/components/Topics/Details/Details.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { ClusterId, Topic, TopicDetails, TopicName } from 'lib/interfaces'; +import { ClusterId, Topic, TopicDetails, TopicName } from 'redux/interfaces'; import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb'; import { NavLink, Switch, Route } from 'react-router-dom'; import { clusterTopicsPath, clusterTopicSettingsPath, clusterTopicPath, clusterTopicMessagesPath } from 'lib/paths'; diff --git a/src/components/Topics/Details/DetailsContainer.ts b/src/components/Topics/Details/DetailsContainer.ts index 3a706ec055acbce540210dfc5fd4cade2b5c9bbd..177ed134dc4e448107fc703403a63bd4ab1a71fd 100644 --- a/src/components/Topics/Details/DetailsContainer.ts +++ b/src/components/Topics/Details/DetailsContainer.ts @@ -1,6 +1,6 @@ import { connect } from 'react-redux'; import Details from './Details'; -import { RootState } from 'lib/interfaces'; +import { RootState } from 'redux/interfaces'; import { withRouter, RouteComponentProps } from 'react-router-dom'; interface RouteProps { diff --git a/src/components/Topics/Details/Messages/Messages.tsx b/src/components/Topics/Details/Messages/Messages.tsx index e9715491db1951d8e6bad985fcb0647d130626f8..a6264e8fb44802c3e5508a31a9d270ff1adada7b 100644 --- a/src/components/Topics/Details/Messages/Messages.tsx +++ b/src/components/Topics/Details/Messages/Messages.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { ClusterId, TopicName } from 'lib/interfaces'; +import { ClusterId, TopicName } from 'redux/interfaces'; interface Props { clusterId: ClusterId; diff --git a/src/components/Topics/Details/Messages/MessagesContainer.ts b/src/components/Topics/Details/Messages/MessagesContainer.ts index a2f0c3aad74c953b3558172e4304ac8cc2349fea..8e3e0a81c008d6b0ab4a39b891d0fddab4d334e4 100644 --- a/src/components/Topics/Details/Messages/MessagesContainer.ts +++ b/src/components/Topics/Details/Messages/MessagesContainer.ts @@ -1,6 +1,6 @@ import { connect } from 'react-redux'; import Messages from './Messages'; -import { RootState } from 'lib/interfaces'; +import { RootState } from 'redux/interfaces'; import { withRouter, RouteComponentProps } from 'react-router-dom'; interface RouteProps { diff --git a/src/components/Topics/Details/Overview/Overview.tsx b/src/components/Topics/Details/Overview/Overview.tsx index a1eed58cf62a468326ce84dc1d4b2a690e5c4ade..c47952867b78d69b9fa5b478291721375a9c9a79 100644 --- a/src/components/Topics/Details/Overview/Overview.tsx +++ b/src/components/Topics/Details/Overview/Overview.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { ClusterId, Topic, TopicDetails, TopicName } from 'lib/interfaces'; +import { ClusterId, Topic, TopicDetails, TopicName } from 'redux/interfaces'; import MetricsWrapper from 'components/common/Dashboard/MetricsWrapper'; import Indicator from 'components/common/Dashboard/Indicator'; diff --git a/src/components/Topics/Details/Overview/OverviewContainer.ts b/src/components/Topics/Details/Overview/OverviewContainer.ts index 2302f244b54a230460419eb2062c2086fa254646..d1912baea482098462b3397055e35c5c49ddbd91 100644 --- a/src/components/Topics/Details/Overview/OverviewContainer.ts +++ b/src/components/Topics/Details/Overview/OverviewContainer.ts @@ -1,9 +1,9 @@ import { connect } from 'react-redux'; import { fetchTopicDetails, -} from 'redux/reducers/topics/thunks'; +} from 'redux/actions'; import Overview from './Overview'; -import { RootState, TopicName, ClusterId } from 'lib/interfaces'; +import { RootState, TopicName, ClusterId } from 'redux/interfaces'; import { getTopicByName, getIsTopicDetailsFetched } from 'redux/reducers/topics/selectors'; import { withRouter, RouteComponentProps } from 'react-router-dom'; diff --git a/src/components/Topics/Details/Settings/Settings.tsx b/src/components/Topics/Details/Settings/Settings.tsx index d07203cffd30facc39568832b6a07a5dfe7be26c..4312649fbfef328fa09031ecaef1aa0ef9f48bca 100644 --- a/src/components/Topics/Details/Settings/Settings.tsx +++ b/src/components/Topics/Details/Settings/Settings.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { ClusterId, TopicName, TopicConfig } from 'lib/interfaces'; +import { ClusterId, TopicName, TopicConfig } from 'redux/interfaces'; interface Props { clusterId: ClusterId; diff --git a/src/components/Topics/Details/Settings/SettingsContainer.ts b/src/components/Topics/Details/Settings/SettingsContainer.ts index e10c0cd293c648a583db8ed2533b9210a5d9f05a..d3108efb39020ec79f1e3678989f167c1becf0d5 100644 --- a/src/components/Topics/Details/Settings/SettingsContainer.ts +++ b/src/components/Topics/Details/Settings/SettingsContainer.ts @@ -1,9 +1,9 @@ import { connect } from 'react-redux'; -import { RootState, ClusterId, TopicName } from 'lib/interfaces'; +import { RootState, ClusterId, TopicName } from 'redux/interfaces'; import { withRouter, RouteComponentProps } from 'react-router-dom'; import { fetchTopicConfig, -} from 'redux/reducers/topics/thunks'; +} from 'redux/actions'; import Settings from './Settings'; import { getTopicConfig, diff --git a/src/components/Topics/List/List.tsx b/src/components/Topics/List/List.tsx index 41b87989546031f59b5f8db54a26e033611ea834..e058dbb102fc2315fbf95072c332e42e24920da7 100644 --- a/src/components/Topics/List/List.tsx +++ b/src/components/Topics/List/List.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { TopicWithDetailedInfo, ClusterId } from 'lib/interfaces'; +import { TopicWithDetailedInfo, ClusterId } from 'redux/interfaces'; import ListItem from './ListItem'; import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb'; import { NavLink } from 'react-router-dom'; diff --git a/src/components/Topics/List/ListContainer.ts b/src/components/Topics/List/ListContainer.ts index 15a348a1d9738402fe0dd25a490373fd5614e4b5..1c6450c510b6e5c0c12f539c400ea4f9ace73af7 100644 --- a/src/components/Topics/List/ListContainer.ts +++ b/src/components/Topics/List/ListContainer.ts @@ -1,5 +1,5 @@ import { connect } from 'react-redux'; -import { RootState } from 'lib/interfaces'; +import { RootState } from 'redux/interfaces'; import { getTopicList, getExternalTopicList } from 'redux/reducers/topics/selectors'; import List from './List'; import { withRouter, RouteComponentProps } from 'react-router-dom'; diff --git a/src/components/Topics/List/ListItem.tsx b/src/components/Topics/List/ListItem.tsx index de0bf42bde707e334744b0ffb403e7a7e0b172f0..a9197877f138e7d873d0d7070b5a591c9cc1cf9e 100644 --- a/src/components/Topics/List/ListItem.tsx +++ b/src/components/Topics/List/ListItem.tsx @@ -1,7 +1,7 @@ import React from 'react'; import cx from 'classnames'; import { NavLink } from 'react-router-dom'; -import { TopicWithDetailedInfo } from 'lib/interfaces'; +import { TopicWithDetailedInfo } from 'redux/interfaces'; const ListItem: React.FC = ({ name, diff --git a/src/components/Topics/New/New.tsx b/src/components/Topics/New/New.tsx index 63d581302e039cf69a60f8b275ecbe521c9b1f7d..0b4a1d5f0fea54848ca2ae58b9ec62624974b37e 100644 --- a/src/components/Topics/New/New.tsx +++ b/src/components/Topics/New/New.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { ClusterId, CleanupPolicy, TopicFormData, TopicName } from 'lib/interfaces'; +import { ClusterId, CleanupPolicy, TopicFormData, TopicName } from 'redux/interfaces'; import Breadcrumb from 'components/common/Breadcrumb/Breadcrumb'; import { clusterTopicsPath } from 'lib/paths'; import { useForm, ErrorMessage } from 'react-hook-form'; diff --git a/src/components/Topics/New/NewContainer.ts b/src/components/Topics/New/NewContainer.ts index 9a006909ac64e004e7780bcd3cedb8005ebb34af..7049d814d19df2f6b8aad68e35f236079213ed41 100644 --- a/src/components/Topics/New/NewContainer.ts +++ b/src/components/Topics/New/NewContainer.ts @@ -1,8 +1,8 @@ import { connect } from 'react-redux'; -import { RootState, ClusterId, TopicFormData, TopicName, Action } from 'lib/interfaces'; +import { RootState, ClusterId, TopicFormData, TopicName, Action } from 'redux/interfaces'; import New from './New'; import { withRouter, RouteComponentProps } from 'react-router-dom'; -import { createTopic } from 'redux/reducers/topics/thunks'; +import { createTopic } from 'redux/actions'; import { getTopicCreated } from 'redux/reducers/topics/selectors'; import { clusterTopicPath } from 'lib/paths'; import { ThunkDispatch } from 'redux-thunk'; diff --git a/src/components/Topics/Topics.tsx b/src/components/Topics/Topics.tsx index d1074575cf984d169740edeba4da773d93e22f5f..3c1131fcf839460dd8b58ac7d06a35f881767fc6 100644 --- a/src/components/Topics/Topics.tsx +++ b/src/components/Topics/Topics.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { ClusterId } from 'lib/interfaces'; +import { ClusterId } from 'redux/interfaces'; import { Switch, Route, diff --git a/src/components/Topics/TopicsContainer.ts b/src/components/Topics/TopicsContainer.ts index 4928366f8df57788cef4ee3cf88ca64483ea1b04..ef09cbd1887ecec3a7f9af4dc857e9d91af2c25c 100644 --- a/src/components/Topics/TopicsContainer.ts +++ b/src/components/Topics/TopicsContainer.ts @@ -1,8 +1,8 @@ import { connect } from 'react-redux'; -import { fetchTopicList } from 'redux/reducers/topics/thunks'; +import { fetchTopicList } from 'redux/actions'; import Topics from './Topics'; import { getIsTopicListFetched } from 'redux/reducers/topics/selectors'; -import { RootState, ClusterId } from 'lib/interfaces'; +import { RootState, ClusterId } from 'redux/interfaces'; import { RouteComponentProps } from 'react-router-dom'; interface RouteProps { diff --git a/src/lib/constants.ts b/src/lib/constants.ts index 8cc6b562be456f6c6481f189e8a75e728c43c703..554de1b02f3d7f86c4535733d9ed837185971a59 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -9,5 +9,7 @@ export const BASE_PARAMS: RequestInit = { export const BASE_URL = process.env.REACT_APP_API_URL; export const TOPIC_NAME_VALIDATION_PATTERN = RegExp(/^[.,A-Za-z0-9_-]+$/); + export const MILLISECONDS_IN_DAY = 86_400_000; + export const BYTES_IN_GB = 1_073_741_824; diff --git a/src/lib/paths.ts b/src/lib/paths.ts index a0eccbb23b989613907ec3d1eeb2beaee490e3fb..ea137f7cb9aecdf0fe7b63d00a44f48bb2cc0bee 100644 --- a/src/lib/paths.ts +++ b/src/lib/paths.ts @@ -1,4 +1,7 @@ -import { ClusterId, TopicName } from 'lib/interfaces'; +import { + ClusterId, + TopicName, +} from 'redux/interfaces'; const clusterPath = (clusterId: ClusterId) => `/clusters/${clusterId}`; diff --git a/src/redux/reducers/topics/actionType.ts b/src/redux/actionType.ts similarity index 55% rename from src/redux/reducers/topics/actionType.ts rename to src/redux/actionType.ts index 29250575c2a175406e3827b4a5ce689b17b80f13..a07b08b3ee723534de8eda637c221a44d5ca67f4 100644 --- a/src/redux/reducers/topics/actionType.ts +++ b/src/redux/actionType.ts @@ -1,4 +1,16 @@ -enum ActionType { +export enum ActionType { + GET_CLUSTERS__REQUEST = 'GET_CLUSTERS__REQUEST', + GET_CLUSTERS__SUCCESS = 'GET_CLUSTERS__SUCCESS', + GET_CLUSTERS__FAILURE = 'GET_CLUSTERS__FAILURE', + + GET_BROKERS__REQUEST = 'GET_BROKERS__REQUEST', + GET_BROKERS__SUCCESS = 'GET_BROKERS__SUCCESS', + GET_BROKERS__FAILURE = 'GET_BROKERS__FAILURE', + + GET_BROKER_METRICS__REQUEST = 'GET_BROKER_METRICS__REQUEST', + GET_BROKER_METRICS__SUCCESS = 'GET_BROKER_METRICS__SUCCESS', + GET_BROKER_METRICS__FAILURE = 'GET_BROKER_METRICS__FAILURE', + GET_TOPICS__REQUEST = 'GET_TOPICS__REQUEST', GET_TOPICS__SUCCESS = 'GET_TOPICS__SUCCESS', GET_TOPICS__FAILURE = 'GET_TOPICS__FAILURE', @@ -14,6 +26,4 @@ enum ActionType { POST_TOPIC__REQUEST = 'POST_TOPIC__REQUEST', POST_TOPIC__SUCCESS = 'POST_TOPIC__SUCCESS', POST_TOPIC__FAILURE = 'POST_TOPIC__FAILURE', -} - -export default ActionType; +}; diff --git a/src/redux/reducers/topics/actions.ts b/src/redux/actions/actions.ts similarity index 54% rename from src/redux/reducers/topics/actions.ts rename to src/redux/actions/actions.ts index 5dc79a350ce066f9eb38c72ae5ed5572b3830079..138231a4ea2135cb814e4aab6bafadae118b4e16 100644 --- a/src/redux/reducers/topics/actions.ts +++ b/src/redux/actions/actions.ts @@ -1,6 +1,32 @@ import { createAsyncAction} from 'typesafe-actions'; -import ActionType from './actionType'; -import { Topic, TopicDetails, TopicName, TopicConfig} from 'lib/interfaces'; +import { ActionType } from 'redux/actionType'; +import { + Broker, + BrokerMetrics, + Cluster, + Topic, + TopicConfig, + TopicDetails, + TopicName, +} from 'redux/interfaces'; + +export const fetchBrokersAction = createAsyncAction( + ActionType.GET_BROKERS__REQUEST, + ActionType.GET_BROKERS__SUCCESS, + ActionType.GET_BROKERS__FAILURE, +)(); + +export const fetchBrokerMetricsAction = createAsyncAction( + ActionType.GET_BROKER_METRICS__REQUEST, + ActionType.GET_BROKER_METRICS__SUCCESS, + ActionType.GET_BROKER_METRICS__FAILURE, +)(); + +export const fetchClusterListAction = createAsyncAction( + ActionType.GET_CLUSTERS__REQUEST, + ActionType.GET_CLUSTERS__SUCCESS, + ActionType.GET_CLUSTERS__FAILURE, +)(); export const fetchTopicListAction = createAsyncAction( ActionType.GET_TOPICS__REQUEST, diff --git a/src/redux/actions/index.ts b/src/redux/actions/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..166f708c81b98d85503685ffbcae433d0990e643 --- /dev/null +++ b/src/redux/actions/index.ts @@ -0,0 +1,2 @@ +export * from './actions'; +export * from './thunks'; diff --git a/src/redux/actions/thunks.ts b/src/redux/actions/thunks.ts new file mode 100644 index 0000000000000000000000000000000000000000..8ce45a817f791d900dfc8b883910a3cedf96cf31 --- /dev/null +++ b/src/redux/actions/thunks.ts @@ -0,0 +1,79 @@ +import * as api from 'redux/api'; +import * as actions from './actions'; +import { + PromiseThunk, + Cluster, + ClusterId, + TopicFormData, + TopicName, +} from 'redux/interfaces'; + +export const fetchBrokers = (clusterId: ClusterId): PromiseThunk => async (dispatch) => { + dispatch(actions.fetchBrokersAction.request()); + try { + const payload = await api.getBrokers(clusterId); + dispatch(actions.fetchBrokersAction.success(payload)); + } catch (e) { + dispatch(actions.fetchBrokersAction.failure()); + } +} + +export const fetchBrokerMetrics = (clusterId: ClusterId): PromiseThunk => async (dispatch) => { + dispatch(actions.fetchBrokerMetricsAction.request()); + try { + const payload = await api.getBrokerMetrics(clusterId); + dispatch(actions.fetchBrokerMetricsAction.success(payload)); + } catch (e) { + dispatch(actions.fetchBrokerMetricsAction.failure()); + } +} + +export const fetchClustersList = (): PromiseThunk => async (dispatch) => { + dispatch(actions.fetchClusterListAction.request()); + try { + const clusters: Cluster[] = await api.getClusters(); + dispatch(actions.fetchClusterListAction.success(clusters)); + } catch (e) { + dispatch(actions.fetchClusterListAction.failure()); + } +} + +export const fetchTopicList = (clusterId: ClusterId): PromiseThunk => async (dispatch) => { + dispatch(actions.fetchTopicListAction.request()); + try { + const topics = await api.getTopics(clusterId); + dispatch(actions.fetchTopicListAction.success(topics)); + } catch (e) { + dispatch(actions.fetchTopicListAction.failure()); + } +} + +export const fetchTopicDetails = (clusterId: ClusterId, topicName: TopicName): PromiseThunk => async (dispatch) => { + dispatch(actions.fetchTopicDetailsAction.request()); + try { + const topicDetails = await api.getTopicDetails(clusterId, topicName); + dispatch(actions.fetchTopicDetailsAction.success({ topicName, details: topicDetails })); + } catch (e) { + dispatch(actions.fetchTopicDetailsAction.failure()); + } +} + +export const fetchTopicConfig = (clusterId: ClusterId, topicName: TopicName): PromiseThunk => async (dispatch) => { + dispatch(actions.fetchTopicConfigAction.request()); + try { + const config = await api.getTopicConfig(clusterId, topicName); + dispatch(actions.fetchTopicConfigAction.success({ topicName, config })); + } catch (e) { + dispatch(actions.fetchTopicConfigAction.failure()); + } +} + +export const createTopic = (clusterId: ClusterId, form: TopicFormData): PromiseThunk => async (dispatch) => { + dispatch(actions.createTopicAction.request()); + try { + await api.postTopic(clusterId, form); + dispatch(actions.createTopicAction.success()); + } catch (e) { + dispatch(actions.createTopicAction.failure()); + } +} diff --git a/src/lib/api/brokers.ts b/src/redux/api/brokers.ts similarity index 94% rename from src/lib/api/brokers.ts rename to src/redux/api/brokers.ts index 3789222936b5392574a5fa64a70ef6eafd15efb6..5ae1f19150dd0d851bd4c905e847d4e6fa0ce3a6 100644 --- a/src/lib/api/brokers.ts +++ b/src/redux/api/brokers.ts @@ -2,7 +2,7 @@ import { Broker, ClusterId, BrokerMetrics, -} from 'lib/interfaces'; +} from 'redux/interfaces'; import { BASE_URL, BASE_PARAMS, diff --git a/src/lib/api/clusters.ts b/src/redux/api/clusters.ts similarity index 88% rename from src/lib/api/clusters.ts rename to src/redux/api/clusters.ts index f4af3b482d6c1dcf74561177756c51732bedfb10..374e8cbe5cd139ef71c479d460edf48a898f609d 100644 --- a/src/lib/api/clusters.ts +++ b/src/redux/api/clusters.ts @@ -1,6 +1,6 @@ import { Cluster, -} from 'lib/interfaces'; +} from 'redux/interfaces'; import { BASE_URL, BASE_PARAMS, diff --git a/src/lib/api/index.ts b/src/redux/api/index.ts similarity index 100% rename from src/lib/api/index.ts rename to src/redux/api/index.ts diff --git a/src/lib/api/topics.ts b/src/redux/api/topics.ts similarity index 98% rename from src/lib/api/topics.ts rename to src/redux/api/topics.ts index 2769b8441d8df4cf7fd50c75b5ad7c62eb050c46..353f99564e88a8dfa9e5e6b7dea389ab385dda28 100644 --- a/src/lib/api/topics.ts +++ b/src/redux/api/topics.ts @@ -5,7 +5,7 @@ import { TopicDetails, TopicConfig, TopicFormData, -} from 'lib/interfaces'; +} from 'redux/interfaces'; import { BASE_URL, BASE_PARAMS, diff --git a/src/lib/interfaces/broker.ts b/src/redux/interfaces/broker.ts similarity index 100% rename from src/lib/interfaces/broker.ts rename to src/redux/interfaces/broker.ts diff --git a/src/lib/interfaces/cluster.ts b/src/redux/interfaces/cluster.ts similarity index 100% rename from src/lib/interfaces/cluster.ts rename to src/redux/interfaces/cluster.ts diff --git a/src/lib/interfaces/index.ts b/src/redux/interfaces/index.ts similarity index 71% rename from src/lib/interfaces/index.ts rename to src/redux/interfaces/index.ts index 62a6f81d247a2c31a284aa3915d6680805c932a4..9878a7d90c52fc423969a1ac1237cfad85376058 100644 --- a/src/lib/interfaces/index.ts +++ b/src/redux/interfaces/index.ts @@ -2,9 +2,7 @@ import { AnyAction } from 'redux'; import { ActionType } from 'typesafe-actions'; import { ThunkAction } from 'redux-thunk'; -import * as topicsActions from 'redux/reducers/topics/actions'; -import * as clustersActions from 'redux/reducers/clusters/actions'; -import * as brokersActions from 'redux/reducers/brokers/actions'; +import * as actions from 'redux/actions/actions'; import { TopicsState } from './topic'; import { Cluster } from './cluster'; @@ -30,6 +28,6 @@ export interface RootState { loader: LoaderState; } -export type Action = ActionType; +export type Action = ActionType; export type PromiseThunk = ThunkAction, RootState, undefined, AnyAction>; diff --git a/src/lib/interfaces/loader.ts b/src/redux/interfaces/loader.ts similarity index 57% rename from src/lib/interfaces/loader.ts rename to src/redux/interfaces/loader.ts index 0ff91468cce3e9369b3f83d11ab6986895ca6faa..df4123c9d697123b2cbf9e850549483130a0f71a 100644 --- a/src/lib/interfaces/loader.ts +++ b/src/redux/interfaces/loader.ts @@ -1,4 +1,4 @@ -import { FetchStatus } from 'lib/interfaces'; +import { FetchStatus } from 'redux/interfaces'; export interface LoaderState { [key: string]: FetchStatus; diff --git a/src/lib/interfaces/topic.ts b/src/redux/interfaces/topic.ts similarity index 100% rename from src/lib/interfaces/topic.ts rename to src/redux/interfaces/topic.ts diff --git a/src/redux/reducers/actionType.ts b/src/redux/reducers/actionType.ts deleted file mode 100644 index 33006ca457550e38dc0f2fbc626e70973c642d6f..0000000000000000000000000000000000000000 --- a/src/redux/reducers/actionType.ts +++ /dev/null @@ -1,9 +0,0 @@ -import topicsActionType from './topics/actionType'; -import clustersActionType from './clusters/actionType'; -import brokersActionType from './brokers/actionType'; - -export default { - ...topicsActionType, - ...clustersActionType, - ...brokersActionType, -}; diff --git a/src/redux/reducers/brokers/actionType.ts b/src/redux/reducers/brokers/actionType.ts deleted file mode 100644 index 075a2f1ed3a9474050b5c5828308624d6e5d79ab..0000000000000000000000000000000000000000 --- a/src/redux/reducers/brokers/actionType.ts +++ /dev/null @@ -1,11 +0,0 @@ -enum ActionType { - GET_BROKERS__REQUEST = 'GET_BROKERS__REQUEST', - GET_BROKERS__SUCCESS = 'GET_BROKERS__SUCCESS', - GET_BROKERS__FAILURE = 'GET_BROKERS__FAILURE', - - GET_BROKER_METRICS__REQUEST = 'GET_BROKER_METRICS__REQUEST', - GET_BROKER_METRICS__SUCCESS = 'GET_BROKER_METRICS__SUCCESS', - GET_BROKER_METRICS__FAILURE = 'GET_BROKER_METRICS__FAILURE', -} - -export default ActionType; diff --git a/src/redux/reducers/brokers/actions.ts b/src/redux/reducers/brokers/actions.ts deleted file mode 100644 index a50af6e28c2ed22ec27284ca4b4d0ea9d8fe458d..0000000000000000000000000000000000000000 --- a/src/redux/reducers/brokers/actions.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { createAsyncAction} from 'typesafe-actions'; -import ActionType from './actionType'; -import { Broker, BrokerMetrics } from 'lib/interfaces'; - -export const fetchBrokersAction = createAsyncAction( - ActionType.GET_BROKERS__REQUEST, - ActionType.GET_BROKERS__SUCCESS, - ActionType.GET_BROKERS__FAILURE, -)(); - -export const fetchBrokerMetricsAction = createAsyncAction( - ActionType.GET_BROKER_METRICS__REQUEST, - ActionType.GET_BROKER_METRICS__SUCCESS, - ActionType.GET_BROKER_METRICS__FAILURE, -)(); diff --git a/src/redux/reducers/brokers/reducer.ts b/src/redux/reducers/brokers/reducer.ts index efd1d9a51bd58c9b74ef3d4cc19ef0a37b53139a..3d73d601940c93dd9fc61a251ccc96a6264180a7 100644 --- a/src/redux/reducers/brokers/reducer.ts +++ b/src/redux/reducers/brokers/reducer.ts @@ -1,5 +1,12 @@ -import { Action, BrokersState, ZooKeeperStatus, BrokerMetrics } from 'lib/interfaces'; -import actionType from 'redux/reducers/actionType'; +import { + Action, + BrokersState, + ZooKeeperStatus, + BrokerMetrics, +} from 'redux/interfaces'; +import { + ActionType, +} from 'redux/actionType'; export const initialState: BrokersState = { items: [], @@ -32,14 +39,14 @@ const updateBrokerSegmentSize = (state: BrokersState, payload: BrokerMetrics) => const reducer = (state = initialState, action: Action): BrokersState => { switch (action.type) { - case actionType.GET_BROKERS__REQUEST: + case ActionType.GET_BROKERS__REQUEST: return initialState; - case actionType.GET_BROKERS__SUCCESS: + case ActionType.GET_BROKERS__SUCCESS: return { ...state, items: action.payload, }; - case actionType.GET_BROKER_METRICS__SUCCESS: + case ActionType.GET_BROKER_METRICS__SUCCESS: return updateBrokerSegmentSize(state, action.payload); default: return state; diff --git a/src/redux/reducers/brokers/selectors.ts b/src/redux/reducers/brokers/selectors.ts index 767a9888188b873d56571565a7ab41554a3b4e4f..71cc116d6fb6b692d1f95f53081b46c8f4cea92f 100644 --- a/src/redux/reducers/brokers/selectors.ts +++ b/src/redux/reducers/brokers/selectors.ts @@ -1,5 +1,5 @@ import { createSelector } from 'reselect'; -import { RootState, FetchStatus, BrokersState } from 'lib/interfaces'; +import { RootState, FetchStatus, BrokersState } from 'redux/interfaces'; import { createFetchingSelector } from 'redux/reducers/loader/selectors'; const brokersState = ({ brokers }: RootState): BrokersState => brokers; @@ -29,7 +29,6 @@ export const getMinDiskUsage = createSelector( if (brokers.length === 0) { return 0; } - return Math.min(...brokers.map(({ segmentSize }) => segmentSize)); }, ); @@ -40,7 +39,6 @@ export const getMaxDiskUsage = createSelector( if (brokers.length === 0) { return 0; } - return Math.max(...brokers.map(({ segmentSize }) => segmentSize)); }, ); diff --git a/src/redux/reducers/brokers/thunks.ts b/src/redux/reducers/brokers/thunks.ts deleted file mode 100644 index 9dd07c3807666f5a1d72197179d0a6f6704f99d9..0000000000000000000000000000000000000000 --- a/src/redux/reducers/brokers/thunks.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { getBrokers, getBrokerMetrics } from 'lib/api'; -import { - fetchBrokersAction, - fetchBrokerMetricsAction, -} from './actions'; -import { PromiseThunk, ClusterId } from 'lib/interfaces'; - - -export const fetchBrokers = (clusterId: ClusterId): PromiseThunk => async (dispatch) => { - dispatch(fetchBrokersAction.request()); - try { - const payload = await getBrokers(clusterId); - dispatch(fetchBrokersAction.success(payload)); - } catch (e) { - dispatch(fetchBrokersAction.failure()); - } -} - -export const fetchBrokerMetrics = (clusterId: ClusterId): PromiseThunk => async (dispatch) => { - dispatch(fetchBrokerMetricsAction.request()); - try { - const payload = await getBrokerMetrics(clusterId); - dispatch(fetchBrokerMetricsAction.success(payload)); - } catch (e) { - dispatch(fetchBrokerMetricsAction.failure()); - } -} diff --git a/src/redux/reducers/clusters/actionType.ts b/src/redux/reducers/clusters/actionType.ts deleted file mode 100644 index e4856edceadec05004a8445d5726df5112beb0fd..0000000000000000000000000000000000000000 --- a/src/redux/reducers/clusters/actionType.ts +++ /dev/null @@ -1,7 +0,0 @@ -enum ActionType { - GET_CLUSTERS__REQUEST = 'GET_CLUSTERS__REQUEST', - GET_CLUSTERS__SUCCESS = 'GET_CLUSTERS__SUCCESS', - GET_CLUSTERS__FAILURE = 'GET_CLUSTERS__FAILURE', -} - -export default ActionType; diff --git a/src/redux/reducers/clusters/actions.ts b/src/redux/reducers/clusters/actions.ts deleted file mode 100644 index 867643aa485b210334f54d96066159d345b6cb1b..0000000000000000000000000000000000000000 --- a/src/redux/reducers/clusters/actions.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { createAsyncAction} from 'typesafe-actions'; -import ActionType from './actionType'; -import { Cluster } from 'lib/interfaces'; - -export const fetchClusterListAction = createAsyncAction( - ActionType.GET_CLUSTERS__REQUEST, - ActionType.GET_CLUSTERS__SUCCESS, - ActionType.GET_CLUSTERS__FAILURE, -)(); diff --git a/src/redux/reducers/clusters/reducer.ts b/src/redux/reducers/clusters/reducer.ts index e6f283b79944d9c87e4a16566bb519b4eb86862c..93dd8fbd53e59e10a94f21699104bd0e6bab0d4a 100644 --- a/src/redux/reducers/clusters/reducer.ts +++ b/src/redux/reducers/clusters/reducer.ts @@ -1,11 +1,11 @@ -import { Cluster, Action } from 'lib/interfaces'; -import actionType from 'redux/reducers/actionType'; +import { Cluster, Action } from 'redux/interfaces'; +import { ActionType } from 'redux/actionType'; export const initialState: Cluster[] = []; const reducer = (state = initialState, action: Action): Cluster[] => { switch (action.type) { - case actionType.GET_CLUSTERS__SUCCESS: + case ActionType.GET_CLUSTERS__SUCCESS: return action.payload; default: return state; diff --git a/src/redux/reducers/clusters/selectors.ts b/src/redux/reducers/clusters/selectors.ts index 2df487f575e5c914ae759d90ebebc18b1965a88e..8ac3c5f0c11706f1304b640324c6b8d566f34328 100644 --- a/src/redux/reducers/clusters/selectors.ts +++ b/src/redux/reducers/clusters/selectors.ts @@ -1,5 +1,5 @@ import { createSelector } from 'reselect'; -import { Cluster, RootState, FetchStatus, ClusterStatus } from 'lib/interfaces'; +import { Cluster, RootState, FetchStatus, ClusterStatus } from 'redux/interfaces'; import { createFetchingSelector } from 'redux/reducers/loader/selectors'; const clustersState = ({ clusters }: RootState): Cluster[] => clusters; diff --git a/src/redux/reducers/clusters/thunks.ts b/src/redux/reducers/clusters/thunks.ts deleted file mode 100644 index 6c281faed482e010693e30fbdc98c47956c97990..0000000000000000000000000000000000000000 --- a/src/redux/reducers/clusters/thunks.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { - getClusters, -} from 'lib/api'; -import { - fetchClusterListAction, -} from './actions'; -import { Cluster, PromiseThunk } from 'lib/interfaces'; - -export const fetchClustersList = (): PromiseThunk => async (dispatch) => { - dispatch(fetchClusterListAction.request()); - - try { - const clusters: Cluster[] = await getClusters(); - - dispatch(fetchClusterListAction.success(clusters)); - } catch (e) { - dispatch(fetchClusterListAction.failure()); - } -} diff --git a/src/redux/reducers/index.ts b/src/redux/reducers/index.ts index c2b6cac28a9c74f122a97cb25f7215145195fb74..babf641ae013b1972efefadc18b15d131398265c 100644 --- a/src/redux/reducers/index.ts +++ b/src/redux/reducers/index.ts @@ -3,7 +3,7 @@ import topics from './topics/reducer'; import clusters from './clusters/reducer'; import brokers from './brokers/reducer'; import loader from './loader/reducer'; -import { RootState } from 'lib/interfaces'; +import { RootState } from 'redux/interfaces'; export default combineReducers({ topics, diff --git a/src/redux/reducers/loader/reducer.ts b/src/redux/reducers/loader/reducer.ts index a60a2eaca5c37b33f3c825844ebae61cf63487be..ccb0722dfea6d90bc6915fe94462224cf5925222 100644 --- a/src/redux/reducers/loader/reducer.ts +++ b/src/redux/reducers/loader/reducer.ts @@ -1,10 +1,14 @@ -import { FetchStatus, Action, LoaderState } from 'lib/interfaces'; +import { + FetchStatus, + Action, + LoaderState, +} from 'redux/interfaces'; export const initialState: LoaderState = {}; const reducer = (state = initialState, action: Action): LoaderState => { const { type } = action; - const matches = /(.*)__(REQUEST|SUCCESS|FAILURE)/.exec(type); + const matches = /(.*)__(REQUEST|SUCCESS|FAILURE)$/.exec(type); // not a *__REQUEST / *__SUCCESS / *__FAILURE actions, so we ignore them if (!matches) return state; diff --git a/src/redux/reducers/loader/selectors.ts b/src/redux/reducers/loader/selectors.ts index 3f43c75609138f04a1d068be13ccf16572601b6b..a6837497fa4019654534c24c1d0b5aad956c561e 100644 --- a/src/redux/reducers/loader/selectors.ts +++ b/src/redux/reducers/loader/selectors.ts @@ -1,4 +1,4 @@ -import { RootState, FetchStatus } from 'lib/interfaces'; +import { RootState, FetchStatus } from 'redux/interfaces'; export const createFetchingSelector = (action: string) => (state: RootState) => (state.loader[action] || FetchStatus.notFetched); diff --git a/src/redux/reducers/topics/reducer.ts b/src/redux/reducers/topics/reducer.ts index f2701da5df14ae6d855dd9bd06f1880867003fa1..4ed0a1fd1f8c63185c056e348d4e82bb6393319e 100644 --- a/src/redux/reducers/topics/reducer.ts +++ b/src/redux/reducers/topics/reducer.ts @@ -1,5 +1,5 @@ -import { Action, TopicsState, Topic } from 'lib/interfaces'; -import actionType from 'redux/reducers/actionType'; +import { Action, TopicsState, Topic } from 'redux/interfaces'; +import { ActionType } from 'redux/actionType'; export const initialState: TopicsState = { byName: {}, @@ -29,9 +29,9 @@ const updateTopicList = (state: TopicsState, payload: Topic[]) => { const reducer = (state = initialState, action: Action): TopicsState => { switch (action.type) { - case actionType.GET_TOPICS__SUCCESS: + case ActionType.GET_TOPICS__SUCCESS: return updateTopicList(state, action.payload); - case actionType.GET_TOPIC_DETAILS__SUCCESS: + case ActionType.GET_TOPIC_DETAILS__SUCCESS: return { ...state, byName: { @@ -42,7 +42,7 @@ const reducer = (state = initialState, action: Action): TopicsState => { } } } - case actionType.GET_TOPIC_CONFIG__SUCCESS: + case ActionType.GET_TOPIC_CONFIG__SUCCESS: return { ...state, byName: { diff --git a/src/redux/reducers/topics/selectors.ts b/src/redux/reducers/topics/selectors.ts index a071f310590b0b5e550f9673ce557c1bfe0d27b5..351d39286ec2dbeb7a00ab919dac1f66473bd0a4 100644 --- a/src/redux/reducers/topics/selectors.ts +++ b/src/redux/reducers/topics/selectors.ts @@ -1,5 +1,5 @@ import { createSelector } from 'reselect'; -import { RootState, TopicName, FetchStatus, TopicsState } from 'lib/interfaces'; +import { RootState, TopicName, FetchStatus, TopicsState } from 'redux/interfaces'; import { createFetchingSelector } from 'redux/reducers/loader/selectors'; const topicsState = ({ topics }: RootState): TopicsState => topics; @@ -37,11 +37,10 @@ export const getTopicList = createSelector( getAllNames, getTopicMap, (isFetched, allNames, byName) => { - if (isFetched) { - return allNames.map((name) => byName[name]) + if (!isFetched) { + return []; } - - return []; + return allNames.map((name) => byName[name]) }, ); diff --git a/src/redux/reducers/topics/thunks.ts b/src/redux/reducers/topics/thunks.ts deleted file mode 100644 index 72c732a835d4f0094ebd37bc33c0d60718c2b5ae..0000000000000000000000000000000000000000 --- a/src/redux/reducers/topics/thunks.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { - getTopics, - getTopicDetails, - getTopicConfig, - postTopic, -} from 'lib/api'; -import { - fetchTopicListAction, - fetchTopicDetailsAction, - fetchTopicConfigAction, - createTopicAction, -} from './actions'; -import { PromiseThunk, ClusterId, TopicName, TopicFormData } from 'lib/interfaces'; - -export const fetchTopicList = (clusterId: ClusterId): PromiseThunk => async (dispatch) => { - dispatch(fetchTopicListAction.request()); - try { - const topics = await getTopics(clusterId); - dispatch(fetchTopicListAction.success(topics)); - } catch (e) { - dispatch(fetchTopicListAction.failure()); - } -} - -export const fetchTopicDetails = (clusterId: ClusterId, topicName: TopicName): PromiseThunk => async (dispatch) => { - dispatch(fetchTopicDetailsAction.request()); - try { - const topicDetails = await getTopicDetails(clusterId, topicName); - dispatch(fetchTopicDetailsAction.success({ topicName, details: topicDetails })); - } catch (e) { - dispatch(fetchTopicDetailsAction.failure()); - } -} - -export const fetchTopicConfig = (clusterId: ClusterId, topicName: TopicName): PromiseThunk => async (dispatch) => { - dispatch(fetchTopicConfigAction.request()); - try { - const config = await getTopicConfig(clusterId, topicName); - dispatch(fetchTopicConfigAction.success({ topicName, config })); - } catch (e) { - dispatch(fetchTopicConfigAction.failure()); - } -} - -export const createTopic = (clusterId: ClusterId, form: TopicFormData): PromiseThunk => async (dispatch) => { - dispatch(createTopicAction.request()); - - try { - await postTopic(clusterId, form); - dispatch(createTopicAction.success()); - } catch (e) { - dispatch(createTopicAction.failure()); - } -}