Skip to content

Collection Filter

Overview

This module exports two composables that work together to provide tag-based and time-based filtering for collections, driven by state stored in the current activity context.

  • useCollectionFilter() — exposes the raw filter state and setter functions.
  • useCollectionFilterQuery(options) — builds a reactive filterQuery object ready to be passed to useCollection.

useCollectionFilter()

Overview

Reads and writes the tagsFilter and timeFilter objects from the current activity's state store. No arguments required.

Usage

javascript
import { useCollectionFilter } from '@kalisio/kdk/core.client'

const { tagsFilterSelection, setTagsFilterSelection, hasTimeFilterSelection } = useCollectionFilter()

Exposed

NameTypeDescription
tagsFilterComputedRef<Object>The full tags filter object from activity state.
timeFilterComputedRef<Object>The full time filter object from activity state.
tagsFilterOptionsComputedRef<Array>Available tag options (tagsFilter.options).
tagsFilterSelectionComputedRef<Array>Currently selected tags (tagsFilter.selection).
timeFilterRangeComputedRef<Object>Available time range bounds (timeFilter.range).
timeFilterSelectionComputedRef<Object>Currently selected time range (timeFilter.selection: { start, end }).
hasTagsFilterOptionsComputedRef<boolean>true when tag options are available.
hasTagsFilterSelectionComputedRef<boolean>true when at least one tag is selected.
hasTimeFilterRangeComputedRef<boolean>true when a valid, non-zero time range is available.
hasTimeFilterSelectionComputedRef<boolean>true when a valid time range selection (start and end) is set.
setTagsFilterOptions(options)FunctionSets the available tag filter options.
setTagsFilterSelection(selection)FunctionSets the selected tags.
setTimeFilterRange(range)FunctionSets the available time filter range bounds.
setTimeFilterSelection(selection)FunctionSets the selected time range ({ start, end }).
clearTagsFilterSelection()FunctionClears the selected tags.
clearTimeFilterSelection()FunctionClears the selected time range.

useCollectionFilterQuery(options)

Overview

Builds a reactive filterQuery derived from the current tag and time filter selections. Also fetches the available filter options (time range bounds and tag options) on mount and keeps them updated via service events.

Usage

javascript
import { ref } from 'vue'
import { useCollectionFilterQuery } from '@kalisio/kdk/core.client'

const { filterQuery } = useCollectionFilterQuery({
  service: ref('events'),
  timeField: ref('createdAt'),
  tagFields: { status: { active: { label: 'Active' }, closed: { label: 'Closed' } } }
})

Options

OptionTypeDefaultDescription
serviceRef<string>The FeathersJS service name.
contextRef<string>Optional context ID.
baseQueryRef<Object>{}Base query for fetching time range bounds.
timeFieldRef<string>ref('createdAt')The document field used for time filtering.
tagFieldsObjectA map of { property: { tagKey: tagState } } defining available tag filter options.

Exposed

NameTypeDescription
filterQueryRef<Object>The computed FeathersJS query fragment combining active tag and time filters. Pass this to useCollection as filterQuery.
tagsFilterSelectionComputedRef<Array>Currently selected tags (from useCollectionFilter).
timeFilterSelectionComputedRef<Object>Currently selected time range (from useCollectionFilter).
hasTagsFilterSelectionComputedRef<boolean>Whether any tags are selected.
hasTimeFilterSelectionComputedRef<boolean>Whether a time range is selected.

Lifecycle

  • mounted: fetches time range bounds and tag options, then registers service event listeners to keep them current.
  • beforeUnmount: removes service event listeners.