Skip to content

Commit

Permalink
Reset topology search filter on namespace change
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitkrai03 committed Apr 27, 2020
1 parent 00493af commit 9930c3f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,21 @@ import { Helmet } from 'react-helmet';
import { matchPath, match as RMatch, Link, Redirect } from 'react-router-dom';
import { Tooltip, Popover, Button } from '@patternfly/react-core';
import { ListIcon, TopologyIcon, QuestionCircleIcon } from '@patternfly/react-icons';
import { StatusBox, Firehose, HintBlock, AsyncComponent } from '@console/internal/components/utils';
import {
StatusBox,
Firehose,
HintBlock,
AsyncComponent,
removeQueryArgument,
} from '@console/internal/components/utils';

// FIXME upgrading redux types is causing many errors at this time
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
import { useSelector, useDispatch } from 'react-redux';
import { RootState } from '@console/internal/redux';
import { getTopologyFilters } from './filters/filter-utils';

import EmptyState from '../EmptyState';
import NamespacedPage, { NamespacedPageVariants } from '../NamespacedPage';
import ProjectsExistWrapper from '../ProjectsExistWrapper';
Expand All @@ -14,6 +28,8 @@ import TopologyShortcuts from './TopologyShortcuts';
import { LAST_TOPOLOGY_VIEW_LOCAL_STORAGE_KEY } from './components/const';

import './TopologyPage.scss';
import { TOPOLOGY_SEARCH_FILTER_KEY } from './redux/const';
import { setTopologyFilters } from './redux/action';

export interface TopologyPageProps {
match: RMatch<{
Expand Down Expand Up @@ -70,6 +86,16 @@ export const TopologyPage: React.FC<TopologyPageProps> = ({ match }) => {
exact: true,
});

const dispatch = useDispatch();
const displayFilters = useSelector((state: RootState) => getTopologyFilters(state).display);

const handleNamespaceChange = (ns: string) => {
if (ns !== namespace) {
removeQueryArgument(TOPOLOGY_SEARCH_FILTER_KEY);
dispatch(setTopologyFilters({ display: displayFilters, searchQuery: '' }));
}
};

React.useEffect(() => setTopologyActiveView(showListView && !showGraphView ? 'list' : 'graph'), [
showListView,
showGraphView,
Expand All @@ -93,6 +119,7 @@ export const TopologyPage: React.FC<TopologyPageProps> = ({ match }) => {
<NamespacedPage
variant={showListView ? NamespacedPageVariants.light : NamespacedPageVariants.default}
hideApplications={showListView}
onNamespaceChange={handleNamespaceChange}
toolbar={
<>
{!showListView && namespace && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ type RenderTopologyProps = React.ComponentProps<typeof renderTopology>;
let topologyProps: TopologyPageProps;
let renderTopologyProps: RenderTopologyProps;

jest.mock('react-redux', () => {
const ActualReactRedux = require.requireActual('react-redux');
return {
...ActualReactRedux,
useSelector: jest.fn(),
useDispatch: jest.fn(),
};
});

describe('Topology page tests', () => {
beforeEach(() => {
topologyProps = {
Expand Down

0 comments on commit 9930c3f

Please sign in to comment.