Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Move url params to filters object

Krzysztof Białogłowiczf3b56d907a8f
diff --git a/saleor/static/js/components/ProductFilters.js b/saleor/static/js/components/ProductFilters.js
index 60d3e1ff70..32b4ff3740 100644
--- a/saleor/static/js/components/ProductFilters.js
+++ b/saleor/static/js/components/ProductFilters.js
@@ -13,14 +13,16 @@ class ProductFilters extends Component {
constructor(props) {
super(props);
this.state = {
- filters: {},
- params: {}
+ filters: {}
};
}
onClick = (attribute, value, event) => {
+
const attrValue = `${attribute}:${value}`;
+ let url = '';
const element = event.target;
+
this.setState({
filters: Object.assign(
this.state.filters,
@@ -28,28 +30,9 @@ class ProductFilters extends Component {
});
const enabled = Object.keys(this.state.filters).filter(key => this.state.filters[key] === true);
this.props.onFilterChanged(enabled);
- if (element.classList.contains("active")) {
- element.classList.remove("active");
- } else {
- element.classList.add("active");
- }
- this.setUrlParams(attribute, value);
-
- }
-
- setUrlParams(attribute, value) {
-
- const attrValue = `${attribute}=${value}`;
- let url = '';
- this.setState({
- params: Object.assign(
- this.state.params,
- {[attrValue]: !this.state.params[attrValue]})
- });
-
- const activeParams = Object.keys(this.state.params).filter(key => this.state.params[key] === true);
- activeParams.map((param, index) => {
+ enabled.map((param, index) => {
+ param = param.replace(':',"=")
if (index == 0) {
url += '?'+param
} else {
@@ -57,14 +40,14 @@ class ProductFilters extends Component {
}
})
- if (activeParams.length == 0) {
+ if (enabled.length == 0) {
url = location.href.split("?")[0];
}
-
+
history.pushState({}, null , url);
+
}
-
componentDidMount() {
let url_params = queryString.parse(location.search);