adding AsyncRequestStatus enum to avoid possible gramatical issues (#2093)

This commit is contained in:
Robert Azizbekyan 2022-06-02 13:33:13 +04:00 committed by GitHub
parent 70d3cee0bf
commit a211c41207
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 56 additions and 49 deletions

View file

@ -10,6 +10,7 @@ import { topicFormValidationSchema } from 'lib/yupExtended';
import PageHeading from 'components/common/PageHeading/PageHeading'; import PageHeading from 'components/common/PageHeading/PageHeading';
import { useAppDispatch } from 'lib/hooks/redux'; import { useAppDispatch } from 'lib/hooks/redux';
import useAppParams from 'lib/hooks/useAppParams'; import useAppParams from 'lib/hooks/useAppParams';
import { AsyncRequestStatus } from 'lib/constants';
enum Filters { enum Filters {
NAME = 'name', NAME = 'name',
@ -41,7 +42,7 @@ const New: React.FC = () => {
const onSubmit = async (data: TopicFormData) => { const onSubmit = async (data: TopicFormData) => {
const { meta } = await dispatch(createTopic({ clusterName, data })); const { meta } = await dispatch(createTopic({ clusterName, data }));
if (meta.requestStatus === 'fulfilled') { if (meta.requestStatus === AsyncRequestStatus.fulfilled) {
navigate(`../${data.name}`); navigate(`../${data.name}`);
} }
}; };

View file

@ -62,3 +62,10 @@ export const GIT_COMMIT = process.env.REACT_APP_COMMIT;
export const BREADCRUMB_DEFINITIONS: BreadcrumbDefinitions = { export const BREADCRUMB_DEFINITIONS: BreadcrumbDefinitions = {
Ksqldb: 'ksqlDB', Ksqldb: 'ksqlDB',
}; };
export enum AsyncRequestStatus {
initial = 'initial',
pending = 'pending',
fulfilled = 'fulfilled',
rejected = 'rejected',
}

View file

@ -1,13 +1,8 @@
import { AsyncRequestStatus } from 'lib/constants';
export interface LoaderState { export interface LoaderState {
[key: string]: 'notFetched' | 'fetching' | 'fetched' | 'errorFetching'; [key: string]: 'notFetched' | 'fetching' | 'fetched' | 'errorFetching';
} }
export type AsyncRequestStatus =
| 'initial'
| 'pending'
| 'fulfilled'
| 'rejected';
export interface LoaderSliceState { export interface LoaderSliceState {
[key: string]: AsyncRequestStatus; [key: string]: AsyncRequestStatus;
} }

View file

@ -10,7 +10,7 @@ import {
ServerStatus, ServerStatus,
ClusterFeaturesEnum, ClusterFeaturesEnum,
} from 'generated-sources'; } from 'generated-sources';
import { BASE_PARAMS } from 'lib/constants'; import { BASE_PARAMS, AsyncRequestStatus } from 'lib/constants';
import { RootState } from 'redux/interfaces'; import { RootState } from 'redux/interfaces';
import { createFetchingSelector } from 'redux/reducers/loader/selectors'; import { createFetchingSelector } from 'redux/reducers/loader/selectors';
@ -41,7 +41,7 @@ const getClusterListFetchingStatus = createFetchingSelector(
); );
export const getAreClustersFulfilled = createSelector( export const getAreClustersFulfilled = createSelector(
getClusterListFetchingStatus, getClusterListFetchingStatus,
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
export const getClusterList = createSelector( export const getClusterList = createSelector(
clustersState, clustersState,

View file

@ -7,6 +7,7 @@ import {
FullConnectorInfo, FullConnectorInfo,
} from 'generated-sources'; } from 'generated-sources';
import { sortBy } from 'lodash'; import { sortBy } from 'lodash';
import { AsyncRequestStatus } from 'lib/constants';
import { import {
deleteConnector, deleteConnector,
@ -27,7 +28,7 @@ const getConnectsFetchingStatus = createFetchingSelector(
); );
export const getAreConnectsFetching = createSelector( export const getAreConnectsFetching = createSelector(
getConnectsFetchingStatus, getConnectsFetchingStatus,
(status) => status === 'pending' (status) => status === AsyncRequestStatus.pending
); );
export const getConnects = createSelector( export const getConnects = createSelector(
@ -40,7 +41,7 @@ const getConnectorsFetchingStatus = createFetchingSelector(
); );
export const getAreConnectorsFetching = createSelector( export const getAreConnectorsFetching = createSelector(
getConnectorsFetchingStatus, getConnectorsFetchingStatus,
(status) => status === 'pending' (status) => status === AsyncRequestStatus.pending
); );
export const getConnectors = createSelector( export const getConnectors = createSelector(
@ -73,7 +74,7 @@ const getConnectorFetchingStatus = createFetchingSelector(
); );
export const getIsConnectorFetching = createSelector( export const getIsConnectorFetching = createSelector(
getConnectorFetchingStatus, getConnectorFetchingStatus,
(status) => status === 'pending' (status) => status === AsyncRequestStatus.pending
); );
const getCurrentConnector = createSelector( const getCurrentConnector = createSelector(
@ -96,7 +97,7 @@ const getConnectorDeletingStatus = createFetchingSelector(
); );
export const getIsConnectorDeleting = createSelector( export const getIsConnectorDeleting = createSelector(
getConnectorDeletingStatus, getConnectorDeletingStatus,
(status) => status === 'pending' (status) => status === AsyncRequestStatus.pending
); );
const getConnectorRestartingStatus = createFetchingSelector( const getConnectorRestartingStatus = createFetchingSelector(
@ -104,7 +105,7 @@ const getConnectorRestartingStatus = createFetchingSelector(
); );
export const getIsConnectorRestarting = createSelector( export const getIsConnectorRestarting = createSelector(
getConnectorRestartingStatus, getConnectorRestartingStatus,
(status) => status === 'pending' (status) => status === AsyncRequestStatus.pending
); );
const getConnectorPausingStatus = createFetchingSelector( const getConnectorPausingStatus = createFetchingSelector(
@ -112,7 +113,7 @@ const getConnectorPausingStatus = createFetchingSelector(
); );
export const getIsConnectorPausing = createSelector( export const getIsConnectorPausing = createSelector(
getConnectorPausingStatus, getConnectorPausingStatus,
(status) => status === 'pending' (status) => status === AsyncRequestStatus.pending
); );
const getConnectorResumingStatus = createFetchingSelector( const getConnectorResumingStatus = createFetchingSelector(
@ -120,7 +121,7 @@ const getConnectorResumingStatus = createFetchingSelector(
); );
export const getIsConnectorResuming = createSelector( export const getIsConnectorResuming = createSelector(
getConnectorResumingStatus, getConnectorResumingStatus,
(status) => status === 'pending' (status) => status === AsyncRequestStatus.pending
); );
export const getIsConnectorActionRunning = createSelector( export const getIsConnectorActionRunning = createSelector(
@ -135,7 +136,7 @@ const getConnectorTasksFetchingStatus = createFetchingSelector(
); );
export const getAreConnectorTasksFetching = createSelector( export const getAreConnectorTasksFetching = createSelector(
getConnectorTasksFetchingStatus, getConnectorTasksFetchingStatus,
(status) => status === 'pending' (status) => status === AsyncRequestStatus.pending
); );
export const getConnectorTasks = createSelector( export const getConnectorTasks = createSelector(
@ -162,7 +163,7 @@ const getConnectorConfigFetchingStatus = createFetchingSelector(
); );
export const getIsConnectorConfigFetching = createSelector( export const getIsConnectorConfigFetching = createSelector(
getConnectorConfigFetchingStatus, getConnectorConfigFetchingStatus,
(status) => status === 'pending' (status) => status === AsyncRequestStatus.pending
); );
export const getConnectorConfig = createSelector( export const getConnectorConfig = createSelector(

View file

@ -13,7 +13,7 @@ import {
ConsumerGroupsPageResponse, ConsumerGroupsPageResponse,
SortOrder, SortOrder,
} from 'generated-sources'; } from 'generated-sources';
import { BASE_PARAMS } from 'lib/constants'; import { BASE_PARAMS, AsyncRequestStatus } from 'lib/constants';
import { getResponse } from 'lib/errorHandling'; import { getResponse } from 'lib/errorHandling';
import { import {
ClusterName, ClusterName,
@ -184,22 +184,22 @@ export const { selectAll, selectById } =
export const getAreConsumerGroupsPagedFulfilled = createSelector( export const getAreConsumerGroupsPagedFulfilled = createSelector(
createFetchingSelector('consumerGroups/fetchConsumerGroupsPaged'), createFetchingSelector('consumerGroups/fetchConsumerGroupsPaged'),
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
export const getIsConsumerGroupDeleted = createSelector( export const getIsConsumerGroupDeleted = createSelector(
createFetchingSelector('consumerGroups/deleteConsumerGroup'), createFetchingSelector('consumerGroups/deleteConsumerGroup'),
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
export const getAreConsumerGroupDetailsFulfilled = createSelector( export const getAreConsumerGroupDetailsFulfilled = createSelector(
createFetchingSelector('consumerGroups/fetchConsumerGroupDetails'), createFetchingSelector('consumerGroups/fetchConsumerGroupDetails'),
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
export const getIsOffsetReseted = createSelector( export const getIsOffsetReseted = createSelector(
createFetchingSelector('consumerGroups/resetConsumerGroupOffsets'), createFetchingSelector('consumerGroups/resetConsumerGroupOffsets'),
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
export const getConsumerGroupsOrderBy = createSelector( export const getConsumerGroupsOrderBy = createSelector(

View file

@ -2,6 +2,7 @@ import { createSelector } from '@reduxjs/toolkit';
import { RootState } from 'redux/interfaces'; import { RootState } from 'redux/interfaces';
import { createFetchingSelector } from 'redux/reducers/loader/selectors'; import { createFetchingSelector } from 'redux/reducers/loader/selectors';
import { KsqlState } from 'redux/interfaces/ksqlDb'; import { KsqlState } from 'redux/interfaces/ksqlDb';
import { AsyncRequestStatus } from 'lib/constants';
const ksqlDbState = ({ ksqlDb }: RootState): KsqlState => ksqlDb; const ksqlDbState = ({ ksqlDb }: RootState): KsqlState => ksqlDb;
@ -15,8 +16,8 @@ export const getKsqlDbTables = createSelector(
[ksqlDbState, getKsqlDbFetchTablesAndStreamsFetchingStatus], [ksqlDbState, getKsqlDbFetchTablesAndStreamsFetchingStatus],
(state, status) => ({ (state, status) => ({
rows: [...state.streams, ...state.tables], rows: [...state.streams, ...state.tables],
fetched: status === 'fulfilled', fetched: status === AsyncRequestStatus.fulfilled,
fetching: status === 'pending', fetching: status === AsyncRequestStatus.pending,
tablesCount: state.tables.length, tablesCount: state.tables.length,
streamsCount: state.streams.length, streamsCount: state.streams.length,
}) })
@ -26,7 +27,7 @@ export const getKsqlExecution = createSelector(
[ksqlDbState, getKsqlExecutionStatus], [ksqlDbState, getKsqlExecutionStatus],
(state, status) => ({ (state, status) => ({
executionResult: state.executionResult, executionResult: state.executionResult,
fetched: status === 'fulfilled', fetched: status === AsyncRequestStatus.fulfilled,
fetching: status === 'pending', fetching: status === AsyncRequestStatus.pending,
}) })
); );

View file

@ -5,7 +5,7 @@ import {
UnknownAsyncThunkRejectedAction, UnknownAsyncThunkRejectedAction,
} from '@reduxjs/toolkit/dist/matchers'; } from '@reduxjs/toolkit/dist/matchers';
import { ClustersApi, Configuration } from 'generated-sources'; import { ClustersApi, Configuration } from 'generated-sources';
import { BASE_PARAMS } from 'lib/constants'; import { BASE_PARAMS, AsyncRequestStatus } from 'lib/constants';
import { LoaderSliceState } from 'redux/interfaces'; import { LoaderSliceState } from 'redux/interfaces';
const apiClientConf = new Configuration(BASE_PARAMS); const apiClientConf = new Configuration(BASE_PARAMS);
@ -30,21 +30,21 @@ export const loaderSlice = createSlice({
(action): action is UnknownAsyncThunkPendingAction => (action): action is UnknownAsyncThunkPendingAction =>
action.type.endsWith('/pending'), action.type.endsWith('/pending'),
(state, { type }) => { (state, { type }) => {
state[type.replace('/pending', '')] = 'pending'; state[type.replace('/pending', '')] = AsyncRequestStatus.pending;
} }
) )
.addMatcher( .addMatcher(
(action): action is UnknownAsyncThunkFulfilledAction => (action): action is UnknownAsyncThunkFulfilledAction =>
action.type.endsWith('/fulfilled'), action.type.endsWith('/fulfilled'),
(state, { type }) => { (state, { type }) => {
state[type.replace('/fulfilled', '')] = 'fulfilled'; state[type.replace('/fulfilled', '')] = AsyncRequestStatus.fulfilled;
} }
) )
.addMatcher( .addMatcher(
(action): action is UnknownAsyncThunkRejectedAction => (action): action is UnknownAsyncThunkRejectedAction =>
action.type.endsWith('/rejected'), action.type.endsWith('/rejected'),
(state, { type }) => { (state, { type }) => {
state[type.replace('/rejected', '')] = 'rejected'; state[type.replace('/rejected', '')] = AsyncRequestStatus.rejected;
} }
); );
}, },

View file

@ -1,4 +1,5 @@
import { RootState } from 'redux/interfaces'; import { RootState } from 'redux/interfaces';
import { AsyncRequestStatus } from 'lib/constants';
export const createFetchingSelector = (action: string) => (state: RootState) => export const createFetchingSelector = (action: string) => (state: RootState) =>
state.loader[action] || 'initial'; state.loader[action] || AsyncRequestStatus.initial;

View file

@ -12,7 +12,7 @@ import {
GetSchemasRequest, GetSchemasRequest,
GetLatestSchemaRequest, GetLatestSchemaRequest,
} from 'generated-sources'; } from 'generated-sources';
import { BASE_PARAMS } from 'lib/constants'; import { BASE_PARAMS, AsyncRequestStatus } from 'lib/constants';
import { getResponse } from 'lib/errorHandling'; import { getResponse } from 'lib/errorHandling';
import { ClusterName, RootState } from 'redux/interfaces'; import { ClusterName, RootState } from 'redux/interfaces';
import { createFetchingSelector } from 'redux/reducers/loader/selectors'; import { createFetchingSelector } from 'redux/reducers/loader/selectors';
@ -130,16 +130,16 @@ export const { schemaAdded, schemaUpdated } = schemasSlice.actions;
export const getAreSchemasFulfilled = createSelector( export const getAreSchemasFulfilled = createSelector(
createFetchingSelector(SCHEMAS_FETCH_ACTION), createFetchingSelector(SCHEMAS_FETCH_ACTION),
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
export const getAreSchemaLatestFulfilled = createSelector( export const getAreSchemaLatestFulfilled = createSelector(
createFetchingSelector(SCHEMA_LATEST_FETCH_ACTION), createFetchingSelector(SCHEMA_LATEST_FETCH_ACTION),
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
export const getAreSchemaVersionsFulfilled = createSelector( export const getAreSchemaVersionsFulfilled = createSelector(
createFetchingSelector(SCHEMAS_VERSIONS_FETCH_ACTION), createFetchingSelector(SCHEMAS_VERSIONS_FETCH_ACTION),
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
export default schemasSlice.reducer; export default schemasSlice.reducer;

View file

@ -19,6 +19,7 @@ import {
updateTopicPartitionsCount, updateTopicPartitionsCount,
updateTopicReplicationFactor, updateTopicReplicationFactor,
} from 'redux/reducers/topics/topicsSlice'; } from 'redux/reducers/topics/topicsSlice';
import { AsyncRequestStatus } from 'lib/constants';
const topicsState = ({ topics }: RootState): TopicsState => topics; const topicsState = ({ topics }: RootState): TopicsState => topics;
@ -32,7 +33,7 @@ const getTopicDeletingStatus = createFetchingSelector(deleteTopic.typePrefix);
export const getIsTopicDeleted = createSelector( export const getIsTopicDeleted = createSelector(
getTopicDeletingStatus, getTopicDeletingStatus,
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
const getAreTopicsFetchingStatus = createFetchingSelector( const getAreTopicsFetchingStatus = createFetchingSelector(
@ -41,11 +42,11 @@ const getAreTopicsFetchingStatus = createFetchingSelector(
export const getAreTopicsFetching = createSelector( export const getAreTopicsFetching = createSelector(
getAreTopicsFetchingStatus, getAreTopicsFetchingStatus,
(status) => status === 'pending' (status) => status === AsyncRequestStatus.pending
); );
export const getAreTopicsFetched = createSelector( export const getAreTopicsFetched = createSelector(
getAreTopicsFetchingStatus, getAreTopicsFetchingStatus,
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
const getTopicDetailsFetchingStatus = createFetchingSelector( const getTopicDetailsFetchingStatus = createFetchingSelector(
@ -54,12 +55,12 @@ const getTopicDetailsFetchingStatus = createFetchingSelector(
export const getIsTopicDetailsFetching = createSelector( export const getIsTopicDetailsFetching = createSelector(
getTopicDetailsFetchingStatus, getTopicDetailsFetchingStatus,
(status) => status === 'pending' (status) => status === AsyncRequestStatus.pending
); );
export const getIsTopicDetailsFetched = createSelector( export const getIsTopicDetailsFetched = createSelector(
getTopicDetailsFetchingStatus, getTopicDetailsFetchingStatus,
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
const getTopicConfigFetchingStatus = createFetchingSelector( const getTopicConfigFetchingStatus = createFetchingSelector(
@ -68,21 +69,21 @@ const getTopicConfigFetchingStatus = createFetchingSelector(
export const getTopicConfigFetched = createSelector( export const getTopicConfigFetched = createSelector(
getTopicConfigFetchingStatus, getTopicConfigFetchingStatus,
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
const getTopicCreationStatus = createFetchingSelector(createTopic.typePrefix); const getTopicCreationStatus = createFetchingSelector(createTopic.typePrefix);
export const getTopicCreated = createSelector( export const getTopicCreated = createSelector(
getTopicCreationStatus, getTopicCreationStatus,
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
const getTopicUpdateStatus = createFetchingSelector(updateTopic.typePrefix); const getTopicUpdateStatus = createFetchingSelector(updateTopic.typePrefix);
export const getTopicUpdated = createSelector( export const getTopicUpdated = createSelector(
getTopicUpdateStatus, getTopicUpdateStatus,
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
const getTopicMessageSchemaFetchingStatus = createFetchingSelector( const getTopicMessageSchemaFetchingStatus = createFetchingSelector(
@ -91,7 +92,7 @@ const getTopicMessageSchemaFetchingStatus = createFetchingSelector(
export const getTopicMessageSchemaFetched = createSelector( export const getTopicMessageSchemaFetched = createSelector(
getTopicMessageSchemaFetchingStatus, getTopicMessageSchemaFetchingStatus,
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
const getPartitionsCountIncreaseStatus = createFetchingSelector( const getPartitionsCountIncreaseStatus = createFetchingSelector(
@ -100,7 +101,7 @@ const getPartitionsCountIncreaseStatus = createFetchingSelector(
export const getTopicPartitionsCountIncreased = createSelector( export const getTopicPartitionsCountIncreased = createSelector(
getPartitionsCountIncreaseStatus, getPartitionsCountIncreaseStatus,
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
const getReplicationFactorUpdateStatus = createFetchingSelector( const getReplicationFactorUpdateStatus = createFetchingSelector(
@ -109,7 +110,7 @@ const getReplicationFactorUpdateStatus = createFetchingSelector(
export const getTopicReplicationFactorUpdated = createSelector( export const getTopicReplicationFactorUpdated = createSelector(
getReplicationFactorUpdateStatus, getReplicationFactorUpdateStatus,
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
const getTopicConsumerGroupsStatus = createFetchingSelector( const getTopicConsumerGroupsStatus = createFetchingSelector(
@ -118,7 +119,7 @@ const getTopicConsumerGroupsStatus = createFetchingSelector(
export const getTopicsConsumerGroupsFetched = createSelector( export const getTopicsConsumerGroupsFetched = createSelector(
getTopicConsumerGroupsStatus, getTopicConsumerGroupsStatus,
(status) => status === 'fulfilled' (status) => status === AsyncRequestStatus.fulfilled
); );
export const getTopicList = createSelector( export const getTopicList = createSelector(