From 06b43f6d4b0898d393bb703677331ce36c0475af Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Fri, 19 Jul 2019 07:11:16 -0700 Subject: [PATCH] Plugins: avoid app importDashboards() NPE (#18128) * tables display * add missing file * adding toolbar option * adding toolbar option * add items to index * use root import path * merge master * show tables info * add importDashboards code * remove table changes * remove table changes * use deprecation warning --- docs/sources/plugins/developing/apps.md | 12 ++++-------- packages/grafana-ui/src/utils/deprecationWarning.ts | 7 +++++-- .../features/plugins/wrappers/AppConfigWrapper.tsx | 8 +++++++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/sources/plugins/developing/apps.md b/docs/sources/plugins/developing/apps.md index 155f97461c9..989b7e5c741 100644 --- a/docs/sources/plugins/developing/apps.md +++ b/docs/sources/plugins/developing/apps.md @@ -37,15 +37,11 @@ export class ConfigCtrl { postUpdate() { if (!this.appModel.enabled) { - return this.$q.resolve(); + return; } - return this.appEditCtrl.importDashboards().then(() => { - this.enabled = true; - return { - url: "plugins/raintank-kubernetes-app/page/clusters", - message: "Kubernetes App enabled!" - }; - }); + + // TODO, whatever you want + console.log('Post Update:', this); } } ConfigCtrl.templateUrl = 'components/config/config.html'; diff --git a/packages/grafana-ui/src/utils/deprecationWarning.ts b/packages/grafana-ui/src/utils/deprecationWarning.ts index 88231eaf0c4..8bd15bb5b9e 100644 --- a/packages/grafana-ui/src/utils/deprecationWarning.ts +++ b/packages/grafana-ui/src/utils/deprecationWarning.ts @@ -1,4 +1,7 @@ -export const deprecationWarning = (file: string, oldName: string, newName: string) => { - const message = `[Deprecation warning] ${file}: ${oldName} is deprecated. Use ${newName} instead`; +export const deprecationWarning = (file: string, oldName: string, newName?: string) => { + let message = `[Deprecation warning] ${file}: ${oldName} is deprecated`; + if (newName) { + message += `. Use ${newName} instead`; + } console.warn(message); }; diff --git a/public/app/features/plugins/wrappers/AppConfigWrapper.tsx b/public/app/features/plugins/wrappers/AppConfigWrapper.tsx index bf01f7c10a4..ba5aa1ef5db 100644 --- a/public/app/features/plugins/wrappers/AppConfigWrapper.tsx +++ b/public/app/features/plugins/wrappers/AppConfigWrapper.tsx @@ -3,7 +3,7 @@ import React, { PureComponent } from 'react'; import cloneDeep from 'lodash/cloneDeep'; import extend from 'lodash/extend'; -import { PluginMeta, AppPlugin, Button } from '@grafana/ui'; +import { PluginMeta, AppPlugin, Button, deprecationWarning } from '@grafana/ui'; import { AngularComponent, getAngularLoader } from '@grafana/runtime'; import { getBackendSrv } from 'app/core/services/backend_srv'; @@ -124,6 +124,12 @@ export class AppConfigCtrlWrapper extends PureComponent { this.postUpdateHook = callback; }; + // Stub to avoid unknown function in legacy code + importDashboards = (): Promise => { + deprecationWarning('AppConfig', 'importDashboards()'); + return Promise.resolve(); + }; + enable = () => { this.model.enabled = true; this.model.pinned = true;