From 409a179c77d490cf17abac45b92ec55d4bfcc1df Mon Sep 17 00:00:00 2001 From: dleadbetter Date: Wed, 8 Jan 2025 15:12:49 -0500 Subject: [PATCH 1/3] CDP #23 - Adjusting FacetListsGrouped component to lookup existing groups by ID or label --- packages/core-data/src/components/FacetListsGrouped.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/core-data/src/components/FacetListsGrouped.js b/packages/core-data/src/components/FacetListsGrouped.js index ed742999..7f677d24 100644 --- a/packages/core-data/src/components/FacetListsGrouped.js +++ b/packages/core-data/src/components/FacetListsGrouped.js @@ -43,6 +43,13 @@ const FacetListsGrouped = (props: Props) => { const label = props.resolveLabel(id); let group = _.findWhere(value, { id }); + + // If we cannot find a value by ID, lookup the value by label + if (!group) { + group = _.findWhere(value, { label }); + } + + // If we cannot find a value by ID or label, create new group if (!group) { group = { id, label, items: [] }; value.push(group); From ef4d8a77890c898ae4daa94ecb502f473ce7c0d8 Mon Sep 17 00:00:00 2001 From: dleadbetter Date: Wed, 8 Jan 2025 15:28:39 -0500 Subject: [PATCH 2/3] CDP #23 - Updating FacetStateContextProvider to allow include/exclude props --- .../components/FacetStateContextProvider.js | 38 +++++++++++++++++-- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/packages/core-data/src/components/FacetStateContextProvider.js b/packages/core-data/src/components/FacetStateContextProvider.js index fd0cc21f..3aae9bcc 100644 --- a/packages/core-data/src/components/FacetStateContextProvider.js +++ b/packages/core-data/src/components/FacetStateContextProvider.js @@ -1,6 +1,7 @@ // @flow import React, { + useCallback, useEffect, useMemo, useState, @@ -46,11 +47,21 @@ type Props = { */ children: Node, + /** + * A list of facets to exclude. + */ + exclude?: Array, + /** * Search host URI. */ host: string, + /** + * A list of facets to include. + */ + include?: Array, + /** * Search index name. */ @@ -86,19 +97,38 @@ const TYPE_INT_ARRAY = 'int64[]'; const FacetStateContextProvider = (props: Props) => { const [facets, setFacets] = useState>([]); + /** + * Returns true if the passed field should be included as a facet. + * + * @type {(function(*): (*|boolean))|*} + */ + const isValid = useCallback((field) => { + if (!_.isEmpty(props.include)) { + return _.contains(props.include, field.name); + } + + if (!_.isEmpty(props.exclude)) { + return _.contains(props.exclude, field.name); + } + + return true; + }, [props.exclude, props.include]); + /** * Memo-ize the refinement list facets. */ const listFacets = useMemo(() => ( - _.filter(facets, (field: any) => field.facet && field.type !== TYPE_AUTO && field.type !== TYPE_INT_ARRAY) - ), [facets]); + _.filter(facets, (field: any) => isValid(field) + && field.facet && field.type !== TYPE_AUTO + && field.type !== TYPE_INT_ARRAY) + ), [facets, isValid]); /** * Memo-ize the range facets. */ const rangeFacets = useMemo(() => ( - _.filter(facets, (field: any) => field.facet && field.type === TYPE_INT_ARRAY) - ), [facets]); + _.filter(facets, (field: any) => isValid(field) && field.facet && field.type === TYPE_INT_ARRAY) + ), [facets, isValid]); /** * Backwards compatability for consumers using the "attributes" return value. From 952ddc57ae0bfd0c1318ccc6b81315a15076cf2a Mon Sep 17 00:00:00 2001 From: dleadbetter Date: Wed, 8 Jan 2025 15:43:20 -0500 Subject: [PATCH 3/3] CDP #23 - Fixing include/exclude logic in FacetStateContextProvider --- packages/core-data/src/components/FacetStateContextProvider.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core-data/src/components/FacetStateContextProvider.js b/packages/core-data/src/components/FacetStateContextProvider.js index 3aae9bcc..1b5cbabd 100644 --- a/packages/core-data/src/components/FacetStateContextProvider.js +++ b/packages/core-data/src/components/FacetStateContextProvider.js @@ -108,7 +108,7 @@ const FacetStateContextProvider = (props: Props) => { } if (!_.isEmpty(props.exclude)) { - return _.contains(props.exclude, field.name); + return !_.contains(props.exclude, field.name); } return true;