From 744682e6480f1cc8756ec0f70d5d70464dce4c53 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Tue, 21 May 2019 01:39:29 -0700 Subject: [PATCH] AppPlugin: add types for jsonData (#17177) * add types for App jsonData * add types for App jsonData * add value as possible type * make it extend {} --- packages/grafana-ui/src/types/app.ts | 16 ++++++++-------- packages/grafana-ui/src/types/plugin.ts | 10 ++++++---- .../plugins/app/example-app/ExampleRootPage.tsx | 5 +++-- public/app/plugins/app/example-app/module.ts | 3 ++- public/app/plugins/app/example-app/types.ts | 4 ++++ 5 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 public/app/plugins/app/example-app/types.ts diff --git a/packages/grafana-ui/src/types/app.ts b/packages/grafana-ui/src/types/app.ts index 16302feefd9..79d6fce5066 100644 --- a/packages/grafana-ui/src/types/app.ts +++ b/packages/grafana-ui/src/types/app.ts @@ -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 { + meta: AppPluginMeta; 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 extends PluginMeta { // TODO anything specific to apps? } -export class AppPlugin extends GrafanaPlugin { +export class AppPlugin extends GrafanaPlugin> { // Content under: /a/${plugin-id}/* - root?: ComponentClass; + root?: ComponentClass>; rootNav?: NavModel; // Initial navigation model // Old style pages @@ -37,7 +37,7 @@ export class AppPlugin extends GrafanaPlugin { * Set the component displayed under: * /a/${plugin-id}/* */ - setRootPage(root: ComponentClass, rootNav?: NavModel) { + setRootPage(root: ComponentClass>, rootNav?: NavModel) { this.root = root; this.rootNav = rootNav; return this; diff --git a/packages/grafana-ui/src/types/plugin.ts b/packages/grafana-ui/src/types/plugin.ts index 72e9d2453fd..a9885e00cf8 100644 --- a/packages/grafana-ui/src/types/plugin.ts +++ b/packages/grafana-ui/src/types/plugin.ts @@ -11,7 +11,9 @@ export enum PluginType { app = 'app', } -export interface PluginMeta { +export type KeyValue = { [s: string]: T }; + +export interface PluginMeta { 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 { plugin: T; - query: { [s: string]: any }; // The URL query parameters + query: KeyValue; // The URL query parameters } export interface PluginConfigPage { diff --git a/public/app/plugins/app/example-app/ExampleRootPage.tsx b/public/app/plugins/app/example-app/ExampleRootPage.tsx index 488d3b511a1..565a9fa37d4 100644 --- a/public/app/plugins/app/example-app/ExampleRootPage.tsx +++ b/public/app/plugins/app/example-app/ExampleRootPage.tsx @@ -10,7 +10,7 @@ const TAB_ID_A = 'A'; const TAB_ID_B = 'B'; const TAB_ID_C = 'C'; -export class ExampleRootPage extends PureComponent { +export class ExampleRootPage extends PureComponent { constructor(props: Props) { super(props); } @@ -79,7 +79,7 @@ export class ExampleRootPage extends PureComponent { } render() { - const { path, query } = this.props; + const { path, query, meta } = this.props; return (
@@ -96,6 +96,7 @@ export class ExampleRootPage extends PureComponent { ZZZ +
{JSON.stringify(meta.jsonData)}
); } diff --git a/public/app/plugins/app/example-app/module.ts b/public/app/plugins/app/example-app/module.ts index f82f7faec08..8b7ea7b42f4 100644 --- a/public/app/plugins/app/example-app/module.ts +++ b/public/app/plugins/app/example-app/module.ts @@ -5,6 +5,7 @@ import { AppPlugin } from '@grafana/ui'; import { ExamplePage1 } from './config/ExamplePage1'; import { ExamplePage2 } from './config/ExamplePage2'; import { ExampleRootPage } from './ExampleRootPage'; +import { ExampleAppSettings } from './types'; // Legacy exports just for testing export { @@ -12,7 +13,7 @@ export { AngularExamplePageCtrl, // Must match `pages.component` in plugin.json }; -export const plugin = new AppPlugin() +export const plugin = new AppPlugin() .setRootPage(ExampleRootPage) .addConfigPage({ title: 'Page 1', diff --git a/public/app/plugins/app/example-app/types.ts b/public/app/plugins/app/example-app/types.ts new file mode 100644 index 00000000000..c3c5bad5e76 --- /dev/null +++ b/public/app/plugins/app/example-app/types.ts @@ -0,0 +1,4 @@ +export interface ExampleAppSettings { + customText?: string; + customCheckbox?: boolean; +}