Skip to main content
Version: 10.9.x

Data Querying

bk-expanded-filters

Manages the display, application, and modification of filters.

<bk-expanded-filters></bk-expanded-filters>
danger

bk-expanded-filters should not be included in the same configuration as bk-filters-drawer/bk-filters-manager since they listen and emit the same events and clashing behavior might occur.

Displays a grid of filters, with which it is possible to interacted by editing the value field. The grid has a maximum number of columns of 4, which shrink to 3 or 2 depending on the window width.

Fields property and operator of each filter will not be editable.

Configuration

Property filtersConfig allows to specify the filters to show. It is an array of properties and/or pairs of property - operator.

type FiltersConfig = string | {
property: string
operator: string
}

If the operator is missing, includesAll operator is set by default for multilookups properties and equal operator for the others. It is not possible to specify the same property more than once, and properties with filterOptions.hidden set to true are not shown.

Example

Given the following configuration,

...
{
"type": "element",
"tag": "bk-expanded-filters",
"properties": {
"dataSchema": {
"type": "object",
"properties": {
"dishes": {"type": "array", "format": "multilookup"},
"name": {"type": "string"},
"orderedAt": {"type": "string", "format": "date-time"},
}
},
"filtersConfig": [
{
"property": "orderedAt",
"operator": "between"
},
"dishes",
"name"
]
}
}
...

it is possible to specify a value for filtering properties dishes, name and orderedAt. Assuming the inserted values to be representable as:

{
"orderedAt": ["2023-03-03T09:00:00.000Z", "2023-03-03T12:00:00.000Z"],
"name": "Joe",
"dishes": ["dish-1", "dish-2"]
}

Then the emitted filters will look like:

{
"property": "orderedAt",
"operator": "between",
"value": ["2023-03-03T09:00:00.000Z", "2023-03-03T12:00:00.000Z"]
},
{
"property": "name",
"operator": "equal",
"value": "Joe"
},
{
"property": "dishes",
"operator": "includesAll",
"value": ["dish-1", "dish-2"]
}

If a component such as bk-crud-client is included in the page (and provided with the same data-schema), these filters are chained inside an $and mongo-like query and used to filter data.

Properties & Attributes

propertyattributetypedefaultdescription
dataSchema-ExtendedJSONSchema7Definition-data-schema describing the fields of the collection to query
filtersConfig-FiltersConfig[]-lists the filters to include in the component
openByDefaultopen-by-defaultbooleanfalsewhether to show the component by default
liveSearchTimeoutlive-search-timeoutnumber5000live-search timeout
liveSearchItemsLimitlive-search-items-limitnumber10max items to fetch on regex live search

Listens to

eventactionemitson error
filterdisplay/close the expanded filters component--

Emits

eventdescription
change-querywhen done filling or clearing the form, applies or clear the filters

Bootstrap

None

bk-export-modal

Modal to allow user configuration of a data export task.

<bk-export-modal></bk-export-modal>

Properties & Attributes

propertyattributetypedefaultdescription

Listens to

eventactionemitson error
export-data/awaiting-configprompts modal opening--

Emits

eventdescription
export-data/user-confignotifies the bus of user config for next export data task

Bootstrap

None

bk-filter-drawer

This is the filter drawer filter-drawer

<bk-filter-drawer></bk-filter-drawer>

bk-filter-drawer allows to compile filters and injects them into the payload of add-filter events, which are listened by components such as bk-filters-manager.

FiltersOptions

filtersOptions fields in dataSchmea properties can be used to further configure bk-filter-drawer behavior. In particular,

  • hidden controls whether the property should not be available to be selected for compiling a filter
  • availableOperators controls what operators should be available for the given property. Note that the type of each property also limits the available operators

Properties & Attributes

propertyattributetypedefaultdescription
dataSchema-ExtendedJSONSchema7Definition-data-schema describing the fields of the collection to query
liveSearchItemsLimitlive-search-items-limitnumber10max items to fetch on regex live search
liveSearchTimeoutlive-search-timeoutnumber5000live-search timeout
rootElementSelectorroot-element-selectorstring-root element to append the drawer to
widthwidthstring-width occupied by the component
editorHeighteditor-heightstring | number-height of object/array editor

