Hooks

useDocyrusPivotFilter

Connects a Docyrus data source to a native PivotFilter strip. It detects the field type, runs a pivot aggregate query, builds pill items and date buckets, and emits filter rules. DocyrusPivotFilterGroup stacks several strips that cross-filter each other.

iOSAndroidExpo Go

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-docyrus-pivot-filter
Required Packages(4 packages)
pnpm add @docyrus/app-utils @docyrus/api-client @tanstack/react-query date-fns

This is a straight port of the web hook, with the same signature and the same query payloads. It needs an authenticated RestApiClient and a QueryClientProvider above it. The hook:

  • loads the data source schema (createDataSourceClient(client).getBySlug(app, ds, { expand: 'enums' }))
  • detects the field strategy from field.type
  • sends a native Docyrus pivot query to /v1/apps/{app}/data-sources/{ds}/items: columns: '<field>(id, name, icon, color)' for list fields, '<field>(id, name)' for users, '<bucket>@<field>' for dates, together with calculations
  • turns the rows into PivotFilterItems. Enum colours and icons come straight from the join. Date buckets are generated on the device, with Before, Upcoming and Not Set pills.
  • returns filterRule for the current selection and settingsContent (the PivotFilterSettings panel), which PivotFilter renders in a bottom sheet
Field typeStrategyFilter rule emitted
field-select, field-status, field-radioGroup, field-relationlist{ field, operator: '=', value: id }
field-userSelectuser{ field, operator: '=', value: userId }
field-datedatebetween with wall-clock bounds stamped +00:00
field-dateTimedatebetween with the device's local offset
field-multiSelect, field-tagSelect, field-userMultiSelectunsupportednone (query skipped)

The Not Set pill emits { operator: 'empty', value: null }. Before and Upcoming emit < and > against the window bounds.

Usage

Single strip

import { useDocyrusClient } from '@docyrus/signin/react-native';

import { PivotFilter } from '@/components/docyrus-native/pivot-filter';
import { useDocyrusPivotFilter } from '@/hooks/docyrus-native/use-docyrus-pivot-filter';

export function TaskStatusFilter() {
  const client = useDocyrusClient();

  const pivot = useDocyrusPivotFilter({
    client: client!,
    appSlug: 'base',
    dataSourceSlug: 'task',
    fieldSlug: 'status'
  });

  // pivot.filterRule → AND it into your list query
  return <PivotFilter {...pivot.pivotFilterProps} totalLabel="All statuses" />;
}

DocyrusPivotFilterGroup

import { DocyrusPivotFilterGroup } from '@/hooks/docyrus-native/use-docyrus-pivot-filter';

<DocyrusPivotFilterGroup
  client={client}
  appSlug="base"
  dataSourceSlug="task"
  fields={[
    { fieldSlug: 'status', totalLabel: 'All statuses' },
    { fieldSlug: 'priority', totalLabel: 'All priorities' }
  ]}
  onFilterRuleChange={rule => setPivotRule(rule)} />

Each strip is fed the other strips' selections through activeFilters, so the counts react to what is selected elsewhere. onFilterRuleChange receives the AND of all selections, or null. On native, horizontal strips stack vertically with thin separators between them. With vertical, the rails sit side by side in a row (this suits tablets; on phones, prefer horizontal strips).

API Reference

Options (UseDocyrusPivotFilterOptions)

