Share dashboards with persisted widget states
A dashboard can have widgets which the user can interact with. For an example, there can be a widget which the user can pick a date range which resulting another set of widgets change there dataset based on the selected date range. In this kind of scenario, there needs to be a way the user can save the current state of the dashboard or share it with someone else. In order to handle this scenario, a set of APIs has been introduced to the widget developer via the base widget component.
Follow the steps mentioned below to implement state persistence.
NOTE: This guide assumes that you already have a widget which is deployable in dashboard portal.
- Make sure your widget has extended from the based widget provided by the dashboard portal. If not please refer “Extending from base widget component”.
Call the following method to store the state of the widget.
super.setWidgetState(key, stateObj);
Call the following method to retrieved the saved state of the widget.
const state = super.getWidgetState(key);
A sample widget has been shipped with WSO2 Stream Processor named "WidgetState" to demonstrate this feature. You can find the source code of the sample widget at https://github.com/wso2/carbon-dashboards/tree/v4.0.8/samples/widgets/WidgetState.