@graphcommerce/algolia-search 6.2.0-canary.55 → 6.2.0-canary.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/components/Chip/SortChip/SortChip.tsx +15 -3
- package/components/SearchBox/SearchBox.tsx +7 -7
- package/hooks/useAlgoliaCategoryResults.ts +6 -3
- package/hooks/useAlgoliaPageResults.ts +2 -1
- package/package.json +13 -13
- package/plugins/AlgoliaPageSearchResults.tsx +1 -0
- package/plugins/AlgoliaSearchContextPlugin.tsx +2 -2
- package/plugins/AlgoliaSearchFieldPlugin.tsx +1 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @graphcommerce/algolia-search
|
|
2
2
|
|
|
3
|
+
## 6.2.0-canary.56
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1971](https://github.com/graphcommerce-org/graphcommerce/pull/1971) [`1c77da7f9`](https://github.com/graphcommerce-org/graphcommerce/commit/1c77da7f951e34a28df586fcaedf7a0a2c97ba60) - Bug fixes for Algolia Search. Linking via indexed categories is now possible, Mobile Header wil now render results correctly and server side data hydration will no longer be reliant on the locale provided by Lingui. ([@mikekeehnen](https://github.com/mikekeehnen))
|
|
8
|
+
|
|
3
9
|
## 6.2.0-canary.55
|
|
4
10
|
|
|
5
11
|
## 6.2.0-canary.54
|
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ return {
|
|
|
79
79
|
params: productListParams,
|
|
80
80
|
up: { href: '/', title: 'Home' },
|
|
81
81
|
apolloState: await conf.then(() => client.cache.extract()),
|
|
82
|
-
+ serverState: await getServerState(<SearchContext />, {
|
|
82
|
+
+ serverState: await getServerState(<SearchContext rendersInsideNextjs={false} />, {
|
|
83
83
|
+ renderToString,
|
|
84
84
|
+ }),
|
|
85
85
|
},
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ChipMenu,
|
|
3
|
+
extendableComponent,
|
|
4
|
+
responsiveVal,
|
|
5
|
+
useStorefrontConfig,
|
|
6
|
+
} from '@graphcommerce/next-ui'
|
|
2
7
|
import { SxProps, Theme } from '@mui/material'
|
|
3
8
|
import Box from '@mui/material/Box'
|
|
4
9
|
import Checkbox from '@mui/material/Checkbox'
|
|
5
10
|
import ListItem from '@mui/material/ListItem'
|
|
6
11
|
import ListItemText from '@mui/material/ListItemText'
|
|
12
|
+
import { useSortBy } from 'react-instantsearch-hooks-web'
|
|
7
13
|
|
|
8
14
|
const name = 'SortChip' as const
|
|
9
15
|
const parts = ['menu', 'item'] as const
|
|
@@ -22,13 +28,19 @@ export type SortByRenderState = {
|
|
|
22
28
|
canRefine: boolean
|
|
23
29
|
}
|
|
24
30
|
|
|
25
|
-
export
|
|
31
|
+
export type SortChipProps = {
|
|
26
32
|
title: string
|
|
27
33
|
sx?: SxProps<Theme>
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
export function SortChip(props: SortChipProps) {
|
|
31
|
-
const {
|
|
37
|
+
const { title, sx } = props
|
|
38
|
+
|
|
39
|
+
const { initialIndex, currentRefinement, options, refine, canRefine } = useSortBy({
|
|
40
|
+
items: useStorefrontConfig().sortOptions ?? [],
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
if (options.length < 1) return null
|
|
32
44
|
|
|
33
45
|
const selectedOption = options.find((option) => option.value === currentRefinement)
|
|
34
46
|
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
+
import { SearchFormProps } from '@graphcommerce/magento-search'
|
|
1
2
|
import { Trans } from '@lingui/react'
|
|
2
3
|
import { Box, debounce } from '@mui/material'
|
|
3
4
|
import TextField from '@mui/material/TextField'
|
|
4
5
|
import { ChangeEvent, useCallback, useEffect, useRef } from 'react'
|
|
5
6
|
import { useHits, useSearchBox, UseSearchBoxProps } from 'react-instantsearch-hooks-web'
|
|
6
7
|
|
|
7
|
-
type SearchBoxProps =
|
|
8
|
-
defaultValue?: string
|
|
9
|
-
} & UseSearchBoxProps
|
|
8
|
+
type SearchBoxProps = UseSearchBoxProps & SearchFormProps
|
|
10
9
|
|
|
11
10
|
export function SearchBox(props: SearchBoxProps) {
|
|
12
|
-
const {
|
|
11
|
+
const { search, textFieldProps } = props
|
|
13
12
|
const searchInputElement = useRef<HTMLInputElement>(null)
|
|
14
13
|
|
|
15
14
|
const { refine } = useSearchBox()
|
|
@@ -25,8 +24,8 @@ export function SearchBox(props: SearchBoxProps) {
|
|
|
25
24
|
)
|
|
26
25
|
|
|
27
26
|
useEffect(() => {
|
|
28
|
-
if (
|
|
29
|
-
}, [
|
|
27
|
+
if (search) refine(search)
|
|
28
|
+
}, [search, refine])
|
|
30
29
|
|
|
31
30
|
const totalResults = results?.nbHits ?? 0
|
|
32
31
|
|
|
@@ -52,7 +51,8 @@ export function SearchBox(props: SearchBoxProps) {
|
|
|
52
51
|
inputRef={searchInputElement}
|
|
53
52
|
onChange={debounceSearch}
|
|
54
53
|
fullWidth
|
|
55
|
-
sx={{ mt: 1 }}
|
|
54
|
+
sx={{ mt: 1, mb: 1 }}
|
|
55
|
+
{...textFieldProps}
|
|
56
56
|
/>
|
|
57
57
|
)
|
|
58
58
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { useQuery } from '@graphcommerce/graphql'
|
|
2
|
+
import { StoreConfigDocument } from '@graphcommerce/magento-store'
|
|
1
3
|
import { useHits } from 'react-instantsearch-hooks-web'
|
|
2
4
|
import { AlgoliaCategoryHit } from '../lib/types'
|
|
3
5
|
|
|
4
|
-
function hitToCategory(hits: AlgoliaCategoryHit[]) {
|
|
6
|
+
function hitToCategory(hits: AlgoliaCategoryHit[], categoryUrlSuffix?: string | null) {
|
|
5
7
|
return hits.map((h) => {
|
|
6
8
|
const urlSplit = h.url.split('/')
|
|
7
9
|
const categoryUrl = urlSplit.reduce((prev, curr, currIndex) => {
|
|
8
10
|
if (currIndex > 2) return `${prev}/${curr}`
|
|
9
11
|
return ''
|
|
10
12
|
})
|
|
11
|
-
const url_key = categoryUrl.substring(
|
|
13
|
+
const url_key = categoryUrl.substring(1, categoryUrl.length - (categoryUrlSuffix?.length ?? 0))
|
|
12
14
|
return {
|
|
13
15
|
category_uid: h.objectID,
|
|
14
16
|
category_level: h.level,
|
|
@@ -20,6 +22,7 @@ function hitToCategory(hits: AlgoliaCategoryHit[]) {
|
|
|
20
22
|
|
|
21
23
|
export function useAlgoliaCategoryResults() {
|
|
22
24
|
const { hits, results } = useHits<AlgoliaCategoryHit>()
|
|
23
|
-
const
|
|
25
|
+
const { data } = useQuery(StoreConfigDocument)
|
|
26
|
+
const categories = hitToCategory(hits, data?.storeConfig?.category_url_suffix)
|
|
24
27
|
return { categories, search: results?.query }
|
|
25
28
|
}
|
|
@@ -4,10 +4,11 @@ import { AlgoliaPageHit } from '../lib/types'
|
|
|
4
4
|
function hitToPage(hits: AlgoliaPageHit[]) {
|
|
5
5
|
return hits.map((h) => {
|
|
6
6
|
const urlSplit = h.url.split('/')
|
|
7
|
-
const
|
|
7
|
+
const prep = urlSplit.reduce((prev, curr, currIndex) => {
|
|
8
8
|
if (currIndex > 2) return `${prev}/${curr}`
|
|
9
9
|
return ''
|
|
10
10
|
})
|
|
11
|
+
const url = prep.substring(1, prep.length)
|
|
11
12
|
return {
|
|
12
13
|
objectID: h.objectID,
|
|
13
14
|
name: h.name,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/algolia-search",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "6.2.0-canary.
|
|
5
|
+
"version": "6.2.0-canary.56",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,20 +12,20 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@graphcommerce/eslint-config-pwa": "6.2.0-canary.
|
|
16
|
-
"@graphcommerce/next-config": "^6.2.0-canary.
|
|
17
|
-
"@graphcommerce/prettier-config-pwa": "6.2.0-canary.
|
|
18
|
-
"@graphcommerce/typescript-config-pwa": "6.2.0-canary.
|
|
15
|
+
"@graphcommerce/eslint-config-pwa": "6.2.0-canary.56",
|
|
16
|
+
"@graphcommerce/next-config": "^6.2.0-canary.56",
|
|
17
|
+
"@graphcommerce/prettier-config-pwa": "6.2.0-canary.56",
|
|
18
|
+
"@graphcommerce/typescript-config-pwa": "6.2.0-canary.56"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@graphcommerce/graphql": "6.2.0-canary.
|
|
22
|
-
"@graphcommerce/ecommerce-ui": "6.2.0-canary.
|
|
23
|
-
"@graphcommerce/magento-search": "6.2.0-canary.
|
|
24
|
-
"@graphcommerce/next-config": "^6.2.0-canary.
|
|
25
|
-
"@graphcommerce/next-ui": "6.2.0-canary.
|
|
26
|
-
"@graphcommerce/magento-product": "6.2.0-canary.
|
|
27
|
-
"@graphcommerce/graphql-mesh": "6.2.0-canary.
|
|
28
|
-
"@graphcommerce/magento-store": "6.2.0-canary.
|
|
21
|
+
"@graphcommerce/graphql": "6.2.0-canary.56",
|
|
22
|
+
"@graphcommerce/ecommerce-ui": "6.2.0-canary.56",
|
|
23
|
+
"@graphcommerce/magento-search": "6.2.0-canary.56",
|
|
24
|
+
"@graphcommerce/next-config": "^6.2.0-canary.56",
|
|
25
|
+
"@graphcommerce/next-ui": "6.2.0-canary.56",
|
|
26
|
+
"@graphcommerce/magento-product": "6.2.0-canary.56",
|
|
27
|
+
"@graphcommerce/graphql-mesh": "6.2.0-canary.56",
|
|
28
|
+
"@graphcommerce/magento-store": "6.2.0-canary.56",
|
|
29
29
|
"algoliasearch": "^4.15.0",
|
|
30
30
|
"react-instantsearch-hooks-web": "^6.41.0"
|
|
31
31
|
},
|
|
@@ -12,7 +12,7 @@ export const ifConfig: IfConfig = 'algoliaApplicationId'
|
|
|
12
12
|
const searchClient = algoliasearch(applicationId, searchOnlyApiKey)
|
|
13
13
|
|
|
14
14
|
function AlgoliaSearchContextPlugin(props: PluginProps<SearchContextProps>) {
|
|
15
|
-
const { Prev, serverProps, ...rest } = props
|
|
15
|
+
const { Prev, serverProps, rendersInsideNextjs = true, ...rest } = props
|
|
16
16
|
const searchIndex = useAlgoliaSearchIndexConfig('_products')?.searchIndex
|
|
17
17
|
|
|
18
18
|
if (!searchIndex)
|
|
@@ -23,7 +23,7 @@ function AlgoliaSearchContextPlugin(props: PluginProps<SearchContextProps>) {
|
|
|
23
23
|
return (
|
|
24
24
|
<InstantSearchSSRProvider {...(typeof serverProps === 'object' ? serverProps : {})}>
|
|
25
25
|
<InstantSearch searchClient={searchClient} indexName={searchIndex}>
|
|
26
|
-
<Prev {...rest} />
|
|
26
|
+
{rendersInsideNextjs && <Prev {...rest} />}
|
|
27
27
|
</InstantSearch>
|
|
28
28
|
</InstantSearchSSRProvider>
|
|
29
29
|
)
|
|
@@ -7,8 +7,7 @@ export const exported = '@graphcommerce/magento-search'
|
|
|
7
7
|
export const ifConfig: IfConfig = 'algoliaApplicationId'
|
|
8
8
|
|
|
9
9
|
function AlgoliaSearchFieldPlugin(props: PluginProps<SearchFormProps>) {
|
|
10
|
-
|
|
11
|
-
return <SearchBox defaultValue={search} />
|
|
10
|
+
return <SearchBox {...props} />
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
export const Plugin = AlgoliaSearchFieldPlugin
|