mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
PluginExtensions: Fixed issue in typings for the onClick link callback (#65978)
* Fixed bug with event being forced. * Made onClick undefinable in the config as well. * Fixed some more type issues.
This commit is contained in:
parent
d974e5f25a
commit
9719ee9bd3
@ -20,7 +20,7 @@ export type PluginExtension = {
|
|||||||
export type PluginExtensionLink = PluginExtension & {
|
export type PluginExtensionLink = PluginExtension & {
|
||||||
type: PluginExtensionTypes.link;
|
type: PluginExtensionTypes.link;
|
||||||
path?: string;
|
path?: string;
|
||||||
onClick?: (event: React.MouseEvent) => void;
|
onClick?: (event?: React.MouseEvent) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Objects used for registering extensions (in app plugins)
|
// Objects used for registering extensions (in app plugins)
|
||||||
@ -45,7 +45,7 @@ export type PluginExtensionLinkConfig<Context extends object = object> = PluginE
|
|||||||
Context,
|
Context,
|
||||||
Pick<PluginExtensionLink, 'path'> & {
|
Pick<PluginExtensionLink, 'path'> & {
|
||||||
type: PluginExtensionTypes.link;
|
type: PluginExtensionTypes.link;
|
||||||
onClick?: (event: React.MouseEvent, helpers: PluginExtensionEventHelpers<Context>) => void;
|
onClick?: (event: React.MouseEvent | undefined, helpers: PluginExtensionEventHelpers<Context>) => void;
|
||||||
}
|
}
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
@ -108,14 +108,14 @@ function getLinkExtensionOverrides(pluginId: string, config: PluginExtensionLink
|
|||||||
function getLinkExtensionOnClick(
|
function getLinkExtensionOnClick(
|
||||||
config: PluginExtensionLinkConfig,
|
config: PluginExtensionLinkConfig,
|
||||||
context?: object
|
context?: object
|
||||||
): ((event: React.MouseEvent) => void) | undefined {
|
): ((event?: React.MouseEvent) => void) | undefined {
|
||||||
const { onClick } = config;
|
const { onClick } = config;
|
||||||
|
|
||||||
if (!onClick) {
|
if (!onClick) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return function onClickExtensionLink(event: React.MouseEvent) {
|
return function onClickExtensionLink(event?: React.MouseEvent) {
|
||||||
try {
|
try {
|
||||||
const result = onClick(event, getEventHelpers(context));
|
const result = onClick(event, getEventHelpers(context));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user