BreadcrumbManager (Search Engine)
BreadcrumbManager (Search Engine)
|
|
Note
This component was introduced in version |
Example implementation
breadcrumb-manager.fn.tsx
import {BreadcrumbManager as HeadlessBreadcrumbManager} from '@coveo/headless';
import {useEffect, useState, FunctionComponent} from 'react';
interface BreadcrumbManagerProps {
controller: HeadlessBreadcrumbManager;
}
export const BreadcrumbManager: FunctionComponent<BreadcrumbManagerProps> = (
props
) => {
const {controller} = props;
const [state, setState] = useState(controller.state);
useEffect(() => controller.subscribe(() => setState(controller.state)), []);
if (!state?.hasBreadcrumbs) {
return null;
}
return (
<ul>
{state.facetBreadcrumbs.map((facet) => (
<li key={facet.facetId}>
{facet.field}:{' '}
{facet.values.map((breadcrumb) => (
<button
key={breadcrumb.value.value}
onClick={() => breadcrumb.deselect()}
>
{breadcrumb.value.value}
</button>
))}
</li>
))}
</ul>
);
};
// usage
/**
* ```tsx
* const controller = buildBreadcrumbManager(engine);
*
* <BreadcrumbManager controller={controller} />;
* ```
*/
The BreadcrumbManager headless controller manages a summary of the currently active facet filters.
Methods
deselectAll
Deselects all facet values.
deselectBreadcrumb
Deselects a breadcrumb value.
Parameters
-
value:
DeselectableValueThe breadcrumb value to deselect.
subscribe
Adds a callback that’s invoked on state change.
Parameters
-
listener:
() => voidA callback that’s invoked on state change.
Returns Unsubscribe: A function to remove the listener.
Attributes
state
The state of the BreadcrumbManager controller.
Properties
-
automaticFacetBreadcrumbs:
AutomaticFacetBreadcrumb[]The list of automatic facet breadcrumbs.
-
categoryFacetBreadcrumbs:
CategoryFacetBreadcrumb[]The list of category facet breadcrumbs.
-
dateFacetBreadcrumbs:
Breadcrumb<DateFacetValue>The list of date facet breadcrumbs.
-
facetBreadcrumbs:
Breadcrumb<FacetValue>The list of specific facet breadcrumbs.
-
hasBreadcrumbs:
booleanReturns
trueif there are any available breadcrumbs (that is, if there are any active facet values), andfalseif not. -
numericFacetBreadcrumbs:
Breadcrumb<NumericFacetValue>The list of numeric facet breadcrumbs.
-
staticFilterBreadcrumbs:
StaticFilterBreadcrumb[]The list of static filter breadcrumbs.
Initialize
buildBreadcrumbManager
Creates a BreadcrumbManager controller instance.
Parameters
-
engine:
SearchEngineThe headless engine.
Returns BreadcrumbManager
Related types
AutomaticFacetBreadcrumb
Properties
-
label:
stringThe label of the underlying facet.
-
facetId:
stringThe ID of the underlying facet.
-
field:
stringThe field on which the underlying facet is configured.
-
values:
BreadcrumbValue<T>[]The list of facet values currently selected.
BreadcrumbValue<T>
Properties
-
value:
TThe underlying value linked to this breadcrumb.
-
deselect: functionA function that when called dispatches actions to deselect a breadcrumb value.
CategoryFacetBreadcrumb
Properties
-
facetId:
stringThe ID of the underlying facet.
-
field:
stringThe field on which the underlying facet is configured.
-
path:
CategoryFacetValue[]The complete path to the underlying facet value.
-
deselect: functionA function that when called dispatches actions to deselect a breadcrumb value.
CategoryFacetValue
Properties
-
children:
CategoryFacetValue[]The children of this facet value.
-
isLeafValue:
booleanWhen the hierarchical value has no children, this property is true.
-
moreValuesAvailable:
booleanWhether more facet values are available.
-
numberOfResults:
numberThe number of results that match the facet value.
-
path:
string[]The hierarchical path to the facet value.
-
state:
'idle' | 'selected' | 'excluded'Whether a facet value is filtering results (
selected) or not (idle). -
value:
stringThe facet value.
DeselectableValue
Properties
-
deselect: functionA function that when called dispatches actions to deselect a breadcrumb value.
StaticFilterBreadcrumb
Properties
-
id:
stringThe ID of the underlying static filter.
-
values:
StaticFilterBreadcrumbValue[]The list of static filter values currently selected.
Unsubscribe
Call signatures
-
(): void;