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

Plugins: Share the plugin context with apps and ui-extensions #77933

Merged
merged 5 commits into from
Nov 14, 2023

Conversation

leventebalogh
Copy link
Contributor

@leventebalogh leventebalogh commented Nov 9, 2023

What changed?

This PR is basically sharing the PluginContext with app plugins and UI-extension modal components, so they can get hold of the plugin meta information in the following way:

import { usePluginContext } from '@grafana/data';

// This can either be a component inside of an app plugin, or the component being used 
// for rendering the modal. 
const MyComponent = () => {
    const { meta } = usePluginContext();

    return (<div>{ meta.info.version }</div>);
}

Also introduced new hooks:

import { usePluginMeta, usePluginJsonData, usePluginVersion } from '@grafana/data';

// Anywhere in your app plugin
const meta = usePluginMeta();
const jsonData = usePluginJsonData();
const pluginVersion = usePluginVersion();

Notes for the reviewer

  • Pre-fetching: we are now pre-fetching the meta information from the API for each pre-loaded app plugin. We are not "awaiting" these, so we don't block the booting process of the Grafana app. The same meta information for panel plugins is already present in the GrafanaBootConfig, so that would be the other option, to have app plugin meta on the config instead.

Copy link
Contributor

@mckn mckn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!

Copy link
Contributor

@jackw jackw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely stuff! 🚀

Copy link
Contributor

@sunker sunker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neat! Didn't know we had a usePluginContext hook. I wonder if plugin authors in general are aware of this?

@mckn
Copy link
Contributor

mckn commented Nov 10, 2023

This is neat! Didn't know we had a usePluginContext hook. I wonder if plugin authors in general are aware of this?

Probably not, something we added a while back but without any proper documentation. It is being used under the hood by the tracking hook. We should probably improve the docs around this.

@mckn
Copy link
Contributor

mckn commented Nov 10, 2023

@leventebalogh we should probably also add a wrapper around the components being shared via pluginExtensionCoponents so these hooks can be used there as well. But lets do that in a follow up PR.

@leventebalogh leventebalogh force-pushed the leventebalogh/expose-plugin-context-for-apps branch 2 times, most recently from 75d6a9c to b310e22 Compare November 13, 2023 13:25
@leventebalogh leventebalogh force-pushed the leventebalogh/expose-plugin-context-for-apps branch from b310e22 to 9e7c5a4 Compare November 14, 2023 07:17
@leventebalogh leventebalogh merged commit ea2b493 into main Nov 14, 2023
19 checks passed
@leventebalogh leventebalogh deleted the leventebalogh/expose-plugin-context-for-apps branch November 14, 2023 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants