Skip to content

Commit

Permalink
[Discover] Centralize dependencies in kibana_services.ts (#48072)
Browse files Browse the repository at this point in the history
* Move doc folder to discover folder

* Move doc_viewer folder to discover folder

* Move context folder to discover folder

* Move context scss import to discover folder

* Introduce angular folder, start migration

* Add basic NP structure, structural refactoring

* Add context placeholder readme

* Move doc_viewer directive to angular

* Move doc_table directive to angular directory

* Migrate doc_table dependencies to central file

* Create kibana_services.ts

* Centralize context deps

* Centralize embeddable deps

* Migrate context to angular folder

* Add dependencies to kibana_services.ts, implement getServices function

* Refactor SEARCH_EMBEDDABLE_TYPE to contants.ts

* Fix tests
  • Loading branch information
kertal authored Oct 25, 2019
1 parent 6deac56 commit f104e23
Show file tree
Hide file tree
Showing 132 changed files with 617 additions and 397 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import _ from 'lodash';
import sinon from 'sinon';
import ngMock from 'ng_mock';
import expect from '@kbn/expect';
import 'ui/private';
import '../../components/field_chooser/discover_field';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import _ from 'lodash';
import ngMock from 'ng_mock';
import { fieldCalculator } from '../../components/field_chooser/lib/field_calculator';
import expect from '@kbn/expect';
import 'ui/private';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

// Load the kibana app dependencies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import _ from 'lodash';
import sinon from 'sinon';
import expect from '@kbn/expect';
import $ from 'jquery';
import 'ui/private';
import '../../components/field_chooser/field_chooser';
import FixturesHitsProvider from 'fixtures/hits';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/kibana/public/discover/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@import 'components/fetch_error/index';
@import 'components/field_chooser/index';
@import 'angular/directives/index';
@import 'doc_table/index';
@import 'angular/doc_table/index';

@import 'hacks';

Expand All @@ -23,4 +23,4 @@
@import 'doc_viewer/index';

// Context styles
@import 'context/index';
@import 'angular/context/index';
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
*/

import _ from 'lodash';

import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';
import uiRoutes from 'ui/routes';
import { i18n } from '@kbn/i18n';
import { getServices, subscribeWithScope } from './../kibana_services';

import './app';
import contextAppRouteTemplate from './index.html';
import './context_app';
import contextAppRouteTemplate from './context.html';
import { getRootBreadcrumbs } from '../breadcrumbs';
import { npStart } from 'ui/new_platform';
import { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
const { FilterBarQueryFilterProvider, uiRoutes, chrome } = getServices();

const k7Breadcrumbs = $route => {
const { indexPattern } = $route.current.locals;
Expand All @@ -47,12 +44,11 @@ const k7Breadcrumbs = $route => {
];
};


uiRoutes
// deprecated route, kept for compatibility
// should be removed in the future
.when('/context/:indexPatternId/:type/:id*', {
redirectTo: '/context/:indexPatternId/:id'
redirectTo: '/context/:indexPatternId/:id',
})
.when('/context/:indexPatternId/:id*', {
controller: ContextAppRouteController,
Expand Down Expand Up @@ -92,7 +88,7 @@ function ContextAppRouteController($routeParams, $scope, AppState, config, index
});
this.anchorId = $routeParams.id;
this.indexPattern = indexPattern;
this.discoverUrl = npStart.core.chrome.navLinks.get('kibana:discover').url;
this.discoverUrl = chrome.navLinks.get('kibana:discover').url;
this.filters = _.cloneDeep(queryFilter.getFilters());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import sinon from 'sinon';
import moment from 'moment';
import { SearchSource } from 'ui/courier';
import { SearchSource } from '../../../../kibana_services';

export function createIndexPatternsStub() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
*/

import _ from 'lodash';

import { i18n } from '@kbn/i18n';
import { getServices } from '../../../kibana_services';

import { SearchSource } from 'ui/courier';

const { SearchSource } = getServices();
export function fetchAnchorProvider(indexPatterns) {
return async function fetchAnchor(
indexPatternId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
* under the License.
*/

// @ts-ignore
import { SearchSource } from 'ui/courier';
import { Filter } from '@kbn/es-query';
import { IndexPatterns, IndexPattern } from 'ui/index_patterns';
import { IndexPatterns, IndexPattern, getServices } from '../../../kibana_services';
import { reverseSortDir, SortDirection } from './utils/sorting';
import { extractNanos, convertIsoToMillis } from './utils/date_conversion';
import { fetchHitsInInterval } from './utils/fetch_hits_in_interval';
Expand All @@ -36,6 +34,8 @@ export interface EsHitRecord {
}
export type EsHitRecordList = EsHitRecord[];

const { SearchSource } = getServices();

const DAY_MILLIS = 24 * 60 * 60 * 1000;

// look from 1 day up to 10000 days into the past and future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { SearchSource } from 'ui/courier';
import { SearchSource } from '../../../../kibana_services';
import { convertTimeValueToIso } from './date_conversion';
import { SortDirection } from './sorting';
import { EsHitRecordList } from '../context';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { IndexPattern } from 'src/legacy/core_plugins/data/public';
import { IndexPattern } from '../../../../kibana_services';

export enum SortDirection {
asc = 'asc',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
// @ts-ignore
import { uiModules } from 'ui/modules';
import { wrapInI18nContext } from 'ui/i18n';
import { getServices } from '../../../../kibana_services';
import { ActionBar } from './action_bar';

const { uiModules, wrapInI18nContext } = getServices();

uiModules.get('apps/context').directive('contextActionBar', function(reactDirective: any) {
return reactDirective(wrapInI18nContext(ActionBar));
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { toastNotifications } from 'ui/notify';
import { toastNotifications } from '../../../kibana_services';

import { fetchAnchorProvider } from '../api/anchor';
import { fetchContextProvider } from '../api/context';
import { QueryParameterActionsProvider } from '../query_parameters';
import { FAILURE_REASONS, LOADING_STATUS } from './constants';
import { MarkdownSimple } from '../../../../../kibana_react/public';
import { MarkdownSimple } from '../../../../../../kibana_react/public';

export function QueryActionsProvider(Private, Promise) {
const fetchAnchor = Private(fetchAnchorProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import sinon from 'sinon';

import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';

import { getServices } from '../../../../kibana_services';
import { createStateStub } from './_utils';
import { QueryParameterActionsProvider } from '../actions';

Expand All @@ -36,7 +34,7 @@ describe('context app', function () {

beforeEach(ngMock.inject(function createPrivateStubs(Private) {
filterManagerStub = createQueryFilterStub();
Private.stub(FilterBarQueryFilterProvider, filterManagerStub);
Private.stub(getServices().FilterBarQueryFilterProvider, filterManagerStub);

addFilter = Private(QueryParameterActionsProvider).addFilter;
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
*/

import _ from 'lodash';
import { getServices, getFilterGenerator } from '../../../kibana_services';

import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';
import { getFilterGenerator } from 'ui/filter_manager';
import {
MAX_CONTEXT_SIZE,
MIN_CONTEXT_SIZE,
Expand All @@ -29,7 +28,7 @@ import {


export function QueryParameterActionsProvider(indexPatterns, Private) {
const queryFilter = Private(FilterBarQueryFilterProvider);
const queryFilter = Private(getServices().FilterBarQueryFilterProvider);
const filterGen = getFilterGenerator(queryFilter);

const setPredecessorCount = (state) => (predecessorCount) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,23 @@
*/

import _ from 'lodash';

import { callAfterBindingsWorkaround } from 'ui/compat';
import { uiModules } from 'ui/modules';
import contextAppTemplate from './app.html';
import './components/action_bar';
import { getFirstSortableField } from './api/utils/sorting';
import { getServices, callAfterBindingsWorkaround } from './../kibana_services';
import contextAppTemplate from './context_app.html';
import './context/components/action_bar';
import { getFirstSortableField } from './context/api/utils/sorting';
import {
createInitialQueryParametersState,
QueryParameterActionsProvider,
QUERY_PARAMETER_KEYS,
} from './query_parameters';
} from './context/query_parameters';
import {
createInitialLoadingStatusState,
FAILURE_REASONS,
LOADING_STATUS,
QueryActionsProvider,
} from './query';
import { timefilter } from 'ui/timefilter';
} from './context/query';

const { uiModules, timefilter } = getServices();

// load directives
import '../../../../data/public/legacy';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import lightEuiTheme from '@elastic/eui/dist/eui_theme_light.json';
import darkEuiTheme from '@elastic/eui/dist/eui_theme_dark.json';
import { npStart } from 'ui/new_platform';

import {
AnnotationDomainTypes,
Expand All @@ -44,12 +43,9 @@ import {
} from '@elastic/charts';

import { i18n } from '@kbn/i18n';

import chrome from 'ui/chrome';
// @ts-ignore: path dynamic for kibana
import { timezoneProvider } from 'ui/vis/lib/timezone';
import { EuiChartThemeType } from '@elastic/eui/src/themes/charts/themes';
import { Subscription } from 'rxjs';
import { getServices, timezoneProvider } from '../../kibana_services';

export interface DiscoverHistogramProps {
chartData: any;
Expand All @@ -68,12 +64,12 @@ export class DiscoverHistogram extends Component<DiscoverHistogramProps, Discove

private subscription?: Subscription;
public state = {
chartsTheme: npStart.plugins.eui_utils.getChartsThemeDefault(),
chartsTheme: getServices().eui_utils.getChartsThemeDefault(),
};

componentDidMount() {
this.subscription = npStart.plugins.eui_utils
.getChartsTheme$()
this.subscription = getServices()
.eui_utils.getChartsTheme$()
.subscribe(chartsTheme => this.setState({ chartsTheme }));
}

Expand Down Expand Up @@ -145,7 +141,7 @@ export class DiscoverHistogram extends Component<DiscoverHistogramProps, Discove
};

public render() {
const uiSettings = chrome.getUiSettingsClient();
const uiSettings = getServices().uiSettings;
const timeZone = timezoneProvider(uiSettings)();
const { chartData } = this.props;
const { chartsTheme } = this.state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@
* under the License.
*/

import 'ngreact';
import { wrapInI18nContext } from 'ui/i18n';
import { uiModules } from 'ui/modules';
import '../../../../../../ui/public/render_complete/directive';

import '../../../../../../ui/public/render_complete/directive';
import { DiscoverNoResults } from './no_results';
import { DiscoverUninitialized } from './uninitialized';
import { DiscoverUnsupportedIndexPattern } from './unsupported_index_pattern';
import { DiscoverHistogram } from './histogram';
import { getServices } from '../../kibana_services';

const { wrapInI18nContext, uiModules } = getServices();
const app = uiModules.get('apps/discover', ['react']);

app.directive('discoverNoResults', reactDirective =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,21 @@ import {
EuiSpacer,
EuiText,
} from '@elastic/eui';
import { getServices } from '../../kibana_services';

// eslint-disable-next-line react/prefer-stateless-function
export class DiscoverNoResults extends Component {
static propTypes = {
shardFailures: PropTypes.array,
timeFieldName: PropTypes.string,
queryLanguage: PropTypes.string,
getDocLink: PropTypes.func.isRequired,
};

render() {
const {
shardFailures,
timeFieldName,
queryLanguage,
getDocLink,
} = this.props;

let shardFailuresMessage;
Expand Down Expand Up @@ -226,7 +225,7 @@ export class DiscoverNoResults extends Component {
queryStringSyntaxLink: (
<EuiLink
target="_blank"
href={getDocLink('query.luceneQuerySyntax')}
href={getServices().docLinks.links.query.luceneQuerySyntax}
>
<FormattedMessage
id="kbn.discover.noResults.searchExamples.queryStringSyntaxLinkText"
Expand Down
Loading

0 comments on commit f104e23

Please sign in to comment.