nodegraph-api-plugin
nodegraph-api-plugin copied to clipboard
Added support to links on fields
This solves issue #20 and is a very simple (3 line solution).
the way to use it is by specifying a links array in the fields JSON
{ "edges_fields": [ { "field_name": "id", "type": "string" }, { "field_name": "source", "type": "string" }, { "field_name": "target", "type": "string" }, { "field_name": "mainStat", "type": "number" } ], "nodes_fields": [ { "field_name": "id", "type": "string", "links": [ { "title": "Section One/First Link", "url": "https://google.com/${__data.fields.title}" }, { "title": "Section One/Second Link", "url": "https://google.com" }, { "title": "Section One/Second Link", "url": "https://google.com" }, }, { "field_name": "title", "type": "string" }, { "field_name": "mainStat", "type": "string" }, { "field_name": "secondaryStat", "type": "number" }, { "color": "red", "field_name": "arc__failed", "type": "number" }, { "color": "green", "field_name": "arc__passed", "type": "number" }, { "displayName": "Role", "field_name": "detail__role", "type": "string" } ] }
This way it also supports all the internal links and stuff that Node Graph have on their example:
@perotta Thanks for your contribution and sorry for being very late in sending my feedback. I'm reviewing it and will get back to you soon.
Hi @hoptical,
My implementation is pretty simple both on the changes and on how to use links on fields.
As I mention on the other issue, this is how I declare my fields (PHP code which will just json_encode this after to get a JSON):
This PR solves issue #17
@perotta Just curious if you can share your code (python?) as I'm also attempting to leverage the context menu to provide links for additional data about the node.
Hi @zosocanuck. The image above (https://github.com/hoptical/nodegraph-api-plugin/pull/23#issuecomment-1426172496) is literally the code (PHP) that matters to declare links. Showing the rest of my code would be pointless as it just encodes the array to json using json_encode() function and writes the json to buffer on the HTTP response (nothing different from the other stuff this library does)
On the other end, this does require you to manually modify nodegraph-api-plugin to add these 4 lines https://github.com/hoptical/nodegraph-api-plugin/compare/main...perotta:nodegraph-api-plugin:links-support Then you need to create your own unsinged grafana plugin and load it into your grafana instance.
Unless @hoptical accepts this PR and publishes a new version on the official signed plugin, this is the only way to get the Links working.
Hi @perotta I ended up forking a plugin with your PR however it had no impact. Here is my sample json:
{"edges_fields":[{"field_name":"id","type":"string"},{"field_name":"source","type":"string"},{"field_name":"target","type":"string"},{"field_name":"mainStat","type":"number"}],"nodes_fields":[{"field_name":"id","links":[{"title":"Section One/First Link","url":"https://myservice/info"}],"type":"string"},{"field_name":"title","type":"string"},{"field_name":"subTitle","type":"string"},{"field_name":"mainStat","type":"string"},{"field_name":"secondaryStat","type":"number"},{"color":"red","displayName":"Failed","field_name":"arc__failed","type":"number"},{"color":"green","displayName":"Passed","field_name":"arc__passed","type":"number"},{"displayName":"Role","field_name":"detail__role","type":"string"}]}
I'm using grafana v9.4.1, and not sure if that makes a difference.
Hi @perotta I ended up forking a plugin with your PR however it had no impact. Here is my sample json:
{"edges_fields":[{"field_name":"id","type":"string"},{"field_name":"source","type":"string"},{"field_name":"target","type":"string"},{"field_name":"mainStat","type":"number"}],"nodes_fields":[{"field_name":"id","links":[{"title":"Section One/First Link","url":"https://myservice/info"}],"type":"string"},{"field_name":"title","type":"string"},{"field_name":"subTitle","type":"string"},{"field_name":"mainStat","type":"string"},{"field_name":"secondaryStat","type":"number"},{"color":"red","displayName":"Failed","field_name":"arc__failed","type":"number"},{"color":"green","displayName":"Passed","field_name":"arc__passed","type":"number"},{"displayName":"Role","field_name":"detail__role","type":"string"}]}
I'm using grafana v9.4.1, and not sure if that makes a difference.
This looks like should be working to me. My final json looks essentially the same as yours and it works just find. The problem must be elsewhere?
No idea if it's your case, but for me it was a little tricky to get grafana to use my unsigned plugin instead of the official one
Hey @hoptical , can we expect this feature to get merged soon? I would really need this too!
Hey @hoptical , can we expect this feature to get merged soon? I would really need this too!