nodegraph-api-plugin icon indicating copy to clipboard operation
nodegraph-api-plugin copied to clipboard

Added support to links on fields

Open perotta opened this issue 2 years ago • 8 comments

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: image

perotta avatar Dec 02 '22 13:12 perotta

@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.

hoptical avatar Feb 10 '23 17:02 hoptical

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): image_2023-02-10_11-12-18

This PR solves issue #17

perotta avatar Feb 10 '23 18:02 perotta

@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.

zosocanuck avatar Mar 01 '23 18:03 zosocanuck

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.

perotta avatar Mar 01 '23 20:03 perotta

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.

zosocanuck avatar Mar 01 '23 21:03 zosocanuck

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

perotta avatar Mar 01 '23 21:03 perotta

Hey @hoptical , can we expect this feature to get merged soon? I would really need this too!

JulianJesacher avatar Jul 25 '23 09:07 JulianJesacher

Hey @hoptical , can we expect this feature to get merged soon? I would really need this too!

Chaos2Byte avatar Mar 25 '24 14:03 Chaos2Byte