VolkovLabs / volkovlabs-dynamictext-panel

Business Text Panel for @grafana
https://docs.volkovlabs.io
Apache License 2.0
78 stars 14 forks source link

Returning data using fetch #182

Closed yosiasz closed 1 year ago

yosiasz commented 1 year ago

Greetings!

I am returning data as follows

handlebars.registerHelper("getEntities", () =>
  fetch('http://localhost:5000/api/v4/entities?search=7676')
    .then(response => response.json())
    .then(data => {
      return data
    })
);

Data returned is

{
    "event": "DevicesM",
    "podName": "alliswell",
    "Time": "2023-06-09T07:56:19.483Z",
    "totalConnected": "30",
    "totalPType": "8",
    "totalJType": "2",
    "totalBType": "7",
    "totalWType": "2",
    "totalFIType": "11"
}
  1. Is the return ok or do I need to use something like a spread? return [...new Set(context.map(data => data[key]))];
  2. on the Content side of things I am not getting any data with the following
<div>
  {{#each (getEntities data)}}
    {{ event }}; 
  {{/each}}
</div>

Been at this for 3 hours and I give up Thanks!

yosiasz commented 1 year ago

it's async call and I handlebars can't wait for async call to display it

mikhail-vl commented 1 year ago

I will keep it opened for now to explore a way to add async Handlebars handlers.

yosiasz commented 1 year ago

does not seem anywhere near the horizon

https://github.com/handlebars-lang/handlebars.js/issues/717

mikhail-vl commented 1 year ago

We implemented the JavaScript Values editor in the latest version of the Static Data Source, which should be used instead of implementing asynchronous calls in the panels.

Release: https://github.com/VolkovLabs/volkovlabs-static-datasource/releases/tag/v3.0.0.