New Async API + React HTML Components
This page covers the changes added to the Buzzy Frame API, giving full control to the user when calling API endpoints. Usage of such an API is explored as React components.
What's new?
The new iframe API gives users access to pre-existing sandbox API endpoints without the need for message handling. We've exposed a set of asynchronous functions that can be awaited, this ensures that HTML components can be more deterministic as a result is guaranteed. Buzzy handles the message handling, making your HTML code snippets simpler!
This feature is current opt-in and you must enable it through the HTML field settings under "Enable Async API".
Script Placement
Warning
You must place the <script> inside the <body> of your custom HTML code.
This is important as the Buzzy Frame API is loaded in the head and may not be available due to loading order.
Available Asynchronous Functions
Insert a Row
Usage
Return
Update a Row
Usage
Return
Remove a Row
Usage
Return
None.
Fetch Embedded Row Data
Usage
Return
Resource as JSON.
Fetch All Embedded Data
Usage
Return
Object with all data tables and sub tables resolves to N levels.
Fetch Data Table Rows 🆕
Usage
Return
Array of data table rows as JSON.
Query Options (Pagination) and Filtering
When fetching embedded row data, you might to do pagination, filtering, and/or limit the number of results that you get. Buzzy uses MongoDB under the hood, as such, view filters follow the rules for MongoDB queries.
Query Options (Pagination and Data Limits)
Query options allow you to control the number of results you get back from the query, as well as allowing you to do pagination using the skip
parameter. Common supported MongoDB aggregation parameters:
More info on Sorting:
The data fetched from the Microapp can be sorted. The order
and field
parameters are used in the searchFilter to specify which Microapp sort field and if it is ascending or descending. The sort fields are configured in the Microapp Results Tab. Sort field 1 corresponds to the field
value 1 and so on. Where order
is either 1
= ascending or -1
= descending.
Example fetching microapp rows using Sort Field 1.
View Filters (Filtering)
In cases where you might want to filter the results based on the value of a field, you can query based on the value of a field of the data table row. viewFilters
is an array of view filters to be used, as such you may filter many views as they are scoped to the data table ID (resourceID).
Combining the Above Concepts, see the following example with filtering and pagination included:
In the example above, the query will fetch rows where the sortVal
contains the word "Lasagna", in this case, the sortVal
is referencing the data table row title (the recipe title). The query options them limit the rows to only 1 row, while skipping 0. If we were doing some pagination, when a user clicked a "Next Page" button, we could change the skip to 1 so it would get the next recipe that satisfies the filters.
Listen for Updates
Usage
Register a listener function for a given microapp (aka data table).
Whenever data is added or updated that fits the query you have running on the given microapp, the supplied listener function will be executed. In the native app version, this function will also be run if the user initiates a refresh by dragging down on the screen.
Typically this would be used to re-run your query and set the results to a state variable, and thus trigger re-rendering of your fetched data whenever it is updated.
The listener will be passed on object with these properties:
microAppID - the id that passed into the listener
isUserRefresh - true if this is a user initiated refresh
timestamp - timestamp of the update that triggered the listener
Code Example
Preamble
Buzzy HTML Field Settings
Due to the usage of React, we want to disable handlebars and opt-in to the new Async API. This is easily accomplished in the settings panel of the HTML field definition:
Our Example Data table Layout
As a reference for the code snippet, the fields and set up of the data tables referenced in the code example are provided below:
Fruit Reports (Data table)
Fruit Report (Text)
Date (Datetime)
Fruit Counters (Sub table)
Graphic-HTML (HTML Field)
Fruit Counters (Sub table)
Fruit Type (Select list)
Number (Count)
Date Counted (Datetime)
Code
Result
With some data table rows, the above example provides the following output in Buzzy:
Limitations
The current iteration of the new API is still under development. There are a number of key issue yet to be resolved:
Last updated