Field picker

The field picker is used for choosing fields (Dimensions & Metrics) and have them in a certain order.

Usage

The store

The FieldPicker uses seperate store for its state. To allow for multiple FieldPickers with seperate stores, createFieldPickerStore() is used to create each store. This function must be used to create a store before the FieldPicker is used.

The external store is used to avoid having to rebuild the field tree everytime the FieldPicker is mounted, the store is persisted across renders. As a consequence, you need to build the store using the buildFieldTree function as a part of the state management of your app, for instance when the account changes. The store expects metadata v2 field and group definitions and can be set up like this:

Components

This will render a FieldPicker with no selected fields and using default components.

Spying

Most likely you will want to know what is going on inside the store, or update your own application state when things change. We provide a Hook for this purpose.

WARNING: you can create a loop using this, as initialSelectedFields is set using an action, which causes the hook to be called, which causes a re-render. initialSelectedFields should not be re-created on each render, like it is in the example above.

Instead either get initialSelectedFields from outside the component or use an effect hook to set it once.

The FieldPicker above will console log actions to demonstrate.

FieldPicker props

store

Store used to track the FieldPicker state.

initialSelectedFields

To reset the selected fields in the picker on mount set the initialSelectedFields prop to an array containing field ids.

virtualisationThreshold

When the number of fields in a tree group is larger than this number, the fields will be rendered using a virtualized window. This allows for really large groups, but has a tradeoff with potentially double scrollbars. The default is 500.

components

Custom components are deprecated.

The FieldPicker accepts custom components:

The FieldListItem component will receive two props:

The FieldListToolbar has no props.

getField

getField is deprecated.

You can pass in a function that will be called to find the field that should be displayed in the field list. The result of this function will be passed to the FieldListItem component as the field prop.

Custom group and field objects

Internally the FieldPicker maintains structures containing custom group and field definitions. These have more properties than the vanilla versions.

Group

Field

Field states

A field is shown in the tree if it is:

A field is shown in search results if it is:

For example optional (unavailable) are hidden and selectable, formula metrics are hidden and not selectable. Both are visible when searching but not in the tree. Formula metrics cannot not be selected, even when found.

Search Gunnel

Powered byAlgolia