Hooks

useDocyrusDataViewSelect

Load a Docyrus data source's fields, saved views and forms, and wire them into the native DataGridViewSelect with one hook — view CRUD, reorder, hidden views and persisted active view included.

iOSAndroidExpo Go

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-docyrus-data-view-select
Required Packages(4 packages)
pnpm add @docyrus/app-utils @docyrus/api-client @tanstack/react-query @react-querybuilder/core

A 1:1 port of the web hook (same options, same result). It needs an authenticated RestApiClient and a QueryClientProvider above it. Schema, saved views and forms are served from the shared inventory cache (useDocyrusInventoryLoader), so a warmed app pays no per-mount request.

Overview

  • Loads the data source (cache-first, then a scoped getBySlug with expand for data sources outside the inventory) and maps its fields to query-builder FullFields — enum / status / select options become values, relation fields get their first 200 records (id, name, autonumber_id) as picker values.
  • Loads saved views (createDataViewClient) sorted by sort_order then name, prepends developer-defined systemViews, and wires create / save / delete / reorder with list invalidation (reorder is optimistic, one PATCH per moved view).
  • Loads active forms (createDataFormClient), default form first, so the view editor can bind a form to each view.
  • Owns the active view: current selection → persisted id → backend isDefault → first view.
  • Keeps a per-user hidden views list (onViewHide / onViewUnhide).

Usage

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

import { DataGridViewSelect } from '@/components/docyrus-native/data-grid-view-select';
import { useDocyrusDataViewSelect } from '@/hooks/docyrus-native/use-docyrus-data-view-select';

export function OrganizationViews({ table }) {
  const client = useDocyrusClient();
  const { gridViewSelectProps, hasNoViews } = useDocyrusDataViewSelect({
    client: client!,
    appSlug: 'base',
    dataSourceSlug: 'organization'
  });

  return (
    <DataGridViewSelect
      table={table}
      variant="horizontal-tabs"
      editable
      {...gridViewSelectProps} />
  );
}

The hook does not take table — spread gridViewSelectProps and pass table separately. useDocyrusDataGrid and useDocyrusDataTable call this hook for you.

API Reference

Options (UseDocyrusDataViewSelectOptions)

OptionTypeDefaultDescription
clientRestApiClient—Authenticated Docyrus API client.
appSlugstring—App slug of the data source.
dataSourceSlugstring—Data source slug.
appIdstring—App id filter for views scoped to another app; also part of the storage keys.
overrideFieldsFullField[]—Replace the derived query-builder fields entirely.
dataSourceDataSource | null—Pre-resolved schema — skips the schema fetch; fields, relation targets and the returned dataSource come from it.
mapField(field: DataSourceField, defaultMapped: FullField) => FullField | null—Per-field transform after the default mapping. null drops the field.
staleTimenumber30_000TanStack Query staleTime for every query.
enabledbooleantrueDisable every query.
enableDataViewsbooleantrueFetch / manage saved views. false for data sources without a view backend — only systemViews are shown.
dataSourceExpandstring | false'enums'expand for the scoped schema fetch. false / '' omits it.
enableFormsbooleantrueFetch the data source's saved forms (forms result + gridViewSelectProps.forms).
persistActiveViewbooleantruePersist the last-selected view.
persistKeystringdocyrus:data-grid-view:<appSlug>:<dataSourceSlug>[:<appId>]Storage key override for the active view.
activeViewStorage'session' | 'local''local'lib/storage backend for the active-view id. The data-listing hooks thread persistState.storage here.
defaultRowGroupingColumnstring—Default row-grouping column for views without a grouping (applied by the grid / table hooks).
systemViewsSavedDataGridView[]—Developer-defined views shown before the saved views; marked isSystem (no edit / delete).

Result (UseDocyrusDataViewSelectResult)

FieldTypeDescription
gridViewSelectPropsPick<DataGridViewSelectProps, …>Spread onto DataGridViewSelect: views, activeViewId, fields, forms, onViewChange, onViewCreate, onViewSave, onViewDelete, onViewHide, onViewUnhide, onViewReorder, hiddenViewIds, disabled, defaultRowGroupingColumn, isSaving, isLoading.
viewsSavedDataGridView[]System views + saved views (mapped from the backend shape).
fieldsFullField[]Query-builder fields (from @react-querybuilder/core).
formsDataForm[]Active saved forms, default first.
dataSourceDataSource | undefinedResolved schema (injected or fetched).
activeViewIdstringActive view id ('' while loading / no views).
setActiveViewId(viewId: string) => voidSwitch views programmatically.
isLoadingbooleanSchema or views query loading.
errorError | nullFirst error of the schema / views queries.
refetch() => voidRefetch schema + views.
hasNoViewsbooleanThe view list loaded and is empty (the grid then uses the raw field order — a dev warning is logged).

How It Works

View shape mapping

DataView fieldSavedDataGridView fields
columnscolumnVisibility, columnOrder, columnPinning, grouping, rowHeight, displayMode, pagingEnabled, pagingMode, pageSize, inlineEditingEnabled, readOnlyColumns, columnOptions, formId, galleryCardConfig, galleryDisplayConfig
filterscolumnFilters, filterQuery
sortsorting
color_rulesrowColorRules, cellColorRules

Active view & persistence

The id is persisted under persistKey in the lib/storage store picked by activeViewStorage ('local' = the store registered through <DocyStorageProvider> / setDocyLocalStore(); 'session' = in-memory for the app process). With persistState on a data-listing hook, the key becomes docyrus:view-params:<appSlug>:<dataSourceSlug>[:<appId>]:__active-view__. The hidden-views list always lives in the 'local' store under docyrus:data-grid-view-hidden:<appSlug>:<dataSourceSlug>[:<appId>].

Native deltas

  • FullField comes from @react-querybuilder/core (no DOM react-querybuilder).
  • Storage goes through lib/storage (getDocyStore('local') / getPersistStore) instead of window.localStorage / sessionStorage. Register a synchronous persistent store (e.g. expo-sqlite/kv-store) to survive restarts.
  • The "no saved view" warning is gated on __DEV__.

Type Exports

TypeDescription
UseDocyrusDataViewSelectOptionsHook options.
UseDocyrusDataViewSelectResultHook result.

On this page