diff --git a/plugins/woocommerce-admin/packages/navigation/src/filters.js b/plugins/woocommerce-admin/packages/navigation/src/filters.js index 6e724e24a8c..0a008c4108d 100644 --- a/plugins/woocommerce-admin/packages/navigation/src/filters.js +++ b/plugins/woocommerce-admin/packages/navigation/src/filters.js @@ -109,6 +109,13 @@ export function getQueryFromActiveFilters( activeFilters, query, config ) { return data; }, {} ); const nextData = activeFilters.reduce( ( data, filter ) => { + if ( + 'between' === filter.rule && + ( ! Array.isArray( filter.value ) || filter.value.some( value => ! value ) ) + ) { + return data; + } + if ( filter.value ) { data[ getUrlKey( filter.key, filter.rule ) ] = filter.value; } diff --git a/plugins/woocommerce-admin/packages/navigation/src/test/filters.js b/plugins/woocommerce-admin/packages/navigation/src/test/filters.js index d70dac6fcc6..bfefb0a90f8 100644 --- a/plugins/woocommerce-admin/packages/navigation/src/test/filters.js +++ b/plugins/woocommerce-admin/packages/navigation/src/test/filters.js @@ -126,6 +126,20 @@ describe( 'getQueryFromActiveFilters', () => { expect( nextQuery.with_select_is ).toBeUndefined(); expect( nextQuery.with_search_includes ).toBeUndefined(); } ); + + it( 'should only reflect complete filters with multiple values', () => { + const activeFilters = [ + { key: 'valid_date', rule: 'between', value: [ '2018-04-04', '2018-04-10' ] }, + { key: 'invalid_date_1', rule: 'between', value: [ '2018-04-04', undefined ] }, + { key: 'invalid_date_2', rule: 'between', value: '2018-04-04' }, + ]; + const query = {}; + const nextQuery = getQueryFromActiveFilters( activeFilters, query, config ); + + expect( nextQuery.valid_date_between ).toBeDefined(); + expect( nextQuery.invalid_date_1_between ).toBeUndefined(); + expect( nextQuery.invalid_date_2_between ).toBeUndefined(); + } ); } ); describe( 'getDefaultOptionValue', () => {