fix topic messages old data persistence (#1838)

This commit is contained in:
Arsen Simonyan 2022-04-22 11:13:01 +04:00 committed by GitHub
parent f6e98ec5f5
commit efe135342e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View file

@ -14,12 +14,14 @@ interface RouterParams {
interface TopicProps { interface TopicProps {
isTopicFetching: boolean; isTopicFetching: boolean;
resetTopicMessages: () => void;
fetchTopicDetails: (clusterName: ClusterName, topicName: TopicName) => void; fetchTopicDetails: (clusterName: ClusterName, topicName: TopicName) => void;
} }
const Topic: React.FC<TopicProps> = ({ const Topic: React.FC<TopicProps> = ({
isTopicFetching, isTopicFetching,
fetchTopicDetails, fetchTopicDetails,
resetTopicMessages,
}) => { }) => {
const { clusterName, topicName } = useParams<RouterParams>(); const { clusterName, topicName } = useParams<RouterParams>();
@ -27,6 +29,12 @@ const Topic: React.FC<TopicProps> = ({
fetchTopicDetails(clusterName, topicName); fetchTopicDetails(clusterName, topicName);
}, [fetchTopicDetails, clusterName, topicName]); }, [fetchTopicDetails, clusterName, topicName]);
React.useEffect(() => {
return () => {
resetTopicMessages();
};
}, []);
if (isTopicFetching) { if (isTopicFetching) {
return <PageLoader />; return <PageLoader />;
} }

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { RootState } from 'redux/interfaces'; import { RootState } from 'redux/interfaces';
import { fetchTopicDetails } from 'redux/actions'; import { fetchTopicDetails, resetTopicMessages } from 'redux/actions';
import { getIsTopicDetailsFetching } from 'redux/reducers/topics/selectors'; import { getIsTopicDetailsFetching } from 'redux/reducers/topics/selectors';
import Topic from './Topic'; import Topic from './Topic';
@ -11,6 +11,7 @@ const mapStateToProps = (state: RootState) => ({
const mapDispatchToProps = { const mapDispatchToProps = {
fetchTopicDetails, fetchTopicDetails,
resetTopicMessages,
}; };
export default connect(mapStateToProps, mapDispatchToProps)(Topic); export default connect(mapStateToProps, mapDispatchToProps)(Topic);

View file

@ -22,6 +22,7 @@ jest.mock('components/common/PageLoader/PageLoader', () => () => (
<div>Loading</div> <div>Loading</div>
)); ));
const resetTopicMessages = jest.fn();
const fetchTopicDetailsMock = jest.fn(); const fetchTopicDetailsMock = jest.fn();
const renderComponent = (pathname: string, topicFetching: boolean) => const renderComponent = (pathname: string, topicFetching: boolean) =>
@ -29,6 +30,7 @@ const renderComponent = (pathname: string, topicFetching: boolean) =>
<Route path={clusterTopicPath(':clusterName', ':topicName')}> <Route path={clusterTopicPath(':clusterName', ':topicName')}>
<Topic <Topic
isTopicFetching={topicFetching} isTopicFetching={topicFetching}
resetTopicMessages={resetTopicMessages}
fetchTopicDetails={fetchTopicDetailsMock} fetchTopicDetails={fetchTopicDetailsMock}
/> />
</Route>, </Route>,
@ -59,3 +61,12 @@ it('fetches topicDetails', () => {
renderComponent(clusterTopicPath('local', 'myTopicName'), false); renderComponent(clusterTopicPath('local', 'myTopicName'), false);
expect(fetchTopicDetailsMock).toHaveBeenCalledTimes(1); expect(fetchTopicDetailsMock).toHaveBeenCalledTimes(1);
}); });
it('resets topic messages after unmount', () => {
const component = renderComponent(
clusterTopicPath('local', 'myTopicName'),
false
);
component.unmount();
expect(resetTopicMessages).toHaveBeenCalledTimes(1);
});