diff --git a/src/legacy/core_plugins/kibana/public/dashboard/legacy.ts b/src/legacy/core_plugins/kibana/public/dashboard/legacy.ts index ca2dc9d5fb4f5..9c13337a71126 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/legacy.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/legacy.ts @@ -18,34 +18,14 @@ */ import { PluginInitializerContext } from 'kibana/public'; -import { npSetup, npStart, legacyChrome } from './legacy_imports'; -import { LegacyAngularInjectedDependencies } from './plugin'; +import { npSetup, npStart } from './legacy_imports'; import { start as data } from '../../../data/public/legacy'; import { start as embeddables } from '../../../embeddable_api/public/np_ready/public/legacy'; -import './dashboard_config'; import { plugin } from './index'; -/** - * Get dependencies relying on the global angular context. - * They also have to get resolved together with the legacy imports above - */ -async function getAngularDependencies(): Promise { - const injector = await legacyChrome.dangerouslyGetActiveInjector(); - - return { - dashboardConfig: injector.get('dashboardConfig'), - }; -} - (async () => { const instance = plugin({} as PluginInitializerContext); - instance.setup(npSetup.core, { - ...npSetup.plugins, - npData: npSetup.plugins.data, - __LEGACY: { - getAngularDependencies, - }, - }); + instance.setup(npSetup.core, npSetup.plugins); instance.start(npStart.core, { ...npStart.plugins, data, diff --git a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/application.ts b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/application.ts index b0e4785edcb0b..3af0b29b80acb 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/application.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/application.ts @@ -54,7 +54,7 @@ export interface RenderDeps { navigation: NavigationStart; savedObjectsClient: SavedObjectsClientContract; savedDashboards: SavedObjectLoader; - dashboardConfig: any; + dashboardConfig: KibanaLegacyStart['dashboardConfig']; dashboardCapabilities: any; uiSettings: IUiSettingsClient; chrome: ChromeStart; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx index 9f6b01d5beb49..c44e36eab8c76 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx @@ -82,13 +82,14 @@ import { removeQueryParam, unhashUrl, } from '../../../../../../plugins/kibana_utils/public'; +import { KibanaLegacyStart } from '../../../../../../plugins/kibana_legacy/public'; export interface DashboardAppControllerDependencies extends RenderDeps { $scope: DashboardAppScope; $route: any; $routeParams: any; indexPatterns: IndexPatternsContract; - dashboardConfig: any; + dashboardConfig: KibanaLegacyStart['dashboardConfig']; confirmModal: ConfirmModalFn; history: History; kbnUrlStateStorage: IKbnUrlStateStorage; diff --git a/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts b/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts index 7ae1c723a3914..09ae49f2305fd 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts +++ b/src/legacy/core_plugins/kibana/public/dashboard/plugin.ts @@ -45,30 +45,25 @@ import { SharePluginStart } from '../../../../../plugins/share/public'; import { AngularRenderedAppUpdater, KibanaLegacySetup, + KibanaLegacyStart, } from '../../../../../plugins/kibana_legacy/public'; import { createSavedDashboardLoader } from './saved_dashboard/saved_dashboards'; import { createKbnUrlTracker } from '../../../../../plugins/kibana_utils/public'; import { getQueryStateContainer } from '../../../../../plugins/data/public'; -export interface LegacyAngularInjectedDependencies { - dashboardConfig: any; -} - export interface DashboardPluginStartDependencies { data: DataStart; npData: NpDataStart; embeddables: IEmbeddableStart; navigation: NavigationStart; share: SharePluginStart; + kibanaLegacy: KibanaLegacyStart; } export interface DashboardPluginSetupDependencies { - __LEGACY: { - getAngularDependencies: () => Promise; - }; home: HomePublicPluginSetup; kibanaLegacy: KibanaLegacySetup; - npData: NpDataSetup; + data: NpDataSetup; } export class DashboardPlugin implements Plugin { @@ -78,6 +73,7 @@ export class DashboardPlugin implements Plugin { embeddables: IEmbeddableStart; navigation: NavigationStart; share: SharePluginStart; + dashboardConfig: KibanaLegacyStart['dashboardConfig']; } | null = null; private appStateUpdater = new BehaviorSubject(() => ({})); @@ -85,12 +81,7 @@ export class DashboardPlugin implements Plugin { public setup( core: CoreSetup, - { - __LEGACY: { getAngularDependencies }, - home, - kibanaLegacy, - npData, - }: DashboardPluginSetupDependencies + { home, kibanaLegacy, data: npData }: DashboardPluginSetupDependencies ) { const { querySyncStateContainer, stop: stopQuerySyncStateContainer } = getQueryStateContainer( npData.query @@ -126,8 +117,8 @@ export class DashboardPlugin implements Plugin { navigation, share, npDataStart, + dashboardConfig, } = this.startDependencies; - const angularDependencies = await getAngularDependencies(); const savedDashboards = createSavedDashboardLoader({ savedObjectsClient, indexPatterns: npDataStart.indexPatterns, @@ -137,7 +128,7 @@ export class DashboardPlugin implements Plugin { const deps: RenderDeps = { core: contextCore as LegacyCoreStart, - ...angularDependencies, + dashboardConfig, navigation, share, npDataStart, @@ -186,7 +177,14 @@ export class DashboardPlugin implements Plugin { start( { savedObjects: { client: savedObjectsClient } }: CoreStart, - { data: dataStart, embeddables, navigation, npData, share }: DashboardPluginStartDependencies + { + data: dataStart, + embeddables, + navigation, + npData, + share, + kibanaLegacy: { dashboardConfig }, + }: DashboardPluginStartDependencies ) { this.startDependencies = { npDataStart: npData, @@ -194,6 +192,7 @@ export class DashboardPlugin implements Plugin { embeddables, navigation, share, + dashboardConfig, }; } diff --git a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js index 3cc33504d3daa..985dbc78e2f77 100644 --- a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js +++ b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js @@ -212,6 +212,10 @@ export const npStart = { config: { defaultAppId: 'home', }, + dashboardConfig: { + turnHideWriteControlsOn: sinon.fake(), + getHideWriteControls: sinon.fake(), + }, }, data: { autocomplete: { diff --git a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_config.js b/src/plugins/kibana_legacy/public/dashboard_config.ts similarity index 69% rename from src/legacy/core_plugins/kibana/public/dashboard/dashboard_config.js rename to src/plugins/kibana_legacy/public/dashboard_config.ts index aa8333a1bafca..3c7670682ce25 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/dashboard_config.js +++ b/src/plugins/kibana_legacy/public/dashboard_config.ts @@ -17,11 +17,13 @@ * under the License. */ -import { uiModules } from 'ui/modules'; -import { capabilities } from 'ui/capabilities'; +export interface DashboardConfig { + turnHideWriteControlsOn(): void; + getHideWriteControls(): boolean; +} -export function dashboardConfigProvider() { - let hideWriteControls = !capabilities.get().dashboard.showWriteControls; +export function getDashboardConfig(hideWriteControls: boolean): DashboardConfig { + let _hideWriteControls = hideWriteControls; return { /** @@ -29,16 +31,10 @@ export function dashboardConfigProvider() { * @type {boolean} */ turnHideWriteControlsOn() { - hideWriteControls = true; + _hideWriteControls = true; }, - $get() { - return { - getHideWriteControls() { - return hideWriteControls; - }, - }; + getHideWriteControls() { + return _hideWriteControls; }, }; } - -uiModules.get('kibana').provider('dashboardConfig', dashboardConfigProvider); diff --git a/src/plugins/kibana_legacy/public/mocks.ts b/src/plugins/kibana_legacy/public/mocks.ts index b6287dd9d9a55..aab3ab315f0c6 100644 --- a/src/plugins/kibana_legacy/public/mocks.ts +++ b/src/plugins/kibana_legacy/public/mocks.ts @@ -36,6 +36,10 @@ const createStartContract = (): Start => ({ config: { defaultAppId: 'home', }, + dashboardConfig: { + turnHideWriteControlsOn: jest.fn(), + getHideWriteControls: jest.fn(), + }, }); export const kibanaLegacyPluginMock = { diff --git a/src/plugins/kibana_legacy/public/plugin.ts b/src/plugins/kibana_legacy/public/plugin.ts index 7c4b3428cbb6d..86e56c44646c0 100644 --- a/src/plugins/kibana_legacy/public/plugin.ts +++ b/src/plugins/kibana_legacy/public/plugin.ts @@ -17,9 +17,16 @@ * under the License. */ -import { App, AppBase, PluginInitializerContext, AppUpdatableFields } from 'kibana/public'; +import { + App, + AppBase, + PluginInitializerContext, + AppUpdatableFields, + CoreStart, +} from 'kibana/public'; import { Observable } from 'rxjs'; import { ConfigSchema } from '../config'; +import { getDashboardConfig } from './dashboard_config'; interface ForwardDefinition { legacyAppId: string; @@ -104,7 +111,7 @@ export class KibanaLegacyPlugin { }; } - public start() { + public start({ application }: CoreStart) { return { /** * @deprecated @@ -117,6 +124,7 @@ export class KibanaLegacyPlugin { */ getForwards: () => this.forwards, config: this.initializerContext.config.get(), + dashboardConfig: getDashboardConfig(!application.capabilities.dashboard.showWriteControls), }; } } diff --git a/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js b/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js index 44c4b81c8ad93..8ca023aa90cf1 100644 --- a/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js +++ b/x-pack/legacy/plugins/dashboard_mode/public/dashboard_viewer.js @@ -40,9 +40,7 @@ import { localApplicationService } from 'plugins/kibana/local_application_servic import { showAppRedirectNotification } from 'ui/notify'; import { DashboardConstants, createDashboardEditUrl } from 'plugins/kibana/dashboard'; -uiModules - .get('kibana') - .config(dashboardConfigProvider => dashboardConfigProvider.turnHideWriteControlsOn()); +npStart.plugins.kibanaLegacy.dashboardConfig.turnHideWriteControlsOn(); localApplicationService.attachToAngular(routes); diff --git a/x-pack/legacy/plugins/reporting/public/share_context_menu/register_reporting.tsx b/x-pack/legacy/plugins/reporting/public/share_context_menu/register_reporting.tsx index 8e0da6a69225e..4153c7cdbdb0b 100644 --- a/x-pack/legacy/plugins/reporting/public/share_context_menu/register_reporting.tsx +++ b/x-pack/legacy/plugins/reporting/public/share_context_menu/register_reporting.tsx @@ -8,16 +8,14 @@ import { i18n } from '@kbn/i18n'; import moment from 'moment-timezone'; // @ts-ignore: implicit any for JS file import { xpackInfo } from 'plugins/xpack_main/services/xpack_info'; -import { npSetup } from 'ui/new_platform'; +import { npSetup, npStart } from 'ui/new_platform'; import React from 'react'; -import chrome from 'ui/chrome'; import { ScreenCapturePanelContent } from '../components/screen_capture_panel_content'; import { ShareContext } from '../../../../../../src/plugins/share/public'; const { core } = npSetup; async function reportingProvider() { - const injector = await chrome.dangerouslyGetActiveInjector(); const getShareMenuItems = ({ objectType, objectId, @@ -31,7 +29,10 @@ async function reportingProvider() { } // Dashboard only mode does not currently support reporting // https://github.com/elastic/kibana/issues/18286 - if (objectType === 'dashboard' && injector.get('dashboardConfig').getHideWriteControls()) { + if ( + objectType === 'dashboard' && + npStart.plugins.kibanaLegacy.dashboardConfig.getHideWriteControls() + ) { return []; }