Advanced Filters: Ranges: Allow update only on complete selection
This commit is contained in:
parent
c9df5861a8
commit
7856a58b49
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
Loading…
Reference in New Issue