AppPlugin: add types for jsonData (#17177)

* add types for App jsonData

* add types for App jsonData

* add value as possible type

* make it extend {}
This commit is contained in:
Ryan McKinley
2019-05-21 01:39:29 -07:00
committed by Torkel Ödegaard
parent f98095d629
commit 744682e648
5 changed files with 23 additions and 15 deletions

View File

@@ -1,12 +1,12 @@
import { ComponentClass } from 'react';
import { NavModel } from './navModel';
import { PluginMeta, PluginIncludeType, GrafanaPlugin } from './plugin';
import { PluginMeta, PluginIncludeType, GrafanaPlugin, KeyValue } from './plugin';
export interface AppRootProps {
meta: AppPluginMeta;
export interface AppRootProps<T = KeyValue> {
meta: AppPluginMeta<T>;
path: string; // The URL path to this page
query: { [s: string]: any }; // The URL query parameters
query: KeyValue; // The URL query parameters
/**
* Pass the nav model to the container... is there a better way?
@@ -14,13 +14,13 @@ export interface AppRootProps {
onNavChanged: (nav: NavModel) => void;
}
export interface AppPluginMeta extends PluginMeta {
export interface AppPluginMeta<T = KeyValue> extends PluginMeta<T> {
// TODO anything specific to apps?
}
export class AppPlugin extends GrafanaPlugin<AppPluginMeta> {
export class AppPlugin<T = KeyValue> extends GrafanaPlugin<AppPluginMeta<T>> {
// Content under: /a/${plugin-id}/*
root?: ComponentClass<AppRootProps>;
root?: ComponentClass<AppRootProps<T>>;
rootNav?: NavModel; // Initial navigation model
// Old style pages
@@ -37,7 +37,7 @@ export class AppPlugin extends GrafanaPlugin<AppPluginMeta> {
* Set the component displayed under:
* /a/${plugin-id}/*
*/
setRootPage(root: ComponentClass<AppRootProps>, rootNav?: NavModel) {
setRootPage(root: ComponentClass<AppRootProps<T>>, rootNav?: NavModel) {
this.root = root;
this.rootNav = rootNav;
return this;

View File

@@ -11,7 +11,9 @@ export enum PluginType {
app = 'app',
}
export interface PluginMeta {
export type KeyValue<T = any> = { [s: string]: T };
export interface PluginMeta<T extends {} = KeyValue> {
id: string;
name: string;
type: PluginType;
@@ -27,8 +29,8 @@ export interface PluginMeta {
dependencies?: PluginDependencies;
// Filled in by the backend
jsonData?: { [str: string]: any };
secureJsonData?: { [str: string]: any };
jsonData?: T;
secureJsonData?: KeyValue;
enabled?: boolean;
defaultNavUrl?: string;
hasUpdate?: boolean;
@@ -93,7 +95,7 @@ export interface PluginMetaInfo {
export interface PluginConfigPageProps<T extends GrafanaPlugin> {
plugin: T;
query: { [s: string]: any }; // The URL query parameters
query: KeyValue; // The URL query parameters
}
export interface PluginConfigPage<T extends GrafanaPlugin> {