Fix advancedFilter filter order (https://github.com/woocommerce/woocommerce-admin/pull/4559)
This commit is contained in:
parent
fe865b0c84
commit
f71706d4f4
|
@ -226,6 +226,18 @@ class AdvancedFilters extends Component {
|
|||
onAdvancedFilterAction( 'filter', { ...updatedQuery, match } );
|
||||
}
|
||||
|
||||
orderFilters( a, b ) {
|
||||
const qs = window.location.search;
|
||||
const aPos = qs.indexOf( a.key );
|
||||
const bPos = qs.indexOf( b.key );
|
||||
// If either isn't in the url, it means its just been added, so leave it as is.
|
||||
if ( aPos === -1 || bPos === -1 ) {
|
||||
return 0;
|
||||
}
|
||||
// Otherwise use the url to determine order in which filter was added.
|
||||
return aPos - bPos;
|
||||
}
|
||||
|
||||
render() {
|
||||
const { config, query, currency } = this.props;
|
||||
const { activeFilters, match } = this.state;
|
||||
|
@ -244,7 +256,9 @@ class AdvancedFilters extends Component {
|
|||
className="woocommerce-filters-advanced__list"
|
||||
ref={ this.filterListRef }
|
||||
>
|
||||
{ activeFilters.map( ( filter ) => {
|
||||
{ activeFilters
|
||||
.sort( this.orderFilters )
|
||||
.map( ( filter ) => {
|
||||
const { key } = filter;
|
||||
const { input, labels } = config.filters[ key ];
|
||||
return (
|
||||
|
@ -257,7 +271,9 @@ class AdvancedFilters extends Component {
|
|||
className="woocommerce-filters-advanced__fieldset-item"
|
||||
filter={ filter }
|
||||
config={ config.filters[ key ] }
|
||||
onFilterChange={ this.onFilterChange }
|
||||
onFilterChange={
|
||||
this.onFilterChange
|
||||
}
|
||||
isEnglish={ isEnglish }
|
||||
/>
|
||||
) }
|
||||
|
@ -266,7 +282,9 @@ class AdvancedFilters extends Component {
|
|||
className="woocommerce-filters-advanced__fieldset-item"
|
||||
filter={ filter }
|
||||
config={ config.filters[ key ] }
|
||||
onFilterChange={ this.onFilterChange }
|
||||
onFilterChange={
|
||||
this.onFilterChange
|
||||
}
|
||||
isEnglish={ isEnglish }
|
||||
query={ query }
|
||||
/>
|
||||
|
@ -276,7 +294,9 @@ class AdvancedFilters extends Component {
|
|||
className="woocommerce-filters-advanced__fieldset-item"
|
||||
filter={ filter }
|
||||
config={ config.filters[ key ] }
|
||||
onFilterChange={ this.onFilterChange }
|
||||
onFilterChange={
|
||||
this.onFilterChange
|
||||
}
|
||||
isEnglish={ isEnglish }
|
||||
query={ query }
|
||||
currency={ currency }
|
||||
|
@ -295,7 +315,9 @@ class AdvancedFilters extends Component {
|
|||
},
|
||||
},
|
||||
} }
|
||||
onFilterChange={ this.onFilterChange }
|
||||
onFilterChange={
|
||||
this.onFilterChange
|
||||
}
|
||||
isEnglish={ isEnglish }
|
||||
query={ query }
|
||||
currency={ currency }
|
||||
|
@ -306,7 +328,9 @@ class AdvancedFilters extends Component {
|
|||
className="woocommerce-filters-advanced__fieldset-item"
|
||||
filter={ filter }
|
||||
config={ config.filters[ key ] }
|
||||
onFilterChange={ this.onFilterChange }
|
||||
onFilterChange={
|
||||
this.onFilterChange
|
||||
}
|
||||
isEnglish={ isEnglish }
|
||||
query={ query }
|
||||
updateFilter={ this.updateFilter }
|
||||
|
|
Loading…
Reference in New Issue