Replace use of 'all' in filters with check for config.defaultValue

This commit is contained in:
Paul Sealock 2019-05-08 08:40:39 +12:00
parent f529143e14
commit 448d12b91d
1 changed files with 11 additions and 7 deletions

View File

@ -110,7 +110,7 @@ class FilterPicker extends Component {
// Keep only time related queries when updating to a new filter // Keep only time related queries when updating to a new filter
const persistedQuery = getPersistedQuery( query ); const persistedQuery = getPersistedQuery( query );
const update = { const update = {
[ config.param ]: 'all' === value ? undefined : value, [ config.param ]: ( config.defaultValue || DEFAULT_FILTER ) === value ? undefined : value,
...additionalQueries, ...additionalQueries,
}; };
// Keep any url parameters as designated by the config // Keep any url parameters as designated by the config
@ -120,7 +120,7 @@ class FilterPicker extends Component {
updateQueryString( update, path, persistedQuery ); updateQueryString( update, path, persistedQuery );
} }
onTagChange( filter, onClose, tags ) { onTagChange( filter, onClose, config, tags ) {
const tag = last( tags ); const tag = last( tags );
const { value, settings } = filter; const { value, settings } = filter;
const { param: filterParam } = settings; const { param: filterParam } = settings;
@ -128,12 +128,12 @@ class FilterPicker extends Component {
this.update( value, { [ filterParam ]: tag.id } ); this.update( value, { [ filterParam ]: tag.id } );
onClose(); onClose();
} else { } else {
this.update( 'all' ); this.update( config.defaultValue || DEFAULT_FILTER );
} }
this.updateSelectedTag( [ tag ] ); this.updateSelectedTag( [ tag ] );
} }
renderButton( filter, onClose ) { renderButton( filter, onClose, config ) {
if ( filter.component ) { if ( filter.component ) {
const { type, labels } = filter.settings; const { type, labels } = filter.settings;
const persistedFilter = this.getFilter(); const persistedFilter = this.getFilter();
@ -145,7 +145,7 @@ class FilterPicker extends Component {
type={ type } type={ type }
placeholder={ labels.placeholder } placeholder={ labels.placeholder }
selected={ selectedTag ? [ selectedTag ] : [] } selected={ selectedTag ? [ selectedTag ] : [] }
onChange={ partial( this.onTagChange, filter, onClose ) } onChange={ partial( this.onTagChange, filter, onClose, config ) }
inlineTags inlineTags
staticResults staticResults
/> />
@ -202,7 +202,11 @@ class FilterPicker extends Component {
/> />
) } ) }
renderContent={ ( { onClose } ) => ( renderContent={ ( { onClose } ) => (
<AnimationSlider animationKey={ nav } animate={ animate } onExited={ this.onContentMount }> <AnimationSlider
animationKey={ nav }
animate={ animate }
onExited={ this.onContentMount }
>
{ () => ( { () => (
<ul className="woocommerce-filters-filter__content-list"> <ul className="woocommerce-filters-filter__content-list">
{ parentFilter && ( { parentFilter && (
@ -225,7 +229,7 @@ class FilterPicker extends Component {
( selectedFilter.path && includes( selectedFilter.path, filter.value ) ), ( selectedFilter.path && includes( selectedFilter.path, filter.value ) ),
} ) } } ) }
> >
{ this.renderButton( filter, onClose ) } { this.renderButton( filter, onClose, config ) }
</li> </li>
) ) } ) ) }
</ul> </ul>