Listens to

eventactionemitson error
using-form-containertoggles the drawer into visible mode only if the id payload property matches this drawer--
filterclaims the drawer, closing concurrent ones, to enter a new filterusing-form-container-
change-filterenters filter edit modeusing-form-container-
lookup-datareceives lookup data--
loading-datasets the component to loading state--

Emits

eventdescription
add-filterwhen done filling the form, notices deployment of a new filter

Bootstrap

None

bk-filters-manager

Manages the display, application, and modification of filters.

<bk-filters-manager></bk-filters-manager>

bk-filters-manager listens to add-filter events, which might be emitted by a component such as bk-filter-drawer, converts their payload to mongo-like queries and injects them into the payload of change-query events. A component like bk-crud-client listens to the change-query event and fetches data using its payload as query.

Persisten filters

Property saveFilters allows to save filters to local-storage. Filters are saved in local-storage through a key which can be customized with property localStorageKey, and defaults to bk-filters-manager-store- followed by the pathname of the current URL.

Upon connecting to the DOM, bk-filters-manager with saveFilters to true will fetch filters from local-storage, scoped through localStorageKey, and apply them.

caution

To avoid data leaking, localStorageKey should be unique per plugin.

Properties & Attributes

propertyattributetypedefaultdescription
dataSchema-ExtendedJSONSchema7Definition-data-schema describing the fields of the collection to query
filters-Filter[][]List of currently applied filters
hidehidebooleanfalseHides the rendered component
saveFilterssave-filtersbooleanfalseif true, filters are automatically saved to local storage
localStorageKeylocal-storage-keystrignbk-filters-manager-storage-{pathname}key used to identify filters saved in local-storage. Defaults to a string composed of 'bk-filters-manager-storage-' and the pathname of the current URL.

Listens to

eventactionemitson error
add-filterapplies a new filterchange-query-

Emits

eventdescription
change-queryrequires data filtering
change-filtertriggers the modification of an existing filter

Bootstrap

None

bk-pagination

displays pagination navigation tools to query pages of a dataset. It allows going back and forward and skip to first and last page. It shows the current page and total elements in a given dataset while interacting with dynamic filters

<bk-pagination></bk-pagination>

pagination

Properties & Attributes

propertyattributetypedefaultdescription
pageSizepage-sizenumberDEFAULT_PAGE_SIZEnumber of data items per page
pageSizeOptions-number[]DEFAULT_PAGE_OPTIONSavailable page sizes

Listens to

eventactionemitson error
loading-datasets internal loading state--
count-dataadjusts footer counter to currently viewed dataset--
nested-navigation-state/pushupdates internal representation of the current navigation path by adding one step. Emits nested-navigation-state/display with slice of data to displaynested-navigation-state/display-
nested-navigation-state/backupdates internal representation of the current navigation path by removing the specified number of steps. Emits nested-navigation-state/display with slice of data to displaynested-navigation-state/display-

Emits

eventdescription
change-queryrequires data filtered according with the current pagination
nested-navigation-state/displayemits nested-navigation-state/display with slice of data to display

Bootstrap

None

Allows data filtering by matching a text string

<bk-search-bar></bk-search-bar>

search-bar

Search bar allows to filter data against text using a regex. If searchLookups is true, lookups and multi-lookups that specify excludeFromSearch as false in the schema are also searched. The text value is compared against the lookupFields specified in the lookupOptions in the schema.

danger

Searching lookup fields could be computationally heavy. The number of searchable lookups should be kept to the needed minimum and search-bar properties such as liveSearchItemsLimit and autoSearchMinInput should be configured carefully.

Properties & Attributes

