VolkovLabs / business-forms

The Business Forms panel is a conceptually new plugin for Grafana. It is the first plugin that allows inserting and updating application data, as well as modifying configuration directly from your Grafana dashboard.
https://docs.volkovlabs.io
Apache License 2.0
86 stars 10 forks source link

Can not get the custom code to work #270

Closed Evgeny243 closed 1 year ago

Evgeny243 commented 1 year ago

Hi @mikhail-vl . I have essentially no experience in JavaScript, so i would really appreciate if you can help me with the following simple task: I use Query in Initial Request. The data is loaded from InfluxDB into element "PD". Then I try in the Custom Code of the Initial Request to write a "new_value" string into the value of another element "Copy" using following code:

onChange(elements.map((element) => { return element.id === 'Copy' ? { ...element, value: 'new_value' } : element }); console.log(data, response, initial, elements); return;

Nothing happens. Also the console.log is not producing anything on the screen, so I am not sure how that function works. I attached a snapshot. Once this works the next step is to write the value of the "PD" element into the value of the "Copy" element.

Thanks!

Screen Shot 2023-10-17 at 3 30 32 PM
mikhail-vl commented 1 year ago

@Evgeny243 Try console.error() or warn() instead of console.log().

Show me your form elements, what is the id for the 'Copy' element. Id and Label are different.

Evgeny243 commented 1 year ago
image image
Evgeny243 commented 1 year ago

I can see the console now. Much easier to troubleshoot. The function also works now. How should I change the code above to replace the value of "Copy" by the value of "PD"?

mikhail-vl commented 1 year ago

@Evgeny243 Like that:

const PD = elements.find((element) => element.id === "PD");
console.warn(PD.value);
Evgeny243 commented 1 year ago

@mikhail-vl A followup question: When I try to write something to database using fetch I see an error: Blocked loading mixed active content “http://influxdb.......&precision=ms

When I change that to https:// then I get an error: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://influxdb........&precision=ms. (Reason: CORS request did not succeed). Status code: (null).

Is that something that has a known remedy?