Data Sources
So far we have learned how to define your connections, actions and events. The combination of these can create a full-fletched usable app. However, your users will most likely still have to ‘hard-code’ a lot of values like language codes, entity IDs, enumerated statusses, etc. That’s why we created Data sources. Data sources allow you to specify for certain input paremeters (on both actions and events) what data Blackbird can display in a dropdown. This saves the user time copying and pasting! There are two types of data sources: static data sources and dynamic data sources. Static data sources allow you to define a finite list of values that never change. An example of this could be different statusses a project can be in. Dynamic data sources allow you to fetch dynamic content based on the connection of the user. An example of this would be a list of existing projects. We’re first going to discuss how dynamic data sources work and then we’ll look at static data sources.
Dynamic data sources
Let’s take a look at the anatomy of a dynamic data source:
We see that the data source ‘handler’ class can inherit from BaseInvocable
, meaning that you have complete access to the context (including credentials).
The DataSourceContext.SearchString
provides the typed in search string by the user. You can use this to filter your result.
You should return a IEnumerable<DataSourceItem>
where the value
argument of a DataSourceItem
represents the value that will be “filled in” e.g. the ID of a certain status or entity. The second argument is the displayed name.
Advanced context
You can also get even more context than just the search string. What if you want to know the values of some other fields that were selected in an action? You can pass an [ActionParameter]
to the constructor in order to see the other fields the user filled in.
Usage
Simply add the [DataSource]
attribute to any string
or IEnumerable<string>
typed input value, and the free typing field will turn into a dropdown!
Static data sources
Static data sources are very similar to dynamic data sources. The main difference in usage is the interface and attributes you have to use to implement then. Secondly, you have to be aware that you cannot get a connection context. You should instead simply return a pre-defined IEnumerable<DataSourceItem>
.
Blackbird compiles these static data sources on build time, meaning that when someone uses your app, they won’t see a loading spinner when clicking on a static dropdown. Instead the values will be displayed instantly.
If your app does not properly upload to Blackbird, it could be because you have duplicate values in your static data sources.
Static data source class:
And its usage as an attribute: