Skip to content

Commit

Permalink
Kibana app migration: Move static code dependencies into kibana_legac…
Browse files Browse the repository at this point in the history
…y plugin, part 1 (#56408) (#57095)

* Migrate PromiseServiceCreator

* Migrate migrateLegacyQuery

* Migrate watch_multi decorator

* Migrate call_after_bindings_workaround

* Migrate configureAppAngularModule, ensureDefaultIndexPattern and deps

* Migrate kbn_accessible_clicks

* Migrate PrivateProvider

* Migrate registerListenEventListener

* Adapt i18n files
  • Loading branch information
kertal authored Feb 7, 2020
1 parent 3e21bfd commit a21218d
Show file tree
Hide file tree
Showing 64 changed files with 553 additions and 491 deletions.
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"src/plugins/management"
],
"advancedSettings": "src/plugins/advanced_settings",
"kibana_legacy": "src/plugins/kibana_legacy",
"kibana_react": "src/legacy/core_plugins/kibana_react",
"kibana-react": "src/plugins/kibana_react",
"kibana_utils": "src/plugins/kibana_utils",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ import chrome from 'ui/chrome';
export const legacyChrome = chrome;
export { SavedObjectSaveOpts } from 'ui/saved_objects/types';
export { npSetup, npStart } from 'ui/new_platform';
export { IPrivate } from 'ui/private';
export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
// @ts-ignore
export { ConfirmationButtonTypes } from 'ui/modals/confirm_modal';
export { migrateLegacyQuery } from 'ui/utils/migrate_legacy_query';
export { KbnUrl } from 'ui/url/kbn_url';
// @ts-ignore
export { PrivateProvider } from 'ui/private/private';
// @ts-ignore
export { createTopNavDirective, createTopNavHelper } from 'ui/kbn_top_nav/kbn_top_nav';
// @ts-ignore
export { PromiseServiceCreator } from 'ui/promises/promises';
// @ts-ignore
export { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url/index';
// @ts-ignore
export { confirmModalFactory } from 'ui/modals/confirm_modal';
export { configureAppAngularModule } from 'ui/legacy_compat';
export { ensureDefaultIndexPattern } from 'ui/legacy_compat';
export { IInjector } from 'ui/chrome';
export { SavedObjectLoader } from 'ui/saved_objects';
export { VISUALIZE_EMBEDDABLE_TYPE } from '../../../visualizations/public/embeddable';
export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router';
export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url';
export {
configureAppAngularModule,
ensureDefaultIndexPattern,
IPrivate,
migrateLegacyQuery,
PrivateProvider,
PromiseServiceCreator,
} from '../../../../../plugins/kibana_legacy/public';
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,15 @@
// They can stay even after NP cutover
import angular from 'angular';
import 'ui/angular-bootstrap';
import { IPrivate } from 'ui/private';
import { EuiIcon } from '@elastic/eui';
// @ts-ignore
import { StateProvider } from 'ui/state_management/state';
// @ts-ignore
import { EventsProvider } from 'ui/events';
import { PersistedState } from 'ui/persisted_state';
// @ts-ignore
import { PromiseServiceCreator } from 'ui/promises/promises';
import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular';
// @ts-ignore
import { PrivateProvider } from 'ui/private/private';
import { CoreStart, LegacyCoreStart, IUiSettingsClient } from 'kibana/public';
// @ts-ignore
import { watchMultiDecorator } from 'ui/directives/watch_multi/watch_multi';
// @ts-ignore
import { registerListenEventListener } from 'ui/directives/listen/listen';
// @ts-ignore
import { KbnAccessibleClickProvider } from 'ui/accessibility/kbn_accessible_click';
// @ts-ignore
import { AppStateProvider } from 'ui/state_management/app_state';
// @ts-ignore
import { GlobalStateProvider } from 'ui/state_management/global_state';
Expand All @@ -51,7 +40,6 @@ import { StateManagementConfigProvider } from 'ui/state_management/config_provid
import { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url';
// @ts-ignore
import { createTopNavDirective, createTopNavHelper } from 'ui/kbn_top_nav/kbn_top_nav';
import { configureAppAngularModule } from 'ui/legacy_compat';
import { IndexPatterns, DataPublicPluginStart } from '../../../../../plugins/data/public';
import { Storage } from '../../../../../plugins/kibana_utils/public';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public';
Expand Down Expand Up @@ -82,6 +70,15 @@ import { FixedScrollProvider } from './np_ready/angular/directives/fixed_scroll'
// @ts-ignore
import { DebounceProviderTimeout } from './np_ready/angular/directives/debounce/debounce';
import { createRenderCompleteDirective } from './np_ready/angular/directives/render_complete';
import {
configureAppAngularModule,
IPrivate,
KbnAccessibleClickProvider,
PrivateProvider,
PromiseServiceCreator,
registerListenEventListener,
watchMultiDecorator,
} from '../../../../../plugins/kibana_legacy/public';

/**
* returns the main inner angular module, it contains all the parts of Angular Discover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,22 @@ export function setServices(newServices: any) {
export { angular };
export { wrapInI18nContext } from 'ui/i18n';
export { buildVislibDimensions } from '../../../visualizations/public';
// @ts-ignore
export { callAfterBindingsWorkaround } from 'ui/compat';
export { getRequestInspectorStats, getResponseInspectorStats } from '../../../data/public';
// @ts-ignore
export { intervalOptions } from 'ui/agg_types';
// @ts-ignore
export { migrateLegacyQuery } from 'ui/utils/migrate_legacy_query';
export { stateMonitorFactory } from 'ui/state_management/state_monitor_factory';
export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
// @ts-ignore
export { timezoneProvider } from 'ui/vis/lib/timezone';
// @ts-ignore
export { tabifyAggResponse } from 'ui/agg_response/tabify';
export { ensureDefaultIndexPattern } from 'ui/legacy_compat';
export { unhashUrl } from '../../../../../plugins/kibana_utils/public';
// @ts-ignore
export { formatMsg, formatStack } from 'ui/notify/lib/index';
export {
migrateLegacyQuery,
ensureDefaultIndexPattern,
formatMsg,
formatStack,
} from '../../../../../plugins/kibana_legacy/public';

// EXPORT types
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,6 @@
*
*/

export class InitAfterBindingsWorkaround {
static $inject = ['$injector', '$attrs', '$element', '$scope', '$transclude'];
constructor($injector, $attrs, $element, $scope, $transclude) {
if (!this.initAfterBindings) {
throw new Error(
'When using inheritance you must move the logic in the constructor to the `initAfterBindings` method'
);
}

this.$onInit = () => {
$injector.invoke(this.initAfterBindings, this, {
$attrs,
$element,
$scope,
$transclude,
});
};
}
}

export function callAfterBindingsWorkaround(constructor) {
return function InitAfterBindingsWrapper($injector, $attrs, $element, $scope, $transclude) {
this.$onInit = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import _ from 'lodash';
import { callAfterBindingsWorkaround, getAngularModule } from '../../kibana_services';
import { getAngularModule } from '../../kibana_services';
import contextAppTemplate from './context_app.html';
import './context/components/action_bar';
import { getFirstSortableField } from './context/api/utils/sorting';
Expand All @@ -33,6 +33,7 @@ import {
LOADING_STATUS,
QueryActionsProvider,
} from './context/query';
import { callAfterBindingsWorkaround } from './context/helpers/call_after_bindings_workaround';

const module = getAngularModule();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import { EuiCallOut, EuiCodeBlock } from '@elastic/eui';
import { formatMsg, formatStack } from '../../../kibana_services';

interface Props {
error: Error | string | null;
error: Error | string;
}

export function DocViewerError({ error }: Props) {
const errMsg = formatMsg(error);
const errStack = error ? formatStack(error) : '';
const errStack = typeof error === 'object' ? formatStack(error) : '';

return (
<EuiCallOut title={errMsg} color="danger" iconType="cross" data-test-subj="docViewerError">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface Props {
}

interface State {
error: null | Error | string;
error: Error | string;
hasError: boolean;
}
/**
Expand All @@ -42,7 +42,7 @@ interface State {
export class DocViewerTab extends React.Component<Props, State> {
state = {
hasError: false,
error: null,
error: '',
};

static getDerivedStateFromError(error: unknown) {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/home/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import { FeatureCatalogueRegistryProvider } from 'ui/registry/feature_catalogue';
import { npSetup, npStart } from 'ui/new_platform';
import chrome from 'ui/chrome';
import { IPrivate } from 'ui/private';
import { HomePlugin, LegacyAngularInjectedDependencies } from './plugin';
import { TelemetryOptInProvider } from '../../../telemetry/public/services';
import { IPrivate } from '../../../../../plugins/kibana_legacy/public';

/**
* Get dependencies relying on the global angular context.
Expand Down
18 changes: 8 additions & 10 deletions src/legacy/core_plugins/kibana/public/visualize/legacy_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,29 @@ export { stateMonitorFactory } from 'ui/state_management/state_monitor_factory';
export { PersistedState } from 'ui/persisted_state';

export { npSetup, npStart } from 'ui/new_platform';
export { IPrivate } from 'ui/private';
// @ts-ignore
export { PrivateProvider } from 'ui/private/private';

export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
export { migrateLegacyQuery } from 'ui/utils/migrate_legacy_query';
// @ts-ignore
export { EventsProvider } from 'ui/events';
// @ts-ignore
export { createTopNavDirective, createTopNavHelper } from 'ui/kbn_top_nav/kbn_top_nav';
// @ts-ignore
export { PromiseServiceCreator } from 'ui/promises/promises';
// @ts-ignore
export { confirmModalFactory } from 'ui/modals/confirm_modal';
export { configureAppAngularModule, ensureDefaultIndexPattern } from 'ui/legacy_compat';
export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router';

// @ts-ignore
export { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url';
export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url';
export { KibanaParsedUrl } from 'ui/url/kibana_parsed_url';

export { wrapInI18nContext } from 'ui/i18n';

export { DashboardConstants } from '../dashboard/np_ready/dashboard_constants';
export { VisSavedObject } from '../../../visualizations/public/embeddable/visualize_embeddable';
export { VISUALIZE_EMBEDDABLE_TYPE } from '../../../visualizations/public/embeddable';
export { VisType } from '../../../visualizations/public';
export {
configureAppAngularModule,
ensureDefaultIndexPattern,
IPrivate,
migrateLegacyQuery,
PrivateProvider,
PromiseServiceCreator,
} from '../../../../../plugins/kibana_legacy/public';
16 changes: 6 additions & 10 deletions src/legacy/core_plugins/vis_type_table/public/legacy_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,18 @@
export { npSetup, npStart } from 'ui/new_platform';
export { getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities';
export { IAggConfig, AggGroupNames, Schemas } from 'ui/agg_types';

// @ts-ignore
export { PrivateProvider } from 'ui/private/private';
// @ts-ignore
export { PaginateDirectiveProvider } from 'ui/directives/paginate';
// @ts-ignore
export { PaginateControlsDirectiveProvider } from 'ui/directives/paginate';
// @ts-ignore
export { watchMultiDecorator } from 'ui/directives/watch_multi/watch_multi';

// @ts-ignore
export { KbnAccessibleClickProvider } from 'ui/accessibility/kbn_accessible_click';
// @ts-ignore
export { StateManagementConfigProvider } from 'ui/state_management/config_provider';
export { configureAppAngularModule } from 'ui/legacy_compat';

export { tabifyGetColumns } from 'ui/agg_response/tabify/_get_columns';
// @ts-ignore
export { tabifyAggResponse } from 'ui/agg_response/tabify';
export {
configureAppAngularModule,
KbnAccessibleClickProvider,
PrivateProvider,
watchMultiDecorator,
} from '../../../../plugins/kibana_legacy/public';
2 changes: 1 addition & 1 deletion src/legacy/ui/public/UI_SYSTEMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ In this directory you'll find various UI systems you can use to craft effective
## ui/notify

* [banners](notify/banners/BANNERS.md)
* [toastNotifications](notify/toasts/TOAST_NOTIFICATIONS.md)
* [toastNotifications](../../../plugins/kibana_legacy/public/notify/toasts/TOAST_NOTIFICATIONS.md)
53 changes: 1 addition & 52 deletions src/legacy/ui/public/accessibility/kbn_accessible_click.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,58 +37,7 @@
* Apply this directive to any of these elements to automatically do the above.
*/

import { accessibleClickKeys, keyCodes } from '@elastic/eui';
import { uiModules } from '../modules';

export function KbnAccessibleClickProvider() {
return {
restrict: 'A',
controller: $element => {
$element.on('keydown', e => {
// Prevent a scroll from occurring if the user has hit space.
if (e.keyCode === keyCodes.SPACE) {
e.preventDefault();
}
});
},
link: (scope, element, attrs) => {
// The whole point of this directive is to hack in functionality that native buttons provide
// by default.
const elementType = element.prop('tagName');

if (elementType === 'BUTTON') {
throw new Error(`kbnAccessibleClick doesn't need to be used on a button.`);
}

if (elementType === 'A' && attrs.href !== undefined) {
throw new Error(
`kbnAccessibleClick doesn't need to be used on a link if it has a href attribute.`
);
}

// We're emulating a click action, so we should already have a regular click handler defined.
if (!attrs.ngClick) {
throw new Error('kbnAccessibleClick requires ng-click to be defined on its element.');
}

// If the developer hasn't already specified attributes required for accessibility, add them.
if (attrs.tabindex === undefined) {
element.attr('tabindex', '0');
}

if (attrs.role === undefined) {
element.attr('role', 'button');
}

element.on('keyup', e => {
// Support keyboard accessibility by emulating mouse click on ENTER or SPACE keypress.
if (accessibleClickKeys[e.keyCode]) {
// Delegate to the click handler on the element (assumed to be ng-click).
element.click();
}
});
},
};
}
import { KbnAccessibleClickProvider } from '../../../../plugins/kibana_legacy/public';

uiModules.get('kibana').directive('kbnAccessibleClick', KbnAccessibleClickProvider);
19 changes: 1 addition & 18 deletions src/legacy/ui/public/directives/listen/listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,6 @@
*/

import { uiModules } from '../../modules';

export function registerListenEventListener($rootScope) {
/**
* Helper that registers an event listener, and removes that listener when
* the $scope is destroyed.
*
* @param {SimpleEmitter} emitter - the event emitter to listen to
* @param {string} eventName - the event name
* @param {Function} handler - the event handler
* @return {undefined}
*/
$rootScope.constructor.prototype.$listen = function(emitter, eventName, handler) {
emitter.on(eventName, handler);
this.$on('$destroy', function() {
emitter.off(eventName, handler);
});
};
}
import { registerListenEventListener } from '../../../../../plugins/kibana_legacy/public';

uiModules.get('kibana').run(registerListenEventListener);
4 changes: 3 additions & 1 deletion src/legacy/ui/public/directives/watch_multi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
* under the License.
*/

import './watch_multi';
import { uiModules } from '../../modules';
import { watchMultiDecorator } from '../../../../../plugins/kibana_legacy/public';
uiModules.get('kibana').config(watchMultiDecorator);
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import expect from '@kbn/expect';
import { IE_REGEX } from '../url_overflow_service.js';
import { IE_REGEX } from '../../../../../plugins/kibana_legacy/public';

describe('IE_REGEX', () => {
it('should detect IE 9', () => {
Expand Down
Loading

0 comments on commit a21218d

Please sign in to comment.