Skip to content

Commit

Permalink
Merge branch 'master' into cypress-cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Feb 10, 2020
2 parents ef117c8 + 181a3a0 commit 46777c0
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 63 deletions.
24 changes: 2 additions & 22 deletions src/legacy/core_plugins/kibana/public/dashboard/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<LegacyAngularInjectedDependencies> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface RenderDeps {
navigation: NavigationStart;
savedObjectsClient: SavedObjectsClientContract;
savedDashboards: SavedObjectLoader;
dashboardConfig: any;
dashboardConfig: KibanaLegacyStart['dashboardConfig'];
dashboardCapabilities: any;
uiSettings: IUiSettingsClient;
chrome: ChromeStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 16 additions & 17 deletions src/legacy/core_plugins/kibana/public/dashboard/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<LegacyAngularInjectedDependencies>;
};
home: HomePublicPluginSetup;
kibanaLegacy: KibanaLegacySetup;
npData: NpDataSetup;
data: NpDataSetup;
}

export class DashboardPlugin implements Plugin {
Expand All @@ -78,19 +73,15 @@ export class DashboardPlugin implements Plugin {
embeddables: IEmbeddableStart;
navigation: NavigationStart;
share: SharePluginStart;
dashboardConfig: KibanaLegacyStart['dashboardConfig'];
} | null = null;

private appStateUpdater = new BehaviorSubject<AngularRenderedAppUpdater>(() => ({}));
private stopUrlTracking: (() => void) | undefined = undefined;

public setup(
core: CoreSetup,
{
__LEGACY: { getAngularDependencies },
home,
kibanaLegacy,
npData,
}: DashboardPluginSetupDependencies
{ home, kibanaLegacy, data: npData }: DashboardPluginSetupDependencies
) {
const { querySyncStateContainer, stop: stopQuerySyncStateContainer } = getQueryStateContainer(
npData.query
Expand Down Expand Up @@ -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,
Expand All @@ -137,7 +128,7 @@ export class DashboardPlugin implements Plugin {

const deps: RenderDeps = {
core: contextCore as LegacyCoreStart,
...angularDependencies,
dashboardConfig,
navigation,
share,
npDataStart,
Expand Down Expand Up @@ -186,14 +177,22 @@ 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,
savedObjectsClient,
embeddables,
navigation,
share,
dashboardConfig,
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ export const npStart = {
config: {
defaultAppId: 'home',
},
dashboardConfig: {
turnHideWriteControlsOn: sinon.fake(),
getHideWriteControls: sinon.fake(),
},
},
data: {
autocomplete: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,24 @@
* 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 {
/**
* Part of the exposed plugin API - do not remove without careful consideration.
* @type {boolean}
*/
turnHideWriteControlsOn() {
hideWriteControls = true;
_hideWriteControls = true;
},
$get() {
return {
getHideWriteControls() {
return hideWriteControls;
},
};
getHideWriteControls() {
return _hideWriteControls;
},
};
}

uiModules.get('kibana').provider('dashboardConfig', dashboardConfigProvider);
4 changes: 4 additions & 0 deletions src/plugins/kibana_legacy/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const createStartContract = (): Start => ({
config: {
defaultAppId: 'home',
},
dashboardConfig: {
turnHideWriteControlsOn: jest.fn(),
getHideWriteControls: jest.fn(),
},
});

export const kibanaLegacyPluginMock = {
Expand Down
12 changes: 10 additions & 2 deletions src/plugins/kibana_legacy/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -104,7 +111,7 @@ export class KibanaLegacyPlugin {
};
}

public start() {
public start({ application }: CoreStart) {
return {
/**
* @deprecated
Expand All @@ -117,6 +124,7 @@ export class KibanaLegacyPlugin {
*/
getForwards: () => this.forwards,
config: this.initializerContext.config.get(),
dashboardConfig: getDashboardConfig(!application.capabilities.dashboard.showWriteControls),
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<any>('dashboardConfig').getHideWriteControls()) {
if (
objectType === 'dashboard' &&
npStart.plugins.kibanaLegacy.dashboardConfig.getHideWriteControls()
) {
return [];
}

Expand Down

0 comments on commit 46777c0

Please sign in to comment.