timeStampFilterDates

This commit is contained in:
Paul Sealock 2019-01-15 15:40:12 +13:00
parent 01cf0eba2f
commit 7b11e40981
1 changed files with 22 additions and 4 deletions

View File

@ -46,9 +46,27 @@ export function getFilterQuery( endpoint, query ) {
return {}; return {};
} }
// export function timeStampFilterDates() { export function timeStampFilterDates( config, activeFilter ) {
// if ( 'Date' === config.filters[ activeFilter.key ].input.component ) {
// } const { rule, value } = activeFilter;
const timeOfDayMap = {
after: 'start',
before: 'end',
};
let appendedValue;
if ( Array.isArray( value ) ) {
const [ after, before ] = value;
appendedValue = [
appendTimestamp( moment( after ), timeOfDayMap.after ),
appendTimestamp( moment( before ), timeOfDayMap.before ),
];
} else {
appendedValue = appendTimestamp( moment( value ), timeOfDayMap[ rule ] );
}
return Object.assign( {}, activeFilter, { value: appendedValue } );
}
return activeFilter;
}
export function getQueryFromConfig( config, advancedFilters, query ) { export function getQueryFromConfig( config, advancedFilters, query ) {
const queryValue = query[ config.param ]; const queryValue = query[ config.param ];
@ -64,7 +82,7 @@ export function getQueryFromConfig( config, advancedFilters, query ) {
return {}; return {};
} }
return activeFilters.reduce( return activeFilters.map( filter => timeStampFilterDates( advancedFilters, filter ) ).reduce(
( result, activeFilter ) => { ( result, activeFilter ) => {
const { key, rule, value } = activeFilter; const { key, rule, value } = activeFilter;
result[ getUrlKey( key, rule ) ] = value; result[ getUrlKey( key, rule ) ] = value;