React Panel Plugin: How to get access to grafana internal services?

I want to get some dashboard service (timeSrv for example), but there is no such servise in the @grafana/runtime/services. What is the legal way to get them to my plugin code?

And one more spesific question:
I want to set up dashboard time range from within my panel plugin so I’m going to use timeSrv.setTime(). Is this a legal way to change dashboard taime range with new plugin API?

2 Likes

up. I also need an answer to this question.

It seems like the TimeSrv has not yet been migrated to grafana/runtime and is only accessible within internal Grafana repo.

What’s your use case for accessing the timeSrv?

1 Like

I wrote the example use case in the question: I need to tune dashboard time range from my plugin code. The more simple example is month switcher

1 Like

Up … also need it …

Same here.
My use case is to stop the refresh after some data is collected.

I also want to get the time range to display it in the report. Found something but this did not work for me and don’t know why. How to dynamic get system time range variable?

Does anyone has found a solution/work around?

Found a working solution for my case, needed to set “disable_sanitize_html = true” in grfana.ini

I found a script and did some small modifications. This needs to be placed in a “Text” Visualization and the mode set to “html” to let it work.

<div id="time_range_info">
Time window: 
</div>

<script>
  function getDashboardTimeRange(){
    var f = (new Date($__from) + '').split(' ');
    fWeekDay = f[0];
    fMonth = f[1];
    fDay = [f[2], ','].join('');t
    fYear = f[3];
    var from = [fWeekDay, fMonth, fDay, fYear].join(' ');
  
    var t = (new Date($__to) + '').split(' ');
    tWeekDay = t[0];
    tMonth = t[1];
    tDay = [t[2], ','].join('');
    tYear = t[3];
    var to = [tWeekDay, tMonth, tDay, tYear].join(' ');

    return ['from', from, ' to ', to].join(' ');

//    if you only need month and year for instance  
//    return [tMonth, tYear].join(' ');
  }
  $('#time_range_info').append(getDashboardTimeRange());
</script>
indent preformatted text by 4 spaces