@constructor-io/constructorio-ui-autocomplete 1.7.2 → 1.8.1
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/dist/constructorio-ui-autocomplete-bundled.js +11 -11
- package/lib/cjs/constants.js +23 -6
- package/lib/cjs/hooks/useCioAutocomplete.js +1 -1
- package/lib/cjs/hooks/useDebouncedFetchSections.js +16 -12
- package/lib/cjs/hooks/useFetchRecommendationPod.js +1 -0
- package/lib/cjs/hooks/useSections.js +1 -1
- package/lib/mjs/constants.js +22 -5
- package/lib/mjs/hooks/useCioAutocomplete.js +1 -1
- package/lib/mjs/hooks/useDebouncedFetchSections.js +20 -16
- package/lib/mjs/hooks/useFetchRecommendationPod.js +1 -0
- package/lib/mjs/hooks/useSections.js +2 -2
- package/lib/types/constants.d.ts +4 -3
- package/lib/types/hooks/useDebouncedFetchSections.d.ts +1 -1
- package/lib/types/hooks/useSections.d.ts +1 -1
- package/lib/types/types.d.ts +2 -1
- package/package.json +1 -1
package/lib/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.termsWithGroupSuggestionsDescription = exports.advancedParametersDefaultDescription = exports.advancedParametersDescription = exports.customStylesDescription = exports.multipleSectionsDescription = exports.openOnFocusDescription = exports.zeroStateSectionsDescription = exports.onSubmitDefault = exports.onSubmitDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.recommendationsDescription = exports.sectionOrderDescription = exports.numResultsDescription = exports.contentDescription = exports.productsDescription = exports.searchSuggestionsDescription = exports.placeholderDescription = exports.cioJsClientDescription = exports.apiKeyDescription = exports.zeroStateDescription = exports.userEventsDescription = exports.sectionsDescription = exports.hookDescription = exports.componentDescription = exports.apiKey = void 0;
|
|
3
|
+
exports.filteredSuggestionsDescription = exports.termsWithGroupSuggestionsDescription = exports.advancedParametersDefaultDescription = exports.advancedParametersDescription = exports.customStylesDescription = exports.multipleSectionsDescription = exports.openOnFocusDescription = exports.zeroStateSectionsDescription = exports.onSubmitDefault = exports.onSubmitDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.recommendationsDescription = exports.sectionOrderDescription = exports.numResultsDescription = exports.contentDescription = exports.productsDescription = exports.searchSuggestionsDescription = exports.placeholderDescription = exports.cioJsClientDescription = exports.apiKeyDescription = exports.zeroStateDescription = exports.userEventsDescription = exports.sectionsDescription = exports.hookDescription = exports.componentDescription = exports.apiKey = void 0;
|
|
4
4
|
// Autocomplete key index
|
|
5
5
|
exports.apiKey = 'key_M57QS8SMPdLdLx4x';
|
|
6
6
|
/// //////////////////////////////
|
|
@@ -186,8 +186,25 @@ import '@constructor-io/constructorio-ui-autocomplete/styles.css';
|
|
|
186
186
|
}
|
|
187
187
|
\`\`\`
|
|
188
188
|
`;
|
|
189
|
-
exports.advancedParametersDescription = `
|
|
190
|
-
exports.advancedParametersDefaultDescription = `Passing an \`advancedParameters\` object is optional. Passing an empty object for the \`advancedParameters\` field behaves the same as not passing an \`advancedParameters\` object at all
|
|
191
|
-
exports.termsWithGroupSuggestionsDescription = `Pass integers for the \`numTermsWithGroupSuggestions\` and \`numGroupsSuggestedPerTerm\` fields to add suggested group filters to search term suggestions. Not all suggested search terms will have group filters, so these integers are upper limits, used to specify the maximum number of terms with group filters and the maximum number of suggested group filters per term.
|
|
192
|
-
|
|
193
|
-
|
|
189
|
+
exports.advancedParametersDescription = `The stories below show how optional fields within this \`advancedParameters\` object that can be used to fine-tune the autosuggest data returned from constructor's servers.`;
|
|
190
|
+
exports.advancedParametersDefaultDescription = `Passing an \`advancedParameters\` object is optional. Passing an empty object for the \`advancedParameters\` field behaves the same as not passing an \`advancedParameters\` object at all.`;
|
|
191
|
+
exports.termsWithGroupSuggestionsDescription = `Pass integers for the \`numTermsWithGroupSuggestions\` and \`numGroupsSuggestedPerTerm\` fields to add suggested group filters to search term suggestions. Not all suggested search terms will have group filters, so these integers are upper limits, used to specify the maximum number of terms with group filters and the maximum number of suggested group filters per term.
|
|
192
|
+
|
|
193
|
+
To see this in action:
|
|
194
|
+
1. Type "pan" in the example below.
|
|
195
|
+
- Notice how the user is presented with a search term of "all week flex pant" as well as "all week flex pant in Chinos" and "all week flex pant baby in Athleisure Pants & Joggers"
|
|
196
|
+
2. Navigate to the "Terms With Group Suggestions" story (using the navigation menu to the left)
|
|
197
|
+
3. Then use the Controls to adjust the values of \`numTermsWithGroupSuggestions\` to \`3\` and \`numGroupsSuggestedPerTerm\` to \`1\`
|
|
198
|
+
4. Next, type "pan" in the example autocomplete input field.
|
|
199
|
+
- Notice how the user is presented with three different search terms that have a maximum of one "in {group}" suggestion each`;
|
|
200
|
+
exports.filteredSuggestionsDescription = `Pass a \`filters\` object under \`advancedParameters\` to apply filters to the suggestions. Any parameter supported by <a href="https://docs.constructor.io/rest_api/autocomplete_queries/" target="__blank">our autocomplete endpoint</a> can be passed under \`advancedParameters\`.
|
|
201
|
+
|
|
202
|
+
To see this in action:
|
|
203
|
+
1. Type "short" in the example below.
|
|
204
|
+
- Notice how the user is presented with only short pants as results.
|
|
205
|
+
- This is because the results are currently filtered to belong to the "Shorts" group.
|
|
206
|
+
2. Navigate to the "Filtered Suggestions" story (using the navigation menu to the left)
|
|
207
|
+
3. Then use the Controls to adjust the values of \`"group_id"\` to \`"1030"\`.
|
|
208
|
+
4. Next, type "short" in the example autocomplete input field.
|
|
209
|
+
- Notice how the user is presented with only short sleeved items as results.
|
|
210
|
+
- This is because we are filtering to the "Shirts" group`;
|
|
@@ -21,7 +21,7 @@ exports.defaultSections = [
|
|
|
21
21
|
},
|
|
22
22
|
];
|
|
23
23
|
const useCioAutocomplete = (options) => {
|
|
24
|
-
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, placeholder = 'What can we help you find today?', sections = exports.defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters
|
|
24
|
+
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, placeholder = 'What can we help you find today?', sections = exports.defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters, } = options;
|
|
25
25
|
const [query, setQuery] = (0, react_1.useState)('');
|
|
26
26
|
const previousQuery = (0, usePrevious_1.default)(query);
|
|
27
27
|
const cioClient = (0, useCioClient_1.default)({ apiKey, cioJsClient });
|
|
@@ -30,20 +30,17 @@ const transformResponse = (response, options) => {
|
|
|
30
30
|
});
|
|
31
31
|
return newSectionsData;
|
|
32
32
|
};
|
|
33
|
-
const autocompleteParameters = {
|
|
34
|
-
resultsPerSection: {},
|
|
35
|
-
// numResults: 8,
|
|
36
|
-
// hiddenFields: [],
|
|
37
|
-
// filters: {},
|
|
38
|
-
// variationsMap: {}
|
|
39
|
-
};
|
|
40
33
|
const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advancedParameters) => {
|
|
41
34
|
const [sectionsData, setSectionsData] = (0, react_1.useState)({});
|
|
42
35
|
const debouncedSearchTerm = (0, useDebounce_1.default)(query);
|
|
43
|
-
const { numTermsWithGroupSuggestions = 0, numGroupsSuggestedPerTerm = 0 } = advancedParameters;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
const { numTermsWithGroupSuggestions = 0, numGroupsSuggestedPerTerm = 0 } = advancedParameters || {};
|
|
37
|
+
const autocompleteParameters = (0, react_1.useMemo)(() => {
|
|
38
|
+
const decoratedParameters = Object.assign({}, advancedParameters);
|
|
39
|
+
if (autocompleteSections) {
|
|
40
|
+
decoratedParameters.resultsPerSection = autocompleteSections.reduce((acc, sectionConfig) => (Object.assign(Object.assign({}, acc), { [sectionConfig.identifier]: (sectionConfig === null || sectionConfig === void 0 ? void 0 : sectionConfig.numResults) || 8 })), {});
|
|
41
|
+
}
|
|
42
|
+
return decoratedParameters;
|
|
43
|
+
}, [autocompleteSections, advancedParameters]);
|
|
47
44
|
(0, react_1.useEffect)(() => {
|
|
48
45
|
(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
49
46
|
if (debouncedSearchTerm.trim()) {
|
|
@@ -56,6 +53,7 @@ const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advanc
|
|
|
56
53
|
setSectionsData(newSectionsData);
|
|
57
54
|
}
|
|
58
55
|
catch (error) {
|
|
56
|
+
// eslint-disable-next-line no-console
|
|
59
57
|
console.log(error);
|
|
60
58
|
}
|
|
61
59
|
}
|
|
@@ -63,7 +61,13 @@ const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advanc
|
|
|
63
61
|
setSectionsData({});
|
|
64
62
|
}
|
|
65
63
|
}))();
|
|
66
|
-
}, [
|
|
64
|
+
}, [
|
|
65
|
+
debouncedSearchTerm,
|
|
66
|
+
cioClient,
|
|
67
|
+
numTermsWithGroupSuggestions,
|
|
68
|
+
numGroupsSuggestedPerTerm,
|
|
69
|
+
autocompleteParameters,
|
|
70
|
+
]);
|
|
67
71
|
return sectionsData;
|
|
68
72
|
};
|
|
69
73
|
exports.default = useDebouncedFetchSection;
|
|
@@ -8,7 +8,7 @@ const useFetchRecommendationPod_1 = tslib_1.__importDefault(require("./useFetchR
|
|
|
8
8
|
function useSections(query, cioClient, sections, zeroStateSections, advancedParameters) {
|
|
9
9
|
const zeroStateActiveSections = !query.length && zeroStateSections;
|
|
10
10
|
const [activeSections, setActiveSections] = (0, react_1.useState)(zeroStateActiveSections ? zeroStateSections : sections);
|
|
11
|
-
const autocompleteSections = activeSections === null || activeSections === void 0 ? void 0 : activeSections.filter((config) => config.type === 'autocomplete' || !config.type);
|
|
11
|
+
const autocompleteSections = (0, react_1.useMemo)(() => activeSections === null || activeSections === void 0 ? void 0 : activeSections.filter((config) => config.type === 'autocomplete' || !config.type), [activeSections]);
|
|
12
12
|
const recommendationsSections = activeSections === null || activeSections === void 0 ? void 0 : activeSections.filter((config) => config.type === 'recommendations');
|
|
13
13
|
// Fetch Autocomplete Results
|
|
14
14
|
const autocompleteResults = (0, useDebouncedFetchSections_1.default)(query, cioClient, autocompleteSections, advancedParameters);
|
package/lib/mjs/constants.js
CHANGED
|
@@ -182,8 +182,25 @@ import '@constructor-io/constructorio-ui-autocomplete/styles.css';
|
|
|
182
182
|
}
|
|
183
183
|
\`\`\`
|
|
184
184
|
`;
|
|
185
|
-
export const advancedParametersDescription = `
|
|
186
|
-
export const advancedParametersDefaultDescription = `Passing an \`advancedParameters\` object is optional. Passing an empty object for the \`advancedParameters\` field behaves the same as not passing an \`advancedParameters\` object at all
|
|
187
|
-
export const termsWithGroupSuggestionsDescription = `Pass integers for the \`numTermsWithGroupSuggestions\` and \`numGroupsSuggestedPerTerm\` fields to add suggested group filters to search term suggestions. Not all suggested search terms will have group filters, so these integers are upper limits, used to specify the maximum number of terms with group filters and the maximum number of suggested group filters per term.
|
|
188
|
-
|
|
189
|
-
|
|
185
|
+
export const advancedParametersDescription = `The stories below show how optional fields within this \`advancedParameters\` object that can be used to fine-tune the autosuggest data returned from constructor's servers.`;
|
|
186
|
+
export const advancedParametersDefaultDescription = `Passing an \`advancedParameters\` object is optional. Passing an empty object for the \`advancedParameters\` field behaves the same as not passing an \`advancedParameters\` object at all.`;
|
|
187
|
+
export const termsWithGroupSuggestionsDescription = `Pass integers for the \`numTermsWithGroupSuggestions\` and \`numGroupsSuggestedPerTerm\` fields to add suggested group filters to search term suggestions. Not all suggested search terms will have group filters, so these integers are upper limits, used to specify the maximum number of terms with group filters and the maximum number of suggested group filters per term.
|
|
188
|
+
|
|
189
|
+
To see this in action:
|
|
190
|
+
1. Type "pan" in the example below.
|
|
191
|
+
- Notice how the user is presented with a search term of "all week flex pant" as well as "all week flex pant in Chinos" and "all week flex pant baby in Athleisure Pants & Joggers"
|
|
192
|
+
2. Navigate to the "Terms With Group Suggestions" story (using the navigation menu to the left)
|
|
193
|
+
3. Then use the Controls to adjust the values of \`numTermsWithGroupSuggestions\` to \`3\` and \`numGroupsSuggestedPerTerm\` to \`1\`
|
|
194
|
+
4. Next, type "pan" in the example autocomplete input field.
|
|
195
|
+
- Notice how the user is presented with three different search terms that have a maximum of one "in {group}" suggestion each`;
|
|
196
|
+
export const filteredSuggestionsDescription = `Pass a \`filters\` object under \`advancedParameters\` to apply filters to the suggestions. Any parameter supported by <a href="https://docs.constructor.io/rest_api/autocomplete_queries/" target="__blank">our autocomplete endpoint</a> can be passed under \`advancedParameters\`.
|
|
197
|
+
|
|
198
|
+
To see this in action:
|
|
199
|
+
1. Type "short" in the example below.
|
|
200
|
+
- Notice how the user is presented with only short pants as results.
|
|
201
|
+
- This is because the results are currently filtered to belong to the "Shorts" group.
|
|
202
|
+
2. Navigate to the "Filtered Suggestions" story (using the navigation menu to the left)
|
|
203
|
+
3. Then use the Controls to adjust the values of \`"group_id"\` to \`"1030"\`.
|
|
204
|
+
4. Next, type "short" in the example autocomplete input field.
|
|
205
|
+
- Notice how the user is presented with only short sleeved items as results.
|
|
206
|
+
- This is because we are filtering to the "Shirts" group`;
|
|
@@ -17,7 +17,7 @@ export const defaultSections = [
|
|
|
17
17
|
},
|
|
18
18
|
];
|
|
19
19
|
const useCioAutocomplete = (options) => {
|
|
20
|
-
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, placeholder = 'What can we help you find today?', sections = defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters
|
|
20
|
+
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, placeholder = 'What can we help you find today?', sections = defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters, } = options;
|
|
21
21
|
const [query, setQuery] = useState('');
|
|
22
22
|
const previousQuery = usePrevious(query);
|
|
23
23
|
const cioClient = useCioClient({ apiKey, cioJsClient });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import useDebounce from './useDebounce';
|
|
3
3
|
const transformResponse = (response, options) => {
|
|
4
4
|
const { numTermsWithGroupSuggestions, numGroupsSuggestedPerTerm } = options;
|
|
@@ -31,23 +31,20 @@ const transformResponse = (response, options) => {
|
|
|
31
31
|
});
|
|
32
32
|
return newSectionsData;
|
|
33
33
|
};
|
|
34
|
-
const autocompleteParameters = {
|
|
35
|
-
resultsPerSection: {},
|
|
36
|
-
// numResults: 8,
|
|
37
|
-
// hiddenFields: [],
|
|
38
|
-
// filters: {},
|
|
39
|
-
// variationsMap: {}
|
|
40
|
-
};
|
|
41
34
|
const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advancedParameters) => {
|
|
42
35
|
const [sectionsData, setSectionsData] = useState({});
|
|
43
36
|
const debouncedSearchTerm = useDebounce(query);
|
|
44
|
-
const { numTermsWithGroupSuggestions = 0, numGroupsSuggestedPerTerm = 0 } = advancedParameters;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
const { numTermsWithGroupSuggestions = 0, numGroupsSuggestedPerTerm = 0 } = advancedParameters || {};
|
|
38
|
+
const autocompleteParameters = useMemo(() => {
|
|
39
|
+
const decoratedParameters = { ...advancedParameters };
|
|
40
|
+
if (autocompleteSections) {
|
|
41
|
+
decoratedParameters.resultsPerSection = autocompleteSections.reduce((acc, sectionConfig) => ({
|
|
42
|
+
...acc,
|
|
43
|
+
[sectionConfig.identifier]: sectionConfig?.numResults || 8,
|
|
44
|
+
}), {});
|
|
45
|
+
}
|
|
46
|
+
return decoratedParameters;
|
|
47
|
+
}, [autocompleteSections, advancedParameters]);
|
|
51
48
|
useEffect(() => {
|
|
52
49
|
(async () => {
|
|
53
50
|
if (debouncedSearchTerm.trim()) {
|
|
@@ -60,6 +57,7 @@ const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advanc
|
|
|
60
57
|
setSectionsData(newSectionsData);
|
|
61
58
|
}
|
|
62
59
|
catch (error) {
|
|
60
|
+
// eslint-disable-next-line no-console
|
|
63
61
|
console.log(error);
|
|
64
62
|
}
|
|
65
63
|
}
|
|
@@ -67,7 +65,13 @@ const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advanc
|
|
|
67
65
|
setSectionsData({});
|
|
68
66
|
}
|
|
69
67
|
})();
|
|
70
|
-
}, [
|
|
68
|
+
}, [
|
|
69
|
+
debouncedSearchTerm,
|
|
70
|
+
cioClient,
|
|
71
|
+
numTermsWithGroupSuggestions,
|
|
72
|
+
numGroupsSuggestedPerTerm,
|
|
73
|
+
autocompleteParameters,
|
|
74
|
+
]);
|
|
71
75
|
return sectionsData;
|
|
72
76
|
};
|
|
73
77
|
export default useDebouncedFetchSection;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import { getActiveSectionsWithData } from '../utils';
|
|
3
3
|
import useDebouncedFetchSection from './useDebouncedFetchSections';
|
|
4
4
|
import useFetchRecommendationPod from './useFetchRecommendationPod';
|
|
5
5
|
export default function useSections(query, cioClient, sections, zeroStateSections, advancedParameters) {
|
|
6
6
|
const zeroStateActiveSections = !query.length && zeroStateSections;
|
|
7
7
|
const [activeSections, setActiveSections] = useState(zeroStateActiveSections ? zeroStateSections : sections);
|
|
8
|
-
const autocompleteSections = activeSections?.filter((config) => config.type === 'autocomplete' || !config.type);
|
|
8
|
+
const autocompleteSections = useMemo(() => activeSections?.filter((config) => config.type === 'autocomplete' || !config.type), [activeSections]);
|
|
9
9
|
const recommendationsSections = activeSections?.filter((config) => config.type === 'recommendations');
|
|
10
10
|
// Fetch Autocomplete Results
|
|
11
11
|
const autocompleteResults = useDebouncedFetchSection(query, cioClient, autocompleteSections, advancedParameters);
|
package/lib/types/constants.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export declare const zeroStateSectionsDescription = "Use `zeroStateSections` to
|
|
|
23
23
|
export declare const openOnFocusDescription = "Use `openOnFocus: false` to show suggestions after a user clears their query, but not when they initially apply focus to the search input field";
|
|
24
24
|
export declare const multipleSectionsDescription = "Use as many different `recommendations` and `custom` sections as you'd like and in whatever order you would like!";
|
|
25
25
|
export declare const customStylesDescription = "\nBy default, importing react components or hooks from this library does not pull any css into your project.\n\nIf you wish to use some starter styles from this library, add an import statement similar to the example import statement below:\n\n`\nimport '@constructor-io/constructorio-ui-autocomplete/styles.css';\n`\n\n<i></i>\n\n- To opt out of all default styling, do not import the `styles.css` stylesheet.\n- The path and syntax in the example above may change depending on your module bundling strategy\n- These starter styles can be used as a foundation to build on top of, or just as a reference for you to replace completely.\n- All starter styles in this library are scoped within the `.cio-autocomplete` css selector.\n- These starter styles are intended to be extended by layering in your own css rules\n- If you like, you can override the container's className like so:\n`autocompleteClassName='custom-autocomplete-container'`\n- If you like, you can pass additional className(s) of your choosing like so:\n`autocompleteClassName='cio-autocomplete custom-autocomplete-container'`\n\n\n```css\n/* Custom Style Sheet */\n.cio-autocomplete.custom-autocomplete-styles form {\n height: 44px;\n width: 600px;\n border-radius: 8px;\n background-color: rgb(247, 247, 247);\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-input {\n font-weight: bold;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-form button {\n width: 44px;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-clear-btn {\n right: 24px;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-sectionName {\n margin: 5px 3px;\n}\n\n.cio-autocomplete.custom-autocomplete-styles .cio-results {\n width: 620px;\n max-height: 334px;\n overflow: hidden;\n border-radius: 0px 0px 8px 8px;\n color: rgb(51, 51, 51);\n}\n\n.cio-autocomplete.custom-autocomplete-styles .Products p {\n padding: 5px 5px 0;\n}\n```\n";
|
|
26
|
-
export declare const advancedParametersDescription = "
|
|
27
|
-
export declare const advancedParametersDefaultDescription = "Passing an `advancedParameters` object is optional. Passing an empty object for the `advancedParameters` field behaves the same as not passing an `advancedParameters` object at all.
|
|
28
|
-
export declare const termsWithGroupSuggestionsDescription = "Pass integers for the `numTermsWithGroupSuggestions` and `numGroupsSuggestedPerTerm` fields to add suggested group filters to search term suggestions. Not all suggested search terms will have group filters, so these integers are upper limits, used to specify the maximum number of terms with group filters and the maximum number of suggested group filters per term
|
|
26
|
+
export declare const advancedParametersDescription = "The stories below show how optional fields within this `advancedParameters` object that can be used to fine-tune the autosuggest data returned from constructor's servers.";
|
|
27
|
+
export declare const advancedParametersDefaultDescription = "Passing an `advancedParameters` object is optional. Passing an empty object for the `advancedParameters` field behaves the same as not passing an `advancedParameters` object at all.";
|
|
28
|
+
export declare const termsWithGroupSuggestionsDescription = "Pass integers for the `numTermsWithGroupSuggestions` and `numGroupsSuggestedPerTerm` fields to add suggested group filters to search term suggestions. Not all suggested search terms will have group filters, so these integers are upper limits, used to specify the maximum number of terms with group filters and the maximum number of suggested group filters per term.\n\nTo see this in action:\n1. Type \"pan\" in the example below.\n - Notice how the user is presented with a search term of \"all week flex pant\" as well as \"all week flex pant in Chinos\" and \"all week flex pant baby in Athleisure Pants & Joggers\"\n2. Navigate to the \"Terms With Group Suggestions\" story (using the navigation menu to the left)\n3. Then use the Controls to adjust the values of `numTermsWithGroupSuggestions` to `3` and `numGroupsSuggestedPerTerm` to `1`\n4. Next, type \"pan\" in the example autocomplete input field.\n - Notice how the user is presented with three different search terms that have a maximum of one \"in {group}\" suggestion each";
|
|
29
|
+
export declare const filteredSuggestionsDescription = "Pass a `filters` object under `advancedParameters` to apply filters to the suggestions. Any parameter supported by <a href=\"https://docs.constructor.io/rest_api/autocomplete_queries/\" target=\"__blank\">our autocomplete endpoint</a> can be passed under `advancedParameters`.\n\nTo see this in action:\n1. Type \"short\" in the example below.\n - Notice how the user is presented with only short pants as results.\n - This is because the results are currently filtered to belong to the \"Shorts\" group.\n2. Navigate to the \"Filtered Suggestions\" story (using the navigation menu to the left)\n3. Then use the Controls to adjust the values of `\"group_id\"` to `\"1030\"`.\n4. Next, type \"short\" in the example autocomplete input field.\n - Notice how the user is presented with only short sleeved items as results.\n - This is because we are filtering to the \"Shirts\" group";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
2
|
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types/types';
|
|
3
3
|
import { AutocompleteResultSections, UserDefinedSection, AdvancedParameters } from '../types';
|
|
4
|
-
declare const useDebouncedFetchSection: (query: string, cioClient: Nullable<ConstructorIOClient>, autocompleteSections: UserDefinedSection[], advancedParameters
|
|
4
|
+
declare const useDebouncedFetchSection: (query: string, cioClient: Nullable<ConstructorIOClient>, autocompleteSections: UserDefinedSection[], advancedParameters?: AdvancedParameters) => AutocompleteResultSections;
|
|
5
5
|
export default useDebouncedFetchSection;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ConstructorIO from '@constructor-io/constructorio-client-javascript';
|
|
2
2
|
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types/types';
|
|
3
3
|
import { AdvancedParameters, UserDefinedSection } from '../types';
|
|
4
|
-
export default function useSections(query: string, cioClient: Nullable<ConstructorIO>, sections: UserDefinedSection[], zeroStateSections: UserDefinedSection[] | undefined, advancedParameters
|
|
4
|
+
export default function useSections(query: string, cioClient: Nullable<ConstructorIO>, sections: UserDefinedSection[], zeroStateSections: UserDefinedSection[] | undefined, advancedParameters?: AdvancedParameters): {
|
|
5
5
|
activeSections: UserDefinedSection[];
|
|
6
6
|
activeSectionsWithData: import("../types").Section[];
|
|
7
7
|
zeroStateActiveSections: false | UserDefinedSection[] | undefined;
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GetItemPropsOptions } from 'downshift';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
4
|
+
import { IAutocompleteParameters } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
4
5
|
export type CioClientConfig = {
|
|
5
6
|
apiKey?: string;
|
|
6
7
|
cioJsClient?: ConstructorIOClient;
|
|
@@ -8,7 +9,7 @@ export type CioClientConfig = {
|
|
|
8
9
|
export type AdvancedParameters = {
|
|
9
10
|
numTermsWithGroupSuggestions?: number;
|
|
10
11
|
numGroupsSuggestedPerTerm?: number;
|
|
11
|
-
}
|
|
12
|
+
} & Omit<IAutocompleteParameters, 'resultsPerSection'>;
|
|
12
13
|
export type CioAutocompleteProps = CioClientConfig & {
|
|
13
14
|
openOnFocus?: boolean;
|
|
14
15
|
onSubmit: OnSubmit;
|
package/package.json
CHANGED