OptionTypeDefaultDescription
clientRestApiClient—Authenticated API client (required).
appSlugstring—App slug (required).
dataSourceSlugstring—Data source slug (required).
fieldSlugstring—Field to pivot on (required).
calculationPivotFilterCalculation | nullnullInitial aggregate; null = COUNT of id.
defaultDateBucketPivotFilterDateBucket'days_of_week'Initial date bucket (date fields only).
defaultFiltersunknown—Base filter merged into every query (e.g. a saved view's filter).
activeFiltersunknown—The consumer's active filter. Pill counts react to it.
parentPivotFiltersunknown—Filter from a parent pivot (drill-down). A change resets the selection.
hideZeroValuesbooleanfalseHide items with a zero stat (except the selected one).
defaultSelectedItemIdstring | nullnullInitial selection.
referenceDateDatenew Date()Reference date for the date-bucket window.
disableSettingsbooleanfalseHide the settings sheet (settingsContent becomes undefined).
onConfigurationChange(config: { dateBucket: PivotFilterDateBucket; calculation: PivotFilterCalculation | null }) => void—Fired when the bucket or calculation changes.
staleTimenumber30000TanStack Query staleTime (ms).
enabledbooleantrueSkip fetching when false.
dataSourceExpandstring | false'enums'expand param of the schema fetch. false or '' omits it (core/tenant system data sources).

Date buckets (PivotFilterDateBucket): hours_of_today, days_of_week, days_of_month, weeks_of_month, weeks_of_quarter, months_of_quarter, months_of_year, quarters_of_year. Weeks start on Monday.

Result (UseDocyrusPivotFilterResult)

FieldTypeDescription
pivotFilterPropsPivotFilterPropsSpread onto <PivotFilter /> (items, selection, total, loading, hideZeroValues, onRefresh, settingsContent).
itemsPivotFilterItem[]Items built from the response.
totalnumberSum of all item stats.
selectedItemIdstring | nullCurrent selection (null = All).
setSelectedItemId(id: string | null) => voidSet the selection programmatically.
selectedItemPivotFilterItem | nullSelected item.
filterRulePivotFilterRule[] | nullRule(s) for the selection; null for All.
fieldDataSourceField | nullResolved field definition.
fieldTypePivotFilterFieldTypeStrategy derived from field.type.
dateBucketPivotFilterDateBucketCurrent bucket.
setDateBucket(bucket: PivotFilterDateBucket) => voidChange the bucket (also resets the selection).
calculationPivotFilterCalculation | nullCurrent calculation.
setCalculation(calc: PivotFilterCalculation | null) => voidChange the calculation.
reload() => voidInvalidate the schema and refetch the items.
isLoadingbooleanFirst load of the schema or items.
isFetchingbooleanAny fetch in progress.
errorError | nullSchema or items error.

DocyrusPivotFilterGroupProps

PropTypeDefaultDescription
clientRestApiClient—Authenticated API client (required).
appSlugstring—App slug (required).
dataSourceSlugstring—Data source slug (required).
fieldsReadonlyArray<DocyrusPivotFilterGroupField>—One entry per strip, top to bottom (required).
defaultFiltersunknown—Base filter for every strip.
activeFiltersunknown—External filter for every strip (e.g. the list's toolbar filter).
onFilterRuleChange(rule: PivotFilterRule[] | null) => void—AND-combined rule of every selection.
verticalbooleanfalseVertical rails side by side instead of stacked horizontal strips.
compactbooleanfalseCompact pills.
classNamestring—Wrapper View classes.
staleTimenumber—Forwarded to every strip.
dataSourceExpandstring | false—Forwarded to every strip.

DocyrusPivotFilterGroupField

FieldTypeDescription
fieldSlugstringField to pivot on (required).
defaultDateBucketPivotFilterDateBucketInitial bucket for date fields.
calculationPivotFilterCalculation | nullInitial calculation.
totalLabelstring"All" pill label for this strip.
hideZeroValuesbooleanHide zero-stat items.
disableSettingsbooleanHide the settings sheet for this strip.
defaultSelectedItemIdstring | nullInitial selection.

Translation keys

The hook reads ui.pivotFilter.notSet ("Not Set"), ui.pivotFilter.before ("Before") and ui.pivotFilter.upcoming ("Upcoming") through useUiTranslation(). For the component and settings-panel keys, see PivotFilter.

Differences from web

  • The settings content renders in a bottom sheet instead of a popover. Its aggregate-function and field pickers are chip rows instead of Selects.
  • DocyrusPivotFilterGroup puts a thin separator between horizontal strips.
  • PivotFilterAggregateFunc / PivotFilterCalculation / PivotFilterDateBucket / PivotFilterFieldType are declared in the component's types.ts and re-exported here under the same names.

Type Exports

TypeDescription
UseDocyrusPivotFilterOptionsHook options.
UseDocyrusPivotFilterResultHook result.
DocyrusPivotFilterGroupPropsGroup component props.
DocyrusPivotFilterGroupFieldPer-strip config of the group.
PivotFilterRule{ field, operator, value }.
PivotFilterAggregateFunc'count' | 'sum' | 'avg' | 'min' | 'max'.
PivotFilterCalculation{ func, field }.
PivotFilterDateBucketThe 8 date buckets.
PivotFilterFieldType'list' | 'user' | 'user-multi' | 'date' | 'unsupported'.

On this page