@usereactify/search 5.55.0-beta.1 → 5.55.0-beta.3
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 +14 -0
- package/dist/package.json +1 -1
- package/dist/src/components/Filter/Filter.js +8 -35
- package/dist/src/components/Filter/Filter.js.map +1 -1
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js +15 -0
- package/dist/src/components/ReactifySearchProvider/ReactifySearchProvider.js.map +1 -1
- package/dist/src/hooks/useFilterSliderProps.d.ts +1 -0
- package/dist/src/hooks/useFilterSliderProps.js +35 -0
- package/dist/src/hooks/useFilterSliderProps.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
## [5.55.0-beta.3](https://bitbucket.org/usereactify/reactify-search-ui/compare/beta-v5.55.0-beta.2...beta-v5.55.0-beta.3) (2024-11-21)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* parse initial query for sliders before page load ([8896226](https://bitbucket.org/usereactify/reactify-search-ui/commit/889622623081121e65af4408983e426b1d1f4b4b))
|
|
11
|
+
|
|
12
|
+
## [5.55.0-beta.2](https://bitbucket.org/usereactify/reactify-search-ui/compare/beta-v5.55.0-beta.1...beta-v5.55.0-beta.2) (2024-11-20)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* disable URL params analysis when mode is instant-search ([a460a8c](https://bitbucket.org/usereactify/reactify-search-ui/commit/a460a8c56cbeb1352b4a258ee6452d8324f3342a))
|
|
18
|
+
|
|
5
19
|
## [5.55.0-beta.1](https://bitbucket.org/usereactify/reactify-search-ui/compare/beta-v5.55.0-beta.0...beta-v5.55.0-beta.1) (2024-11-17)
|
|
6
20
|
|
|
7
21
|
|
package/dist/package.json
CHANGED
|
@@ -122,6 +122,7 @@ const FilterSlider = (props) => {
|
|
|
122
122
|
config: reactifySearchContext.config,
|
|
123
123
|
filterGroup: filtersHook.filterStack,
|
|
124
124
|
}, props.filter);
|
|
125
|
+
const filterSliderProps = (0, hooks_1.useFilterSliderProps)(props.filter);
|
|
125
126
|
return (react_1.default.createElement(ReactiveComponent_1.default, Object.assign({}, sharedProps, { defaultQuery: () => ({
|
|
126
127
|
aggs: {
|
|
127
128
|
min: {
|
|
@@ -135,21 +136,20 @@ const FilterSlider = (props) => {
|
|
|
135
136
|
},
|
|
136
137
|
},
|
|
137
138
|
},
|
|
138
|
-
}), render: (reactivesearchFilterProps) => {
|
|
139
|
+
}), customQuery: filterSliderProps.query, render: (reactivesearchFilterProps) => {
|
|
139
140
|
var _a, _b, _c, _d;
|
|
140
141
|
if (!props.showEmptyFilters &&
|
|
141
142
|
((_b = (_a = reactivesearchFilterProps === null || reactivesearchFilterProps === void 0 ? void 0 : reactivesearchFilterProps.aggregations) === null || _a === void 0 ? void 0 : _a.min) === null || _b === void 0 ? void 0 : _b.value) ===
|
|
142
143
|
((_d = (_c = reactivesearchFilterProps === null || reactivesearchFilterProps === void 0 ? void 0 : reactivesearchFilterProps.aggregations) === null || _c === void 0 ? void 0 : _c.max) === null || _d === void 0 ? void 0 : _d.value)) {
|
|
143
144
|
return null;
|
|
144
145
|
}
|
|
145
|
-
return (react_1.default.createElement(FilterSliderInner, Object.assign({}, props, { reactivesearchFilterProps: reactivesearchFilterProps })));
|
|
146
|
+
return (react_1.default.createElement(FilterSliderInner, Object.assign({}, props, { filterSliderProps: filterSliderProps, reactivesearchFilterProps: reactivesearchFilterProps })));
|
|
146
147
|
} })));
|
|
147
148
|
};
|
|
148
149
|
// inner component exists only so we can use memos in reactivesearch render functions
|
|
149
150
|
const FilterSliderInner = (props) => {
|
|
150
151
|
var _a, _b, _c;
|
|
151
|
-
const { filter, renderFilterSlider, reactivesearchFilterProps } = props, otherProps = __rest(props, ["filter", "renderFilterSlider", "reactivesearchFilterProps"]);
|
|
152
|
-
const filterSliderProps = (0, hooks_1.useFilterSliderProps)(filter);
|
|
152
|
+
const { filter, renderFilterSlider, filterSliderProps, reactivesearchFilterProps } = props, otherProps = __rest(props, ["filter", "renderFilterSlider", "filterSliderProps", "reactivesearchFilterProps"]);
|
|
153
153
|
react_1.default.useEffect(() => {
|
|
154
154
|
if (reactivesearchFilterProps.aggregations) {
|
|
155
155
|
filterSliderProps.handleRange([
|
|
@@ -162,43 +162,16 @@ const FilterSliderInner = (props) => {
|
|
|
162
162
|
(_b = reactivesearchFilterProps.aggregations) === null || _b === void 0 ? void 0 : _b.max.value,
|
|
163
163
|
]);
|
|
164
164
|
react_1.default.useEffect(() => {
|
|
165
|
-
if (filterSliderProps.
|
|
165
|
+
if (!filterSliderProps.query) {
|
|
166
166
|
return;
|
|
167
167
|
}
|
|
168
168
|
props.reactivesearchFilterProps.setQuery({
|
|
169
|
-
query:
|
|
170
|
-
query: {
|
|
171
|
-
bool: {
|
|
172
|
-
must: [
|
|
173
|
-
{
|
|
174
|
-
bool: {
|
|
175
|
-
must: [
|
|
176
|
-
{
|
|
177
|
-
match: {
|
|
178
|
-
published: true,
|
|
179
|
-
},
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
range: {
|
|
183
|
-
[props.filter.field]: {
|
|
184
|
-
gte: filterSliderProps.value[0],
|
|
185
|
-
lte: filterSliderProps.value[1],
|
|
186
|
-
boost: 2,
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
],
|
|
191
|
-
},
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
},
|
|
169
|
+
query: filterSliderProps.query,
|
|
197
170
|
value: filterSliderProps.value,
|
|
198
171
|
});
|
|
199
172
|
}, [filterSliderProps.value]);
|
|
200
|
-
const
|
|
201
|
-
return (react_1.default.createElement(
|
|
173
|
+
const RenderSliderComponent = (_c = props.renderFilterSlider) !== null && _c !== void 0 ? _c : components_1.ExampleFilterSlider;
|
|
174
|
+
return (react_1.default.createElement(RenderSliderComponent, Object.assign({ filterSliderProps: filterSliderProps, filter: filter }, otherProps)));
|
|
202
175
|
};
|
|
203
176
|
// inner component exists only so we can use memos in reactivesearch render functions
|
|
204
177
|
const FilterListInner = (props) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Filter.js","sourceRoot":"","sources":["../../../../src/components/Filter/Filter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,6HAAqG;AACrG,4GAAoF;AACpF,8GAAsF;AACtF,iHAAyF;AACzF,+GAAuF;AAMvF,uCAMqB;AACrB,iDAI0B;AAC1B,+CAA8F;AAyBvF,MAAM,MAAM,GAA0B,CAAC,KAAK,EAAE,EAAE;IACrD,IAAI,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAC1C,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACzC,OAAO,8BAAC,iBAAiB,oBAAK,KAAK,EAAI,CAAC;QAC1C,CAAC;QACD,OAAO,8BAAC,gBAAgB,oBAAK,KAAK,EAAI,CAAC;IACzC,CAAC;IAED,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QACzC,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACzC,OAAO,8BAAC,gBAAgB,oBAAK,KAAK,EAAI,CAAC;QACzC,CAAC;QACD,OAAO,8BAAC,eAAe,oBAAK,KAAK,EAAI,CAAC;IACxC,CAAC;IAED,IAAI,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAC1C,OAAO,8BAAC,YAAY,oBAAK,KAAK,EAAI,CAAC;IACr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ACL,CAAC,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IAE9B,MAAM,mBAAmB,GAAG,MAAA,KAAK,CAAC,kBAAkB,mCAAI,gCAAmB,CAAC;IAE5E,OAAO,CACL,8BAAC,mBAAmB,kBAClB,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,qFAAqF;AACrF,MAAM,eAAe,GAEjB,CAAC,KAAK,EAAE,EAAE;;IACZ,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,yBAAyB,KACzD,KAAK,EADyD,UAAU,UACxE,KAAK,EADD,2DAAsE,CACrE,CAAC;IAER,MAAM,eAAe,GAAG,IAAA,0BAAkB,EAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;IAE9E,+CAA+C;IAC/C,IAAI,CAAC,KAAK,CAAC,gBAAgB,IAAI,CAAC,KAAK,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,mBAAmB,GAAG,MAAA,KAAK,CAAC,gBAAgB,mCAAI,8BAAiB,CAAC;IAExE,OAAO,CACL,8BAAC,mBAAmB,kBAClB,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@usereactify/search-internals/lib/components/basic/ReactiveComponent\";\nimport MultiList from \"@usereactify/search-internals/lib/components/list/MultiList\";\nimport SingleList from \"@usereactify/search-internals/lib/components/list/SingleList\";\nimport SingleRange from \"@usereactify/search-internals/lib/components/range/SingleRange\";\nimport MultiRange from \"@usereactify/search-internals/lib/components/range/MultiRange\";\n\nimport type {\n ConfigFilterFacet,\n ReactivesearchFilterListProps,\n} from \"../../types\";\nimport {\n useFilterListProps,\n useFilterRangeProps,\n useFilterSliderProps,\n useFilters,\n useReactifySearchContext,\n} from \"../../hooks\";\nimport {\n ExampleFilterList,\n ExampleFilterRange,\n ExampleFilterSlider,\n} from \"../../components\";\nimport { getPropsFilterList, getPropsFilterRange, getPropsShared } from \"../../utility/props\";\n\nexport type FilterProps = {\n /** The filter option being rendered */\n filter: ConfigFilterFacet;\n /** Render method for List filters */\n renderFilterList?: React.FC<{\n filter: ConfigFilterFacet;\n filterListProps: ReturnType<typeof useFilterListProps>;\n }>;\n /** Render method for Range filters */\n renderFilterRange?: React.FC<{\n filter: ConfigFilterFacet;\n filterRangeProps: ReturnType<typeof useFilterRangeProps>;\n }>;\n /** Render method for Slider filters */\n renderFilterSlider?: React.FC<{\n filter: ConfigFilterFacet;\n filterSliderProps: ReturnType<typeof useFilterSliderProps>;\n // reactSliderProps: ReturnType<typeof useReactSliderProps>;\n }>;\n /** Show filters even when no options are available */\n showEmptyFilters?: boolean;\n};\n\nexport const Filter: React.FC<FilterProps> = (props) => {\n if (\"single\" === props.filter.displayType) {\n if (\"range\" === props.filter.displayView) {\n return <FilterRangeSingle {...props} />;\n }\n return <FilterSingleList {...props} />;\n }\n\n if (\"multi\" === props.filter.displayType) {\n if (\"range\" === props.filter.displayView) {\n return <FilterRangeMulti {...props} />;\n }\n return <FilterMultiList {...props} />;\n }\n\n if (\"slider\" === props.filter.displayType) {\n return <FilterSlider {...props} />;\n }\n\n // TODO: Legacy range filter, migrate to new single and multi ranges\n if (\"range\" === props.filter.displayType) {\n return <FilterRangeSingle {...props} />;\n }\n\n console.warn(\n `filter with display type \"${props.filter.displayType}\" not yet supported`\n );\n\n return null;\n};\n\nconst FilterSingleList: React.FC<FilterProps> = (props) => {\n const reactifySearchContext = useReactifySearchContext();\n const filtersHook = useFilters();\n const sharedProps = getPropsShared({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n filterGroup: filtersHook.filterStack,\n }, props.filter);\n const reactiveProps = getPropsFilterList(props.filter);\n\n return (\n <SingleList\n {...sharedProps}\n {...reactiveProps}\n render={(reactivesearchFilterProps: ReactivesearchFilterListProps) => (\n <FilterListInner\n {...props}\n reactivesearchFilterProps={reactivesearchFilterProps}\n />\n )}\n />\n );\n};\n\nconst FilterMultiList: React.FC<FilterProps> = (props) => {\n const reactifySearchContext = useReactifySearchContext();\n const filtersHook = useFilters();\n const sharedProps = getPropsShared({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n filterGroup: filtersHook.filterStack,\n }, props.filter);\n const reactiveProps = getPropsFilterList(props.filter);\n\n return (\n <MultiList\n {...sharedProps}\n {...reactiveProps}\n render={(reactivesearchFilterProps: ReactivesearchFilterListProps) => (\n <FilterListInner\n {...props}\n reactivesearchFilterProps={reactivesearchFilterProps}\n />\n )}\n />\n );\n};\n\nconst FilterRangeSingle: React.FC<FilterProps> = (props) => {\n const reactifySearchContext = useReactifySearchContext();\n const filtersHook = useFilters();\n const sharedProps = getPropsShared({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n filterGroup: filtersHook.filterStack,\n }, props.filter);\n const reactiveProps = getPropsFilterRange(props.filter);\n\n const filterRangeProps = useFilterRangeProps(props.filter);\n\n const RenderRangeComponent = props.renderFilterRange ?? ExampleFilterRange;\n\n return (\n <>\n <div\n style={{\n display: \"none\",\n }}\n >\n <SingleRange\n {...sharedProps}\n {...reactiveProps}\n value={filterRangeProps.values[0]}\n onChange={filterRangeProps.handleChange}\n />\n </div>\n <RenderRangeComponent\n filterRangeProps={filterRangeProps}\n filter={props.filter}\n />\n </>\n );\n};\n\nconst FilterRangeMulti: React.FC<FilterProps> = (props) => {\n const reactifySearchContext = useReactifySearchContext();\n const filtersHook = useFilters();\n const sharedProps = getPropsShared({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n filterGroup: filtersHook.filterStack,\n }, props.filter);\n const reactiveProps = getPropsFilterRange(props.filter);\n\n const filterRangeProps = useFilterRangeProps(props.filter);\n\n const RenderRangeComponent = props.renderFilterRange ?? ExampleFilterRange;\n\n return (\n <>\n <div\n style={{\n display: \"none\",\n }}\n >\n <MultiRange\n {...sharedProps}\n {...reactiveProps}\n value={filterRangeProps.values}\n // @note: onChange handler must be defined for controlled component to work correctly\n onChange={() => {}}\n onValueChange={(values) => {\n if (values.length === 0) {\n filterRangeProps.handleClear();\n }\n }}\n />\n </div>\n <RenderRangeComponent\n filterRangeProps={filterRangeProps}\n filter={props.filter}\n />\n </>\n );\n};\n\nconst FilterSlider: React.FC<FilterProps> = (props) => {\n const reactifySearchContext = useReactifySearchContext();\n const filtersHook = useFilters();\n const sharedProps = getPropsShared({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n filterGroup: filtersHook.filterStack,\n }, props.filter);\n\n return (\n <ReactiveComponent\n {...sharedProps}\n defaultQuery={() => ({\n aggs: {\n min: {\n min: {\n field: props.filter.field,\n },\n },\n max: {\n max: {\n field: props.filter.field,\n },\n },\n },\n })}\n render={(reactivesearchFilterProps) => {\n if (\n !props.showEmptyFilters &&\n reactivesearchFilterProps?.aggregations?.min?.value ===\n reactivesearchFilterProps?.aggregations?.max?.value\n ) {\n return null;\n }\n\n return (\n <FilterSliderInner\n {...props}\n reactivesearchFilterProps={reactivesearchFilterProps}\n />\n );\n }}\n />\n );\n};\n\n// inner component exists only so we can use memos in reactivesearch render functions\nconst FilterSliderInner: React.FC<\n FilterProps & { reactivesearchFilterProps: any }\n> = (props) => {\n const {\n filter,\n renderFilterSlider,\n reactivesearchFilterProps,\n ...otherProps\n } = props;\n\n const filterSliderProps = useFilterSliderProps(filter);\n\n React.useEffect(() => {\n if (reactivesearchFilterProps.aggregations) {\n filterSliderProps.handleRange([\n reactivesearchFilterProps.aggregations.min.value,\n reactivesearchFilterProps.aggregations.max.value,\n ]);\n }\n }, [\n reactivesearchFilterProps.aggregations?.min.value,\n reactivesearchFilterProps.aggregations?.max.value,\n ]);\n\n React.useEffect(() => {\n if (filterSliderProps.value[0] === 0 && filterSliderProps.value[1] === 0) {\n return;\n }\n\n props.reactivesearchFilterProps.setQuery({\n query: {\n query: {\n bool: {\n must: [\n {\n bool: {\n must: [\n {\n match: {\n published: true,\n },\n },\n {\n range: {\n [props.filter.field]: {\n gte: filterSliderProps.value[0],\n lte: filterSliderProps.value[1],\n boost: 2,\n },\n },\n },\n ],\n },\n },\n ],\n },\n },\n },\n value: filterSliderProps.value,\n });\n }, [filterSliderProps.value]);\n\n const RenderListComponent = props.renderFilterSlider ?? ExampleFilterSlider;\n\n return (\n <RenderListComponent\n filterSliderProps={filterSliderProps}\n filter={filter}\n {...otherProps}\n />\n );\n};\n\n// inner component exists only so we can use memos in reactivesearch render functions\nconst FilterListInner: React.FC<\n FilterProps & { reactivesearchFilterProps: ReactivesearchFilterListProps }\n> = (props) => {\n const { filter, renderFilterList, reactivesearchFilterProps, ...otherProps } =\n props;\n\n const filterListProps = useFilterListProps(filter, reactivesearchFilterProps);\n\n // hide entire filter when no options available\n if (!props.showEmptyFilters && 0 === filterListProps.options.length) {\n return null;\n }\n\n const RenderListComponent = props.renderFilterList ?? ExampleFilterList;\n\n return (\n <RenderListComponent\n filterListProps={filterListProps}\n filter={filter}\n {...otherProps}\n />\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"Filter.js","sourceRoot":"","sources":["../../../../src/components/Filter/Filter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,6HAAqG;AACrG,4GAAoF;AACpF,8GAAsF;AACtF,iHAAyF;AACzF,+GAAuF;AAMvF,uCAMqB;AACrB,iDAI0B;AAC1B,+CAA8F;AAyBvF,MAAM,MAAM,GAA0B,CAAC,KAAK,EAAE,EAAE;IACrD,IAAI,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QAC1C,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACzC,OAAO,8BAAC,iBAAiB,oBAAK,KAAK,EAAI,CAAC;QAC1C,CAAC;QACD,OAAO,8BAAC,gBAAgB,oBAAK,KAA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L,CAAC,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IAE9B,MAAM,qBAAqB,GAAG,MAAA,KAAK,CAAC,kBAAkB,mCAAI,gCAAmB,CAAC;IAE9E,OAAO,CACL,8BAAC,qBAAqB,kBACpB,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;AACJ,CAAC,CAAC;AAEF,qFAAqF;AACrF,MAAM,eAAe,GAEjB,CAAC,KAAK,EAAE,EAAE;;IACZ,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,yBAAyB,KACzD,KAAK,EADyD,UAAU,UACxE,KAAK,EADD,2DAAsE,CACrE,CAAC;IAER,MAAM,eAAe,GAAG,IAAA,0BAAkB,EAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;IAE9E,+CAA+C;IAC/C,IAAI,CAAC,KAAK,CAAC,gBAAgB,IAAI,CAAC,KAAK,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,mBAAmB,GAAG,MAAA,KAAK,CAAC,gBAAgB,mCAAI,8BAAiB,CAAC;IAExE,OAAO,CACL,8BAAC,mBAAmB,kBAClB,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@usereactify/search-internals/lib/components/basic/ReactiveComponent\";\nimport MultiList from \"@usereactify/search-internals/lib/components/list/MultiList\";\nimport SingleList from \"@usereactify/search-internals/lib/components/list/SingleList\";\nimport SingleRange from \"@usereactify/search-internals/lib/components/range/SingleRange\";\nimport MultiRange from \"@usereactify/search-internals/lib/components/range/MultiRange\";\n\nimport type {\n ConfigFilterFacet,\n ReactivesearchFilterListProps,\n} from \"../../types\";\nimport {\n useFilterListProps,\n useFilterRangeProps,\n useFilterSliderProps,\n useFilters,\n useReactifySearchContext,\n} from \"../../hooks\";\nimport {\n ExampleFilterList,\n ExampleFilterRange,\n ExampleFilterSlider,\n} from \"../../components\";\nimport { getPropsFilterList, getPropsFilterRange, getPropsShared } from \"../../utility/props\";\n\nexport type FilterProps = {\n /** The filter option being rendered */\n filter: ConfigFilterFacet;\n /** Render method for List filters */\n renderFilterList?: React.FC<{\n filter: ConfigFilterFacet;\n filterListProps: ReturnType<typeof useFilterListProps>;\n }>;\n /** Render method for Range filters */\n renderFilterRange?: React.FC<{\n filter: ConfigFilterFacet;\n filterRangeProps: ReturnType<typeof useFilterRangeProps>;\n }>;\n /** Render method for Slider filters */\n renderFilterSlider?: React.FC<{\n filter: ConfigFilterFacet;\n filterSliderProps: ReturnType<typeof useFilterSliderProps>;\n // reactSliderProps: ReturnType<typeof useReactSliderProps>;\n }>;\n /** Show filters even when no options are available */\n showEmptyFilters?: boolean;\n};\n\nexport const Filter: React.FC<FilterProps> = (props) => {\n if (\"single\" === props.filter.displayType) {\n if (\"range\" === props.filter.displayView) {\n return <FilterRangeSingle {...props} />;\n }\n return <FilterSingleList {...props} />;\n }\n\n if (\"multi\" === props.filter.displayType) {\n if (\"range\" === props.filter.displayView) {\n return <FilterRangeMulti {...props} />;\n }\n return <FilterMultiList {...props} />;\n }\n\n if (\"slider\" === props.filter.displayType) {\n return <FilterSlider {...props} />;\n }\n\n // TODO: Legacy range filter, migrate to new single and multi ranges\n if (\"range\" === props.filter.displayType) {\n return <FilterRangeSingle {...props} />;\n }\n\n console.warn(\n `filter with display type \"${props.filter.displayType}\" not yet supported`\n );\n\n return null;\n};\n\nconst FilterSingleList: React.FC<FilterProps> = (props) => {\n const reactifySearchContext = useReactifySearchContext();\n const filtersHook = useFilters();\n const sharedProps = getPropsShared({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n filterGroup: filtersHook.filterStack,\n }, props.filter);\n const reactiveProps = getPropsFilterList(props.filter);\n\n return (\n <SingleList\n {...sharedProps}\n {...reactiveProps}\n render={(reactivesearchFilterProps: ReactivesearchFilterListProps) => (\n <FilterListInner\n {...props}\n reactivesearchFilterProps={reactivesearchFilterProps}\n />\n )}\n />\n );\n};\n\nconst FilterMultiList: React.FC<FilterProps> = (props) => {\n const reactifySearchContext = useReactifySearchContext();\n const filtersHook = useFilters();\n const sharedProps = getPropsShared({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n filterGroup: filtersHook.filterStack,\n }, props.filter);\n const reactiveProps = getPropsFilterList(props.filter);\n\n return (\n <MultiList\n {...sharedProps}\n {...reactiveProps}\n render={(reactivesearchFilterProps: ReactivesearchFilterListProps) => (\n <FilterListInner\n {...props}\n reactivesearchFilterProps={reactivesearchFilterProps}\n />\n )}\n />\n );\n};\n\nconst FilterRangeSingle: React.FC<FilterProps> = (props) => {\n const reactifySearchContext = useReactifySearchContext();\n const filtersHook = useFilters();\n const sharedProps = getPropsShared({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n filterGroup: filtersHook.filterStack,\n }, props.filter);\n const reactiveProps = getPropsFilterRange(props.filter);\n\n const filterRangeProps = useFilterRangeProps(props.filter);\n\n const RenderRangeComponent = props.renderFilterRange ?? ExampleFilterRange;\n\n return (\n <>\n <div\n style={{\n display: \"none\",\n }}\n >\n <SingleRange\n {...sharedProps}\n {...reactiveProps}\n value={filterRangeProps.values[0]}\n onChange={filterRangeProps.handleChange}\n />\n </div>\n <RenderRangeComponent\n filterRangeProps={filterRangeProps}\n filter={props.filter}\n />\n </>\n );\n};\n\nconst FilterRangeMulti: React.FC<FilterProps> = (props) => {\n const reactifySearchContext = useReactifySearchContext();\n const filtersHook = useFilters();\n const sharedProps = getPropsShared({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n filterGroup: filtersHook.filterStack,\n }, props.filter);\n const reactiveProps = getPropsFilterRange(props.filter);\n\n const filterRangeProps = useFilterRangeProps(props.filter);\n\n const RenderRangeComponent = props.renderFilterRange ?? ExampleFilterRange;\n\n return (\n <>\n <div\n style={{\n display: \"none\",\n }}\n >\n <MultiRange\n {...sharedProps}\n {...reactiveProps}\n value={filterRangeProps.values}\n // @note: onChange handler must be defined for controlled component to work correctly\n onChange={() => {}}\n onValueChange={(values) => {\n if (values.length === 0) {\n filterRangeProps.handleClear();\n }\n }}\n />\n </div>\n <RenderRangeComponent\n filterRangeProps={filterRangeProps}\n filter={props.filter}\n />\n </>\n );\n};\n\nconst FilterSlider: React.FC<FilterProps> = (props) => {\n const reactifySearchContext = useReactifySearchContext();\n const filtersHook = useFilters();\n const sharedProps = getPropsShared({\n provider: reactifySearchContext.options,\n config: reactifySearchContext.config,\n filterGroup: filtersHook.filterStack,\n }, props.filter);\n\n const filterSliderProps = useFilterSliderProps(props.filter);\n\n return (\n <ReactiveComponent\n {...sharedProps}\n defaultQuery={() => ({\n aggs: {\n min: {\n min: {\n field: props.filter.field,\n },\n },\n max: {\n max: {\n field: props.filter.field,\n },\n },\n },\n })}\n customQuery={filterSliderProps.query}\n render={(reactivesearchFilterProps) => {\n if (\n !props.showEmptyFilters &&\n reactivesearchFilterProps?.aggregations?.min?.value ===\n reactivesearchFilterProps?.aggregations?.max?.value\n ) {\n return null;\n }\n\n return (\n <FilterSliderInner\n {...props}\n filterSliderProps={filterSliderProps}\n reactivesearchFilterProps={reactivesearchFilterProps}\n />\n );\n }}\n />\n );\n};\n\n// inner component exists only so we can use memos in reactivesearch render functions\nconst FilterSliderInner: React.FC<\n FilterProps & { reactivesearchFilterProps: any; filterSliderProps: ReturnType<typeof useFilterSliderProps> }\n> = (props) => {\n const {\n filter,\n renderFilterSlider,\n filterSliderProps,\n reactivesearchFilterProps,\n ...otherProps\n } = props;\n\n React.useEffect(() => {\n if (reactivesearchFilterProps.aggregations) {\n filterSliderProps.handleRange([\n reactivesearchFilterProps.aggregations.min.value,\n reactivesearchFilterProps.aggregations.max.value,\n ]);\n }\n }, [\n reactivesearchFilterProps.aggregations?.min.value,\n reactivesearchFilterProps.aggregations?.max.value,\n ]);\n\n React.useEffect(() => {\n if (!filterSliderProps.query) {\n return;\n }\n\n props.reactivesearchFilterProps.setQuery({\n query: filterSliderProps.query,\n value: filterSliderProps.value,\n });\n }, [filterSliderProps.value]);\n\n const RenderSliderComponent = props.renderFilterSlider ?? ExampleFilterSlider;\n\n return (\n <RenderSliderComponent\n filterSliderProps={filterSliderProps}\n filter={filter}\n {...otherProps}\n />\n );\n};\n\n// inner component exists only so we can use memos in reactivesearch render functions\nconst FilterListInner: React.FC<\n FilterProps & { reactivesearchFilterProps: ReactivesearchFilterListProps }\n> = (props) => {\n const { filter, renderFilterList, reactivesearchFilterProps, ...otherProps } =\n props;\n\n const filterListProps = useFilterListProps(filter, reactivesearchFilterProps);\n\n // hide entire filter when no options available\n if (!props.showEmptyFilters && 0 === filterListProps.options.length) {\n return null;\n }\n\n const RenderListComponent = props.renderFilterList ?? ExampleFilterList;\n\n return (\n <RenderListComponent\n filterListProps={filterListProps}\n filter={filter}\n {...otherProps}\n />\n );\n};\n"]}
|
|
@@ -57,6 +57,7 @@ const ReactifySearchInner = (props) => {
|
|
|
57
57
|
fontSize: "inherit",
|
|
58
58
|
},
|
|
59
59
|
};
|
|
60
|
+
// search from url
|
|
60
61
|
const searchTermFromURL = react_1.default.useMemo(() => {
|
|
61
62
|
var _a;
|
|
62
63
|
if (typeof window === "undefined") {
|
|
@@ -65,6 +66,7 @@ const ReactifySearchInner = (props) => {
|
|
|
65
66
|
const urlParams = new URLSearchParams(window.location.search);
|
|
66
67
|
return (_a = urlParams.get("q")) !== null && _a !== void 0 ? _a : undefined;
|
|
67
68
|
}, [typeof window !== "undefined" && window.location.search]);
|
|
69
|
+
// sort from url
|
|
68
70
|
const searchSortFromURL = react_1.default.useMemo(() => {
|
|
69
71
|
var _a, _b;
|
|
70
72
|
if (typeof window === "undefined") {
|
|
@@ -73,6 +75,7 @@ const ReactifySearchInner = (props) => {
|
|
|
73
75
|
const urlParams = new URLSearchParams(window.location.search);
|
|
74
76
|
return (_b = urlParams.get("sort")) !== null && _b !== void 0 ? _b : undefined;
|
|
75
77
|
}, [typeof window !== "undefined" && window.location.search]);
|
|
78
|
+
// index from url
|
|
76
79
|
const indexFromURL = react_1.default.useMemo(() => {
|
|
77
80
|
var _a;
|
|
78
81
|
if (typeof window === "undefined") {
|
|
@@ -81,20 +84,32 @@ const ReactifySearchInner = (props) => {
|
|
|
81
84
|
const urlParams = new URLSearchParams(window.location.search);
|
|
82
85
|
return (_a = urlParams.get("index")) !== null && _a !== void 0 ? _a : undefined;
|
|
83
86
|
}, [typeof window !== "undefined" && window.location.search]);
|
|
87
|
+
// search term
|
|
84
88
|
const [searchTerm, setSearchTerm] = react_1.default.useState(searchTermFromURL !== null && searchTermFromURL !== void 0 ? searchTermFromURL : "");
|
|
89
|
+
// search term redirect
|
|
85
90
|
const searchRedirect = react_1.default.useMemo(() => {
|
|
86
91
|
return config === null || config === void 0 ? void 0 : config.redirects.find((redirect) => redirect.query.trim().toLowerCase() === searchTerm.trim().toLowerCase());
|
|
87
92
|
}, [config === null || config === void 0 ? void 0 : config.redirects, searchTerm]);
|
|
93
|
+
// show instant-search
|
|
88
94
|
const [showInstantSearchResults, setShowInstantSearchResults] = react_1.default.useState(false);
|
|
95
|
+
// sort option
|
|
89
96
|
const [sortOption, setSortOption] = react_1.default.useState(searchSortFromURL !== null && searchSortFromURL !== void 0 ? searchSortFromURL : "");
|
|
97
|
+
// results
|
|
90
98
|
const [results, setResults] = react_1.default.useState([]);
|
|
99
|
+
// result stats
|
|
91
100
|
const [resultStats, setResultStats] = react_1.default.useState();
|
|
92
101
|
react_1.default.useEffect(() => {
|
|
102
|
+
if (props.mode === "instant-search") {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
93
105
|
if (searchTermFromURL && searchTerm !== searchTermFromURL) {
|
|
94
106
|
setSearchTerm(searchTermFromURL);
|
|
95
107
|
}
|
|
96
108
|
}, [searchTermFromURL]);
|
|
97
109
|
react_1.default.useEffect(() => {
|
|
110
|
+
if (props.mode === "instant-search") {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
98
113
|
if (searchSortFromURL && sortOption !== searchSortFromURL) {
|
|
99
114
|
setSortOption(searchSortFromURL);
|
|
100
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactifySearchProvider.js","sourceRoot":"","sources":["../../../../src/components/ReactifySearchProvider/ReactifySearchProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,iCAAiC;AACjC,gDAAkC;AAElC,yEAAwC;AAExC,uCAA+D;AAC/D,iDAAoE;AACpE,2CAAsC;AAwD/B,MAAM,sBAAsB,GAA0C,CAC3E,KAAK,EACL,EAAE;IACF,eAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,eAAK,CAAC,GAAG,CAAC,wBAAwB,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;QAEpD,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE;YAC7B,aAAa,EAAE,KAAK;YACpB,eAAe,EAAE;gBACf,IAAI,EAAE,KAAK,CAAC,sBAAsB;gBAClC,OAAO,EAAE,sBAAG,CAAC,OAAO;aACrB;SACF,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,8BAAC,mBAAmB,oBAAK,KAAK,EAAI,CAAC;AAC5C,CAAC,CAAC;AAhBW,QAAA,sBAAsB,0BAgBjC;AAEF,MAAM,mBAAmB,GAA0C,CAAC,KAAK,EAAE,EAAE;;IAC3E,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,iBAAS,EAAC,KAAK,CAAC,sBAAsB,EAAE,MAAA,KAAK,CAAC,OAAO,0CAAE,MAAM,CAAC,CAAC;IAElF,MAAM,KAAK,GAAG,MAAA,KAAK,CAAC,KAAK,mCAAI;QAC3B,UAAU,EAAE;YACV,UAAU,EAAE,SAAS;YACrB,QAAQ,EAAE,SAAS;SACpB;KACF,CAAC;IAEF,MAAM,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AAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,8BAAC,6BAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY;QACjD,8BAAC,6CAAgC,QAC9B,KAAK,CAAC,QAAQ,CACkB,CACJ,CAClC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\n// @ts-expect-error missing types\nimport * as GaGtag from \"ga-gtag\";\n\nimport pkg from \"../../../package.json\";\n\nimport { ReactifySearchContext, useConfig } from \"../../hooks\";\nimport { UtilityAuthenticatedReactiveBase } from \"../../components\";\nimport { debug } from \"../../utility\";\nimport { Config, ConfigRedirect, ReactivesearchResultProps } from \"../../types\";\n\nexport type ReactifySearchProviderProps = {\n /** Standard react children */\n children?: React.ReactNode | undefined;\n /** The search area the provider will be used in */\n mode: \"search\" | \"collection\" | \"instant-search\";\n /** Shopify store domain used to resolve the site configuration */\n shopifyPermanentDomain: string;\n /** Market ID used to change merchandising based on market e.g. 7494533198 */\n market?: string;\n /** Callback function for redirects, suitable for headless sites to avoid full page refresh */\n onRedirect?: (type: \"redirect\" | \"search\", url: string) => void;\n /** Render method to display a component when the config is loading */\n renderBooting?: () => JSX.Element | null;\n /** Advanced usage: Override the default Reactify Search id (for telemetry) */\n clientId?: string;\n /** Advanced usage: Override the default Filters selection logic */\n filtersHandle?: string;\n /** Advanced usage: Array of additional component IDs managed outside of Reactify Search */\n additionalComponentIds?: Array<string>;\n /** Advanced usage: Override the default Elasticsearch index */\n index?: string;\n /** Advanced usage: Override the default Reactify Search config (for multi-instance stores) */\n configId?: string;\n /** Advanced usage: Override the default Elasticsearch credentials */\n credentials?: string;\n /** Advanced usage: Override the default ReactiveBase theme */\n theme?: Record<string, unknown>;\n /** Advanced usage: Fields to include in the Elasticsearch response e.g. [\"title\"] */\n includeFields?: Array<string>;\n /** Advanced usage: Fields to exclude from the Elasticsearch response e.g. [\"variant_skus\", \"*price*\"] */\n excludeFields?: Array<string>;\n /** Advanced usage: Flags are used to enable or disable specific features within Reactify Search */\n flags?: Record<string, boolean>;\n /** Advanced usage: Server content for SSR */\n query?: Record<string, string>;\n preload?: {\n config: Config;\n state: unknown;\n }\n} & (\n | {\n mode: \"search\";\n }\n | {\n mode: \"collection\";\n /** Collection object that includes the handle, used to find curations */\n collectionHandle: string;\n }\n | {\n mode: \"instant-search\";\n }\n);\n\nexport const ReactifySearchProvider: React.FC<ReactifySearchProviderProps> = (\n props\n) => {\n React.useEffect(() => {\n debug.log(\"ReactifySearchProvider\", \"props\", props);\n\n GaGtag.install(\"G-DV00Z0X5VP\", {\n cookie_prefix: \"_rs\",\n user_properties: {\n shop: props.shopifyPermanentDomain,\n version: pkg.version,\n },\n });\n }, [props]);\n\n return <ReactifySearchInner {...props} />;\n};\n\nconst ReactifySearchInner: React.FC<ReactifySearchProviderProps> = (props) => {\n const { config } = useConfig(props.shopifyPermanentDomain, props.preload?.config);\n\n const theme = props.theme ?? {\n typography: {\n fontFamily: \"inherit\",\n fontSize: \"inherit\",\n },\n };\n\n const searchTermFromURL = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(\"q\") ?? undefined;\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n const searchSortFromURL = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return props.query?.sort;\n }\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(\"sort\") ?? undefined;\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n const indexFromURL = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(\"index\") ?? undefined;\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n const [searchTerm, setSearchTerm] = React.useState<string>(\n searchTermFromURL ?? \"\"\n );\n const searchRedirect = React.useMemo<ConfigRedirect | undefined>(() => {\n return config?.redirects.find((redirect) => redirect.query.trim().toLowerCase() === searchTerm.trim().toLowerCase());\n }, [config?.redirects, searchTerm]);\n const [showInstantSearchResults, setShowInstantSearchResults] =\n React.useState<boolean>(false);\n const [sortOption, setSortOption] = React.useState<string>(\n searchSortFromURL ?? \"\"\n );\n\n const [results, setResults] = React.useState<\n ReactivesearchResultProps[\"data\"]\n >([]);\n const [resultStats, setResultStats] =\n React.useState<ReactivesearchResultProps[\"resultStats\"]>();\n\n React.useEffect(() => {\n if (searchTermFromURL && searchTerm !== searchTermFromURL) {\n setSearchTerm(searchTermFromURL);\n }\n }, [searchTermFromURL]);\n\n React.useEffect(() => {\n if (searchSortFromURL && sortOption !== searchSortFromURL) {\n setSortOption(searchSortFromURL);\n }\n }, [searchSortFromURL]);\n\n const contextValue = React.useMemo(() => {\n if (!config) {\n return;\n }\n\n return {\n config: config,\n options: {\n ...props,\n clientId: props.clientId ?? \"theme\",\n index: props.index ?? indexFromURL ?? config.index,\n filtersHandle: props.filtersHandle,\n credentials: props.credentials,\n theme: theme,\n },\n search: {\n searchTerm: searchTerm,\n setSearchTerm: setSearchTerm,\n showInstantSearchResults: showInstantSearchResults,\n setShowInstantSearchResults: setShowInstantSearchResults,\n searchRedirect: searchRedirect,\n },\n sortby: {\n sortOption: sortOption,\n setSortOption: setSortOption,\n },\n results: {\n results: results,\n setResults: setResults,\n resultStats: resultStats,\n setResultStats: setResultStats,\n },\n };\n }, [\n config,\n props,\n searchTerm,\n showInstantSearchResults,\n searchRedirect,\n sortOption,\n results,\n resultStats,\n ]);\n\n debug.hook(\"ReactifySearchProvider\", \"context\", contextValue);\n\n if (!contextValue) {\n if (props.renderBooting) {\n return props.renderBooting();\n }\n return null;\n }\n\n return (\n <ReactifySearchContext.Provider value={contextValue}>\n <UtilityAuthenticatedReactiveBase>\n {props.children}\n </UtilityAuthenticatedReactiveBase>\n </ReactifySearchContext.Provider>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"ReactifySearchProvider.js","sourceRoot":"","sources":["../../../../src/components/ReactifySearchProvider/ReactifySearchProvider.tsx"],"names":[],"mappings":";;;;;;;;;;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D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,CACL,8BAAC,6BAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY;QACjD,8BAAC,6CAAgC,QAC9B,KAAK,CAAC,QAAQ,CACkB,CACJ,CAClC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\n// @ts-expect-error missing types\nimport * as GaGtag from \"ga-gtag\";\n\nimport pkg from \"../../../package.json\";\n\nimport { ReactifySearchContext, useConfig } from \"../../hooks\";\nimport { UtilityAuthenticatedReactiveBase } from \"../../components\";\nimport { debug } from \"../../utility\";\nimport { Config, ConfigRedirect, ReactivesearchResultProps } from \"../../types\";\n\nexport type ReactifySearchProviderProps = {\n /** Standard react children */\n children?: React.ReactNode | undefined;\n /** The search area the provider will be used in */\n mode: \"search\" | \"collection\" | \"instant-search\";\n /** Shopify store domain used to resolve the site configuration */\n shopifyPermanentDomain: string;\n /** Market ID used to change merchandising based on market e.g. 7494533198 */\n market?: string;\n /** Callback function for redirects, suitable for headless sites to avoid full page refresh */\n onRedirect?: (type: \"redirect\" | \"search\", url: string) => void;\n /** Render method to display a component when the config is loading */\n renderBooting?: () => JSX.Element | null;\n /** Advanced usage: Override the default Reactify Search id (for telemetry) */\n clientId?: string;\n /** Advanced usage: Override the default Filters selection logic */\n filtersHandle?: string;\n /** Advanced usage: Array of additional component IDs managed outside of Reactify Search */\n additionalComponentIds?: Array<string>;\n /** Advanced usage: Override the default Elasticsearch index */\n index?: string;\n /** Advanced usage: Override the default Reactify Search config (for multi-instance stores) */\n configId?: string;\n /** Advanced usage: Override the default Elasticsearch credentials */\n credentials?: string;\n /** Advanced usage: Override the default ReactiveBase theme */\n theme?: Record<string, unknown>;\n /** Advanced usage: Fields to include in the Elasticsearch response e.g. [\"title\"] */\n includeFields?: Array<string>;\n /** Advanced usage: Fields to exclude from the Elasticsearch response e.g. [\"variant_skus\", \"*price*\"] */\n excludeFields?: Array<string>;\n /** Advanced usage: Flags are used to enable or disable specific features within Reactify Search */\n flags?: Record<string, boolean>;\n /** Advanced usage: Server content for SSR */\n query?: Record<string, string>;\n preload?: {\n config: Config;\n state: unknown;\n }\n} & (\n | {\n mode: \"search\";\n }\n | {\n mode: \"collection\";\n /** Collection object that includes the handle, used to find curations */\n collectionHandle: string;\n }\n | {\n mode: \"instant-search\";\n }\n);\n\nexport const ReactifySearchProvider: React.FC<ReactifySearchProviderProps> = (\n props\n) => {\n React.useEffect(() => {\n debug.log(\"ReactifySearchProvider\", \"props\", props);\n\n GaGtag.install(\"G-DV00Z0X5VP\", {\n cookie_prefix: \"_rs\",\n user_properties: {\n shop: props.shopifyPermanentDomain,\n version: pkg.version,\n },\n });\n }, [props]);\n\n return <ReactifySearchInner {...props} />;\n};\n\nconst ReactifySearchInner: React.FC<ReactifySearchProviderProps> = (props) => {\n const { config } = useConfig(props.shopifyPermanentDomain, props.preload?.config);\n\n const theme = props.theme ?? {\n typography: {\n fontFamily: \"inherit\",\n fontSize: \"inherit\",\n },\n };\n\n // search from url\n const searchTermFromURL = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(\"q\") ?? undefined;\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n // sort from url\n const searchSortFromURL = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return props.query?.sort;\n }\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(\"sort\") ?? undefined;\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n // index from url\n const indexFromURL = React.useMemo(() => {\n if (typeof window === \"undefined\") {\n return;\n }\n const urlParams = new URLSearchParams(window.location.search);\n return urlParams.get(\"index\") ?? undefined;\n }, [typeof window !== \"undefined\" && window.location.search]);\n\n // search term\n const [searchTerm, setSearchTerm] = React.useState<string>(\n searchTermFromURL ?? \"\"\n );\n // search term redirect\n const searchRedirect = React.useMemo<ConfigRedirect | undefined>(() => {\n return config?.redirects.find((redirect) => redirect.query.trim().toLowerCase() === searchTerm.trim().toLowerCase());\n }, [config?.redirects, searchTerm]);\n // show instant-search\n const [showInstantSearchResults, setShowInstantSearchResults] =\n React.useState<boolean>(false);\n // sort option\n const [sortOption, setSortOption] = React.useState<string>(\n searchSortFromURL ?? \"\"\n );\n // results\n const [results, setResults] = React.useState<\n ReactivesearchResultProps[\"data\"]\n >([]);\n // result stats\n const [resultStats, setResultStats] =\n React.useState<ReactivesearchResultProps[\"resultStats\"]>();\n\n React.useEffect(() => {\n if (props.mode === \"instant-search\") {\n return;\n }\n\n if (searchTermFromURL && searchTerm !== searchTermFromURL) {\n setSearchTerm(searchTermFromURL);\n }\n }, [searchTermFromURL]);\n\n React.useEffect(() => {\n if (props.mode === \"instant-search\") {\n return;\n }\n\n if (searchSortFromURL && sortOption !== searchSortFromURL) {\n setSortOption(searchSortFromURL);\n }\n }, [searchSortFromURL]);\n\n const contextValue = React.useMemo(() => {\n if (!config) {\n return;\n }\n\n return {\n config: config,\n options: {\n ...props,\n clientId: props.clientId ?? \"theme\",\n index: props.index ?? indexFromURL ?? config.index,\n filtersHandle: props.filtersHandle,\n credentials: props.credentials,\n theme: theme,\n },\n search: {\n searchTerm: searchTerm,\n setSearchTerm: setSearchTerm,\n showInstantSearchResults: showInstantSearchResults,\n setShowInstantSearchResults: setShowInstantSearchResults,\n searchRedirect: searchRedirect,\n },\n sortby: {\n sortOption: sortOption,\n setSortOption: setSortOption,\n },\n results: {\n results: results,\n setResults: setResults,\n resultStats: resultStats,\n setResultStats: setResultStats,\n },\n };\n }, [\n config,\n props,\n searchTerm,\n showInstantSearchResults,\n searchRedirect,\n sortOption,\n results,\n resultStats,\n ]);\n\n debug.hook(\"ReactifySearchProvider\", \"context\", contextValue);\n\n if (!contextValue) {\n if (props.renderBooting) {\n return props.renderBooting();\n }\n return null;\n }\n\n return (\n <ReactifySearchContext.Provider value={contextValue}>\n <UtilityAuthenticatedReactiveBase>\n {props.children}\n </UtilityAuthenticatedReactiveBase>\n </ReactifySearchContext.Provider>\n );\n};\n"]}
|
|
@@ -7,4 +7,5 @@ export declare const useFilterSliderProps: (filter: ConfigFilterFacet) => {
|
|
|
7
7
|
handleChange: (value: [number | string, number | string]) => void;
|
|
8
8
|
handleRange: (value: [number, number]) => void;
|
|
9
9
|
reactSliderProps: ReturnType<typeof useReactSliderProps>;
|
|
10
|
+
query: any;
|
|
10
11
|
};
|
|
@@ -31,6 +31,39 @@ const useFilterSliderProps = (filter) => {
|
|
|
31
31
|
const handleRange = react_1.default.useCallback((value) => {
|
|
32
32
|
setFilterRange([parseInt(`${value[0]}`), parseInt(`${value[1]}`)]);
|
|
33
33
|
}, [filter]);
|
|
34
|
+
const filterQuery = react_1.default.useMemo(() => {
|
|
35
|
+
if (filterValue[0] === 0 && filterValue[1] === 0) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
query: {
|
|
40
|
+
bool: {
|
|
41
|
+
must: [
|
|
42
|
+
{
|
|
43
|
+
bool: {
|
|
44
|
+
must: [
|
|
45
|
+
{
|
|
46
|
+
match: {
|
|
47
|
+
published: true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
range: {
|
|
52
|
+
[filter.field]: {
|
|
53
|
+
gte: filterValue[0],
|
|
54
|
+
lte: filterValue[1],
|
|
55
|
+
boost: 2,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}, [filter.field, filterValue[0], filterValue[1]]);
|
|
34
67
|
react_1.default.useEffect(() => {
|
|
35
68
|
const handler = (event) => {
|
|
36
69
|
setFilterValue(event.detail.value);
|
|
@@ -47,6 +80,7 @@ const useFilterSliderProps = (filter) => {
|
|
|
47
80
|
value: filterValue,
|
|
48
81
|
range: filterRange,
|
|
49
82
|
reactSliderProps,
|
|
83
|
+
query: filterQuery,
|
|
50
84
|
};
|
|
51
85
|
}, [
|
|
52
86
|
handleChange,
|
|
@@ -55,6 +89,7 @@ const useFilterSliderProps = (filter) => {
|
|
|
55
89
|
filterValue,
|
|
56
90
|
filterRange,
|
|
57
91
|
reactSliderProps,
|
|
92
|
+
filterQuery,
|
|
58
93
|
]);
|
|
59
94
|
return filterSliderProps;
|
|
60
95
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFilterSliderProps.js","sourceRoot":"","sources":["../../../src/hooks/useFilterSliderProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,oCAAkE;AAClE,wCAAmC;AACnC,4EAAyE;AAElE,MAAM,oBAAoB,GAAG,CAClC,MAAyB,
|
|
1
|
+
{"version":3,"file":"useFilterSliderProps.js","sourceRoot":"","sources":["../../../src/hooks/useFilterSliderProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,oCAAkE;AAClE,wCAAmC;AACnC,4EAAyE;AAElE,MAAM,oBAAoB,GAAG,CAClC,MAAyB,EASzB,EAAE;;IACF,MAAM,OAAO,GAAG,IAAA,gCAAwB,GAAE,CAAC;IAC3C,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,oBAAY,GAAE,CAAC;IAEjC,MAAM,cAAc,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACnE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,eAAK,CAAC,QAAQ,CAClD,IAAI,CAAC,KAAK,CAAC,MAAA,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,mCAAI,OAAO,CAAC,CACzD,CAAC;IACF,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,eAAK,CAAC,QAAQ,CAAmB;QACrE,CAAC,EAAE,CAAC;KACL,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,eAAK,CAAC,WAAW,CACpC,CAAC,KAA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AAC;AAC3B,CAAC,CAAC;AA/HW,QAAA,oBAAoB,wBA+H/B","sourcesContent":["import React from \"react\";\nimport { ConfigFilterFacet } from \"../types/config\";\nimport { useAnalytics, useReactifySearchContext } from \"../hooks\";\nimport { debug } from \"../utility\";\nimport { useReactSliderProps } from \"./react-slider/useReactSliderProps\";\n\nexport const useFilterSliderProps = (\n filter: ConfigFilterFacet\n): {\n filter: ConfigFilterFacet;\n value: [number, number];\n range: [number, number];\n handleChange: (value: [number | string, number | string]) => void;\n handleRange: (value: [number, number]) => void;\n reactSliderProps: ReturnType<typeof useReactSliderProps>;\n query: any;\n} => {\n const context = useReactifySearchContext();\n const { track } = useAnalytics();\n\n const urlSearchParam = new URLSearchParams(window.location.search);\n const [filterValue, setFilterValue] = React.useState<[number, number]>(\n JSON.parse(urlSearchParam.get(filter.handle) ?? \"[0,0]\")\n );\n const [filterRange, setFilterRange] = React.useState<[number, number]>([\n 0, 0,\n ]);\n\n const handleChange = React.useCallback(\n (value: [number | string, number | string]) => {\n debug.log(\"useFilterSliderProps\", \"handleChange[value]\", value);\n\n setFilterValue([parseInt(`${value[0]}`), parseInt(`${value[1]}`)]);\n\n track({\n eventName: \"filterChange\",\n payload: {\n name: filter.name,\n value: `${value[0]}:${value[1]}`,\n },\n });\n },\n [filter]\n );\n\n const handleRange = React.useCallback(\n (value: [number | string, number | string]) => {\n setFilterRange([parseInt(`${value[0]}`), parseInt(`${value[1]}`)]);\n },\n [filter]\n );\n\n const filterQuery = React.useMemo<any | undefined>(() => {\n if (filterValue[0] === 0 && filterValue[1] === 0) {\n return;\n }\n\n return {\n query: {\n bool: {\n must: [\n {\n bool: {\n must: [\n {\n match: {\n published: true,\n },\n },\n {\n range: {\n [filter.field]: {\n gte: filterValue[0],\n lte: filterValue[1],\n boost: 2,\n },\n },\n },\n ],\n },\n },\n ],\n },\n }\n };\n }, [filter.field, filterValue[0], filterValue[1]]);\n\n React.useEffect(() => {\n const handler = (\n event: CustomEvent<{ handle: string; value: [number, number] }>\n ) => {\n setFilterValue(event.detail.value);\n };\n window.addEventListener(\n `@usereactify/search:${context.options.mode}:filter:${filter.handle}:update`,\n handler as EventListener\n );\n\n return () =>\n window.removeEventListener(\n `@usereactify/search:${context.options.mode}:filter:${filter.handle}:update`,\n handler as EventListener\n );\n }, [context.options.mode]);\n\n const reactSliderProps = useReactSliderProps(\n filter,\n filterValue,\n filterRange,\n handleChange\n );\n\n const filterSliderProps = React.useMemo(() => {\n return {\n handleChange,\n handleRange,\n filter,\n value: filterValue,\n range: filterRange,\n reactSliderProps,\n query: filterQuery,\n };\n }, [\n handleChange,\n handleRange,\n filter,\n filterValue,\n filterRange,\n reactSliderProps,\n filterQuery,\n ]);\n\n return filterSliderProps;\n};\n"]}
|