-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(commerce): commerce search box + query suggest (#3461)
* create search box controller * simplify controller definition * remove unnecessary mock * apply review suggestions * apply more review suggestions * reset pagination before search * group state tests * Revert "reset pagination before search" This reverts commit 4429385.
- Loading branch information
1 parent
27a8785
commit 74c3b65
Showing
21 changed files
with
996 additions
and
58 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
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
41 changes: 41 additions & 0 deletions
41
packages/headless/src/api/commerce/search/query-suggest/query-suggest-request.ts
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,41 @@ | ||
import {BaseParam} from '../../../platform-service-params'; | ||
import { | ||
ClientIdParam, | ||
CurrencyParam, | ||
LanguageParam, | ||
QueryParam, | ||
TrackingIdParam, | ||
ContextParam, | ||
CountryParam, | ||
} from '../../commerce-api-params'; | ||
import {baseRequest} from '../../common/request'; | ||
|
||
export type QuerySuggestRequest = BaseParam & | ||
TrackingIdParam & | ||
LanguageParam & | ||
CountryParam & | ||
CurrencyParam & | ||
ClientIdParam & | ||
ContextParam & | ||
QueryParam; | ||
|
||
export const buildQuerySuggestRequest = (req: QuerySuggestRequest) => { | ||
return { | ||
...baseRequest(req, 'search/querySuggest'), | ||
requestParams: prepareRequestParams(req), | ||
}; | ||
}; | ||
|
||
const prepareRequestParams = (req: QuerySuggestRequest) => { | ||
const {trackingId, query, clientId, context, language, country, currency} = | ||
req; | ||
return { | ||
trackingId, | ||
query, | ||
clientId, | ||
context, | ||
language, | ||
country, | ||
currency, | ||
}; | ||
}; |
39 changes: 39 additions & 0 deletions
39
packages/headless/src/api/commerce/search/query-suggest/query-suggest-response.ts
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,39 @@ | ||
import { | ||
SearchAPIErrorWithExceptionInBody, | ||
SearchAPIErrorWithStatusCode, | ||
} from '../../../search/search-api-error-response'; | ||
|
||
/** | ||
* A Coveo ML query suggestion. | ||
*/ | ||
export interface QuerySuggestCompletion { | ||
/** | ||
* The original query expression. | ||
*/ | ||
expression: string; | ||
|
||
/** | ||
* The highlighted query completion suggestion. | ||
*/ | ||
highlighted: string; | ||
} | ||
|
||
/** | ||
* A response from the Coveo ML query suggest service. | ||
*/ | ||
export interface QuerySuggestSuccessResponse { | ||
/** | ||
* Contains an array of query suggestions. | ||
*/ | ||
completions: QuerySuggestCompletion[]; | ||
|
||
/** | ||
* The query suggest response ID. | ||
*/ | ||
responseId: string; | ||
} | ||
|
||
export type QuerySuggest = | ||
| QuerySuggestSuccessResponse | ||
| SearchAPIErrorWithExceptionInBody | ||
| SearchAPIErrorWithStatusCode; |
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
23 changes: 23 additions & 0 deletions
23
packages/headless/src/controllers/commerce/search-box/headless-search-box-options.ts
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,23 @@ | ||
import {Schema} from '@coveo/bueno'; | ||
import { | ||
searchBoxOptionDefinitions as coreSearchBoxOptionDefinitions, | ||
SearchBoxOptions as CoreSearchBoxOptions, | ||
} from '../../core/search-box/headless-core-search-box-options'; | ||
|
||
export type SearchBoxOptions = Pick< | ||
CoreSearchBoxOptions, | ||
'id' | 'highlightOptions' | 'clearFilters' | ||
>; | ||
|
||
type DefaultSearchBoxOptions = Pick<SearchBoxOptions, 'clearFilters'>; | ||
|
||
export const defaultSearchBoxOptions: Required<DefaultSearchBoxOptions> = { | ||
clearFilters: true, | ||
}; | ||
|
||
const {id, highlightOptions, clearFilters} = coreSearchBoxOptionDefinitions; | ||
export const searchBoxOptionDefinitions = {id, highlightOptions, clearFilters}; | ||
|
||
export const searchBoxOptionsSchema = new Schema<Required<SearchBoxOptions>>( | ||
searchBoxOptionDefinitions | ||
); |
Oops, something went wrong.