-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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: Add a new UI Extension type #68600
Conversation
Levitate breaking changes |
packages/grafana-runtime/src/services/pluginExtensions/getPluginExtensions.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it looks good! Great work on this! Adding a couple of questions.
[0, 0, 0, "Do not use any type assertions.", "1"], | ||
[0, 0, 0, "Do not use any type assertions.", "2"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably fix these by doing a type assertion when adding the configuration. But lets do that in a follow up PR.
export type PluginExtensionLinkConfig<Context extends object = object> = PluginExtensionBaseConfig< | ||
Context, | ||
Pick<PluginExtensionLink, 'path'> & { | ||
type: PluginExtensionTypes.link; | ||
onClick?: (event: React.MouseEvent | undefined, helpers: PluginExtensionEventHelpers<Context>) => void; | ||
} | ||
>; | ||
|
||
export type PluginExtensionComponentConfig<Context extends object = object> = PluginExtensionBaseConfig< | ||
Context, | ||
Pick<PluginExtensionComponent, 'component'> & { | ||
type: PluginExtensionTypes.component; | ||
} | ||
>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be worth doing some repetition instead of creating the types out of other types with Pick
. But also something we can do in a follow up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's a good point, like this it's becoming quite cryptic 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tidied them up in this commit, ket me know what you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spot on! Great work on this.
packages/grafana-runtime/src/services/pluginExtensions/getPluginExtensions.ts
Show resolved
Hide resolved
1b019bf
to
2fa000e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
By using some repetition now these types are much easier to oversee.
e6a4bec
to
b90d830
Compare
What changed?
This PR adds a new type of UI extension that can be used to register React components.
Using these extensions plugins will be able to extend new parts of the Grafana UI.
Why
components
vselements
?Although we also experimented with using React elements, we have chosen to use components in the end. With elements we needed to pass down the context object through the
configure()
function, and this needed more boilerplate. On the other hand using components we can just pass the whole context object as a component prop, which makes the call-site (the plugin registering the extension) much simpler. This also eliminated the need of theconfigure()
function entirely.Where can it be used?
This PR only adds the ability to register component-type extensions, but doesn't create a new extension point that handles them. This PR (based on this one) on the other hand adds a new extension point to the datasources config page.
How to register a component extension?
You will be able to do the following in your app plugin: