-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Price range filter on PLP (#1364)
- Loading branch information
Showing
24 changed files
with
509 additions
and
403 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,12 @@ | ||
import type { Resolver } from '..' | ||
import type { FacetValueBoolean } from '../clients/search/types/FacetSearchResult' | ||
|
||
export const StoreFacetValueBoolean: Record< | ||
string, | ||
Resolver<FacetValueBoolean> | ||
> = { | ||
value: ({ value }) => value, | ||
label: ({ name }) => name || 'unknown', | ||
selected: ({ selected }) => selected, | ||
quantity: ({ quantity }) => quantity, | ||
} |
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 |
---|---|---|
@@ -1,11 +1,72 @@ | ||
import { parseRange } from '../utils/facets' | ||
import { min } from '../utils/orderStatistics' | ||
import type { | ||
FacetValueBoolean, | ||
Facet, | ||
FacetValueRange, | ||
} from '../clients/search/types/FacetSearchResult' | ||
import type { Resolver } from '..' | ||
import type { Facet } from '../clients/search/types/FacetSearchResult' | ||
|
||
type Root = Facet | ||
|
||
export const StoreFacet: Record<string, Resolver<Root>> = { | ||
key: ({ key }) => key ?? '', | ||
label: ({ name }) => name ?? 'unknown', | ||
values: ({ values }) => values, | ||
type: ({ type }) => (type === 'TEXT' ? 'BOOLEAN' : 'RANGE'), | ||
__resolveType: ({ type }) => | ||
type === 'TEXT' ? 'StoreFacetBoolean' : 'StoreFacetRange', | ||
} | ||
|
||
export const StoreFacetBoolean: Record< | ||
string, | ||
Resolver<Facet<FacetValueBoolean>> | ||
> = { | ||
key: ({ key }) => key, | ||
label: ({ name }) => name, | ||
values: ({ values }) => values.sort((a, b) => a.name.localeCompare(b.name)), | ||
} | ||
|
||
export const StoreFacetRange: Record< | ||
string, | ||
Resolver<Facet<FacetValueRange>> | ||
> = { | ||
key: ({ key }) => key, | ||
label: ({ name }) => name, | ||
min: ({ values, key }, _, { storage: { searchArgs } }) => { | ||
/** | ||
* Fetch the selected range the user queried. | ||
* | ||
* This is necessary because, differently from boolean facets, Search API does | ||
* not return the selected values, making us have to implement it in here | ||
*/ | ||
const selectedRange = parseRange( | ||
searchArgs?.selectedFacets?.find((facet) => facet.key === key)?.value ?? | ||
'' | ||
) | ||
|
||
const facet = min(values, (a, b) => a.range.from - b.range.from) | ||
const globalMin = facet?.range.from ?? 0 | ||
|
||
return { | ||
selected: selectedRange?.[0] ?? globalMin, | ||
absolute: globalMin, | ||
} | ||
}, | ||
max: ({ values, key }, _, { storage: { searchArgs } }) => { | ||
/** | ||
* Fetch the selected range the user queried. | ||
* | ||
* This is necessary because, differently from boolean facets, Search API does | ||
* not return the selected values, making us have to implement it in here | ||
*/ | ||
const selectedRange = parseRange( | ||
searchArgs?.selectedFacets?.find((facet) => facet.key === key)?.value ?? | ||
'' | ||
) | ||
|
||
const facet = min(values, (a, b) => b.range.to - a.range.to) | ||
const globalMax = facet?.range.to ?? 0 | ||
|
||
return { | ||
selected: selectedRange?.[1] ?? globalMax, | ||
absolute: globalMax, | ||
} | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.
a4c3fa7
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.
Successfully deployed to the following URLs:
faststore – ./
faststore-faststore.vercel.app
faststore.dev
faststore-docs.vercel.app
faststore-git-main-faststore.vercel.app
www.faststore.dev