Fix redirect after the topic deletion (#842)
* Implement event canceling * remove unnecessary API call * Remove the codesmell
This commit is contained in:
parent
c19b9a6867
commit
de245e8cc7
5 changed files with 23 additions and 6 deletions
|
@ -13,6 +13,8 @@ import {
|
||||||
} from 'lib/paths';
|
} from 'lib/paths';
|
||||||
import ClusterContext from 'components/contexts/ClusterContext';
|
import ClusterContext from 'components/contexts/ClusterContext';
|
||||||
import ConfirmationModal from 'components/common/ConfirmationModal/ConfirmationModal';
|
import ConfirmationModal from 'components/common/ConfirmationModal/ConfirmationModal';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { deleteTopicAction } from 'redux/actions';
|
||||||
|
|
||||||
import OverviewContainer from './Overview/OverviewContainer';
|
import OverviewContainer from './Overview/OverviewContainer';
|
||||||
import TopicConsumerGroupsContainer from './ConsumerGroups/TopicConsumerGroupsContainer';
|
import TopicConsumerGroupsContainer from './ConsumerGroups/TopicConsumerGroupsContainer';
|
||||||
|
@ -37,6 +39,7 @@ const Details: React.FC<Props> = ({
|
||||||
clearTopicMessages,
|
clearTopicMessages,
|
||||||
}) => {
|
}) => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const dispatch = useDispatch();
|
||||||
const { isReadOnly, isTopicDeletionAllowed } =
|
const { isReadOnly, isTopicDeletionAllowed } =
|
||||||
React.useContext(ClusterContext);
|
React.useContext(ClusterContext);
|
||||||
const [isDeleteTopicConfirmationVisible, setDeleteTopicConfirmationVisible] =
|
const [isDeleteTopicConfirmationVisible, setDeleteTopicConfirmationVisible] =
|
||||||
|
@ -44,8 +47,10 @@ const Details: React.FC<Props> = ({
|
||||||
const deleteTopicHandler = React.useCallback(() => {
|
const deleteTopicHandler = React.useCallback(() => {
|
||||||
deleteTopic(clusterName, topicName);
|
deleteTopic(clusterName, topicName);
|
||||||
}, [clusterName, topicName]);
|
}, [clusterName, topicName]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (isDeleted) {
|
if (isDeleted) {
|
||||||
|
dispatch(deleteTopicAction.cancel());
|
||||||
history.push(clusterTopicsPath(clusterName));
|
history.push(clusterTopicsPath(clusterName));
|
||||||
}
|
}
|
||||||
}, [isDeleted]);
|
}, [isDeleted]);
|
||||||
|
|
|
@ -3,8 +3,8 @@ import { ClusterName, RootState, TopicName } from 'redux/interfaces';
|
||||||
import { withRouter, RouteComponentProps } from 'react-router-dom';
|
import { withRouter, RouteComponentProps } from 'react-router-dom';
|
||||||
import { deleteTopic, clearTopicMessages } from 'redux/actions';
|
import { deleteTopic, clearTopicMessages } from 'redux/actions';
|
||||||
import {
|
import {
|
||||||
|
getIsTopicDeleted,
|
||||||
getIsTopicInternal,
|
getIsTopicInternal,
|
||||||
getTopicList,
|
|
||||||
} from 'redux/reducers/topics/selectors';
|
} from 'redux/reducers/topics/selectors';
|
||||||
|
|
||||||
import Details from './Details';
|
import Details from './Details';
|
||||||
|
@ -27,7 +27,7 @@ const mapStateToProps = (
|
||||||
clusterName,
|
clusterName,
|
||||||
topicName,
|
topicName,
|
||||||
isInternal: getIsTopicInternal(state, topicName),
|
isInternal: getIsTopicInternal(state, topicName),
|
||||||
isDeleted: !getTopicList(state).find((topic) => topic.name === topicName),
|
isDeleted: getIsTopicDeleted(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
|
|
|
@ -97,8 +97,9 @@ export const updateTopicAction = createAsyncAction(
|
||||||
export const deleteTopicAction = createAsyncAction(
|
export const deleteTopicAction = createAsyncAction(
|
||||||
'DELETE_TOPIC__REQUEST',
|
'DELETE_TOPIC__REQUEST',
|
||||||
'DELETE_TOPIC__SUCCESS',
|
'DELETE_TOPIC__SUCCESS',
|
||||||
'DELETE_TOPIC__FAILURE'
|
'DELETE_TOPIC__FAILURE',
|
||||||
)<undefined, TopicName, undefined>();
|
'DELETE_TOPIC__CANCEL'
|
||||||
|
)<undefined, TopicName, undefined, undefined>();
|
||||||
|
|
||||||
export const fetchConsumerGroupsAction = createAsyncAction(
|
export const fetchConsumerGroupsAction = createAsyncAction(
|
||||||
'GET_CONSUMER_GROUPS__REQUEST',
|
'GET_CONSUMER_GROUPS__REQUEST',
|
||||||
|
|
|
@ -4,9 +4,9 @@ export const initialState: LoaderState = {};
|
||||||
|
|
||||||
const reducer = (state = initialState, action: Action): LoaderState => {
|
const reducer = (state = initialState, action: Action): LoaderState => {
|
||||||
const { type } = action;
|
const { type } = action;
|
||||||
const matches = /(.*)__(REQUEST|SUCCESS|FAILURE)$/.exec(type);
|
const matches = /(.*)__(REQUEST|SUCCESS|FAILURE|CANCEL)$/.exec(type);
|
||||||
|
|
||||||
// not a *__REQUEST / *__SUCCESS / *__FAILURE actions, so we ignore them
|
// not a *__REQUEST / *__SUCCESS / *__FAILURE / *__CANCEL actions, so we ignore them
|
||||||
if (!matches) return state;
|
if (!matches) return state;
|
||||||
|
|
||||||
const [, requestName, requestState] = matches;
|
const [, requestName, requestState] = matches;
|
||||||
|
@ -27,6 +27,11 @@ const reducer = (state = initialState, action: Action): LoaderState => {
|
||||||
...state,
|
...state,
|
||||||
[requestName]: 'errorFetching',
|
[requestName]: 'errorFetching',
|
||||||
};
|
};
|
||||||
|
case 'CANCEL':
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
[requestName]: 'notFetched',
|
||||||
|
};
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,12 @@ const getPartitionsCountIncreaseStatus =
|
||||||
const getReplicationFactorUpdateStatus = createFetchingSelector(
|
const getReplicationFactorUpdateStatus = createFetchingSelector(
|
||||||
'UPDATE_REPLICATION_FACTOR'
|
'UPDATE_REPLICATION_FACTOR'
|
||||||
);
|
);
|
||||||
|
const getTopicDeletingStatus = createFetchingSelector('DELETE_TOPIC');
|
||||||
|
|
||||||
|
export const getIsTopicDeleted = createSelector(
|
||||||
|
getTopicDeletingStatus,
|
||||||
|
(status) => status === 'fetched'
|
||||||
|
);
|
||||||
|
|
||||||
export const getAreTopicsFetching = createSelector(
|
export const getAreTopicsFetching = createSelector(
|
||||||
getTopicListFetchingStatus,
|
getTopicListFetchingStatus,
|
||||||
|
|
Loading…
Add table
Reference in a new issue