@usereactify/search 5.19.3 → 5.20.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/CHANGELOG.md +14 -0
- package/dist/package.json +1 -1
- package/dist/src/components/Example/ExampleFiltersSelected.js +12 -39
- package/dist/src/components/Example/ExampleFiltersSelected.js.map +1 -1
- package/dist/src/components/Filter/Filter.js +1 -1
- package/dist/src/components/Filter/Filter.js.map +1 -1
- package/dist/src/components/Filter/FiltersSelected.d.ts +2 -1
- package/dist/src/components/Filter/FiltersSelected.js +36 -2
- package/dist/src/components/Filter/FiltersSelected.js.map +1 -1
- package/dist/src/hooks/useFilterRangeProps.js +20 -0
- package/dist/src/hooks/useFilterRangeProps.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.20.1](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.20.0...release-v5.20.1) (2023-05-09)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* improve types for range values ([597a6f3](https://bitbucket.org/usereactify/reactify-search-ui/commit/597a6f35dd069b5b7f18f6b248049c319981774a))
|
|
11
|
+
|
|
12
|
+
## [5.20.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.19.3...release-v5.20.0) (2023-05-09)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* allow removing one or more (not just all) filters within SelectedFilters component ([4c486a4](https://bitbucket.org/usereactify/reactify-search-ui/commit/4c486a4d6adf64b39776cda8d074c92d5dc92f44))
|
|
18
|
+
|
|
5
19
|
### [5.19.3](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.19.2...release-v5.19.3) (2023-05-07)
|
|
6
20
|
|
|
7
21
|
|
package/dist/package.json
CHANGED
|
@@ -13,48 +13,21 @@ const ExampleFiltersSelected = (props) => {
|
|
|
13
13
|
};
|
|
14
14
|
exports.ExampleFiltersSelected = ExampleFiltersSelected;
|
|
15
15
|
const ExampleFiltersSelectedItem = (props) => {
|
|
16
|
+
var _a;
|
|
16
17
|
const filtersHook = (0, hooks_1.useFilters)();
|
|
17
|
-
const
|
|
18
|
-
var _a;
|
|
19
|
-
return parseFromSelectedValue(props.selectedFilter.value, ((_a = filtersHook.filters) !== null && _a !== void 0 ? _a : []).find((filter) => filter.handle === props.selectedFilter.key));
|
|
20
|
-
}, [props.selectedFilter.value, filtersHook.filters]);
|
|
18
|
+
const filter = (_a = filtersHook.filters) === null || _a === void 0 ? void 0 : _a.find((filter) => filter.handle === props.selectedFilter.key);
|
|
21
19
|
return (react_1.default.createElement("li", { key: props.selectedFilter.key, className: "rs__filters-selected__list-item" },
|
|
22
|
-
react_1.default.createElement("label", { className: "rs__filters-selected__list-item-label"
|
|
23
|
-
react_1.default.createElement("span", { className: "rs__filters-selected__list-item-label" },
|
|
20
|
+
react_1.default.createElement("label", { className: "rs__filters-selected__list-item-label" },
|
|
21
|
+
react_1.default.createElement("span", { className: "rs__filters-selected__list-item-label", onClick: () => props.handleRemove(props.selectedFilter.key) },
|
|
24
22
|
props.selectedFilter.label,
|
|
25
23
|
": "),
|
|
26
|
-
react_1.default.createElement("span", { className: "rs__filters-selected__list-item-value" },
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return value;
|
|
35
|
-
}
|
|
36
|
-
if (filter.displayType === "multi") {
|
|
37
|
-
if (filter.displayView === "range") {
|
|
38
|
-
return value.map((item) => item.label).join(", ");
|
|
39
|
-
}
|
|
40
|
-
return value.join(", ");
|
|
41
|
-
}
|
|
42
|
-
if (filter.displayType === "slider") {
|
|
43
|
-
return `${filter.displaySliderPrefix}${value[0]} to ${filter.displaySliderPrefix}${value[1]}`;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const labelString = typeof value === "string" ? value : false;
|
|
47
|
-
const labelObject = !Array.isArray(value) && typeof value === "object"
|
|
48
|
-
? `${value.start}-${value.end}`.replace("-0", "+")
|
|
49
|
-
: false;
|
|
50
|
-
const labelArray = Array.isArray(value) && typeof value[0] === "string"
|
|
51
|
-
? value.join(", ")
|
|
52
|
-
: false;
|
|
53
|
-
const labelArrayObject = Array.isArray(value) && typeof value[0] === "object"
|
|
54
|
-
? value
|
|
55
|
-
.map((item) => `${item.start}-${item.end}`.replace("-0", "+"))
|
|
56
|
-
.join(", ")
|
|
57
|
-
: false;
|
|
58
|
-
return labelString || labelObject || labelArray || labelArrayObject;
|
|
24
|
+
(filter === null || filter === void 0 ? void 0 : filter.displayType) === "single" && filter.displayView === "range" && (react_1.default.createElement("span", { className: "rs__filters-selected__list-item-value" },
|
|
25
|
+
react_1.default.createElement("span", null, props.selectedFilter.value.label))),
|
|
26
|
+
(filter === null || filter === void 0 ? void 0 : filter.displayType) === "single" && filter.displayView !== "range" && (react_1.default.createElement("span", { className: "rs__filters-selected__list-item-value" },
|
|
27
|
+
react_1.default.createElement("span", null, props.selectedFilter.value))),
|
|
28
|
+
(filter === null || filter === void 0 ? void 0 : filter.displayType) === "multi" && filter.displayView === "range" && (react_1.default.createElement("span", { className: "rs__filters-selected__list-item-value" }, props.selectedFilter.value.map((value) => (react_1.default.createElement("span", { onClick: () => props.handleRemove(props.selectedFilter.key, [value]) }, value.label))))),
|
|
29
|
+
(filter === null || filter === void 0 ? void 0 : filter.displayType) === "multi" && filter.displayView !== "range" && (react_1.default.createElement("span", { className: "rs__filters-selected__list-item-value" }, props.selectedFilter.value.map((value) => (react_1.default.createElement("span", { onClick: () => props.handleRemove(props.selectedFilter.key, [value]) }, value))))),
|
|
30
|
+
(filter === null || filter === void 0 ? void 0 : filter.displayType) === "slider" && (react_1.default.createElement("span", { className: "rs__filters-selected__list-item-value" },
|
|
31
|
+
react_1.default.createElement("span", null, `${filter.displaySliderPrefix}${props.selectedFilter.value[0]} to ${filter.displaySliderPrefix}${props.selectedFilter.value[1]}`))))));
|
|
59
32
|
};
|
|
60
33
|
//# sourceMappingURL=ExampleFiltersSelected.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExampleFiltersSelected.js","sourceRoot":"","sources":["../../../../src/components/Example/ExampleFiltersSelected.tsx"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"ExampleFiltersSelected.js","sourceRoot":"","sources":["../../../../src/components/Example/ExampleFiltersSelected.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,uCAAyC;AAMlC,MAAM,sBAAsB,GAA0C,CAC3E,KAAK,EACL,EAAE;IACF,OAAO,CACL,uCAAK,SAAS,EAAC,sBAAsB;QACnC,sCAAI,SAAS,EAAC,4BAA4B,IAAE,kBAAkB,CAAM;QACpE,sCAAI,SAAS,EAAC,4BAA4B,IACvC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CAAC,CAC7C,8BAAC,0BAA0B,IACzB,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,KAAK,CAAC,YAAY,GAChC,CACH,CAAC,CACC,CACD,CACP,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,sBAAsB,0BAgBjC;AAcF,MAAM,0BAA0B,GAA8C,CAC5E,KAAK,EACL,EAAE;;IACF,MAAM,WAAW,GAAG,IAAA,kBAAU,GAAE,CAAC;IACjC,MAAM,MAAM,GAAG,MAAA,WAAW,CAAC,OAAO,0CAAE,IAAI,CACtC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,KAAK,CAAC,cAAc,CAAC,GAAG,CACvD,CAAC;IAEF,OAAO,CACL,sCACE,GAAG,EAAE,KAAK,CAAC,cAAc,CAAC,GAAG,EAC7B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,cAAc,CAAC,KAAa,CAAC,GAAG,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,CACvD,wCACE,OAAO,EAAE,GAAG,EAAE,CACZ,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,IAGtD,KAAK,CACD,CACR,CAAC,CACG,CACR;YACA,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,MAAK,QAAQ,IAAI,CACnC,wCAAM,SAAS,EAAC,uCAAuC;gBACrD,4CACG,GAAG,MAAM,CAAC,mBAAmB,GAC3B,KAAK,CAAC,cAAc,CAAC,KAAa,CAAC,CAAC,CACvC,OAAO,MAAM,CAAC,mBAAmB,GAC9B,KAAK,CAAC,cAAc,CAAC,KAAa,CAAC,CAAC,CACvC,EAAE,CACG,CACF,CACR,CACK,CACL,CACN,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\n\nimport { FiltersSelectedProps } from \"../../components\";\nimport { useFilters } from \"../../hooks\";\n\nexport type ExampleFiltersSelectedProps = React.ComponentProps<\n NonNullable<FiltersSelectedProps[\"render\"]>\n>;\n\nexport const ExampleFiltersSelected: React.FC<ExampleFiltersSelectedProps> = (\n props\n) => {\n return (\n <div className=\"rs__filters-selected\">\n <h3 className=\"rs__filters-selected__name\">{\"Filters Selected\"}</h3>\n <ul className=\"rs__filters-selected__list\">\n {props.selectedFilters.map((selectedFilter) => (\n <ExampleFiltersSelectedItem\n selectedFilter={selectedFilter}\n handleRemove={props.handleRemove}\n />\n ))}\n </ul>\n </div>\n );\n};\n\ntype ExampleFiltersSelectedItemProps = {\n selectedFilter: {\n label: string;\n key: string;\n value:\n | Array<string>\n | string\n | { label: string; start: number; end: number };\n };\n handleRemove: ExampleFiltersSelectedProps[\"handleRemove\"];\n};\n\nconst ExampleFiltersSelectedItem: React.FC<ExampleFiltersSelectedItemProps> = (\n props\n) => {\n const filtersHook = useFilters();\n const filter = filtersHook.filters?.find(\n (filter) => filter.handle === props.selectedFilter.key\n );\n\n return (\n <li\n key={props.selectedFilter.key}\n className=\"rs__filters-selected__list-item\"\n >\n <label className=\"rs__filters-selected__list-item-label\">\n <span\n className=\"rs__filters-selected__list-item-label\"\n onClick={() => props.handleRemove(props.selectedFilter.key)}\n >\n {props.selectedFilter.label}\n {\": \"}\n </span>\n\n {filter?.displayType === \"single\" && filter.displayView === \"range\" && (\n <span className=\"rs__filters-selected__list-item-value\">\n <span>{(props.selectedFilter.value as any).label}</span>\n </span>\n )}\n {filter?.displayType === \"single\" && filter.displayView !== \"range\" && (\n <span className=\"rs__filters-selected__list-item-value\">\n <span>{props.selectedFilter.value as any}</span>\n </span>\n )}\n {filter?.displayType === \"multi\" && filter.displayView === \"range\" && (\n <span className=\"rs__filters-selected__list-item-value\">\n {(props.selectedFilter.value as any).map((value: any) => (\n <span\n onClick={() =>\n props.handleRemove(props.selectedFilter.key, [value])\n }\n >\n {value.label}\n </span>\n ))}\n </span>\n )}\n {filter?.displayType === \"multi\" && filter.displayView !== \"range\" && (\n <span className=\"rs__filters-selected__list-item-value\">\n {(props.selectedFilter.value as any).map((value: any) => (\n <span\n onClick={() =>\n props.handleRemove(props.selectedFilter.key, [value])\n }\n >\n {value}\n </span>\n ))}\n </span>\n )}\n {filter?.displayType === \"slider\" && (\n <span className=\"rs__filters-selected__list-item-value\">\n <span>\n {`${filter.displaySliderPrefix}${\n (props.selectedFilter.value as any)[0]\n } to ${filter.displaySliderPrefix}${\n (props.selectedFilter.value as any)[1]\n }`}\n </span>\n </span>\n )}\n </label>\n </li>\n );\n};\n"]}
|
|
@@ -77,7 +77,7 @@ const FilterRangeMulti = (props) => {
|
|
|
77
77
|
display: "none",
|
|
78
78
|
} },
|
|
79
79
|
react_1.default.createElement(MultiRange_1.default, Object.assign({}, reactiveFilterRangeProps, { value: filterRangeProps.values,
|
|
80
|
-
//
|
|
80
|
+
// @note: onChange handler must be defined for controlled component to work correctly
|
|
81
81
|
onChange: () => { }, onValueChange: (values) => {
|
|
82
82
|
if (values.length === 0) {
|
|
83
83
|
filterRangeProps.handleClear();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Filter.js","sourceRoot":"","sources":["../../../../src/components/Filter/Filter.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,yHAAiG;AACjG,wGAAgF;AAChF,0GAAkF;AAClF,6GAAqF;AACrF,2GAAmF;AAMnF,uCAQqB;AACrB,iDAI0B;AAwBnB,MAAM,MAAM,GAA0B,CAAC,KAAK,EAAE,EAAE;IACrD,IAAI,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE;QACzC,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE;YACxC,OAAO,8BAAC,iBAAiB,oBAAK,KAAK,EAAI,CAAC;SACzC;QACD,OAAO,8BAAC,gBAAgB,oBAAK,KAAK,EAAI,CAAC;KACxC;IAED,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE;QACxC,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE;YACxC,OAAO,8BAAC,gBAAgB,oBAAK,KAAK,EAAI,CAAC;SACxC;QACD,OAAO,8BAAC,eAAe,oBAAK,KAAK,EAAI,CAAC;KACvC;IAED,IAAI,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE;QACzC,OAAO,8BAAC,YAAY,oBAAK,KAAK,EAAI,CAAC;KACpC;IAED,oEAAoE;IACpE,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE;QACxC,OAAO,8BAAC,iBAAiB,oBAAK,KAAK,EAAI,CAAC;KACzC;IAED,OAAO,CAAC,IAAI,CACV,6BAA6B,KAAK,CAAC,MAAM,CAAC,WAAW,qBAAqB,CAC3E,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AA7BW,QAAA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E;QACpB,MAAM,SAAS,GAAG,gBAAgB,CAAC;QACnC,OAAO,CACL,8BAAC,SAAS,kBACR,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;KACH;IAED,OAAO,CACL,8BAAC,8BAAiB,kBAChB,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent\";\nimport MultiList from \"@appbaseio/reactivesearch/lib/components/list/MultiList\";\nimport SingleList from \"@appbaseio/reactivesearch/lib/components/list/SingleList\";\nimport SingleRange from \"@appbaseio/reactivesearch/lib/components/range/SingleRange\";\nimport MultiRange from \"@appbaseio/reactivesearch/lib/components/range/MultiRange\";\n\nimport type {\n ConfigFilterOption,\n ReactivesearchFilterListProps,\n} from \"../../types\";\nimport {\n useFilterListProps,\n useFilterRangeProps,\n useFilterSliderProps,\n useReactiveFilterListProps,\n useReactiveFilterRangeProps,\n useReactiveFilterSharedProps,\n useReactiveFilterSliderProps,\n} from \"../../hooks\";\nimport {\n ExampleFilterList,\n ExampleFilterRange,\n ExampleFilterSlider,\n} from \"../../components\";\nimport { useReactSliderProps } from \"../../hooks/react-slider/useReactSliderProps\";\n\nexport type FilterProps = {\n /** The filter option being rendered */\n filter: ConfigFilterOption;\n /** Render method for List filters */\n renderFilterList?: React.FC<{\n filter: ConfigFilterOption;\n filterListProps: ReturnType<typeof useFilterListProps>;\n }>;\n /** Render method for Range filters */\n renderFilterRange?: React.FC<{\n filter: ConfigFilterOption;\n filterRangeProps: ReturnType<typeof useFilterRangeProps>;\n }>;\n /** Render method for Slider filters */\n renderFilterSlider?: React.FC<{\n filter: ConfigFilterOption;\n filterSliderProps: ReturnType<typeof useFilterSliderProps>;\n // reactSliderProps: ReturnType<typeof useReactSliderProps>;\n }>;\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 reactiveFilterListProps = useReactiveFilterListProps(props.filter);\n\n return (\n <SingleList\n {...reactiveFilterListProps}\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 reactiveFilterListProps = useReactiveFilterListProps(props.filter);\n\n return (\n <MultiList\n {...reactiveFilterListProps}\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 reactiveFilterRangeProps = useReactiveFilterRangeProps(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 {...reactiveFilterRangeProps}\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 reactiveFilterRangeProps = useReactiveFilterRangeProps(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 {...reactiveFilterRangeProps}\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 reactiveFilterSharedProps = useReactiveFilterSharedProps(props.filter);\n const [value, setValue] = React.useState<[number, number]>();\n\n return (\n <ReactiveComponent\n {...reactiveFilterSharedProps}\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: any) => {\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 if (renderFilterSlider) {\n const Component = renderFilterSlider;\n return (\n <Component\n filterSliderProps={filterSliderProps}\n filter={filter}\n {...otherProps}\n />\n );\n }\n\n return (\n <ExampleFilterSlider\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 (0 === filterListProps.options.length) {\n return null;\n }\n\n if (renderFilterList) {\n const Component = renderFilterList;\n return (\n <Component\n filterListProps={filterListProps}\n filter={filter}\n {...otherProps}\n />\n );\n }\n\n return (\n <ExampleFilterList\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,yHAAiG;AACjG,wGAAgF;AAChF,0GAAkF;AAClF,6GAAqF;AACrF,2GAAmF;AAMnF,uCAQqB;AACrB,iDAI0B;AAuBnB,MAAM,MAAM,GAA0B,CAAC,KAAK,EAAE,EAAE;IACrD,IAAI,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE;QACzC,IAAI,OAAO,KAAK,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE;YACxC,OAAO,8BAAC,iBAAiB,oBAAK,KAAK,EAAI,CAA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9B,IAAI,kBAAkB,EAAE;QACtB,MAAM,SAAS,GAAG,kBAAkB,CAAC;QACrC,OAAO,CACL,8BAAC,SAAS,kBACR,iBAAiB,EAAE,iBAAiB,EACpC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;KACH;IAED,OAAO,CACL,8BAAC,gCAAmB,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,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE;QACxC,OAAO,IAAI,CAAC;KACb;IAED,IAAI,gBAAgB,EAAE;QACpB,MAAM,SAAS,GAAG,gBAAgB,CAAC;QACnC,OAAO,CACL,8BAAC,SAAS,kBACR,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;KACH;IAED,OAAO,CACL,8BAAC,8BAAiB,kBAChB,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,MAAM,IACV,UAAU,EACd,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from \"react\";\nimport ReactiveComponent from \"@appbaseio/reactivesearch/lib/components/basic/ReactiveComponent\";\nimport MultiList from \"@appbaseio/reactivesearch/lib/components/list/MultiList\";\nimport SingleList from \"@appbaseio/reactivesearch/lib/components/list/SingleList\";\nimport SingleRange from \"@appbaseio/reactivesearch/lib/components/range/SingleRange\";\nimport MultiRange from \"@appbaseio/reactivesearch/lib/components/range/MultiRange\";\n\nimport type {\n ConfigFilterOption,\n ReactivesearchFilterListProps,\n} from \"../../types\";\nimport {\n useFilterListProps,\n useFilterRangeProps,\n useFilterSliderProps,\n useReactiveFilterListProps,\n useReactiveFilterRangeProps,\n useReactiveFilterSharedProps,\n useReactiveFilterSliderProps,\n} from \"../../hooks\";\nimport {\n ExampleFilterList,\n ExampleFilterRange,\n ExampleFilterSlider,\n} from \"../../components\";\n\nexport type FilterProps = {\n /** The filter option being rendered */\n filter: ConfigFilterOption;\n /** Render method for List filters */\n renderFilterList?: React.FC<{\n filter: ConfigFilterOption;\n filterListProps: ReturnType<typeof useFilterListProps>;\n }>;\n /** Render method for Range filters */\n renderFilterRange?: React.FC<{\n filter: ConfigFilterOption;\n filterRangeProps: ReturnType<typeof useFilterRangeProps>;\n }>;\n /** Render method for Slider filters */\n renderFilterSlider?: React.FC<{\n filter: ConfigFilterOption;\n filterSliderProps: ReturnType<typeof useFilterSliderProps>;\n // reactSliderProps: ReturnType<typeof useReactSliderProps>;\n }>;\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 reactiveFilterListProps = useReactiveFilterListProps(props.filter);\n\n return (\n <SingleList\n {...reactiveFilterListProps}\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 reactiveFilterListProps = useReactiveFilterListProps(props.filter);\n\n return (\n <MultiList\n {...reactiveFilterListProps}\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 reactiveFilterRangeProps = useReactiveFilterRangeProps(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 {...reactiveFilterRangeProps}\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 reactiveFilterRangeProps = useReactiveFilterRangeProps(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 {...reactiveFilterRangeProps}\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 reactiveFilterSharedProps = useReactiveFilterSharedProps(props.filter);\n const [value, setValue] = React.useState<[number, number]>();\n\n return (\n <ReactiveComponent\n {...reactiveFilterSharedProps}\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: any) => {\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 if (renderFilterSlider) {\n const Component = renderFilterSlider;\n return (\n <Component\n filterSliderProps={filterSliderProps}\n filter={filter}\n {...otherProps}\n />\n );\n }\n\n return (\n <ExampleFilterSlider\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 (0 === filterListProps.options.length) {\n return null;\n }\n\n if (renderFilterList) {\n const Component = renderFilterList;\n return (\n <Component\n filterListProps={filterListProps}\n filter={filter}\n {...otherProps}\n />\n );\n }\n\n return (\n <ExampleFilterList\n filterListProps={filterListProps}\n filter={filter}\n {...otherProps}\n />\n );\n};\n"]}
|
|
@@ -6,11 +6,12 @@ export declare type FiltersSelectedProps = {
|
|
|
6
6
|
key: string;
|
|
7
7
|
label: string;
|
|
8
8
|
value: Array<string> | string | {
|
|
9
|
+
label: string;
|
|
9
10
|
start: number;
|
|
10
11
|
end: number;
|
|
11
12
|
};
|
|
12
13
|
}>;
|
|
13
|
-
handleRemove: (filterKey: string) => void;
|
|
14
|
+
handleRemove: (filterKey: string, filterValues?: Array<string>) => void;
|
|
14
15
|
}>;
|
|
15
16
|
};
|
|
16
17
|
export declare const FiltersSelected: React.FC<FiltersSelectedProps>;
|
|
@@ -7,8 +7,10 @@ exports.FiltersSelected = void 0;
|
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const SelectedFilters_1 = __importDefault(require("@appbaseio/reactivesearch/lib/components/basic/SelectedFilters"));
|
|
9
9
|
const components_1 = require("../../components");
|
|
10
|
+
const hooks_1 = require("../../hooks");
|
|
10
11
|
const FiltersSelected = (props) => {
|
|
11
12
|
var _a;
|
|
13
|
+
const filtersHook = (0, hooks_1.useFilters)();
|
|
12
14
|
const RenderComponent = (_a = props.render) !== null && _a !== void 0 ? _a : components_1.ExampleFiltersSelected;
|
|
13
15
|
return (react_1.default.createElement(SelectedFilters_1.default, { render: ({ selectedValues, setValue }) => {
|
|
14
16
|
const selectedFilters = Object.entries(selectedValues)
|
|
@@ -23,8 +25,40 @@ const FiltersSelected = (props) => {
|
|
|
23
25
|
label: item.label,
|
|
24
26
|
value: item.value,
|
|
25
27
|
}));
|
|
26
|
-
const handleRemove = (selectedFilterKey) => {
|
|
27
|
-
|
|
28
|
+
const handleRemove = (selectedFilterKey, selectedFilterValues = []) => {
|
|
29
|
+
var _a;
|
|
30
|
+
const filter = (_a = filtersHook.filters) === null || _a === void 0 ? void 0 : _a.find((filter) => filter.handle === selectedFilterKey);
|
|
31
|
+
if (!filter) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (selectedFilterValues.length === 0) {
|
|
35
|
+
setValue(selectedFilterKey, null);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (selectedFilterValues.length > 0) {
|
|
39
|
+
if (filter.displayType === "single") {
|
|
40
|
+
setValue(selectedFilterKey, null);
|
|
41
|
+
}
|
|
42
|
+
if (filter.displayType === "multi") {
|
|
43
|
+
if (filter.displayView === "range") {
|
|
44
|
+
const selectedFilterValueLabels = selectedFilterValues.map((selectedFilterValue) => selectedFilterValue.label);
|
|
45
|
+
const values = selectedValues[selectedFilterKey].value
|
|
46
|
+
.filter((value) => !selectedFilterValueLabels.includes(value.label))
|
|
47
|
+
.map((value) => value.label);
|
|
48
|
+
const event = new CustomEvent(`@usereactify/search:filter:${filter.handle}:update`, {
|
|
49
|
+
detail: {
|
|
50
|
+
handle: filter.handle,
|
|
51
|
+
value: values,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
window.dispatchEvent(event);
|
|
55
|
+
}
|
|
56
|
+
if (filter.displayView !== "range") {
|
|
57
|
+
const values = selectedValues[selectedFilterKey].value.filter((value) => !selectedFilterValues.includes(value));
|
|
58
|
+
setValue(selectedFilterKey, values);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
28
62
|
};
|
|
29
63
|
if (!selectedFilters.length) {
|
|
30
64
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FiltersSelected.js","sourceRoot":"","sources":["../../../../src/components/Filter/FiltersSelected.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,qHAA6F;AAE7F,iDAA0D;
|
|
1
|
+
{"version":3,"file":"FiltersSelected.js","sourceRoot":"","sources":["../../../../src/components/Filter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C,CAAC,oBAAoB,CAAC,QAAQ,CAAC,KAAK,CAAC,CACzD,CAAC;4BACF,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;yBACrC;qBACF;iBACF;YACH,CAAC,CAAC;YAEF,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE;gBAC3B,OAAO,IAAI,CAAC;aACb;YAED,OAAO,CACL,8BAAC,eAAe,IACd,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,GAC1B,CACH,CAAC;QACJ,CAAC,GACD,CACH,CAAC;AACJ,CAAC,CAAC;AAzFW,QAAA,eAAe,mBAyF1B","sourcesContent":["import React from \"react\";\nimport SelectedFilters from \"@appbaseio/reactivesearch/lib/components/basic/SelectedFilters\";\n\nimport { ExampleFiltersSelected } from \"../../components\";\nimport { useFilters } from \"../../hooks\";\n\nexport type FiltersSelectedProps = {\n /** Render method called once for all active filters */\n render?: React.FC<{\n selectedFilters: Array<{\n key: string;\n label: string;\n value:\n | Array<string>\n | string\n | { label: string; start: number; end: number };\n }>;\n handleRemove: (filterKey: string, filterValues?: Array<string>) => void;\n }>;\n};\n\nexport const FiltersSelected: React.FC<FiltersSelectedProps> = (props) => {\n const filtersHook = useFilters();\n\n const RenderComponent = props.render ?? ExampleFiltersSelected;\n\n return (\n <SelectedFilters\n render={({ selectedValues, setValue }) => {\n const selectedFilters = (\n Object.entries(selectedValues) as Array<[string, any]>\n )\n .filter(\n ([key, item]) =>\n item?.URLParams &&\n item?.showFilter &&\n (!!item?.value?.length || !!item?.value?.label)\n )\n .map(([key, item]) => ({\n key: key,\n label: item.label,\n value: item.value,\n }));\n\n const handleRemove = (\n selectedFilterKey: string,\n selectedFilterValues: Array<string> = []\n ) => {\n const filter = filtersHook.filters?.find(\n (filter) => filter.handle === selectedFilterKey\n );\n if (!filter) {\n return;\n }\n\n if (selectedFilterValues.length === 0) {\n setValue(selectedFilterKey, null);\n\n return;\n }\n\n if (selectedFilterValues.length > 0) {\n if (filter.displayType === \"single\") {\n setValue(selectedFilterKey, null);\n }\n if (filter.displayType === \"multi\") {\n if (filter.displayView === \"range\") {\n const selectedFilterValueLabels = (\n selectedFilterValues as any as Array<{ label: string }>\n ).map((selectedFilterValue) => selectedFilterValue.label);\n const values = selectedValues[selectedFilterKey].value\n .filter(\n (value: { label: string }) =>\n !selectedFilterValueLabels.includes(value.label)\n )\n .map((value: { label: string }) => value.label);\n const event = new CustomEvent<{\n handle: string;\n value: Array<string>;\n }>(`@usereactify/search:filter:${filter.handle}:update`, {\n detail: {\n handle: filter.handle,\n value: values,\n },\n });\n window.dispatchEvent(event);\n }\n if (filter.displayView !== \"range\") {\n const values = selectedValues[selectedFilterKey].value.filter(\n (value: string) => !selectedFilterValues.includes(value)\n );\n setValue(selectedFilterKey, values);\n }\n }\n }\n };\n\n if (!selectedFilters.length) {\n return null;\n }\n\n return (\n <RenderComponent\n selectedFilters={selectedFilters}\n handleRemove={handleRemove}\n />\n );\n }}\n />\n );\n};\n"]}
|
|
@@ -41,6 +41,26 @@ const useFilterRangeProps = (filter) => {
|
|
|
41
41
|
const handleClear = react_1.default.useCallback(() => {
|
|
42
42
|
setFilterValues([]);
|
|
43
43
|
}, []);
|
|
44
|
+
react_1.default.useEffect(() => {
|
|
45
|
+
var _a;
|
|
46
|
+
try {
|
|
47
|
+
if (filter.displayView === "range") {
|
|
48
|
+
const url = new URL(window.location.href);
|
|
49
|
+
const value = JSON.parse((_a = url.searchParams.get(filter.handle)) !== null && _a !== void 0 ? _a : "[]");
|
|
50
|
+
setFilterValues(value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error(error);
|
|
55
|
+
}
|
|
56
|
+
}, []);
|
|
57
|
+
react_1.default.useEffect(() => {
|
|
58
|
+
const handler = (event) => {
|
|
59
|
+
setFilterValues(event.detail.value);
|
|
60
|
+
};
|
|
61
|
+
window.addEventListener(`@usereactify/search:filter:${filter.handle}:update`, handler);
|
|
62
|
+
return () => window.removeEventListener(`@usereactify/search:filter:${filter.handle}:update`, handler);
|
|
63
|
+
}, []);
|
|
44
64
|
const filterRangeProps = react_1.default.useMemo(() => {
|
|
45
65
|
var _a, _b;
|
|
46
66
|
const options = (_b = (_a = filter.displayRangeOptions) === null || _a === void 0 ? void 0 : _a.map((option) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFilterRangeProps.js","sourceRoot":"","sources":["../../../src/hooks/useFilterRangeProps.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,oCAAwC;AACxC,wCAAmC;AAE5B,MAAM,mBAAmB,GAAG,CACjC,MAA0B,EAW1B,EAAE;IACF,MAAM,EAAE,KAAK,EAAE,GAAG,IAAA,oBAAY,GAAE,CAAC;IACjC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,eAAK,CAAC,QAAQ,CAAW,EAAE,CAAC,CAAC;IAErE,MAAM,YAAY,GAAG,eAAK,CAAC,WAAW,CACpC,CAAC,GAAW,EAAE,EAAE;QACd,eAAK,CAAC,UAAU,CAAC;YACf,QAAQ,EAAE,QAAQ;YAClB,OAAO,EAAE,uBAAuB;YAChC,IAAI,EAAE;gBACJ,MAAM,EAAE,MAAM,CAAC,IAAI;gBACnB,KAAK,EAAE,MAAM,CAAC,KAAK;gBACnB,KAAK,EAAE,GAAG;aACX;SACF,CAAC,CAAC;QAEH,eAAK,CAAC,GAAG,CAAC,0BAA0B,EAAE,mBAAmB,EAAE,GAAG,CAAC,CAAC;QAEhE,IAAI,MAAM,CAAC,WAAW,KAAK,OAAO,EAAE;YAClC,MAAM,QAAQ,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,IAAI,KAAK,GAAG,CAAC;gBAChE,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,GAAG,CAAC;gBAC/C,CAAC,CAAC,CAAC,GAAG,YAAY,EAAE,GA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AA,MAAA,MAAM,CAAC,mBAAmB,0CAAE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACzC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAChC,OAAO;gBACL,GAAG,EAAE,GAAG;gBACR,KAAK,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,GAAG;gBACzD,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC;aACpC,CAAC;QACJ,CAAC,CAAC,mCAAI,EAAE,CAAC;QAEX,OAAO;YACL,YAAY;YACZ,WAAW;YACX,MAAM;YACN,MAAM,EAAE,YAAY;YACpB,OAAO;SACR,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC;IAEzC,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AA3GW,QAAA,mBAAmB,uBA2G9B","sourcesContent":["import React from \"react\";\n\nimport { ConfigFilterOption } from \"../types/config\";\nimport { useAnalytics } from \"../hooks\";\nimport { debug } from \"../utility\";\n\nexport const useFilterRangeProps = (\n filter: ConfigFilterOption\n): {\n filter: ConfigFilterOption;\n options: Array<{\n key: string;\n label: string;\n checked: boolean;\n }>;\n values: string[];\n handleChange: (key: string) => void;\n handleClear: () => void;\n} => {\n const { track } = useAnalytics();\n const [filterValues, setFilterValues] = React.useState<string[]>([]);\n\n const handleChange = React.useCallback(\n (key: string) => {\n debug.breadcrumb({\n category: \"filter\",\n message: \"filter option changed\",\n data: {\n filter: filter.name,\n field: filter.field,\n value: key,\n },\n });\n\n debug.log(\"useFilterRangeMultiProps\", \"handleChange[key]\", key);\n\n if (filter.displayType === \"multi\") {\n const selected = filterValues.find((item: string) => item === key)\n ? filterValues.filter((value) => value !== key)\n : [...filterValues, key];\n\n setFilterValues(selected);\n }\n if (filter.displayType === \"single\") {\n setFilterValues([key]);\n }\n\n track({\n eventName: \"filterChange\",\n payload: {\n name: filter.name,\n value: key,\n },\n });\n },\n [filter, filterValues]\n );\n\n const handleClear = React.useCallback(() => {\n setFilterValues([]);\n }, []);\n\n React.useEffect(() => {\n try {\n if (filter.displayView === \"range\") {\n const url = new URL(window.location.href);\n const value = JSON.parse(url.searchParams.get(filter.handle) ?? \"[]\");\n setFilterValues(value);\n }\n } catch (error) {\n console.error(error);\n }\n }, []);\n\n React.useEffect(() => {\n const handler = (\n event: CustomEvent<{ handle: string; value: Array<string> }>\n ) => {\n setFilterValues(event.detail.value);\n };\n window.addEventListener(\n `@usereactify/search:filter:${filter.handle}:update`,\n handler as EventListener\n );\n\n return () =>\n window.removeEventListener(\n `@usereactify/search:filter:${filter.handle}:update`,\n handler as EventListener\n );\n }, []);\n\n const filterRangeProps = React.useMemo(() => {\n const options =\n filter.displayRangeOptions?.map((option) => {\n const [key] = option.split(\":\");\n return {\n key: key,\n label: filter.settingsUppercase ? key.toUpperCase() : key,\n checked: filterValues.includes(key),\n };\n }) ?? [];\n\n return {\n handleChange,\n handleClear,\n filter,\n values: filterValues,\n options,\n };\n }, [filter, filterValues, handleChange]);\n\n return filterRangeProps;\n};\n"]}
|