@usereactify/search 5.17.0 → 5.17.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 +7 -0
- package/dist/package.json +1 -1
- package/dist/src/components/Filter/Filter.js +7 -1
- package/dist/src/components/Filter/Filter.js.map +1 -1
- package/dist/src/hooks/useFilterRangeProps.d.ts +1 -0
- package/dist/src/hooks/useFilterRangeProps.js +4 -0
- package/dist/src/hooks/useFilterRangeProps.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
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.17.1](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.17.0...release-v5.17.1) (2023-01-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* clear range filter values when values are cleared within underlying reactivesearch component ([720917f](https://bitbucket.org/usereactify/reactify-search-ui/commit/720917f6e3b2c017cfd05a1d2bacf1692212f37e))
|
|
11
|
+
|
|
5
12
|
## [5.17.0](https://bitbucket.org/usereactify/reactify-search-ui/compare/release-v5.16.3...release-v5.17.0) (2022-12-15)
|
|
6
13
|
|
|
7
14
|
|
package/dist/package.json
CHANGED
|
@@ -76,7 +76,13 @@ const FilterRangeMulti = (props) => {
|
|
|
76
76
|
react_1.default.createElement("div", { style: {
|
|
77
77
|
display: "none",
|
|
78
78
|
} },
|
|
79
|
-
react_1.default.createElement(MultiRange_1.default, Object.assign({}, reactiveFilterRangeProps, { value: filterRangeProps.values,
|
|
79
|
+
react_1.default.createElement(MultiRange_1.default, Object.assign({}, reactiveFilterRangeProps, { value: filterRangeProps.values,
|
|
80
|
+
// NOTE: onChange handler must be defined for controlled component to work correctly
|
|
81
|
+
onChange: () => { }, onValueChange: (values) => {
|
|
82
|
+
if (values.length === 0) {
|
|
83
|
+
filterRangeProps.handleClear();
|
|
84
|
+
}
|
|
85
|
+
} }))),
|
|
80
86
|
react_1.default.createElement(RenderRangeComponent, { filterRangeProps: filterRangeProps, filter: props.filter })));
|
|
81
87
|
};
|
|
82
88
|
const FilterSlider = (props) => {
|
|
@@ -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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C,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 onChange={filterRangeProps.handleChange}\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;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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pC,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\";\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"]}
|
|
@@ -38,6 +38,9 @@ const useFilterRangeProps = (filter) => {
|
|
|
38
38
|
},
|
|
39
39
|
});
|
|
40
40
|
}, [filter, filterValues]);
|
|
41
|
+
const handleClear = react_1.default.useCallback(() => {
|
|
42
|
+
setFilterValues([]);
|
|
43
|
+
}, []);
|
|
41
44
|
const filterRangeProps = react_1.default.useMemo(() => {
|
|
42
45
|
var _a, _b;
|
|
43
46
|
const options = (_b = (_a = filter.displayRangeOptions) === null || _a === void 0 ? void 0 : _a.map((option) => {
|
|
@@ -50,6 +53,7 @@ const useFilterRangeProps = (filter) => {
|
|
|
50
53
|
})) !== null && _b !== void 0 ? _b : [];
|
|
51
54
|
return {
|
|
52
55
|
handleChange,
|
|
56
|
+
handleClear,
|
|
53
57
|
filter,
|
|
54
58
|
values: filterValues,
|
|
55
59
|
options,
|
|
@@ -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,
|
|
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,WA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AC,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;AA7EW,QAAA,mBAAmB,uBA6E9B","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 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"]}
|