Plugins: allow using both Function and Class components for app plugins (#46148)

* fix: make it possible to use both class and functional components for plugins

* fix: accept both class and functional components as plugin root pages

* refactor: import types by name

* refactor: use `ComponentType`
This commit is contained in:
Levente Balogh 2022-03-04 09:52:59 +01:00 committed by GitHub
parent c4404982dc
commit c331af93b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import { ComponentClass } from 'react';
import { ComponentType } from 'react';
import { KeyValue } from './data';
import { NavModel } from './navModel';
import { PluginMeta, GrafanaPlugin, PluginIncludeType } from './plugin';
@ -48,7 +48,7 @@ export interface AppPluginMeta<T = KeyValue> extends PluginMeta<T> {
export class AppPlugin<T = KeyValue> extends GrafanaPlugin<AppPluginMeta<T>> {
// Content under: /a/${plugin-id}/*
root?: ComponentClass<AppRootProps<T>>;
root?: ComponentType<AppRootProps<T>>;
rootNav?: NavModel; // Initial navigation model
/**
@ -66,7 +66,7 @@ export class AppPlugin<T = KeyValue> extends GrafanaPlugin<AppPluginMeta<T>> {
*
* NOTE: this structure will change in 7.2+ so that it is managed with a normal react router
*/
setRootPage(root: ComponentClass<AppRootProps<T>>, rootNav?: NavModel) {
setRootPage(root: ComponentType<AppRootProps<T>>, rootNav?: NavModel) {
this.root = root;
this.rootNav = rootNav;
return this;

View File

@ -1,4 +1,4 @@
import { ComponentClass } from 'react';
import { ComponentType } from 'react';
import { KeyValue } from './data';
/** Describes plugins life cycle status */
@ -159,7 +159,7 @@ export interface PluginConfigPage<T extends PluginMeta> {
icon?: string;
id: string; // Unique, in URL
body: ComponentClass<PluginConfigPageProps<T>>;
body: ComponentType<PluginConfigPageProps<T>>;
}
export class GrafanaPlugin<T extends PluginMeta = PluginMeta> {