Skip to content

Commit

Permalink
[Vis] TableVis uses local angular (#50759)
Browse files Browse the repository at this point in the history
* TableVis uses local angular

* Clean up

* Fix TS

* Update angular_config

* Fix export

* Update render_app.ts

* Cetralize ui deps

* Fix loading KbnTableVisController in Dashboard

* Fix graph

* Rename const

* Add table vis mocks

* Fix kbn_top_nav

* Add TS for test

* Complete conversion paginated_table test to Jest

* Convert table_vis_controller test to Jest

* Convert table_vis_controller test to Jest

* Create agg_table.test.ts

* Fix mocha tests

* Refactoring

* Remove module dep

* Remove LegacyDependenciesPlugin

* Move file

* Fix path

* Fix path

* Fix TS

* Fix Jest test
  • Loading branch information
maryia-lapata authored Dec 2, 2019
1 parent 06bef09 commit 5b84b69
Show file tree
Hide file tree
Showing 21 changed files with 1,473 additions and 866 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import ngMock from 'ng_mock';
import expect from '@kbn/expect';
import fixtures from 'fixtures/fake_hierarchical_data';
import sinon from 'sinon';
import { legacyResponseHandlerProvider } from 'ui/vis/response_handlers/legacy';
import { legacyResponseHandlerProvider, tabifyAggResponse, npStart } from '../../legacy_imports';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { Vis } from '../../../../visualizations/public';
import { tabifyAggResponse } from 'ui/agg_response/tabify';
import { round } from 'lodash';

import { Vis } from '../../../../visualizations/public';
import { tableVisTypeDefinition } from '../../table_vis_type';
import { setup as visualizationsSetup } from '../../../../visualizations/public/np_ready/public/legacy';
import { getAngularModule } from '../../get_inner_angular';
import { initTableVisLegacyModule } from '../../table_vis_legacy_module';

describe('Table Vis - AggTable Directive', function () {
let $rootScope;
Expand Down Expand Up @@ -96,11 +97,18 @@ describe('Table Vis - AggTable Directive', function () {
);
};

const initLocalAngular = () => {
const tableVisModule = getAngularModule('kibana/table_vis', npStart.core);
initTableVisLegacyModule(tableVisModule);
};

beforeEach(initLocalAngular);

ngMock.inject(function () {
visualizationsSetup.types.createBaseVisualization(tableVisTypeDefinition);
});

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.module('kibana/table_vis'));
beforeEach(
ngMock.inject(function ($injector, Private, config) {
tableAggResponse = legacyResponseHandlerProvider().handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import $ from 'jquery';
import ngMock from 'ng_mock';
import expect from '@kbn/expect';
import fixtures from 'fixtures/fake_hierarchical_data';
import { legacyResponseHandlerProvider } from 'ui/vis/response_handlers/legacy';
import { legacyResponseHandlerProvider, tabifyAggResponse, npStart } from '../../legacy_imports';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { Vis } from 'ui/vis';
import { tabifyAggResponse } from 'ui/agg_response/tabify';
import { Vis } from '../../../../visualizations/public';
import { getAngularModule } from '../../get_inner_angular';
import { initTableVisLegacyModule } from '../../table_vis_legacy_module';

describe('Table Vis - AggTableGroup Directive', function () {
let $rootScope;
Expand Down Expand Up @@ -52,7 +53,14 @@ describe('Table Vis - AggTableGroup Directive', function () {
tabifiedData.threeTermBuckets = tabifyAggResponse(vis2.aggs, fixtures.threeTermBuckets);
};

beforeEach(ngMock.module('kibana'));
const initLocalAngular = () => {
const tableVisModule = getAngularModule('kibana/table_vis', npStart.core);
initTableVisLegacyModule(tableVisModule);
};

beforeEach(initLocalAngular);

beforeEach(ngMock.module('kibana/table_vis'));
beforeEach(
ngMock.inject(function ($injector, Private) {
// this is provided in table_vis_controller.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import _ from 'lodash';
import aggTableTemplate from './agg_table.html';
import { getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities';
import { getFormat } from '../legacy_imports';
import { i18n } from '@kbn/i18n';

export function KbnAggTable(config, RecursionHelper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import { EuiIconTip, EuiPanel } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { tabifyGetColumns } from 'ui/agg_response/tabify/_get_columns';
import { VisOptionsProps } from 'ui/vis/editors/default';
import { tabifyGetColumns, VisOptionsProps } from '../legacy_imports';
import {
NumberInputOption,
SwitchOption,
Expand Down
104 changes: 104 additions & 0 deletions src/legacy/core_plugins/vis_type_table/public/get_inner_angular.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* 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.
*/

// inner angular imports
// these are necessary to bootstrap the local angular.
// They can stay even after NP cutover
import angular from 'angular';
import 'ui/angular-bootstrap';
import 'angular-recursion';
import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular';
import { CoreStart, LegacyCoreStart, IUiSettingsClient } from 'kibana/public';
import {
PrivateProvider,
PaginateDirectiveProvider,
PaginateControlsDirectiveProvider,
watchMultiDecorator,
KbnAccessibleClickProvider,
StateManagementConfigProvider,
configureAppAngularModule,
} from './legacy_imports';

const thirdPartyAngularDependencies = ['ngSanitize', 'ui.bootstrap', 'RecursionHelper'];

export function getAngularModule(name: string, core: CoreStart) {
const uiModule = getInnerAngular(name, core);
configureAppAngularModule(uiModule, core as LegacyCoreStart, true);
return uiModule;
}

let initialized = false;

export function getInnerAngular(name = 'kibana/table_vis', core: CoreStart) {
if (!initialized) {
createLocalPrivateModule();
createLocalI18nModule();
createLocalConfigModule(core.uiSettings);
createLocalPaginateModule();
initialized = true;
}
return angular
.module(name, [
...thirdPartyAngularDependencies,
'tableVisPaginate',
'tableVisConfig',
'tableVisPrivate',
'tableVisI18n',
])
.config(watchMultiDecorator)
.directive('kbnAccessibleClick', KbnAccessibleClickProvider);
}

function createLocalPrivateModule() {
angular.module('tableVisPrivate', []).provider('Private', PrivateProvider);
}

function createLocalConfigModule(uiSettings: IUiSettingsClient) {
angular
.module('tableVisConfig', ['tableVisPrivate'])
.provider('stateManagementConfig', StateManagementConfigProvider)
.provider('config', function() {
return {
$get: () => ({
get: (value: string) => {
return uiSettings ? uiSettings.get(value) : undefined;
},
// set method is used in agg_table mocha test
set: (key: string, value: string) => {
return uiSettings ? uiSettings.set(key, value) : undefined;
},
}),
};
});
}

function createLocalI18nModule() {
angular
.module('tableVisI18n', [])
.provider('i18n', I18nProvider)
.filter('i18n', i18nFilter)
.directive('i18nId', i18nDirective);
}

function createLocalPaginateModule() {
angular
.module('tableVisPaginate', [])
.directive('paginate', PaginateDirectiveProvider)
.directive('paginateControls', PaginateControlsDirectiveProvider);
}
Loading

0 comments on commit 5b84b69

Please sign in to comment.