Skip to content

Commit

Permalink
Enforce shimmed plugin boundaries (elastic#52633)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Dec 20, 2019
1 parent 0a57403 commit 13a3b75
Show file tree
Hide file tree
Showing 360 changed files with 673 additions and 384 deletions.
3 changes: 0 additions & 3 deletions src/legacy/core_plugins/kibana/public/.eslintrc

This file was deleted.

72 changes: 72 additions & 0 deletions src/legacy/core_plugins/kibana/public/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

const path = require('path');

/**
* Builds custom restricted paths configuration for the shimmed plugins within the kibana plugin.
* These custom rules extend the default checks in the top level `eslintrc.js` by also checking two other things:
* * Making sure nothing within np_ready imports from the `ui` directory
* * Making sure no other code is importing things deep from within the shimmed plugins
* @param shimmedPlugins List of plugin names within the kibana plugin that are partially np ready
* @returns zones configuration for the no-restricted-paths linter
*/
function buildRestrictedPaths(shimmedPlugins) {
return shimmedPlugins.map(shimmedPlugin => ([{
target: [
`src/legacy/core_plugins/kibana/public/${shimmedPlugin}/np_ready/**/*`,
],
from: [
'ui/**/*',
'src/legacy/ui/**/*',
'src/legacy/core_plugins/kibana/public/**/*',
'src/legacy/core_plugins/data/public/**/*',
'!src/legacy/core_plugins/data/public/index.ts',
`!src/legacy/core_plugins/kibana/public/${shimmedPlugin}/**/*`,
],
allowSameFolder: false,
errorMessage: `${shimmedPlugin} is a shimmed plugin that is not allowed to import modules from the legacy platform. If you need legacy modules for the transition period, import them either in the legacy_imports, kibana_services or index module.`,
}, {
target: [
'src/**/*',
`!src/legacy/core_plugins/kibana/public/${shimmedPlugin}/**/*`,
'x-pack/**/*',
],
from: [
`src/legacy/core_plugins/kibana/public/${shimmedPlugin}/**/*`,
`!src/legacy/core_plugins/kibana/public/${shimmedPlugin}/index.ts`,
],
allowSameFolder: false,
errorMessage: `kibana/public/${shimmedPlugin} is behaving like a NP plugin and does not allow deep imports. If you need something from within ${shimmedPlugin} in another plugin, consider re-exporting it from the top level index module`,
}])).reduce((acc, part) => [...acc, ...part], []);
}

module.exports = {
rules: {
'no-console': 2,
'import/no-default-export': 'error',
'@kbn/eslint/no-restricted-paths': [
'error',
{
basePath: path.resolve(__dirname, '../../../../../'),
zones: buildRestrictedPaths(['visualize', 'discover', 'dashboard', 'devTools', 'home']),
},
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
*/
import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { DashboardEmptyScreen, DashboardEmptyScreenProps } from '../dashboard_empty_screen';
import {
DashboardEmptyScreen,
DashboardEmptyScreenProps,
} from '../np_ready/dashboard_empty_screen';
// @ts-ignore
import { findTestSubject } from '@elastic/eui/lib/test';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { searchSourceMock } from '../../../../../ui/public/courier/search_source/mocks';
import { searchSourceMock } from 'ui/courier/search_source/mocks';
import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard';

export function getSavedDashboardMock(
Expand Down
2 changes: 2 additions & 0 deletions src/legacy/core_plugins/kibana/public/dashboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { start as embeddables } from '../../../embeddable_api/public/np_ready/pu
import './saved_dashboard/saved_dashboards';
import './dashboard_config';

export * from './np_ready/dashboard_constants';

/**
* Get dependencies relying on the global angular context.
* They also have to get resolved together with the legacy imports above
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ export { createTopNavDirective, createTopNavHelper } from 'ui/kbn_top_nav/kbn_to
// @ts-ignore
export { PromiseServiceCreator } from 'ui/promises/promises';
// @ts-ignore
export { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url';
export { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url/index';
// @ts-ignore
export { confirmModalFactory } from 'ui/modals/confirm_modal';
export { configureAppAngularModule } from 'ui/legacy_compat';
export { stateMonitorFactory, StateMonitor } from 'ui/state_management/state_monitor_factory';
export { ensureDefaultIndexPattern } from 'ui/legacy_compat';
export { unhashUrl } from '../../../../../plugins/kibana_utils/public';
export { IInjector } from 'ui/chrome';
export { VISUALIZE_EMBEDDABLE_TYPE } from '../visualize_embeddable';
export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router';
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jest.mock(
jest.mock('ui/new_platform');

import { migratePanelsTo730 } from './migrate_to_730_panels';
import { SavedDashboardPanelTo60, SavedDashboardPanel730ToLatest } from '../types';
import { SavedDashboardPanelTo60, SavedDashboardPanel730ToLatest } from '../np_ready/types';
import {
RawSavedDashboardPanelTo60,
RawSavedDashboardPanel610,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
SavedDashboardPanel620,
SavedDashboardPanel630,
SavedDashboardPanel610,
} from '../types';
} from '../np_ready/types';

const PANEL_HEIGHT_SCALE_FACTOR = 5;
const PANEL_HEIGHT_SCALE_FACTOR_WITH_MARGINS = 4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { GridData } from '../types';
import { GridData } from '../np_ready/types';
import { Doc, DocPre700 } from '../../../migrations/types';

export interface SavedObjectAttributes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import { EuiConfirmModal, EuiIcon } from '@elastic/eui';
import angular, { IModule } from 'angular';
import { IPrivate } from 'ui/private';
import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular';
import {
AppMountContext,
Expand All @@ -28,7 +27,7 @@ import {
SavedObjectsClientContract,
IUiSettingsClient,
} from 'kibana/public';
import { Storage } from '../../../../../plugins/kibana_utils/public';
import { Storage } from '../../../../../../plugins/kibana_utils/public';
import {
GlobalStateProvider,
StateManagementConfigProvider,
Expand All @@ -43,14 +42,15 @@ import {
RedirectWhenMissingProvider,
confirmModalFactory,
configureAppAngularModule,
} from './legacy_imports';
IPrivate,
} from '../legacy_imports';

// @ts-ignore
import { initDashboardApp } from './legacy_app';
import { IEmbeddableStart } from '../../../../../plugins/embeddable/public';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public';
import { DataPublicPluginStart as NpDataStart } from '../../../../../plugins/data/public';
import { SharePluginStart } from '../../../../../plugins/share/public';
import { IEmbeddableStart } from '../../../../../../plugins/embeddable/public';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../../plugins/navigation/public';
import { DataPublicPluginStart as NpDataStart } from '../../../../../../plugins/data/public';
import { SharePluginStart } from '../../../../../../plugins/share/public';

export interface RenderDeps {
core: LegacyCoreStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ import {
AppState as TAppState,
IInjector,
KbnUrl,
} from './legacy_imports';
} from '../legacy_imports';

import { ViewMode } from '../../../embeddable_api/public/np_ready/public';
import { SavedObjectDashboard } from './saved_dashboard/saved_dashboard';
import { ViewMode } from '../../../../embeddable_api/public/np_ready/public';
import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard';
import { DashboardAppState, SavedDashboardPanel, ConfirmModalFn } from './types';
import {
IIndexPattern,
TimeRange,
Query,
esFilters,
SavedQuery,
} from '../../../../../../src/plugins/data/public';
} from '../../../../../../plugins/data/public';

import { DashboardAppController } from './dashboard_app_controller';
import { RenderDeps } from './application';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,25 @@ import {
KbnUrl,
SavedObjectSaveOpts,
unhashUrl,
} from './legacy_imports';
import { FilterStateManager, IndexPattern } from '../../../data/public';
import { Query, SavedQuery, IndexPatternsContract } from '../../../../../plugins/data/public';
VISUALIZE_EMBEDDABLE_TYPE,
} from '../legacy_imports';
import { FilterStateManager, IndexPattern } from '../../../../data/public';
import { Query, SavedQuery, IndexPatternsContract } from '../../../../../../plugins/data/public';

import {
DashboardContainer,
DASHBOARD_CONTAINER_TYPE,
DashboardContainerFactory,
DashboardContainerInput,
DashboardPanelState,
} from '../../../dashboard_embeddable_container/public/np_ready/public';
} from '../../../../dashboard_embeddable_container/public/np_ready/public';
import {
isErrorEmbeddable,
ErrorEmbeddable,
ViewMode,
openAddPanelFlyout,
EmbeddableFactoryNotFoundError,
} from '../../../embeddable_api/public/np_ready/public';
} from '../../../../embeddable_api/public/np_ready/public';
import { DashboardAppState, NavAction, ConfirmModalFn, SavedDashboardPanel } from './types';

import { showOptionsPopover } from './top_nav/show_options_popover';
Expand All @@ -67,13 +68,12 @@ import { getTopNavConfig } from './top_nav/get_top_nav_config';
import { TopNavIds } from './top_nav/top_nav_ids';
import { getDashboardTitle } from './dashboard_strings';
import { DashboardAppScope } from './dashboard_app';
import { VISUALIZE_EMBEDDABLE_TYPE } from '../visualize/embeddable';
import { convertSavedDashboardPanelToPanelState } from './lib/embeddable_saved_object_converters';
import { RenderDeps } from './application';
import {
SavedObjectFinderProps,
SavedObjectFinderUi,
} from '../../../../../plugins/kibana_react/public';
} from '../../../../../../plugins/kibana_react/public';

export interface DashboardAppControllerDependencies extends RenderDeps {
$scope: DashboardAppScope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import './np_core.test.mocks';
import { DashboardStateManager } from './dashboard_state_manager';
import { getAppStateMock, getSavedDashboardMock } from './__tests__';
import { AppStateClass } from './legacy_imports';
import { getAppStateMock, getSavedDashboardMock } from '../__tests__';
import { AppStateClass } from '../legacy_imports';
import { DashboardAppState } from './types';
import { TimeRange, TimefilterContract, InputTimeRange } from 'src/plugins/data/public';
import { ViewMode } from 'src/plugins/embeddable/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ import _ from 'lodash';
import { Moment } from 'moment';

import { DashboardContainer } from 'src/legacy/core_plugins/dashboard_embeddable_container/public/np_ready/public';
import { ViewMode } from '../../../../../../src/plugins/embeddable/public';
import { ViewMode } from '../../../../../../plugins/embeddable/public';
import {
stateMonitorFactory,
StateMonitor,
AppStateClass as TAppStateClass,
migrateLegacyQuery,
} from './legacy_imports';
} from '../legacy_imports';
import {
Query,
esFilters,
TimefilterContract as Timefilter,
} from '../../../../../../src/plugins/data/public';
} from '../../../../../../plugins/data/public';

import { getAppStateDefaults, migrateAppState } from './lib';
import { convertPanelStateToSavedDashboardPanel } from './lib/embeddable_saved_object_converters';
import { FilterUtils } from './lib/filter_utils';
import { SavedObjectDashboard } from './saved_dashboard/saved_dashboard';
import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard';

import { SavedDashboardPanel, DashboardAppState, DashboardAppStateDefaults } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { i18n } from '@kbn/i18n';
import { ViewMode } from '../../../../../../src/plugins/embeddable/public';
import { ViewMode } from '../../../../../../plugins/embeddable/public';

/**
* @param title {string} the current title of the dashboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

import { State } from './legacy_imports';
import { DataPublicPluginStart as NpDataStart } from '../../../../../plugins/data/public';
import { State } from '../legacy_imports';
import { DataPublicPluginStart as NpDataStart } from '../../../../../../plugins/data/public';

/**
* Helper function to sync the global state with the various state providers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
*/

import { i18n } from '@kbn/i18n';
import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links';
import { CoreStart } from 'kibana/public';

export function addHelpMenuToAppChrome(chrome) {
export function addHelpMenuToAppChrome(
chrome: CoreStart['chrome'],
docLinks: CoreStart['docLinks']
) {
chrome.setHelpExtension({
appName: i18n.translate('kbn.dashboard.helpMenu.appName', {
defaultMessage: 'Dashboards',
}),
links: [
{
linkType: 'documentation',
href: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/dashboard.html`,
href: `${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/dashboard.html`,
},
],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,35 @@ import { i18n } from '@kbn/i18n';
import dashboardTemplate from './dashboard_app.html';
import dashboardListingTemplate from './listing/dashboard_listing_ng_wrapper.html';

import { ensureDefaultIndexPattern } from './legacy_imports';
import {
ensureDefaultIndexPattern,
registerTimefilterWithGlobalStateFactory,
} from '../legacy_imports';
import { initDashboardAppDirective } from './dashboard_app';
import { DashboardConstants, createDashboardEditUrl } from './dashboard_constants';
import {
InvalidJSONProperty,
SavedObjectNotFound,
} from '../../../../../plugins/kibana_utils/public';
} from '../../../../../../plugins/kibana_utils/public';
import { DashboardListing, EMPTY_FILTER } from './listing/dashboard_listing';
import { addHelpMenuToAppChrome } from './help_menu/help_menu_util';
import { registerTimefilterWithGlobalStateFactory } from '../../../../ui/public/timefilter/setup_router';
import { syncOnMount } from './global_state_sync';

export function initDashboardApp(app, deps) {
initDashboardAppDirective(app, deps);

app.directive('dashboardListing', function(reactDirective) {
return reactDirective(DashboardListing);
return reactDirective(DashboardListing, [
['core', { watchDepth: 'reference' }],
['createItem', { watchDepth: 'reference' }],
['getViewUrl', { watchDepth: 'reference' }],
['editItem', { watchDepth: 'reference' }],
['findItems', { watchDepth: 'reference' }],
['deleteItems', { watchDepth: 'reference' }],
['listingLimit', { watchDepth: 'reference' }],
['hideWriteControls', { watchDepth: 'reference' }],
['initialFilter', { watchDepth: 'reference' }],
]);
});

function createNewDashboardCtrl($scope) {
Expand Down Expand Up @@ -116,6 +128,7 @@ export function initDashboardApp(app, deps) {
},
]);
addHelpMenuToAppChrome(deps.chrome, deps.core.docLinks);
$scope.core = deps.core;
},
resolve: {
dash: function($rootScope, $route, redirectWhenMissing, kbnUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import _ from 'lodash';
import moment, { Moment } from 'moment';
import { esFilters } from '../../../../../../plugins/data/public';
import { esFilters } from '../../../../../../../plugins/data/public';

/**
* @typedef {Object} QueryFilter
Expand Down
Loading

0 comments on commit 13a3b75

Please sign in to comment.