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

Initial fields for multi select - data format to save at DB #531

Closed bperun123 closed 1 month ago

bperun123 commented 1 month ago

Which format do I have to use to save multiple values correctly at DB in order that it can be red by the "Initial fields" logic?

It seems to me that I either have to save the values as a string "2,3" or array {2,3} at my DB. However both doesn't work. It just shows the string term eg "2,3" at the multiple select checkbox.

image

image

Can you give me a hint how to save multi selections correctly?!

mikhail-vl commented 1 month ago

@bperun123 Please try to use Transformation to transform string to a Grafana array, then it should work.

bperun123 commented 1 month ago

@mikhail-vl Sry, I couldn't make it. Please, can you give me an example how to do that? I couldn't find a transformation which would be capable of doing this. I think you mean these transformations, right? image

bperun123 commented 1 month ago

@mikhail-vl After a longer search, I finally found a solution. Usual PostgreSQL arrays can be used to save these values at DB. Use pg function "unnest" to "translate" it. See: image

Maybe could be added to docs ;)

Thx for your amazing work!

bperun123 commented 1 month ago

@mikhail-vl Mh, this solution breaks if I have no values included at this field due to no DB rows are created (unnest just "splits" an empty array to 0 rows).

Maybe you have another idea how to archive it to show the data for multi-selects from the DB?!

image

bperun123 commented 1 month ago

I think with that solution everything should work now. I tested it for empty, single selection, multi selection case.

I also share the part how I write the data into DB for others who encounter the same issues. "used_by_workspace" is a postgresql INT array.

Hint: "Request Payload - All Elements" doesn't work for me due to the fact that the conversion wasn't unified. Eg it converts "6" to an int, "1,3" as array "{1,3}". By converting it by code, everything is now a simple string with can be used at payload query editor between to brackets to indicate a PG array.

I don't know if this is best practise in terms of VolkovLabs, however it works for me now :)

image

mikhail-vl commented 1 month ago

@bperun123 Well done! I will update documentation.