From 0e7f75bf2174a6dd3d5abc0b56df619a6f694e86 Mon Sep 17 00:00:00 2001 From: Azat Gataullin Date: Thu, 9 Apr 2020 13:31:38 +0300 Subject: [PATCH] feature/14-cleanup --- kafka-ui-react-app/.env | 2 +- kafka-ui-react-app/mock/index.js | 3 -- .../mock/payload/topicsCustomParams.json | 32 ------------------- .../New/CustomParams/CustomParamSelect.tsx | 4 +-- .../New/CustomParams/CustomParamValue.tsx | 4 +-- .../src/components/Topics/New/New.tsx | 2 -- kafka-ui-react-app/src/redux/actionType.ts | 6 ---- .../src/redux/actions/actions.ts | 7 ---- .../src/redux/actions/thunks.ts | 10 ------ kafka-ui-react-app/src/redux/api/topics.ts | 6 ---- .../src/redux/interfaces/topic.ts | 20 +++--------- .../src/redux/reducers/topics/reducer.ts | 26 +-------------- 12 files changed, 9 insertions(+), 113 deletions(-) delete mode 100644 kafka-ui-react-app/mock/payload/topicsCustomParams.json diff --git a/kafka-ui-react-app/.env b/kafka-ui-react-app/.env index f52c57a88a..0cb274209b 100644 --- a/kafka-ui-react-app/.env +++ b/kafka-ui-react-app/.env @@ -1,2 +1,2 @@ # Kafka REST API -REACT_APP_API_URL=http://localhost:3004/api +REACT_APP_API_URL=http://localhost:8080/api diff --git a/kafka-ui-react-app/mock/index.js b/kafka-ui-react-app/mock/index.js index cedee52712..8e589dfcdb 100644 --- a/kafka-ui-react-app/mock/index.js +++ b/kafka-ui-react-app/mock/index.js @@ -5,7 +5,6 @@ const brokerMetrics = require('./payload/brokerMetrics.json'); const topics = require('./payload/topics.json'); const topicDetails = require('./payload/topicDetails.json'); const topicConfigs = require('./payload/topicConfigs.json'); -const topicsCustomParams = require('./payload/topicsCustomParams.json'); const db = { clusters, @@ -14,7 +13,6 @@ const db = { topics: topics.map((topic) => ({...topic, id: topic.name})), topicDetails, topicConfigs, - topicsCustomParams, }; const server = jsonServer.create(); const router = jsonServer.router(db); @@ -32,7 +30,6 @@ server.use( jsonServer.rewriter({ '/api/*': '/$1', '/clusters/:clusterName/metrics/broker': '/brokerMetrics/:clusterName', - '/clusters/:clusterName/topics/custom_params': '/topicsCustomParams', '/clusters/:clusterName/topics/:id': '/topicDetails', '/clusters/:clusterName/topics/:id/config': '/topicConfigs', }) diff --git a/kafka-ui-react-app/mock/payload/topicsCustomParams.json b/kafka-ui-react-app/mock/payload/topicsCustomParams.json deleted file mode 100644 index a3b2d342a5..0000000000 --- a/kafka-ui-react-app/mock/payload/topicsCustomParams.json +++ /dev/null @@ -1,32 +0,0 @@ -[ - { - "name": "topic.custom.param.name-1", - "value": "topic.custom.param.value-1", - "defaultValue": "topic.custom.param.defValue-1" - }, - { - "name": "topic.custom.param.name-2", - "value": "topic.custom.param.value-2", - "defaultValue": "topic.custom.param.defValue-2" - }, - { - "name": "topic.custom.param.name-3", - "value": "topic.custom.param.value-3", - "defaultValue": "topic.custom.param.defValue-3" - }, - { - "name": "topic.custom.param.name-4", - "value": "topic.custom.param.value-4", - "defaultValue": "topic.custom.param.defValue-4" - }, - { - "name": "topic.custom.param.name-5", - "value": "topic.custom.param.value-5", - "defaultValue": "topic.custom.param.defValue-5" - }, - { - "name": "topic.custom.param.name-6", - "value": "topic.custom.param.value-6", - "defaultValue": "topic.custom.param.defValue-6" - } -] diff --git a/kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamSelect.tsx b/kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamSelect.tsx index 850430dc08..e25575972f 100644 --- a/kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamSelect.tsx +++ b/kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamSelect.tsx @@ -20,9 +20,7 @@ const CustomParamSelect: React.FC = ({ const optInputName = `${index}[name]`; React.useEffect( - () => { - if (isFirstParam(index)) { unregister(optInputName) } - }, + () => { if (isFirstParam(index)) { unregister(optInputName) } }, ); const selectedMustBeUniq = (selected: string) => { diff --git a/kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamValue.tsx b/kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamValue.tsx index 68f3f40065..a0c90989d5 100644 --- a/kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamValue.tsx +++ b/kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamValue.tsx @@ -32,9 +32,7 @@ const CustomParamValue: React.FC = ({ ); React.useEffect( - () => { - if (isFirstParam(index)) { unregister(valInputName) } - }, + () => { if (isFirstParam(index)) { unregister(valInputName) } }, ); return ( diff --git a/kafka-ui-react-app/src/components/Topics/New/New.tsx b/kafka-ui-react-app/src/components/Topics/New/New.tsx index 373caad2fd..942c6d168c 100644 --- a/kafka-ui-react-app/src/components/Topics/New/New.tsx +++ b/kafka-ui-react-app/src/components/Topics/New/New.tsx @@ -39,8 +39,6 @@ const New: React.FC = ({ ); const onSubmit = async (data: TopicFormData) => { - console.log(data); - //TODO: need to fix loader. After success loading the first time, we won't wait for creation any more, because state is //loaded, and we will try to get entity immediately after pressing the button, and we will receive null //going to object page on the second creation. Resetting loaded state is workaround, need to tweak loader logic diff --git a/kafka-ui-react-app/src/redux/actionType.ts b/kafka-ui-react-app/src/redux/actionType.ts index 10f1167617..a07b08b3ee 100644 --- a/kafka-ui-react-app/src/redux/actionType.ts +++ b/kafka-ui-react-app/src/redux/actionType.ts @@ -23,13 +23,7 @@ export enum ActionType { GET_TOPIC_CONFIG__SUCCESS = 'GET_TOPIC_CONFIG__SUCCESS', GET_TOPIC_CONFIG__FAILURE = 'GET_TOPIC_CONFIG__FAILURE', - GET_TOPICS_CUSTOM_PARAMS__REQUEST = 'GET_TOPICS_CUSTOM_PARAMS__REQUEST', - GET_TOPICS_CUSTOM_PARAMS__SUCCESS = 'GET_TOPICS_CUSTOM_PARAMS__SUCCESS', - GET_TOPICS_CUSTOM_PARAMS__FAILURE = 'GET_TOPICS_CUSTOM_PARAMS__FAILURE', - POST_TOPIC__REQUEST = 'POST_TOPIC__REQUEST', POST_TOPIC__SUCCESS = 'POST_TOPIC__SUCCESS', POST_TOPIC__FAILURE = 'POST_TOPIC__FAILURE', - - ADD_TOPIC_CUSTOM_PARAM = 'ADD_TOPIC_CUSTOM_PARAM', }; diff --git a/kafka-ui-react-app/src/redux/actions/actions.ts b/kafka-ui-react-app/src/redux/actions/actions.ts index 899a05735c..fd4b198a2d 100644 --- a/kafka-ui-react-app/src/redux/actions/actions.ts +++ b/kafka-ui-react-app/src/redux/actions/actions.ts @@ -8,7 +8,6 @@ import { TopicConfig, TopicDetails, TopicName, - TopicCustomParam, } from 'redux/interfaces'; export const fetchBrokersAction = createAsyncAction( @@ -35,12 +34,6 @@ export const fetchTopicListAction = createAsyncAction( ActionType.GET_TOPICS__FAILURE, )(); -export const fetchTopicsCustomParamsAction = createAsyncAction( - ActionType.GET_TOPICS_CUSTOM_PARAMS__REQUEST, - ActionType.GET_TOPICS_CUSTOM_PARAMS__SUCCESS, - ActionType.GET_TOPICS_CUSTOM_PARAMS__FAILURE, -)(); - export const fetchTopicDetailsAction = createAsyncAction( ActionType.GET_TOPIC_DETAILS__REQUEST, ActionType.GET_TOPIC_DETAILS__SUCCESS, diff --git a/kafka-ui-react-app/src/redux/actions/thunks.ts b/kafka-ui-react-app/src/redux/actions/thunks.ts index d1a96ec437..c23f43a56d 100644 --- a/kafka-ui-react-app/src/redux/actions/thunks.ts +++ b/kafka-ui-react-app/src/redux/actions/thunks.ts @@ -48,16 +48,6 @@ export const fetchTopicList = (clusterName: ClusterName): PromiseThunk => } }; -export const fetchTopicsCustomParams = (clusterName: ClusterName): PromiseThunk => async (dispatch) => { - dispatch(actions.fetchTopicsCustomParamsAction.request()); - try { - const customParams = await api.getTopicsCustomParams(clusterName); - dispatch(actions.fetchTopicsCustomParamsAction.success(customParams)); - } catch (e) { - dispatch(actions.fetchTopicsCustomParamsAction.failure()); - } -}; - export const fetchTopicDetails = (clusterName: ClusterName, topicName: TopicName): PromiseThunk => async (dispatch) => { dispatch(actions.fetchTopicDetailsAction.request()); try { diff --git a/kafka-ui-react-app/src/redux/api/topics.ts b/kafka-ui-react-app/src/redux/api/topics.ts index ad78602bc6..160c392c9b 100644 --- a/kafka-ui-react-app/src/redux/api/topics.ts +++ b/kafka-ui-react-app/src/redux/api/topics.ts @@ -5,7 +5,6 @@ import { TopicDetails, TopicConfig, TopicFormData, - TopicCustomParam, } from 'redux/interfaces'; import { BASE_URL, @@ -24,11 +23,6 @@ export const getTopics = (clusterName: ClusterName): Promise => fetch(`${BASE_URL}/clusters/${clusterName}/topics`, { ...BASE_PARAMS }) .then(res => res.json()); -// TODO: the url needs to be reconsiled -export const getTopicsCustomParams = (clusterName: ClusterName): Promise => - fetch(`${BASE_URL}/clusters/${clusterName}/topics/custom_params`, { ...BASE_PARAMS }) - .then(res => res.json()); - export const postTopic = (clusterName: ClusterName, form: TopicFormData): Promise => { const { name, diff --git a/kafka-ui-react-app/src/redux/interfaces/topic.ts b/kafka-ui-react-app/src/redux/interfaces/topic.ts index 7d8ab7d243..465c0522fb 100644 --- a/kafka-ui-react-app/src/redux/interfaces/topic.ts +++ b/kafka-ui-react-app/src/redux/interfaces/topic.ts @@ -23,11 +23,6 @@ export interface TopicPartition { replicas: TopicReplica[]; } -// extend from option -export interface TopicCustomParam extends TopicCustomParamOption { - value: string; -} - export interface TopicCustomParamOption { name: string; defaultValue: string; @@ -49,28 +44,23 @@ export interface Topic { partitions: TopicPartition[]; } +export interface TopicFormCustomParam { + name: string; + value: string; +} + export interface TopicFormCustomParams { byIndex: { [paramIndex: string]: TopicFormCustomParam }; allIndexes: string[]; } -export interface TopicFormCustomParam { - name: string, - value: string, -} - export interface TopicWithDetailedInfo extends Topic, TopicDetails { config?: TopicConfig[]; } -export type TopicCustomParamName = string; - export interface TopicsState { byName: { [topicName: string]: TopicWithDetailedInfo }; allNames: TopicName[]; - customParams: { - byName: { [paramName: string]: TopicCustomParam } - }; } export interface TopicFormData { diff --git a/kafka-ui-react-app/src/redux/reducers/topics/reducer.ts b/kafka-ui-react-app/src/redux/reducers/topics/reducer.ts index 441b482835..68c5bdd5e1 100644 --- a/kafka-ui-react-app/src/redux/reducers/topics/reducer.ts +++ b/kafka-ui-react-app/src/redux/reducers/topics/reducer.ts @@ -1,12 +1,9 @@ -import { Action, TopicsState, Topic, TopicCustomParam } from 'redux/interfaces'; +import { Action, TopicsState, Topic } from 'redux/interfaces'; import { ActionType } from 'redux/actionType'; export const initialState: TopicsState = { byName: {}, allNames: [], - customParams: { - byName: {}, - }, }; const updateTopicList = (state: TopicsState, payload: Topic[]): TopicsState => { @@ -30,25 +27,6 @@ const updateTopicList = (state: TopicsState, payload: Topic[]): TopicsState => { ); }; -const setTopicsCustomParams = (state: TopicsState, payload: TopicCustomParam[]): TopicsState => { - const initialMemo: TopicsState = { - ...state, - customParams: { - ...state.customParams, - byName: {}, - } - }; - - return payload.reduce( - (memo: TopicsState, topicCustomParam) => { - memo.customParams.byName[topicCustomParam.name] = topicCustomParam; - - return memo; - }, - initialMemo, - ); -}; - const addToTopicList = (state: TopicsState, payload: Topic): TopicsState => { const newState: TopicsState = { ...state @@ -86,8 +64,6 @@ const reducer = (state = initialState, action: Action): TopicsState => { }; case ActionType.POST_TOPIC__SUCCESS: return addToTopicList(state, action.payload); - case ActionType.GET_TOPICS_CUSTOM_PARAMS__SUCCESS: - return setTopicsCustomParams(state, action.payload); default: return state; }