feature/14-cleanup

This commit is contained in:
Azat Gataullin 2020-04-09 13:31:38 +03:00
parent 1109240169
commit 0e7f75bf21
12 changed files with 9 additions and 113 deletions

View file

@ -1,2 +1,2 @@
# Kafka REST API
REACT_APP_API_URL=http://localhost:3004/api
REACT_APP_API_URL=http://localhost:8080/api

View file

@ -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',
})

View file

@ -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"
}
]

View file

@ -20,9 +20,7 @@ const CustomParamSelect: React.FC<Props> = ({
const optInputName = `${index}[name]`;
React.useEffect(
() => {
if (isFirstParam(index)) { unregister(optInputName) }
},
() => { if (isFirstParam(index)) { unregister(optInputName) } },
);
const selectedMustBeUniq = (selected: string) => {

View file

@ -32,9 +32,7 @@ const CustomParamValue: React.FC<Props> = ({
);
React.useEffect(
() => {
if (isFirstParam(index)) { unregister(valInputName) }
},
() => { if (isFirstParam(index)) { unregister(valInputName) } },
);
return (

View file

@ -39,8 +39,6 @@ const New: React.FC<Props> = ({
);
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

View file

@ -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',
};

View file

@ -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,
)<undefined, Topic[], undefined>();
export const fetchTopicsCustomParamsAction = createAsyncAction(
ActionType.GET_TOPICS_CUSTOM_PARAMS__REQUEST,
ActionType.GET_TOPICS_CUSTOM_PARAMS__SUCCESS,
ActionType.GET_TOPICS_CUSTOM_PARAMS__FAILURE,
)<undefined, TopicCustomParam[], undefined>();
export const fetchTopicDetailsAction = createAsyncAction(
ActionType.GET_TOPIC_DETAILS__REQUEST,
ActionType.GET_TOPIC_DETAILS__SUCCESS,

View file

@ -48,16 +48,6 @@ export const fetchTopicList = (clusterName: ClusterName): PromiseThunk<void> =>
}
};
export const fetchTopicsCustomParams = (clusterName: ClusterName): PromiseThunk<void> => 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<void> => async (dispatch) => {
dispatch(actions.fetchTopicDetailsAction.request());
try {

View file

@ -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<Topic[]> =>
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<TopicCustomParam[]> =>
fetch(`${BASE_URL}/clusters/${clusterName}/topics/custom_params`, { ...BASE_PARAMS })
.then(res => res.json());
export const postTopic = (clusterName: ClusterName, form: TopicFormData): Promise<Topic> => {
const {
name,

View file

@ -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 {

View file

@ -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;
}