Kibana Plugins: Using _g and _a in URL to pass state

I noticed that Kibana is using the _g and _a parameters in the URL to let the user set a context for elements such as Time Picker and application specific controls. This seems to be the standard way to pass state through URI.

For instance, it is common for a URL such as the one below to set a time window as well as pick what columns are displayed in the discover mode.

#/discover?_g=(refreshInterval:(display:Off,pause:!f,value:0),time:(from:now-6M,mode:quick,to:now))&_a=(columns:!(_source),index:dc10c5e0-758f-11e8-8d34-9705a1fc6f94,interval:auto,query:(language:lucene,query:''),sort:!(timestamp,desc))

My Question is : How does one do the same thing within the context of a Kibana plugin ? I have a plugin that works well but the user is required to change to a desired state every time, after they land on a default page. I want to provide a dynamic URL which stores session state and helps someone land directly at a desired state.

_g is global state, and it can be updated via the globalState angular service. Here is an example of how the timepicker updates the URL via the global service https://github.com/elastic/kibana/blob/6.3/src/ui/public/timepicker/kbn_global_timepicker.js#L12

_a is the application state. You can get the application state with the getAppState angular service. Then just call the save method once you have updated the state as needed.

We are in the process of removing angular from Kibana so these will be changing over future releases so be prepared for breaks between minor Kibana releases.

3 Likes

Thank you ! that helps.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.