propertyattributetypedefaultdescription
autoSearchMinInputauto-search-min-inputnumber2min length of input string before performing automatic search
liveSearchItemsLimitlive-search-items-limitnumber100max items to fetch on regex live search
placeholder-LocalizedText{}placeholder of the search bar input
searchDebouncesearch-debouncenumber0time to wait before performing an automatic search. If 0, automatic search is disabled
searchLookupssearch-lookupsbooleanfalsewhether or not to perform search on lookups. If true, lookup-crud-client (or any component listening to search-lookups and emitting search-lookups-found) should be included in the plugin

Listens to

eventactionemitson error
loading-datasets internal loading state--
nested-navigation-state/backkeeps track of navigation steps--
nested-navigation-state/pushkeeps track of navigation steps--
search-lookups-foundincludes lookup values searched against text searchchange-query-

Emits

eventdescription
change-queryrequires data filtered according with the typed input
search-lookupsnotifies to search lookups against a text

Bootstrap

None

bk-tabs

provides a fixed set of filters rendered as tabs, possibly on top of a bk-table tabs

<bk-tabs></bk-tabs>

Tab Configuration

The Tab configuration object type is:

type Tab {
title: string | Record<string, string>
filters?: ConfigurableTabFilter[]
event?: Partial<Event>
order?: number
key: string
}

in which

  • order is the tab order number
  • filters is an array of filters that will be applied when the tab is opened. Read Filters Configuration for details
  • event an event launched when the tab is opened

An example of configuration:

  {
"key": "pending",
"title": {
"en": "Pending",
"it": "In attesa"
},
"filters": [
{
"property": "status",
"operator": "equal",
"value": "Pending"
},
]
},
{
"key": "preparing",
"title": {
"en": "Preparing",
"it": "In preparazione"
},
"filters": [
{
"property": "status",
"operator": "equal",
"value": "Preparing"
}
]
}

Filters Configuration

The ConfigurableTabFilter object type is:

type ConfigurableTabFilter {
operator: FilterOperator // see add-filter event operator
property: string
value: string | number | boolean | any[] | DateOptions
}

type DateOptions = {
value: string
offset: number
operation: 'add' | 'subtract'
unit: 'day' | 'week' | 'month' | 'year' | 'hour' | 'minute' | 'second' | 'millisecond'
}
info

Link to add-filter event for FilterOperator type

As seen above, an example of a filter configuration could be:

  ...
"filters": [
{
"property": "status",
"operator": "equal",
"value": "Preparing"
}
]

When filtering by a date, it is possible to use a special keyword in the value key: $today. If used, the value will correspond to the current date when the tab is opened. For example:

  ...
"filters": [
{
"property": "orderedAt",
"operator": "less",
"value": "$today"
}
]

It is also possible to make a real-time data manipulation using the DateOptions type for the filter value. For example, if you want to show only the data from one week ago to today, you could configure a filter like this:

  ...
"filters": [
{
"property": "orderedAt",
"operator": "greaterEqual",
"value": {
"value": "$today",
"offset": 1,
"unit": "week",
"operation": "subtract"
}
}
]

In case of filter with operator between, value should be an array. DateOptions are still valid in this case. For instance:

  ...
"filters": [
{
"property": "orderedAt",
"operator": "between",
"value": [
{
"value": "$today",
"offset": 1,
"unit": "week",
"operation": "subtract"
},
"$today"
]
}
]

Accessing current user

It is possible to access information of the current user through handle-bar notation {{currentUser}}. For instance:

  ...
"filters": [
{
"property": "userField",
"operator": "equal",
"value": "{{currentUser.name}}"
}
]

Properties & Attributes

propertyattributetypedefaultdescription
tabs-Tab[][]array with tabs configuration. For configuration ease, Tabs will be provided as an array by the user and remapped on startup to better fit the react component

Listens to

eventactionemitson error
nested-navigation-state/pushupdates internal representation of the current navigation path by adding one step--
nested-navigation-state/backupdates internal representation of the current navigation path by removing the specified number of steps--

Emits

eventdescription
change-queryrequests filtering on dataset

Bootstrap

None