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

add support for links

Open ItsVeryWindy opened this issue 3 years ago • 4 comments

Is your feature request related to a problem? Please describe. I was trying to figure out why the context menu wasn't being displayed, then I came across this issue https://github.com/hoptical/nodegraph-api-plugin/issues/17. Doing some more digging I then came across this other issue https://github.com/grafana/grafana/issues/33358. So I thought great, I'd probably want to return some links anyway, lets see if I add some links if it fixes it. But from what I can see links don't appear to be supported by this plugin.

Describe the solution you'd like I'm not too particular on the implementation, but it will most likely have to be part of the payload returned by the endpoint. At least for my purposes, I'm only interested in being able to add "external" links.

Additional context These can be seen and mentioned on the page for the visualisation https://grafana.com/docs/grafana/latest/visualizations/node-graph/, but I didn't have much luck finding documentation on implementing them.

This I believe describes the interface for links. The more interesting properties are url, title, targetBlank, which are hopefully self explanatory. https://grafana.com/docs/grafana/latest/packages_api/data/datalink/#datalink-interface

Links can be added as an array as part of the config, around this part of the code. https://github.com/hoptical/nodegraph-api-plugin/blob/eaf0cc88c375024c67912afa5b6986db2d301c2d/src/datasource.ts#L58 eg.

outputField.config.links = [{
url: 'http://example.com',
title: 'Example'
}];

I did play around with it a bit hard coding stuff in there, and I was able to get the context menu and links to display.

ItsVeryWindy avatar Sep 15 '22 00:09 ItsVeryWindy

I'm after the same challenge, but targeting internal links to other datasources. Thanks for opening this issue! @ItsVeryWindy could you check if the proposed PR #21 might work for your use case?

lmangani avatar Sep 24 '22 23:09 lmangani

Almost I think 👍, not sure about only one link per field. I also wanted to have different links per data entry or some way to template the links based on the data contained, maybe that does that. Unfortunately I run into issues when trying to build the plugin because I'm stuck on an M1 mac which makes it difficult for me to test these things.

ItsVeryWindy avatar Sep 26 '22 15:09 ItsVeryWindy

Good point... perhaps we might iterate like the details do - ie: link__name__property EDIT: PR updated with brutal multi link support. I have no idea if there's a better/cleaner way to get this done, ts is not my forte. Variables in urls and expressions should work fine, too

"link_prom_expr": "rate(traces_service_graph_request_total{server="${__data.fields.id}"}[$__interval])",

lmangani avatar Sep 26 '22 15:09 lmangani

I created a more generic solution if you are interested on it PR #23

perotta avatar Dec 02 '22 13:12 perotta