Ensured list filtering params are reset when list component unmounts

This commit is contained in:
Alejandro Celaya 2018-09-16 09:01:05 +02:00
parent 5d5a2be498
commit 9b3bfe56bb

View file

@ -11,7 +11,7 @@ import { serverType } from '../servers/prop-types';
import { ShortUrlsRow } from './helpers/ShortUrlsRow'; import { ShortUrlsRow } from './helpers/ShortUrlsRow';
import { listShortUrls, shortUrlType } from './reducers/shortUrlsList'; import { listShortUrls, shortUrlType } from './reducers/shortUrlsList';
import './ShortUrlsList.scss'; import './ShortUrlsList.scss';
import { shortUrlsListParamsType } from './reducers/shortUrlsListParams'; import { shortUrlsListParamsType, resetShortUrlParams } from './reducers/shortUrlsListParams';
const SORTABLE_FIELDS = { const SORTABLE_FIELDS = {
dateCreated: 'Created at', dateCreated: 'Created at',
@ -23,6 +23,7 @@ const SORTABLE_FIELDS = {
export class ShortUrlsListComponent extends React.Component { export class ShortUrlsListComponent extends React.Component {
static propTypes = { static propTypes = {
listShortUrls: PropTypes.func, listShortUrls: PropTypes.func,
resetShortUrlParams: PropTypes.func,
shortUrlsListParams: shortUrlsListParamsType, shortUrlsListParams: shortUrlsListParamsType,
match: PropTypes.object, match: PropTypes.object,
location: PropTypes.object, location: PropTypes.object,
@ -89,6 +90,12 @@ export class ShortUrlsListComponent extends React.Component {
this.refreshList({ page: params.page, tags: query.tag ? [ query.tag ] : shortUrlsListParams.tags }); this.refreshList({ page: params.page, tags: query.tag ? [ query.tag ] : shortUrlsListParams.tags });
} }
componentWillUnmount() {
const { resetShortUrlParams } = this.props;
resetShortUrlParams();
}
renderShortUrls() { renderShortUrls() {
const { shortUrlsList, selectedServer, loading, error, shortUrlsListParams } = this.props; const { shortUrlsList, selectedServer, loading, error, shortUrlsListParams } = this.props;
@ -188,7 +195,7 @@ export class ShortUrlsListComponent extends React.Component {
const ShortUrlsList = connect( const ShortUrlsList = connect(
pick([ 'selectedServer', 'shortUrlsListParams' ]), pick([ 'selectedServer', 'shortUrlsListParams' ]),
{ listShortUrls } { listShortUrls, resetShortUrlParams }
)(ShortUrlsListComponent); )(ShortUrlsListComponent);
export default ShortUrlsList; export default ShortUrlsList;