Skip to Content
Kiva

KivaDataSourcePicker

Picks a Kiva 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 KivaDataSourcePicker.

iOSAndroid
Preview KivaDataSourcePicker on your device

Scan with Expo Go

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

Installation

pnpm dlx @kivacore/ui-cli add @kivacore/rn-kiva-data-source-picker
Required Packages(4 packages)
pnpm add @kivacore/api-client @kivacore/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 { useKivaClient } from '@kivacore/signin/react-native';

import { KivaDataSourcePicker } from '@/components/kiva-native/kiva-data-source-picker';

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

  if (!client) return null;

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

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 useKivaDataSourceJsonSchema 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 + useKivaDataTable): 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

KivaDataSourcePickerProps

PropTypeDefaultDescription
clientRestApiClient-Authenticated Kiva 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: KivaDataSourcePickerRenderProps) => ReactNode-Render prop receiving the schema-derived context and the selected record

KivaDataSourcePickerRenderProps

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
KivaDataSourcePickerData source + record picker with render prop

Type Exports

TypeDescription
KivaDataSourcePickerPropsProps for KivaDataSourcePicker
KivaDataSourcePickerRenderPropsRender-prop payload

On this page