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

Clear specific element on Update in Data Manipulation panel #318

Closed Evgeny243 closed 11 months ago

Evgeny243 commented 11 months ago

In my project upon press of the Update button the contents of first element (String-Input, ID=NameIn) are written into influxdb, and on the next Initial Request they are read out from influxdb into another element (Read-only, ID= NameOut). I want at the pressing of Update button not only the contents written to the influxdb, but also clear them from the String-Input element, so that they are not displayed twice in two elements, but only displayed in the Read-Only element. I found the following code on your website, but I do not understand how it works, and so can not modify for my specific case. I'd appreciate your help, thank you!

onOptionsChange({ ...options, elements: options.elements.map((element) => { return element.id === "name" ? { ...element, value: "test" } : element; }), });

mikhail-vl commented 11 months ago

If you are using one of the latest versions of Data Manipulation 3.1.0+, then use this code to update local state:

onChange(elements.map((element) => {
  return element.id === 'name' ? { ...element, value: 'test' } : element
});

What it does it's going thru all elements (map functions) and looking for the element with id equal to name. If found updates its value to test.

asimonok commented 11 months ago

@Evgeny243 please let us know if the solution above works for you