-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Products are now requested with the exact price range from the filters #320
Merged
richardgorman
merged 5 commits into
PWA-327-Exchange-Router
from
PWA-1098-fix-get-products-requests-with-price-range
Oct 12, 2018
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2a90c5d
PWA-1098: Fixed amount rounding issue when filters where updated
fkloes 1d856dd
Merge branch 'PWA-327-Exchange-Router' into PWA-1098-fix-get-products…
richardgorman cb4e978
PWA-1098 Updated snapshots containing the Backdrop component
richardgorman f9548d7
PWA-1098: Excluded 3rd party extensions from the linter
fkloes d0f2e1a
Merge branch 'PWA-1098-fix-get-products-requests-with-price-range' of…
fkloes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
themes/theme-gmd/pages/Filter/components/Content/helpers/buildUpdatedFilters.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @param {Object} initialFilters The filters before they where modified. | ||
* @param {Object} updatedFilters The filters after they where modified. | ||
* @return {Object} | ||
*/ | ||
const buildUpdatedFilters = (initialFilters, updatedFilters) => { | ||
// Create a set of active filters by combining state and updatedFilters. | ||
const activeFilters = { | ||
...initialFilters, | ||
...updatedFilters, | ||
}; | ||
|
||
return Object.keys(activeFilters).reduce((result, filterId) => { | ||
const filter = activeFilters[filterId]; | ||
|
||
if (filterId === 'display_amount') { | ||
const [min, max] = filter.value; | ||
|
||
// Take care that the values for the display amount reflect the state of the price slider. | ||
filter.value = [ | ||
Math.floor(min / 100) * 100, | ||
Math.ceil(max / 100) * 100, | ||
]; | ||
} | ||
|
||
if (filter.value.length) { | ||
// Only add filters with selected values. | ||
return { | ||
...(result === null ? {} : result), | ||
[filterId]: filter, | ||
}; | ||
} | ||
|
||
return result; | ||
}, null); | ||
}; | ||
|
||
export default buildUpdatedFilters; |
48 changes: 48 additions & 0 deletions
48
themes/theme-gmd/pages/Filter/components/Content/helpers/buildUpdatedFilters.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import set from 'lodash/set'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
import buildUpdatedFilters from './buildUpdatedFilters'; | ||
|
||
const mockedFilter = { | ||
display_amount: { | ||
id: 'display_amount', | ||
label: 'Price', | ||
type: 'range', | ||
value: [100, 2000], | ||
}, | ||
manufacturer: { | ||
id: 'manufacturer', | ||
label: 'Manufacturer', | ||
type: 'multiselect', | ||
value: [{ | ||
id: 'wayland_corp', | ||
label: 'Weyland Corp', | ||
}, { | ||
id: 'tyrell_corp', | ||
label: 'Tyrell Corporation', | ||
}], | ||
}, | ||
}; | ||
|
||
describe('buildUpdatedFilters()', () => { | ||
it('should update filters as expected', () => { | ||
const updated = cloneDeep(mockedFilter); | ||
expect(buildUpdatedFilters({}, updated)).toEqual(updated); | ||
}); | ||
|
||
it('should exclude filters when they do not have values selected', () => { | ||
const initial = cloneDeep(mockedFilter); | ||
const updated = set(cloneDeep(mockedFilter), 'manufacturer.value', []); | ||
const { manufacturer, ...expected } = mockedFilter; | ||
expect(buildUpdatedFilters(initial, updated)).toEqual(expected); | ||
}); | ||
|
||
it('should round the values of a display amount filter', () => { | ||
const initial = cloneDeep(mockedFilter); | ||
const updated = set(cloneDeep(mockedFilter), 'display_amount.value', [125, 1920]); | ||
expect(buildUpdatedFilters(initial, updated)).toEqual(mockedFilter); | ||
}); | ||
|
||
it('should return null both parameters are empty objects', () => { | ||
expect(buildUpdatedFilters({}, {})).toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that here it would be better to check for a range filter type.