Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query/mutation hooks that plugin can use to query/mutate Grafana redux store #84494

Open
jarben opened this issue Mar 14, 2024 · 2 comments

Comments

@jarben
Copy link
Contributor

jarben commented Mar 14, 2024

Why is this needed:

Plugin developers often load data such as data sources, dashboards, etc. This is currently achieved by using Grafana API. The issue is that mutations from plugins or Grafana do not automatically synchronize cached data. We would like to have access to the cached data, including performing mutations such as:

  • starring a dashboard
  • changing data source configuration
  • ...

What would you like to be added:
We would like a query/mutation hooks package that would work similarly to popular data-fetching libraries such as RTKQ, React Query, SWR, etc.

See this documentation for the full RTKQ query hook signature.

Note that we don't necessarily need full RTKQ implementation; a bare minimum would be:
options:

  • skip: boolean (for conditional fetching)

result:

  • data (data on success)
  • error (error on error)
  • isLoading (true when data is being fetched)

See this documentation for the full RTKQ mutation hook signature

A bare minimum would be:
options:

  • fixedCacheKey (enable shared results across hook instances)
  • trigger: (function that triggers the mutation)

result:

  • data
  • error
  • isLoading

Note that we already use a generated client for the grafana API; this can be used by plugins right now. However, the cache is not updated when a mutation occurs in Grafana as it doesn't use this package.

Who is this feature for?

Plugin developers

cc @leventebalogh

@leventebalogh
Copy link
Contributor

Thanks for raising this @jarben 🙏

I will bring it to our @grafana/plugins-platform weekly discussion today and get back soon.

@sympatheticmoose for visibility.

@mikkancso
Copy link
Contributor

mikkancso commented Mar 20, 2024

Thanks for creating this @jarben!
One particular issue that we often face is that we sometimes update/delete some dashboards from the Connections plugin, and show a LinkButton to users which redirects them to their dashboards, and when they go there they don't see the latest state of dashboards if they have visited the dashboards page before, because the it is cached in Grafana. It would be nice if we could invalidate this cache from the plugin. See also #77959

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants