Docyrus

DocyrusDataSourcePicker

Picks a Docyrus data source (apps → data sources tree) and a sample record, then exposes a JSON Schema plus JSONata / Handlebars context paths through a render prop — API-aligned with the web DocyrusDataSourcePicker.

iOSAndroid
Preview DocyrusDataSourcePicker on your device

Scan with Expo Go

Download Expo Go, then scan the QR code to preview native components.

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-docyrus-data-source-picker
Required Packages(4 packages)
pnpm add @docyrus/api-client @docyrus/app-utils @tanstack/react-query @shopify/flash-list

Requires a signed-in RestApiClient and a QueryClientProvider above it (the record list uses useInfiniteQuery).

Usage

import { Text } from 'react-native';

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

import { DocyrusDataSourcePicker } from '@/components/docyrus-native/docyrus-data-source-picker';

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

  if (!client) return null;

  return (
    <DocyrusDataSourcePicker client={client}>
      {({ hasSelection, recordText, jsonataContextPaths }) => (
        hasSelection ? (
          <Text selectable>
            {recordText || jsonataContextPaths.map(path => path.path).join('\n')}
          </Text>
        ) : null
      )}
    </DocyrusDataSourcePicker>
  );
}

How it works

  1. A TreeSelect (leafOnly, showBreadcrumb) lists apps → data sources. The tree is loaded lazily the first time the sheet opens (createDataSourceClient(client).listApps() + listByAppSlug()); apps without data sources are hidden.
  2. Picking a data source loads its fields (getBySlug(app, slug, { expand: 'fields' })), builds a JSON Schema with useDocyrusDataSourceJsonSchema and derives context paths with jsonSchemaToContextPaths — items[0].name for JSONata and items.[0].name for Handlebars.
  3. Select record opens an internal RecordPickerSheet (the native replacement for the web dialog + useDocyrusDataTable): a search box (filterKeyword), a reload button and a paged FlashList (20 records per page, infinite scroll) loaded from /v1/apps/<app>/data-sources/<slug>/items with every field as a column and relation / enum / user fields expanded. Each row shows the record name (or title / autonumber / id) plus a secondary text field. Tapping a row selects it.

API Reference

DocyrusDataSourcePickerProps

PropTypeDefaultDescription
clientRestApiClient-Authenticated Docyrus API client
schemaTitlestringdata source slugTitle of the generated JSON Schema root
dialogTitlestringt('ui.dataSourcePicker.dialogTitle', 'Select a record')Record picker sheet title
classNamestring-Additional classes for the root container
children(props: DocyrusDataSourcePickerRenderProps) => ReactNode-Render prop receiving the schema-derived context and the selected record

DocyrusDataSourcePickerRenderProps

FieldTypeDescription
schemaJsonSchema | nullSelected source's fields as a JSON Schema — null until a source with fields is picked
selectedDataSourceDataSource | nullSelected data source detail (incl. id)
jsonataContextPathsContextPath[]JSONata-style paths (items[0].name)
handlebarsContextPathsContextPath[]Handlebars-style paths (items.[0].name)
selectedRecordRecord<string, unknown> | nullRecord picked in the sheet
recordTextstringPretty-printed JSON of selectedRecord ('' when none)
hasSelectionbooleantrue once a data source is picked and its field list is non-empty

ContextPath

FieldTypeDescription
pathstringDotted path inserted into an expression / template
typestringOptional type label (string, number, object[], …)
descriptionstringOptional description (field description or title)
labelstringOptional human-readable label

ContextPath, normalizeContextPaths and jsonSchemaToContextPaths live in lib/context-paths (a verbatim copy of the web helper, installed with the component).

Translation keys

Same keys as web: ui.dataSourcePicker.placeholder, ui.dataSourcePicker.loading, ui.dataSourcePicker.search, ui.dataSourcePicker.fieldsBadge, ui.dataSourcePicker.selectRecord, ui.dataSourcePicker.changeRecord, ui.dataSourcePicker.dialogTitle, ui.dataSourcePicker.selectButton. Native additions: ui.dataSourcePicker.searchRecords, ui.dataSourcePicker.reload, ui.dataSourcePicker.noRecords.

Components

ComponentDescription
DocyrusDataSourcePickerData source + record picker with render prop

Type Exports

TypeDescription
DocyrusDataSourcePickerPropsProps for DocyrusDataSourcePicker
DocyrusDataSourcePickerRenderPropsRender-prop payload

On this page