From b60ff8acf698674b4f611abe76776ede3fd0857d Mon Sep 17 00:00:00 2001 From: Alexander Krivonosov <31561808+GneyHabub@users.noreply.github.com> Date: Wed, 12 May 2021 21:10:38 +0300 Subject: [PATCH] Fix linter (#452) --- .../components/Schemas/List/ListContainer.tsx | 5 +- .../src/components/Topics/List/ListItem.tsx | 6 +- .../Topics/Topic/Details/Details.tsx | 6 +- .../Topic/Details/Messages/Messages.tsx | 5 +- .../Form/CustomParams/CustomParamSelect.tsx | 11 +- .../shared/Form/CustomParams/CustomParams.tsx | 12 +- .../src/redux/actions/actions.ts | 5 +- .../src/redux/actions/thunks/brokers.ts | 51 ++- .../src/redux/actions/thunks/clusters.ts | 48 +-- .../redux/actions/thunks/consumerGroups.ts | 71 ++-- .../src/redux/actions/thunks/schemas.ts | 308 +++++++------- .../src/redux/actions/thunks/topics.ts | 394 +++++++++--------- .../src/redux/reducers/topics/selectors.ts | 10 +- .../store/configureStore/mockStoreCreator.ts | 6 +- 14 files changed, 465 insertions(+), 473 deletions(-) diff --git a/kafka-ui-react-app/src/components/Schemas/List/ListContainer.tsx b/kafka-ui-react-app/src/components/Schemas/List/ListContainer.tsx index 1019a1bca3..85b65d016d 100644 --- a/kafka-ui-react-app/src/components/Schemas/List/ListContainer.tsx +++ b/kafka-ui-react-app/src/components/Schemas/List/ListContainer.tsx @@ -18,9 +18,8 @@ const mapStateToProps = (state: RootState) => ({ isFetching: getIsSchemaListFetching(state), schemas: getSchemaList(state), globalSchemaCompatibilityLevel: getGlobalSchemaCompatibilityLevel(state), - isGlobalSchemaCompatibilityLevelFetched: getGlobalSchemaCompatibilityLevelFetched( - state - ), + isGlobalSchemaCompatibilityLevelFetched: + getGlobalSchemaCompatibilityLevelFetched(state), }); const mapDispatchToProps = { diff --git a/kafka-ui-react-app/src/components/Topics/List/ListItem.tsx b/kafka-ui-react-app/src/components/Topics/List/ListItem.tsx index 299e6aa1b9..ca92c22f5a 100644 --- a/kafka-ui-react-app/src/components/Topics/List/ListItem.tsx +++ b/kafka-ui-react-app/src/components/Topics/List/ListItem.tsx @@ -23,10 +23,8 @@ const ListItem: React.FC = ({ clusterName, clearTopicMessages, }) => { - const [ - isDeleteTopicConfirmationVisible, - setDeleteTopicConfirmationVisible, - ] = React.useState(false); + const [isDeleteTopicConfirmationVisible, setDeleteTopicConfirmationVisible] = + React.useState(false); const outOfSyncReplicas = React.useMemo(() => { if (partitions === undefined || partitions.length === 0) { diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Details/Details.tsx b/kafka-ui-react-app/src/components/Topics/Topic/Details/Details.tsx index ab1965250b..62fcca3882 100644 --- a/kafka-ui-react-app/src/components/Topics/Topic/Details/Details.tsx +++ b/kafka-ui-react-app/src/components/Topics/Topic/Details/Details.tsx @@ -33,10 +33,8 @@ const Details: React.FC = ({ }) => { const history = useHistory(); const { isReadOnly } = React.useContext(ClusterContext); - const [ - isDeleteTopicConfirmationVisible, - setDeleteTopicConfirmationVisible, - ] = React.useState(false); + const [isDeleteTopicConfirmationVisible, setDeleteTopicConfirmationVisible] = + React.useState(false); const deleteTopicHandler = React.useCallback(() => { deleteTopic(clusterName, topicName); history.push(clusterTopicsPath(clusterName)); diff --git a/kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/Messages.tsx b/kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/Messages.tsx index fd0d4499f8..034d942c68 100644 --- a/kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/Messages.tsx +++ b/kafka-ui-react-app/src/components/Topics/Topic/Details/Messages/Messages.tsx @@ -50,9 +50,8 @@ const Messages: React.FC = ({ fetchTopicMessages, }) => { const [searchQuery, setSearchQuery] = React.useState(''); - const [searchTimestamp, setSearchTimestamp] = React.useState( - null - ); + const [searchTimestamp, setSearchTimestamp] = + React.useState(null); const [filterProps, setFilterProps] = React.useState([]); const [selectedSeekType, setSelectedSeekType] = React.useState( SeekType.OFFSET diff --git a/kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParamSelect.tsx b/kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParamSelect.tsx index 31965e372b..2eb11cf8b5 100644 --- a/kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParamSelect.tsx +++ b/kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParamSelect.tsx @@ -39,12 +39,11 @@ const CustomParamSelect: React.FC = ({ return valid || 'Custom Parameter must be unique'; }; - const onChange = (inputName: string) => ( - event: React.ChangeEvent - ) => { - trigger(inputName); - onNameChange(index, event.target.value); - }; + const onChange = + (inputName: string) => (event: React.ChangeEvent) => { + trigger(inputName); + onNameChange(index, event.target.value); + }; return ( <> diff --git a/kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParams.tsx b/kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParams.tsx index 570d0154f4..f05e33382a 100644 --- a/kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParams.tsx +++ b/kafka-ui-react-app/src/components/Topics/shared/Form/CustomParams/CustomParams.tsx @@ -35,13 +35,11 @@ const CustomParams: React.FC = ({ isSubmitting, config }) => { ) : {}; - const [ - formCustomParams, - setFormCustomParams, - ] = React.useState({ - byIndex, - allIndexes: Object.keys(byIndex), - }); + const [formCustomParams, setFormCustomParams] = + React.useState({ + byIndex, + allIndexes: Object.keys(byIndex), + }); const onAdd = (event: React.MouseEvent) => { event.preventDefault(); diff --git a/kafka-ui-react-app/src/redux/actions/actions.ts b/kafka-ui-react-app/src/redux/actions/actions.ts index d9d5a08e87..ca5769e81b 100644 --- a/kafka-ui-react-app/src/redux/actions/actions.ts +++ b/kafka-ui-react-app/src/redux/actions/actions.ts @@ -235,9 +235,8 @@ export const updateConnectorConfigAction = createAsyncAction( 'PATCH_CONNECTOR_CONFIG__FAILURE' )(); -export const setTopicsSearchAction = createAction( - 'SET_TOPICS_SEARCH' -)(); +export const setTopicsSearchAction = + createAction('SET_TOPICS_SEARCH')(); export const setTopicsOrderByAction = createAction( 'SET_TOPICS_ORDER_BY' diff --git a/kafka-ui-react-app/src/redux/actions/thunks/brokers.ts b/kafka-ui-react-app/src/redux/actions/thunks/brokers.ts index f698f45c29..025929b08f 100644 --- a/kafka-ui-react-app/src/redux/actions/thunks/brokers.ts +++ b/kafka-ui-react-app/src/redux/actions/thunks/brokers.ts @@ -6,30 +6,29 @@ import * as actions from 'redux/actions/actions'; const apiClientConf = new Configuration(BASE_PARAMS); export const brokersApiClient = new BrokersApi(apiClientConf); -export const fetchBrokers = ( - clusterName: ClusterName -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.fetchBrokersAction.request()); - try { - const payload = await brokersApiClient.getBrokers({ clusterName }); - dispatch(actions.fetchBrokersAction.success(payload)); - } catch (e) { - dispatch(actions.fetchBrokersAction.failure()); - } -}; +export const fetchBrokers = + (clusterName: ClusterName): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.fetchBrokersAction.request()); + try { + const payload = await brokersApiClient.getBrokers({ clusterName }); + dispatch(actions.fetchBrokersAction.success(payload)); + } catch (e) { + dispatch(actions.fetchBrokersAction.failure()); + } + }; -export const fetchBrokerMetrics = ( - clusterName: ClusterName, - brokerId: BrokerId -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.fetchBrokerMetricsAction.request()); - try { - const payload = await brokersApiClient.getBrokersMetrics({ - clusterName, - id: brokerId, - }); - dispatch(actions.fetchBrokerMetricsAction.success(payload)); - } catch (e) { - dispatch(actions.fetchBrokerMetricsAction.failure()); - } -}; +export const fetchBrokerMetrics = + (clusterName: ClusterName, brokerId: BrokerId): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.fetchBrokerMetricsAction.request()); + try { + const payload = await brokersApiClient.getBrokersMetrics({ + clusterName, + id: brokerId, + }); + dispatch(actions.fetchBrokerMetricsAction.success(payload)); + } catch (e) { + dispatch(actions.fetchBrokerMetricsAction.failure()); + } + }; diff --git a/kafka-ui-react-app/src/redux/actions/thunks/clusters.ts b/kafka-ui-react-app/src/redux/actions/thunks/clusters.ts index 996da2b016..14d04b01f8 100644 --- a/kafka-ui-react-app/src/redux/actions/thunks/clusters.ts +++ b/kafka-ui-react-app/src/redux/actions/thunks/clusters.ts @@ -16,28 +16,28 @@ export const fetchClustersList = (): PromiseThunkResult => async (dispatch) => { } }; -export const fetchClusterStats = ( - clusterName: ClusterName -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.fetchClusterStatsAction.request()); - try { - const payload = await clustersApiClient.getClusterStats({ clusterName }); - dispatch(actions.fetchClusterStatsAction.success(payload)); - } catch (e) { - dispatch(actions.fetchClusterStatsAction.failure()); - } -}; +export const fetchClusterStats = + (clusterName: ClusterName): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.fetchClusterStatsAction.request()); + try { + const payload = await clustersApiClient.getClusterStats({ clusterName }); + dispatch(actions.fetchClusterStatsAction.success(payload)); + } catch (e) { + dispatch(actions.fetchClusterStatsAction.failure()); + } + }; -export const fetchClusterMetrics = ( - clusterName: ClusterName -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.fetchClusterMetricsAction.request()); - try { - const payload = await clustersApiClient.getClusterMetrics({ - clusterName, - }); - dispatch(actions.fetchClusterMetricsAction.success(payload)); - } catch (e) { - dispatch(actions.fetchClusterMetricsAction.failure()); - } -}; +export const fetchClusterMetrics = + (clusterName: ClusterName): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.fetchClusterMetricsAction.request()); + try { + const payload = await clustersApiClient.getClusterMetrics({ + clusterName, + }); + dispatch(actions.fetchClusterMetricsAction.success(payload)); + } catch (e) { + dispatch(actions.fetchClusterMetricsAction.failure()); + } + }; diff --git a/kafka-ui-react-app/src/redux/actions/thunks/consumerGroups.ts b/kafka-ui-react-app/src/redux/actions/thunks/consumerGroups.ts index 4a5445cb3b..37ce7b9aed 100644 --- a/kafka-ui-react-app/src/redux/actions/thunks/consumerGroups.ts +++ b/kafka-ui-react-app/src/redux/actions/thunks/consumerGroups.ts @@ -10,39 +10,40 @@ import * as actions from 'redux/actions/actions'; const apiClientConf = new Configuration(BASE_PARAMS); export const consumerGroupsApiClient = new ConsumerGroupsApi(apiClientConf); -export const fetchConsumerGroupsList = ( - clusterName: ClusterName -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.fetchConsumerGroupsAction.request()); - try { - const consumerGroups = await consumerGroupsApiClient.getConsumerGroups({ - clusterName, - }); - dispatch(actions.fetchConsumerGroupsAction.success(consumerGroups)); - } catch (e) { - dispatch(actions.fetchConsumerGroupsAction.failure()); - } -}; - -export const fetchConsumerGroupDetails = ( - clusterName: ClusterName, - consumerGroupID: ConsumerGroupID -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.fetchConsumerGroupDetailsAction.request()); - try { - const consumerGroupDetails = await consumerGroupsApiClient.getConsumerGroup( - { +export const fetchConsumerGroupsList = + (clusterName: ClusterName): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.fetchConsumerGroupsAction.request()); + try { + const consumerGroups = await consumerGroupsApiClient.getConsumerGroups({ clusterName, - id: consumerGroupID, - } - ); - dispatch( - actions.fetchConsumerGroupDetailsAction.success({ - consumerGroupID, - details: consumerGroupDetails, - }) - ); - } catch (e) { - dispatch(actions.fetchConsumerGroupDetailsAction.failure()); - } -}; + }); + dispatch(actions.fetchConsumerGroupsAction.success(consumerGroups)); + } catch (e) { + dispatch(actions.fetchConsumerGroupsAction.failure()); + } + }; + +export const fetchConsumerGroupDetails = + ( + clusterName: ClusterName, + consumerGroupID: ConsumerGroupID + ): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.fetchConsumerGroupDetailsAction.request()); + try { + const consumerGroupDetails = + await consumerGroupsApiClient.getConsumerGroup({ + clusterName, + id: consumerGroupID, + }); + dispatch( + actions.fetchConsumerGroupDetailsAction.success({ + consumerGroupID, + details: consumerGroupDetails, + }) + ); + } catch (e) { + dispatch(actions.fetchConsumerGroupDetailsAction.failure()); + } + }; diff --git a/kafka-ui-react-app/src/redux/actions/thunks/schemas.ts b/kafka-ui-react-app/src/redux/actions/thunks/schemas.ts index bc98688afb..03f1c20960 100644 --- a/kafka-ui-react-app/src/redux/actions/thunks/schemas.ts +++ b/kafka-ui-react-app/src/redux/actions/thunks/schemas.ts @@ -20,160 +20,164 @@ import { isEqual } from 'lodash'; const apiClientConf = new Configuration(BASE_PARAMS); export const schemasApiClient = new SchemasApi(apiClientConf); -export const fetchSchemasByClusterName = ( - clusterName: ClusterName -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.fetchSchemasByClusterNameAction.request()); - try { - const schemas = await schemasApiClient.getSchemas({ clusterName }); - dispatch(actions.fetchSchemasByClusterNameAction.success(schemas)); - } catch (e) { - dispatch(actions.fetchSchemasByClusterNameAction.failure()); - } -}; - -export const fetchSchemaVersions = ( - clusterName: ClusterName, - subject: SchemaName -): PromiseThunkResult => async (dispatch) => { - if (!subject) return; - dispatch(actions.fetchSchemaVersionsAction.request()); - try { - const versions = await schemasApiClient.getAllVersionsBySubject({ - clusterName, - subject, - }); - dispatch(actions.fetchSchemaVersionsAction.success(versions)); - } catch (e) { - dispatch(actions.fetchSchemaVersionsAction.failure()); - } -}; - -export const fetchGlobalSchemaCompatibilityLevel = ( - clusterName: ClusterName -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.fetchGlobalSchemaCompatibilityLevelAction.request()); - try { - const result = await schemasApiClient.getGlobalSchemaCompatibilityLevel({ - clusterName, - }); - dispatch( - actions.fetchGlobalSchemaCompatibilityLevelAction.success( - result.compatibility - ) - ); - } catch (e) { - dispatch(actions.fetchGlobalSchemaCompatibilityLevelAction.failure()); - } -}; - -export const updateGlobalSchemaCompatibilityLevel = ( - clusterName: ClusterName, - compatibilityLevel: CompatibilityLevelCompatibilityEnum -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.updateGlobalSchemaCompatibilityLevelAction.request()); - try { - await schemasApiClient.updateGlobalSchemaCompatibilityLevel({ - clusterName, - compatibilityLevel: { compatibility: compatibilityLevel }, - }); - dispatch( - actions.updateGlobalSchemaCompatibilityLevelAction.success( - compatibilityLevel - ) - ); - } catch (e) { - dispatch(actions.updateGlobalSchemaCompatibilityLevelAction.failure()); - } -}; - -export const createSchema = ( - clusterName: ClusterName, - newSchemaSubject: NewSchemaSubject -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.createSchemaAction.request()); - try { - const schema: SchemaSubject = await schemasApiClient.createNewSchema({ - clusterName, - newSchemaSubject, - }); - dispatch(actions.createSchemaAction.success(schema)); - } catch (error) { - const response = await getResponse(error); - const alert: FailurePayload = { - subject: ['schema', newSchemaSubject.subject].join('-'), - title: `Schema ${newSchemaSubject.subject}`, - response, - }; - dispatch(actions.createSchemaAction.failure({ alert })); - throw error; - } -}; - -export const updateSchema = ( - latestSchema: SchemaSubject, - newSchema: string, - newSchemaType: SchemaType, - newCompatibilityLevel: CompatibilityLevelCompatibilityEnum, - clusterName: string, - subject: string -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.updateSchemaAction.request()); - try { - let schema: SchemaSubject = latestSchema; - if ( - (newSchema && - !isEqual(JSON.parse(latestSchema.schema), JSON.parse(newSchema))) || - newSchemaType !== latestSchema.schemaType - ) { - schema = await schemasApiClient.createNewSchema({ - clusterName, - newSchemaSubject: { - ...latestSchema, - schema: newSchema || latestSchema.schema, - schemaType: newSchemaType || latestSchema.schemaType, - }, - }); +export const fetchSchemasByClusterName = + (clusterName: ClusterName): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.fetchSchemasByClusterNameAction.request()); + try { + const schemas = await schemasApiClient.getSchemas({ clusterName }); + dispatch(actions.fetchSchemasByClusterNameAction.success(schemas)); + } catch (e) { + dispatch(actions.fetchSchemasByClusterNameAction.failure()); } - if (newCompatibilityLevel !== latestSchema.compatibilityLevel) { - await schemasApiClient.updateSchemaCompatibilityLevel({ + }; + +export const fetchSchemaVersions = + (clusterName: ClusterName, subject: SchemaName): PromiseThunkResult => + async (dispatch) => { + if (!subject) return; + dispatch(actions.fetchSchemaVersionsAction.request()); + try { + const versions = await schemasApiClient.getAllVersionsBySubject({ clusterName, subject, - compatibilityLevel: { - compatibility: newCompatibilityLevel, - }, }); + dispatch(actions.fetchSchemaVersionsAction.success(versions)); + } catch (e) { + dispatch(actions.fetchSchemaVersionsAction.failure()); } - actions.updateSchemaAction.success(schema); - } catch (e) { - const response = await getResponse(e); - const alert: FailurePayload = { - subject: ['schema', subject].join('-'), - title: `Schema ${subject}`, - response, - }; - dispatch(actions.updateSchemaAction.failure({ alert })); - throw e; - } -}; -export const deleteSchema = ( - clusterName: ClusterName, - subject: string -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.deleteSchemaAction.request()); - try { - await schemasApiClient.deleteSchema({ - clusterName, - subject, - }); - dispatch(actions.deleteSchemaAction.success(subject)); - } catch (error) { - const response = await getResponse(error); - const alert: FailurePayload = { - subject: ['schema', subject].join('-'), - title: `Schema ${subject}`, - response, - }; - dispatch(actions.deleteSchemaAction.failure({ alert })); - } -}; + }; + +export const fetchGlobalSchemaCompatibilityLevel = + (clusterName: ClusterName): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.fetchGlobalSchemaCompatibilityLevelAction.request()); + try { + const result = await schemasApiClient.getGlobalSchemaCompatibilityLevel({ + clusterName, + }); + dispatch( + actions.fetchGlobalSchemaCompatibilityLevelAction.success( + result.compatibility + ) + ); + } catch (e) { + dispatch(actions.fetchGlobalSchemaCompatibilityLevelAction.failure()); + } + }; + +export const updateGlobalSchemaCompatibilityLevel = + ( + clusterName: ClusterName, + compatibilityLevel: CompatibilityLevelCompatibilityEnum + ): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.updateGlobalSchemaCompatibilityLevelAction.request()); + try { + await schemasApiClient.updateGlobalSchemaCompatibilityLevel({ + clusterName, + compatibilityLevel: { compatibility: compatibilityLevel }, + }); + dispatch( + actions.updateGlobalSchemaCompatibilityLevelAction.success( + compatibilityLevel + ) + ); + } catch (e) { + dispatch(actions.updateGlobalSchemaCompatibilityLevelAction.failure()); + } + }; + +export const createSchema = + ( + clusterName: ClusterName, + newSchemaSubject: NewSchemaSubject + ): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.createSchemaAction.request()); + try { + const schema: SchemaSubject = await schemasApiClient.createNewSchema({ + clusterName, + newSchemaSubject, + }); + dispatch(actions.createSchemaAction.success(schema)); + } catch (error) { + const response = await getResponse(error); + const alert: FailurePayload = { + subject: ['schema', newSchemaSubject.subject].join('-'), + title: `Schema ${newSchemaSubject.subject}`, + response, + }; + dispatch(actions.createSchemaAction.failure({ alert })); + throw error; + } + }; + +export const updateSchema = + ( + latestSchema: SchemaSubject, + newSchema: string, + newSchemaType: SchemaType, + newCompatibilityLevel: CompatibilityLevelCompatibilityEnum, + clusterName: string, + subject: string + ): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.updateSchemaAction.request()); + try { + let schema: SchemaSubject = latestSchema; + if ( + (newSchema && + !isEqual(JSON.parse(latestSchema.schema), JSON.parse(newSchema))) || + newSchemaType !== latestSchema.schemaType + ) { + schema = await schemasApiClient.createNewSchema({ + clusterName, + newSchemaSubject: { + ...latestSchema, + schema: newSchema || latestSchema.schema, + schemaType: newSchemaType || latestSchema.schemaType, + }, + }); + } + if (newCompatibilityLevel !== latestSchema.compatibilityLevel) { + await schemasApiClient.updateSchemaCompatibilityLevel({ + clusterName, + subject, + compatibilityLevel: { + compatibility: newCompatibilityLevel, + }, + }); + } + actions.updateSchemaAction.success(schema); + } catch (e) { + const response = await getResponse(e); + const alert: FailurePayload = { + subject: ['schema', subject].join('-'), + title: `Schema ${subject}`, + response, + }; + dispatch(actions.updateSchemaAction.failure({ alert })); + throw e; + } + }; +export const deleteSchema = + (clusterName: ClusterName, subject: string): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.deleteSchemaAction.request()); + try { + await schemasApiClient.deleteSchema({ + clusterName, + subject, + }); + dispatch(actions.deleteSchemaAction.success(subject)); + } catch (error) { + const response = await getResponse(error); + const alert: FailurePayload = { + subject: ['schema', subject].join('-'), + title: `Schema ${subject}`, + response, + }; + dispatch(actions.deleteSchemaAction.failure({ alert })); + } + }; diff --git a/kafka-ui-react-app/src/redux/actions/thunks/topics.ts b/kafka-ui-react-app/src/redux/actions/thunks/topics.ts index 52409911fc..d47a3cec3a 100644 --- a/kafka-ui-react-app/src/redux/actions/thunks/topics.ts +++ b/kafka-ui-react-app/src/redux/actions/thunks/topics.ts @@ -36,136 +36,138 @@ export interface FetchTopicsListParams { orderBy?: TopicColumnsToSort; } -export const fetchTopicsList = ( - params: FetchTopicsListParams -): PromiseThunkResult => async (dispatch, getState) => { - dispatch(actions.fetchTopicsListAction.request()); - try { - const { topics, pageCount } = await topicsApiClient.getTopics(params); - const newState = (topics || []).reduce( - (memo: TopicsState, topic) => ({ - ...memo, +export const fetchTopicsList = + (params: FetchTopicsListParams): PromiseThunkResult => + async (dispatch, getState) => { + dispatch(actions.fetchTopicsListAction.request()); + try { + const { topics, pageCount } = await topicsApiClient.getTopics(params); + const newState = (topics || []).reduce( + (memo: TopicsState, topic) => ({ + ...memo, + byName: { + ...memo.byName, + [topic.name]: { + ...memo.byName[topic.name], + ...topic, + id: v4(), + }, + }, + allNames: [...memo.allNames, topic.name], + }), + { + ...getState().topics, + allNames: [], + totalPages: pageCount || 1, + } + ); + dispatch(actions.fetchTopicsListAction.success(newState)); + } catch (e) { + dispatch(actions.fetchTopicsListAction.failure()); + } + }; + +export const fetchTopicMessages = + ( + clusterName: ClusterName, + topicName: TopicName, + queryParams: Partial + ): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.fetchTopicMessagesAction.request()); + try { + const messages = await messagesApiClient.getTopicMessages({ + clusterName, + topicName, + ...queryParams, + }); + dispatch(actions.fetchTopicMessagesAction.success(messages)); + } catch (e) { + dispatch(actions.fetchTopicMessagesAction.failure()); + } + }; + +export const clearTopicMessages = + ( + clusterName: ClusterName, + topicName: TopicName, + partitions?: number[] + ): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.clearMessagesTopicAction.request()); + try { + await messagesApiClient.deleteTopicMessages({ + clusterName, + topicName, + partitions, + }); + dispatch(actions.clearMessagesTopicAction.success(topicName)); + } catch (e) { + const response = await getResponse(e); + const alert: FailurePayload = { + subject: [clusterName, topicName, partitions].join('-'), + title: `Clear Topic Messages`, + response, + }; + dispatch(actions.clearMessagesTopicAction.failure({ alert })); + } + }; + +export const fetchTopicDetails = + (clusterName: ClusterName, topicName: TopicName): PromiseThunkResult => + async (dispatch, getState) => { + dispatch(actions.fetchTopicDetailsAction.request()); + try { + const topicDetails = await topicsApiClient.getTopicDetails({ + clusterName, + topicName, + }); + const state = getState().topics; + const newState = { + ...state, byName: { - ...memo.byName, - [topic.name]: { - ...memo.byName[topic.name], - ...topic, - id: v4(), + ...state.byName, + [topicName]: { + ...state.byName[topicName], + ...topicDetails, }, }, - allNames: [...memo.allNames, topic.name], - }), - { - ...getState().topics, - allNames: [], - totalPages: pageCount || 1, - } - ); - dispatch(actions.fetchTopicsListAction.success(newState)); - } catch (e) { - dispatch(actions.fetchTopicsListAction.failure()); - } -}; + }; + dispatch(actions.fetchTopicDetailsAction.success(newState)); + } catch (e) { + dispatch(actions.fetchTopicDetailsAction.failure()); + } + }; -export const fetchTopicMessages = ( - clusterName: ClusterName, - topicName: TopicName, - queryParams: Partial -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.fetchTopicMessagesAction.request()); - try { - const messages = await messagesApiClient.getTopicMessages({ - clusterName, - topicName, - ...queryParams, - }); - dispatch(actions.fetchTopicMessagesAction.success(messages)); - } catch (e) { - dispatch(actions.fetchTopicMessagesAction.failure()); - } -}; +export const fetchTopicConfig = + (clusterName: ClusterName, topicName: TopicName): PromiseThunkResult => + async (dispatch, getState) => { + dispatch(actions.fetchTopicConfigAction.request()); + try { + const config = await topicsApiClient.getTopicConfigs({ + clusterName, + topicName, + }); -export const clearTopicMessages = ( - clusterName: ClusterName, - topicName: TopicName, - partitions?: number[] -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.clearMessagesTopicAction.request()); - try { - await messagesApiClient.deleteTopicMessages({ - clusterName, - topicName, - partitions, - }); - dispatch(actions.clearMessagesTopicAction.success(topicName)); - } catch (e) { - const response = await getResponse(e); - const alert: FailurePayload = { - subject: [clusterName, topicName, partitions].join('-'), - title: `Clear Topic Messages`, - response, - }; - dispatch(actions.clearMessagesTopicAction.failure({ alert })); - } -}; - -export const fetchTopicDetails = ( - clusterName: ClusterName, - topicName: TopicName -): PromiseThunkResult => async (dispatch, getState) => { - dispatch(actions.fetchTopicDetailsAction.request()); - try { - const topicDetails = await topicsApiClient.getTopicDetails({ - clusterName, - topicName, - }); - const state = getState().topics; - const newState = { - ...state, - byName: { - ...state.byName, - [topicName]: { - ...state.byName[topicName], - ...topicDetails, + const state = getState().topics; + const newState = { + ...state, + byName: { + ...state.byName, + [topicName]: { + ...state.byName[topicName], + config: config.map((inputConfig) => ({ + ...inputConfig, + })), + }, }, - }, - }; - dispatch(actions.fetchTopicDetailsAction.success(newState)); - } catch (e) { - dispatch(actions.fetchTopicDetailsAction.failure()); - } -}; + }; -export const fetchTopicConfig = ( - clusterName: ClusterName, - topicName: TopicName -): PromiseThunkResult => async (dispatch, getState) => { - dispatch(actions.fetchTopicConfigAction.request()); - try { - const config = await topicsApiClient.getTopicConfigs({ - clusterName, - topicName, - }); - - const state = getState().topics; - const newState = { - ...state, - byName: { - ...state.byName, - [topicName]: { - ...state.byName[topicName], - config: config.map((inputConfig) => ({ - ...inputConfig, - })), - }, - }, - }; - - dispatch(actions.fetchTopicConfigAction.success(newState)); - } catch (e) { - dispatch(actions.fetchTopicConfigAction.failure()); - } -}; + dispatch(actions.fetchTopicConfigAction.success(newState)); + } catch (e) { + dispatch(actions.fetchTopicConfigAction.failure()); + } + }; const formatTopicCreation = (form: TopicFormDataRaw): TopicCreation => { const { @@ -233,84 +235,84 @@ const formatTopicUpdate = (form: TopicFormDataRaw): TopicUpdate => { }; }; -export const createTopic = ( - clusterName: ClusterName, - form: TopicFormDataRaw -): PromiseThunkResult => async (dispatch, getState) => { - dispatch(actions.createTopicAction.request()); - try { - const topic: Topic = await topicsApiClient.createTopic({ - clusterName, - topicCreation: formatTopicCreation(form), - }); +export const createTopic = + (clusterName: ClusterName, form: TopicFormDataRaw): PromiseThunkResult => + async (dispatch, getState) => { + dispatch(actions.createTopicAction.request()); + try { + const topic: Topic = await topicsApiClient.createTopic({ + clusterName, + topicCreation: formatTopicCreation(form), + }); - const state = getState().topics; - const newState = { - ...state, - byName: { - ...state.byName, - [topic.name]: { - ...topic, + const state = getState().topics; + const newState = { + ...state, + byName: { + ...state.byName, + [topic.name]: { + ...topic, + }, }, - }, - allNames: [...state.allNames, topic.name], - }; + allNames: [...state.allNames, topic.name], + }; - dispatch(actions.createTopicAction.success(newState)); - } catch (error) { - const response = await getResponse(error); - const alert: FailurePayload = { - subject: ['schema', form.name].join('-'), - title: `Schema ${form.name}`, - response, - }; - dispatch(actions.createTopicAction.failure({ alert })); - } -}; + dispatch(actions.createTopicAction.success(newState)); + } catch (error) { + const response = await getResponse(error); + const alert: FailurePayload = { + subject: ['schema', form.name].join('-'), + title: `Schema ${form.name}`, + response, + }; + dispatch(actions.createTopicAction.failure({ alert })); + } + }; -export const updateTopic = ( - clusterName: ClusterName, - topicName: TopicName, - form: TopicFormDataRaw -): PromiseThunkResult => async (dispatch, getState) => { - dispatch(actions.updateTopicAction.request()); - try { - const topic: Topic = await topicsApiClient.updateTopic({ - clusterName, - topicName, - topicUpdate: formatTopicUpdate(form), - }); +export const updateTopic = + ( + clusterName: ClusterName, + topicName: TopicName, + form: TopicFormDataRaw + ): PromiseThunkResult => + async (dispatch, getState) => { + dispatch(actions.updateTopicAction.request()); + try { + const topic: Topic = await topicsApiClient.updateTopic({ + clusterName, + topicName, + topicUpdate: formatTopicUpdate(form), + }); - const state = getState().topics; - const newState = { - ...state, - byName: { - ...state.byName, - [topic.name]: { - ...state.byName[topic.name], - ...topic, + const state = getState().topics; + const newState = { + ...state, + byName: { + ...state.byName, + [topic.name]: { + ...state.byName[topic.name], + ...topic, + }, }, - }, - }; + }; - dispatch(actions.updateTopicAction.success(newState)); - } catch (e) { - dispatch(actions.updateTopicAction.failure()); - } -}; + dispatch(actions.updateTopicAction.success(newState)); + } catch (e) { + dispatch(actions.updateTopicAction.failure()); + } + }; -export const deleteTopic = ( - clusterName: ClusterName, - topicName: TopicName -): PromiseThunkResult => async (dispatch) => { - dispatch(actions.deleteTopicAction.request()); - try { - await topicsApiClient.deleteTopic({ - clusterName, - topicName, - }); - dispatch(actions.deleteTopicAction.success(topicName)); - } catch (e) { - dispatch(actions.deleteTopicAction.failure()); - } -}; +export const deleteTopic = + (clusterName: ClusterName, topicName: TopicName): PromiseThunkResult => + async (dispatch) => { + dispatch(actions.deleteTopicAction.request()); + try { + await topicsApiClient.deleteTopic({ + clusterName, + topicName, + }); + dispatch(actions.deleteTopicAction.success(topicName)); + } catch (e) { + dispatch(actions.deleteTopicAction.failure()); + } + }; diff --git a/kafka-ui-react-app/src/redux/reducers/topics/selectors.ts b/kafka-ui-react-app/src/redux/reducers/topics/selectors.ts index c7084f761d..c5394a4917 100644 --- a/kafka-ui-react-app/src/redux/reducers/topics/selectors.ts +++ b/kafka-ui-react-app/src/redux/reducers/topics/selectors.ts @@ -18,12 +18,10 @@ export const getTopicListTotalPages = (state: RootState) => topicsState(state).totalPages; const getTopicListFetchingStatus = createFetchingSelector('GET_TOPICS'); -const getTopicDetailsFetchingStatus = createFetchingSelector( - 'GET_TOPIC_DETAILS' -); -const getTopicMessagesFetchingStatus = createFetchingSelector( - 'GET_TOPIC_MESSAGES' -); +const getTopicDetailsFetchingStatus = + createFetchingSelector('GET_TOPIC_DETAILS'); +const getTopicMessagesFetchingStatus = + createFetchingSelector('GET_TOPIC_MESSAGES'); const getTopicConfigFetchingStatus = createFetchingSelector('GET_TOPIC_CONFIG'); const getTopicCreationStatus = createFetchingSelector('POST_TOPIC'); const getTopicUpdateStatus = createFetchingSelector('PATCH_TOPIC'); diff --git a/kafka-ui-react-app/src/redux/store/configureStore/mockStoreCreator.ts b/kafka-ui-react-app/src/redux/store/configureStore/mockStoreCreator.ts index 373edbe3a0..9c20ad7f1a 100644 --- a/kafka-ui-react-app/src/redux/store/configureStore/mockStoreCreator.ts +++ b/kafka-ui-react-app/src/redux/store/configureStore/mockStoreCreator.ts @@ -6,9 +6,7 @@ import { RootState, Action } from 'redux/interfaces'; const middlewares: Array = [thunk]; type DispatchExts = ThunkDispatch; -const mockStoreCreator: MockStoreCreator< - RootState, - DispatchExts -> = configureMockStore(middlewares); +const mockStoreCreator: MockStoreCreator = + configureMockStore(middlewares); export default mockStoreCreator();