Skip to content

Commit

Permalink
[7.x] [Discover] shim with local application service (#49483) (#51909)
Browse files Browse the repository at this point in the history
* [Discover] shim with local application service (#49483)

Shims discover app within local angular instance (or so called inner angular in the code) to enable migration to the new platform without getting rid of all Angular. Note that apart from Discover's main app, also context, doc view and embeddable are part of this shim. 

There a 2 sorts of local angular used, one for the main plugin, and a slimmer one for it's embeddable, that's needed to render the data table. Both are built on first demand.

There are 2 changes of URLs inside

/context/ becomes /discover/context
/doc/ becomes /discover/doc

Legacy url's are redirected, so they are still valid.

* Migrate UiSettingsClient type to IUiSettingsClient
  • Loading branch information
kertal authored Nov 29, 2019
1 parent 1057c21 commit a066380
Show file tree
Hide file tree
Showing 92 changed files with 1,610 additions and 998 deletions.
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ export default function (kibana) {

uiExports: {
hacks: [
'plugins/kibana/discover',
'plugins/kibana/dev_tools',
],
savedObjectTypes: [
'plugins/kibana/visualize/saved_visualizations/saved_visualization_register',
'plugins/kibana/discover/saved_searches/saved_search_register',
'plugins/kibana/dashboard/saved_dashboard/saved_dashboard_register',
],
app: {
Expand Down
42 changes: 22 additions & 20 deletions src/legacy/core_plugins/kibana/public/dashboard/dashboard_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,26 @@
import { uiModules } from 'ui/modules';
import { capabilities } from 'ui/capabilities';

uiModules.get('kibana')
.provider('dashboardConfig', () => {
let hideWriteControls = !capabilities.get().dashboard.showWriteControls;
export function dashboardConfigProvider() {
let hideWriteControls = !capabilities.get().dashboard.showWriteControls;

return {
/**
* Part of the exposed plugin API - do not remove without careful consideration.
* @type {boolean}
*/
turnHideWriteControlsOn() {
hideWriteControls = true;
},
$get() {
return {
getHideWriteControls() {
return hideWriteControls;
}
};
}
};
}

return {
/**
* Part of the exposed plugin API - do not remove without careful consideration.
* @type {boolean}
*/
turnHideWriteControlsOn() {
hideWriteControls = true;
},
$get() {
return {
getHideWriteControls() {
return hideWriteControls;
}
};
}
};
});
uiModules.get('kibana')
.provider('dashboardConfig', dashboardConfigProvider);
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import _ from 'lodash';
import sinon from 'sinon';
import ngMock from 'ng_mock';
import expect from '@kbn/expect';
import '../../components/field_chooser/discover_field';
import { pluginInstance } from 'plugins/kibana/discover/index';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

// Load the kibana app dependencies.
Expand All @@ -32,8 +32,9 @@ describe('discoverField', function () {
let $scope;
let indexPattern;
let $elem;

beforeEach(ngMock.module('kibana'));
beforeEach(() => pluginInstance.initializeServices(true));
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(ngMock.module('app/discover'));
beforeEach(ngMock.inject(function (Private, $rootScope, $compile) {
$elem = angular.element(`
<discover-field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


import _ from 'lodash';
import { pluginInstance } from 'plugins/kibana/discover/index';
import ngMock from 'ng_mock';
import { fieldCalculator } from '../../components/field_chooser/lib/field_calculator';
import expect from '@kbn/expect';
Expand All @@ -29,7 +30,8 @@ import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logsta
let indexPattern;

describe('fieldCalculator', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(ngMock.module('app/discover'));
beforeEach(ngMock.inject(function (Private) {
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import _ from 'lodash';
import sinon from 'sinon';
import expect from '@kbn/expect';
import $ from 'jquery';
import '../../components/field_chooser/field_chooser';
import { pluginInstance } from 'plugins/kibana/discover/index';
import FixturesHitsProvider from 'fixtures/hits';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { SimpleSavedObject } from '../../../../../../../core/public';
Expand Down Expand Up @@ -70,8 +70,10 @@ describe('discover field chooser directives', function () {
on-remove-field="removeField"
></disc-field-chooser>
`);
beforeEach(() => pluginInstance.initializeServices(true));
beforeEach(() => pluginInstance.initializeInnerAngular());

beforeEach(ngMock.module('kibana', ($provide) => {
beforeEach(ngMock.module('app/discover', ($provide) => {
$provide.decorator('config', ($delegate) => {
// disable shortDots for these tests
$delegate.get = _.wrap($delegate.get, function (origGet, name) {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/discover/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
@import 'embeddable/index';

// Doc Viewer
@import 'doc_viewer/index';
@import 'components/doc_viewer/index';

// Context styles
@import 'angular/context/index';
59 changes: 34 additions & 25 deletions src/legacy/core_plugins/kibana/public/discover/angular/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { getServices, subscribeWithScope } from './../kibana_services';
import { getAngularModule, getServices, subscribeWithScope } from './../kibana_services';

import './context_app';
import contextAppRouteTemplate from './context.html';
import { getRootBreadcrumbs } from '../breadcrumbs';
const { FilterBarQueryFilterProvider, uiRoutes, chrome } = getServices();
import { getRootBreadcrumbs } from '../helpers/breadcrumbs';
import { FilterStateManager } from '../../../../data/public/filter/filter_manager';
const { chrome } = getServices();

const k7Breadcrumbs = $route => {
const { indexPattern } = $route.current.locals;
Expand All @@ -44,26 +45,33 @@ const k7Breadcrumbs = $route => {
];
};

uiRoutes
// deprecated route, kept for compatibility
// should be removed in the future
.when('/context/:indexPatternId/:type/:id*', {
redirectTo: '/context/:indexPatternId/:id',
})
.when('/context/:indexPatternId/:id*', {
controller: ContextAppRouteController,
k7Breadcrumbs,
controllerAs: 'contextAppRoute',
resolve: {
indexPattern: function ($route, indexPatterns) {
return indexPatterns.get($route.current.params.indexPatternId);
getAngularModule().config($routeProvider => {
$routeProvider
// deprecated route, kept for compatibility
// should be removed in the future
.when('/discover/context/:indexPatternId/:type/:id*', {
redirectTo: '/discover/context/:indexPatternId/:id',
})
.when('/discover/context/:indexPatternId/:id*', {
controller: ContextAppRouteController,
k7Breadcrumbs,
controllerAs: 'contextAppRoute',
resolve: {
indexPattern: ($route, Promise) => {
const indexPattern = getServices().indexPatterns.get(
$route.current.params.indexPatternId
);
return Promise.props({ ip: indexPattern });
},
},
},
template: contextAppRouteTemplate,
});
template: contextAppRouteTemplate,
});
});

function ContextAppRouteController($routeParams, $scope, AppState, config, indexPattern, Private) {
const queryFilter = Private(FilterBarQueryFilterProvider);
function ContextAppRouteController($routeParams, $scope, AppState, config, $route, getAppState, globalState) {
const filterManager = getServices().filterManager;
const filterStateManager = new FilterStateManager(globalState, getAppState, filterManager);
const indexPattern = $route.current.locals.indexPattern.ip;

this.state = new AppState(createDefaultAppState(config, indexPattern));
this.state.save(true);
Expand All @@ -77,19 +85,20 @@ function ContextAppRouteController($routeParams, $scope, AppState, config, index
() => this.state.save(true)
);

const updateSubsciption = subscribeWithScope($scope, queryFilter.getUpdates$(), {
const updateSubsciption = subscribeWithScope($scope, filterManager.getUpdates$(), {
next: () => {
this.filters = _.cloneDeep(queryFilter.getFilters());
this.filters = _.cloneDeep(filterManager.getFilters());
},
});

$scope.$on('$destroy', function () {
$scope.$on('$destroy', () => {
filterStateManager.destroy();
updateSubsciption.unsubscribe();
});
this.anchorId = $routeParams.id;
this.indexPattern = indexPattern;
this.discoverUrl = chrome.navLinks.get('kibana:discover').url;
this.filters = _.cloneDeep(queryFilter.getFilters());
this.filters = _.cloneDeep(filterManager.getFilters());
}

function createDefaultAppState(config, indexPattern) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@

import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { pluginInstance } from 'plugins/kibana/discover/index';

import { createIndexPatternsStub, createSearchSourceStub } from './_stubs';

import { fetchAnchorProvider } from '../anchor';

describe('context app', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(ngMock.module('app/discover'));

describe('function fetchAnchor', function () {
let fetchAnchor;
Expand All @@ -35,11 +37,11 @@ describe('context app', function () {
$provide.value('indexPatterns', createIndexPatternsStub());
}));

beforeEach(ngMock.inject(function createPrivateStubs(Private) {
beforeEach(ngMock.inject(function createPrivateStubs() {
searchSourceStub = createSearchSourceStub([
{ _id: 'hit1' },
]);
fetchAnchor = Private(fetchAnchorProvider);
fetchAnchor = fetchAnchorProvider(createIndexPatternsStub(), searchSourceStub);
}));

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import moment from 'moment';
import * as _ from 'lodash';
import { pluginInstance } from 'plugins/kibana/discover/index';

import { createIndexPatternsStub, createContextSearchSourceStub } from './_stubs';

Expand All @@ -33,7 +34,8 @@ const ANCHOR_TIMESTAMP_1000 = (new Date(MS_PER_DAY * 1000)).toJSON();
const ANCHOR_TIMESTAMP_3000 = (new Date(MS_PER_DAY * 3000)).toJSON();

describe('context app', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(ngMock.module('app/discover'));

describe('function fetchPredecessors', function () {
let fetchPredecessors;
Expand All @@ -43,7 +45,7 @@ describe('context app', function () {
$provide.value('indexPatterns', createIndexPatternsStub());
}));

beforeEach(ngMock.inject(function createPrivateStubs(Private) {
beforeEach(ngMock.inject(function createPrivateStubs() {
searchSourceStub = createContextSearchSourceStub([], '@timestamp', MS_PER_DAY * 8);
fetchPredecessors = (indexPatternId, timeField, sortDir, timeValIso, timeValNr, tieBreakerField, tieBreakerValue, size) => {
const anchor = {
Expand All @@ -53,7 +55,7 @@ describe('context app', function () {
sort: [timeValNr, tieBreakerValue]
};

return Private(fetchContextProvider).fetchSurroundingDocs(
return fetchContextProvider(createIndexPatternsStub()).fetchSurroundingDocs(
'predecessors',
indexPatternId,
anchor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import moment from 'moment';
import * as _ from 'lodash';
import { pluginInstance } from 'plugins/kibana/discover/index';

import { createIndexPatternsStub, createContextSearchSourceStub } from './_stubs';

Expand All @@ -32,17 +33,14 @@ const ANCHOR_TIMESTAMP_3 = (new Date(MS_PER_DAY * 3)).toJSON();
const ANCHOR_TIMESTAMP_3000 = (new Date(MS_PER_DAY * 3000)).toJSON();

describe('context app', function () {
beforeEach(ngMock.module('kibana'));
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(ngMock.module('app/discover'));

describe('function fetchSuccessors', function () {
let fetchSuccessors;
let searchSourceStub;

beforeEach(ngMock.module(function createServiceStubs($provide) {
$provide.value('indexPatterns', createIndexPatternsStub());
}));

beforeEach(ngMock.inject(function createPrivateStubs(Private) {
beforeEach(ngMock.inject(function createPrivateStubs() {
searchSourceStub = createContextSearchSourceStub([], '@timestamp');

fetchSuccessors = (indexPatternId, timeField, sortDir, timeValIso, timeValNr, tieBreakerField, tieBreakerValue, size) => {
Expand All @@ -53,7 +51,7 @@ describe('context app', function () {
sort: [timeValNr, tieBreakerValue]
};

return Private(fetchContextProvider).fetchSurroundingDocs(
return fetchContextProvider(createIndexPatternsStub()).fetchSurroundingDocs(
'successors',
indexPatternId,
anchor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@

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

const { SearchSource } = getServices();
export function fetchAnchorProvider(indexPatterns) {
export function fetchAnchorProvider(indexPatterns, searchSource) {
return async function fetchAnchor(
indexPatternId,
anchorId,
sort
) {
const indexPattern = await indexPatterns.get(indexPatternId);
const searchSource = new SearchSource()
searchSource
.setParent(undefined)
.setField('index', indexPattern)
.setField('version', true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
* under the License.
*/

import { SortDirection } from '../../../../../../../ui/public/courier';
import { IndexPatterns, IndexPattern, getServices } from '../../../kibana_services';
import { reverseSortDir } from './utils/sorting';
import { IndexPatterns, IndexPattern, SearchSource } from '../../../kibana_services';
import { reverseSortDir, SortDirection } from './utils/sorting';
import { extractNanos, convertIsoToMillis } from './utils/date_conversion';
import { fetchHitsInInterval } from './utils/fetch_hits_in_interval';
import { generateIntervals } from './utils/generate_intervals';
Expand All @@ -35,8 +34,6 @@ 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,10 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { reverseSortDir } from '../sorting';
import { SortDirection } from '../../../../../../../../../ui/public/courier';

jest.mock('ui/new_platform');
import { reverseSortDir, SortDirection } from '../sorting';

describe('function reverseSortDir', function() {
test('reverse a given sort direction', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
* under the License.
*/

import { SortDirection } from '../../../../../../../../ui/public/courier';
import { IndexPattern } from '../../../../kibana_services';

export enum SortDirection {
asc = 'asc',
desc = 'desc',
}

/**
* The list of field names that are allowed for sorting, but not included in
* index pattern fields.
Expand Down
Loading

0 comments on commit a066380

Please sign in to comment.