Commit 51d4f2d7 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov
Browse files

Merge branch '186-unable-to-apply-filters-after-reset' into 'master'

Unable to apply filters after reset

Closes #186

See merge request genesys-pgr/genesys-ui!189
parents cbe43c57 7b9e180b
...@@ -3,6 +3,7 @@ import {translate} from 'react-i18next'; ...@@ -3,6 +3,7 @@ import {translate} from 'react-i18next';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import {bindActionCreators} from 'redux'; import {bindActionCreators} from 'redux';
import {withStyles} from '@material-ui/core/styles'; import {withStyles} from '@material-ui/core/styles';
import { getFormValues } from 'redux-form';
import {log} from 'utilities/debug'; import {log} from 'utilities/debug';
import { showSnackbar } from 'actions/snackbar'; import { showSnackbar } from 'actions/snackbar';
...@@ -31,7 +32,7 @@ const styles = (theme) => ({ ...@@ -31,7 +32,7 @@ const styles = (theme) => ({
// //
// Renders a standard filters block // Renders a standard filters block
const FiltersBlock = ({ title, children, handleSubmit, onSubmit, initialize, classes, showSnackbar, t }) => { const FiltersBlock = ({ title, children, handleSubmit, onSubmit, initialize, classes, showSnackbar, values, t }) => {
const scrollToTop = () => { const scrollToTop = () => {
if (window) { if (window) {
window.scrollTo(0, 0); window.scrollTo(0, 0);
...@@ -41,7 +42,11 @@ const FiltersBlock = ({ title, children, handleSubmit, onSubmit, initialize, cla ...@@ -41,7 +42,11 @@ const FiltersBlock = ({ title, children, handleSubmit, onSubmit, initialize, cla
const onReset = (e) => { const onReset = (e) => {
showSnackbar('Resetting filters...'); showSnackbar('Resetting filters...');
log('Clearing form'); log('Clearing form');
initialize({}); const initialValues = {};
Object.keys(values).forEach((key) => {
initialValues[key] = null;
});
initialize(initialValues);
setTimeout(handleSubmit, 100); setTimeout(handleSubmit, 100);
scrollToTop(); scrollToTop();
}; };
...@@ -68,8 +73,12 @@ const FiltersBlock = ({ title, children, handleSubmit, onSubmit, initialize, cla ...@@ -68,8 +73,12 @@ const FiltersBlock = ({ title, children, handleSubmit, onSubmit, initialize, cla
); );
}; };
const mapStateToProps = (state, ownProps) => ({
values: getFormValues(ownProps.form)(state),
});
const mapDispatchToProps = (dispatch) => bindActionCreators({ const mapDispatchToProps = (dispatch) => bindActionCreators({
showSnackbar, showSnackbar,
}, dispatch); }, dispatch);
export default translate()(connect(null, mapDispatchToProps)(withStyles(styles)<any>(FiltersBlock))); export default translate()(connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)<any>(FiltersBlock)));
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment