THIS IS ARCHIVED DOCUMENTATION

StaticFilter (Deprecated)

The StaticFilter controller manages a collection of filter values.

Methods

deselectAll

Deselects all static filter values.

isValueSelected

Checks whether the specified static filter value is selected.

Parameters

Returns boolean: Whether the specified static filter value is selected.

toggleSelect

Toggles the specified static filter value.

Parameters

toggleSingleSelect

Toggles the specified static filter value, deselecting others.

Parameters

subscribe

Adds a callback that’s invoked on state change.

Parameters

  • listener: () ⇒ void

    A callback that’s invoked on state change.

Returns Unsubscribe: A function to remove the listener.

Attributes

state

A state of the StaticFilter controller.

Properties

  • hasActiveValues: boolean

    true if there’s at least one non-idle value and false otherwise.

  • id: string

    The static filter id.

  • values: StaticFilterValue[]

    The static filter values.

Initialize

buildStaticFilter

Creates a Static Filter controller instance.

Parameters

  • engine: SearchEngine

    The headless engine.

  • props: StaticFilterProps

    The configurable Sort controller properties.

Returns StaticFilter

StaticFilterProps

The configurable Sort controller properties.

Properties

StaticFilterOptions

The options for the StaticFilter controller.

Properties

  • id: string

    A unique identifier for the static filter.

  • values: StaticFilterValue[]

    The values the static filter is responsible for managing.

Utils

buildStaticFilterValue

Creates a StaticFilterValue.

Parameters

StaticFilterValue

Properties

  • caption: string

    A human-readable caption for the expression (for example, Youtube).

  • expression: string

    The query filter expression to apply when the value is selected (for example, @filetype=="youtubevideo").

  • state: 'idle' | 'selected'

    The state of the static filter value.

StaticFilterValueOptions

Properties

  • caption: string

    A human-readable caption for the expression (for example, Youtube).

  • expression: string

    The query filter expression to apply when the value is selected (for example, @filetype=="youtubevideo").

  • state?: 'idle' | 'selected'

    The state of the static filter value.

Unsubscribe

Call signatures

  • (): void

Example Implementation

static-filter.fn.tsx

import {useEffect, useState, FunctionComponent, useContext} from 'react';
import {StaticFilterOptions, buildStaticFilter} from '@coveo/headless';
import {AppContext} from '../../context/engine';
 
export const StaticFilter: FunctionComponent<StaticFilterOptions> = (props) => {
  const {engine} = useContext(AppContext);
  const controller = buildStaticFilter(engine!, {options: props});
  const [state, setState] = useState(controller.state);
 
  useEffect(() => controller.subscribe(() => setState(controller.state)), []);
 
  return (
    <ul>
      {state.values.map((value) => {
        return (
          <li key={value.caption}>
            <input
              type="checkbox"
              checked={controller.isValueSelected(value)}
              onChange={() => controller.toggleSelect(value)}
            />
            <span>{value.caption}</span>
          </li>
        );
      })}
    </ul>
  );
};
 
/* Usage
 
const youtube = buildStaticFilterValue({
  caption: 'Youtube',
  expression: '@filetype==youtubevideo',
})
const dropbox = buildStaticFilterValue({
  caption: 'Dropbox',
  expression: '(@connectortype==DropboxCrawler AND @objecttype==File)',
})
 
<StaticFilter id="fileType" values={[youtube, dropbox]}/>;
*/

Associated Engines

The StaticFilter controller is available in the following engine: