This commit is contained in:
Paul Sealock 2020-06-17 11:08:54 +12:00 committed by GitHub
parent fe865b0c84
commit f71706d4f4
1 changed files with 107 additions and 83 deletions

View File

@ -226,6 +226,18 @@ class AdvancedFilters extends Component {
onAdvancedFilterAction( 'filter', { ...updatedQuery, match } ); 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() { render() {
const { config, query, currency } = this.props; const { config, query, currency } = this.props;
const { activeFilters, match } = this.state; const { activeFilters, match } = this.state;
@ -244,7 +256,9 @@ class AdvancedFilters extends Component {
className="woocommerce-filters-advanced__list" className="woocommerce-filters-advanced__list"
ref={ this.filterListRef } ref={ this.filterListRef }
> >
{ activeFilters.map( ( filter ) => { { activeFilters
.sort( this.orderFilters )
.map( ( filter ) => {
const { key } = filter; const { key } = filter;
const { input, labels } = config.filters[ key ]; const { input, labels } = config.filters[ key ];
return ( return (
@ -257,7 +271,9 @@ class AdvancedFilters extends Component {
className="woocommerce-filters-advanced__fieldset-item" className="woocommerce-filters-advanced__fieldset-item"
filter={ filter } filter={ filter }
config={ config.filters[ key ] } config={ config.filters[ key ] }
onFilterChange={ this.onFilterChange } onFilterChange={
this.onFilterChange
}
isEnglish={ isEnglish } isEnglish={ isEnglish }
/> />
) } ) }
@ -266,7 +282,9 @@ class AdvancedFilters extends Component {
className="woocommerce-filters-advanced__fieldset-item" className="woocommerce-filters-advanced__fieldset-item"
filter={ filter } filter={ filter }
config={ config.filters[ key ] } config={ config.filters[ key ] }
onFilterChange={ this.onFilterChange } onFilterChange={
this.onFilterChange
}
isEnglish={ isEnglish } isEnglish={ isEnglish }
query={ query } query={ query }
/> />
@ -276,7 +294,9 @@ class AdvancedFilters extends Component {
className="woocommerce-filters-advanced__fieldset-item" className="woocommerce-filters-advanced__fieldset-item"
filter={ filter } filter={ filter }
config={ config.filters[ key ] } config={ config.filters[ key ] }
onFilterChange={ this.onFilterChange } onFilterChange={
this.onFilterChange
}
isEnglish={ isEnglish } isEnglish={ isEnglish }
query={ query } query={ query }
currency={ currency } currency={ currency }
@ -295,7 +315,9 @@ class AdvancedFilters extends Component {
}, },
}, },
} } } }
onFilterChange={ this.onFilterChange } onFilterChange={
this.onFilterChange
}
isEnglish={ isEnglish } isEnglish={ isEnglish }
query={ query } query={ query }
currency={ currency } currency={ currency }
@ -306,7 +328,9 @@ class AdvancedFilters extends Component {
className="woocommerce-filters-advanced__fieldset-item" className="woocommerce-filters-advanced__fieldset-item"
filter={ filter } filter={ filter }
config={ config.filters[ key ] } config={ config.filters[ key ] }
onFilterChange={ this.onFilterChange } onFilterChange={
this.onFilterChange
}
isEnglish={ isEnglish } isEnglish={ isEnglish }
query={ query } query={ query }
updateFilter={ this.updateFilter } updateFilter={ this.updateFilter }