Skip to content

Commit

Permalink
[Discover] Remove StateManagementConfigProvider (elastic#60221)
Browse files Browse the repository at this point in the history
* Remove StateManagementConfigProvider from Discover

* Code cleanups
  • Loading branch information
kertal committed Mar 20, 2020
1 parent 546ad07 commit 9dd5154
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,7 @@ describe('discover field chooser directives', function() {
beforeEach(() => pluginInstance.initializeServices());
beforeEach(() => pluginInstance.initializeInnerAngular());

beforeEach(
ngMock.module('app/discover', $provide => {
$provide.decorator('config', $delegate => {
// disable shortDots for these tests
$delegate.get = _.wrap($delegate.get, function(origGet, name) {
if (name === 'shortDots:enable') {
return false;
} else {
return origGet.call(this, name);
}
});

return $delegate;
});
})
);
beforeEach(ngMock.module('app/discover'));

beforeEach(
ngMock.inject(function(Private) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logsta
describe('Doc Table', function() {
let $parentScope;
let $scope;
let config;

// Stub out a minimal mapping of 4 fields
let mapping;
Expand All @@ -41,8 +40,7 @@ describe('Doc Table', function() {
beforeEach(() => pluginInstance.initializeInnerAngular());
beforeEach(ngMock.module('app/discover'));
beforeEach(
ngMock.inject(function(_config_, $rootScope, Private) {
config = _config_;
ngMock.inject(function($rootScope, Private) {
$parentScope = $rootScope;
$parentScope.indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
mapping = $parentScope.indexPattern.fields;
Expand Down Expand Up @@ -144,12 +142,6 @@ describe('Doc Table', function() {
filter: sinon.spy(),
maxLength: 50,
});

// Ignore the metaFields (_id, _type, etc) since we don't have a mapping for them
sinon
.stub(config, 'get')
.withArgs('metaFields')
.returns([]);
});
afterEach(function() {
destroy();
Expand Down Expand Up @@ -215,11 +207,6 @@ describe('Doc Table', function() {
maxLength: 50,
});

sinon
.stub(config, 'get')
.withArgs('metaFields')
.returns(['_id']);

// Open the row
$scope.toggleRow();
$scope.$digest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import angular from 'angular';
import { EuiIcon } from '@elastic/eui';
import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular';
import { CoreStart, LegacyCoreStart, IUiSettingsClient } from 'kibana/public';
// @ts-ignore
import { StateManagementConfigProvider } from 'ui/state_management/config_provider';
import { CoreStart, LegacyCoreStart } from 'kibana/public';
// @ts-ignore
import { KbnUrlProvider } from 'ui/url';
import { DataPublicPluginStart } from '../../../../../plugins/data/public';
Expand Down Expand Up @@ -108,7 +106,6 @@ export function initializeInnerAngularModule(
createLocalI18nModule();
createLocalPrivateModule();
createLocalPromiseModule();
createLocalConfigModule(core.uiSettings);
createLocalKbnUrlModule();
createLocalTopNavModule(navigation);
createLocalStorageModule();
Expand Down Expand Up @@ -143,7 +140,6 @@ export function initializeInnerAngularModule(
'ngRoute',
'react',
'ui.bootstrap',
'discoverConfig',
'discoverI18n',
'discoverPrivate',
'discoverPromise',
Expand Down Expand Up @@ -176,21 +172,6 @@ function createLocalKbnUrlModule() {
.service('kbnUrl', (Private: IPrivate) => Private(KbnUrlProvider));
}

function createLocalConfigModule(uiSettings: IUiSettingsClient) {
angular
.module('discoverConfig', ['discoverPrivate'])
.provider('stateManagementConfig', StateManagementConfigProvider)
.provider('config', () => {
return {
$get: () => ({
get: (value: string) => {
return uiSettings ? uiSettings.get(value) : undefined;
},
}),
};
});
}

function createLocalPromiseModule() {
angular.module('discoverPromise', []).service('Promise', PromiseServiceCreator);
}
Expand Down Expand Up @@ -229,7 +210,7 @@ const createLocalStorageService = function(type: string) {

function createElasticSearchModule(data: DataPublicPluginStart) {
angular
.module('discoverEs', ['discoverConfig'])
.module('discoverEs', [])
// Elasticsearch client used for requesting data. Connects to the /elasticsearch proxy
.service('es', () => {
return data.search.__LEGACY.esClient;
Expand All @@ -242,12 +223,7 @@ function createPagerFactoryModule() {

function createDocTableModule() {
angular
.module('discoverDocTable', [
'discoverKbnUrl',
'discoverConfig',
'discoverPagerFactory',
'react',
])
.module('discoverDocTable', ['discoverKbnUrl', 'discoverPagerFactory', 'react'])
.directive('docTable', createDocTableDirective)
.directive('kbnTableHeader', createTableHeaderDirective)
.directive('toolBarPagerText', createToolBarPagerTextDirective)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ getAngularModule().config($routeProvider => {
});
});

function ContextAppRouteController($routeParams, $scope, config, $route) {
function ContextAppRouteController($routeParams, $scope, $route) {
const filterManager = getServices().filterManager;
const indexPattern = $route.current.locals.indexPattern.ip;
const {
Expand All @@ -77,9 +77,9 @@ function ContextAppRouteController($routeParams, $scope, config, $route) {
setFilters,
setAppState,
} = getState({
defaultStepSize: config.get('context:defaultSize'),
defaultStepSize: getServices().uiSettings.get('context:defaultSize'),
timeFieldName: indexPattern.timeFieldName,
storeInSessionStorage: config.get('state:storeInSessionStorage'),
storeInSessionStorage: getServices().uiSettings.get('state:storeInSessionStorage'),
});
this.state = { ...appState.getState() };
this.anchorId = $routeParams.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ module.directive('contextApp', function ContextApp() {
};
});

function ContextAppController($scope, config, Private) {
const { filterManager, indexpatterns } = getServices();
function ContextAppController($scope, Private) {
const { filterManager, indexpatterns, uiSettings } = getServices();
const queryParameterActions = getQueryParameterActions(filterManager, indexpatterns);
const queryActions = Private(QueryActionsProvider);
this.state = createInitialState(
parseInt(config.get('context:step'), 10),
getFirstSortableField(this.indexPattern, config.get('context:tieBreakerFields')),
parseInt(uiSettings.get('context:step'), 10),
getFirstSortableField(this.indexPattern, uiSettings.get('context:tieBreakerFields')),
this.discoverUrl
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/
import { FieldName } from './field_name/field_name';
import { wrapInI18nContext } from '../../../kibana_services';
import { getServices, wrapInI18nContext } from '../../../kibana_services';

export function FieldNameDirectiveProvider(config, reactDirective) {
export function FieldNameDirectiveProvider(reactDirective) {
return reactDirective(
wrapInI18nContext(FieldName),
[
Expand All @@ -29,7 +29,7 @@ export function FieldNameDirectiveProvider(config, reactDirective) {
],
{ restrict: 'AE' },
{
useShortDots: config.get('shortDots:enable'),
useShortDots: getServices().uiSettings.get('shortDots:enable'),
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const {
share,
timefilter,
toastNotifications,
uiSettings,
uiSettings: config,
visualizations,
} = getServices();

Expand Down Expand Up @@ -131,7 +131,7 @@ app.config($routeProvider => {
*
* @type {State}
*/
const id = getIndexPatternId(index, indexPatternList, uiSettings.get('defaultIndex'));
const id = getIndexPatternId(index, indexPatternList, config.get('defaultIndex'));
return Promise.props({
list: indexPatternList,
loaded: indexPatterns.get(id),
Expand Down Expand Up @@ -184,7 +184,6 @@ function discoverController(
$timeout,
$window,
Promise,
config,
kbnUrl,
localStorage,
uiCapabilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
* specific language governing permissions and limitations
* under the License.
*/
import { IUiSettingsClient } from 'kibana/public';
import { TableHeader } from './table_header/table_header';
import { wrapInI18nContext } from '../../../../kibana_services';
import { wrapInI18nContext, getServices } from '../../../../kibana_services';

export function createTableHeaderDirective(reactDirective: any) {
const { uiSettings: config } = getServices();

export function createTableHeaderDirective(reactDirective: any, config: IUiSettingsClient) {
return reactDirective(
wrapInI18nContext(TableHeader),
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import _ from 'lodash';
import $ from 'jquery';
import { IUiSettingsClient } from 'kibana/public';
// @ts-ignore
import rison from 'rison-node';
import '../../doc_viewer';
Expand All @@ -45,8 +44,7 @@ interface LazyScope extends ng.IScope {
export function createTableRowDirective(
$compile: ng.ICompileService,
$httpParamSerializer: any,
kbnUrl: any,
config: IUiSettingsClient
kbnUrl: any
) {
const cellTemplate = _.template(noWhiteSpace(cellTemplateHtml));
const truncateByHeightTemplate = _.template(noWhiteSpace(truncateByHeightTemplateHtml));
Expand Down Expand Up @@ -140,7 +138,7 @@ export function createTableRowDirective(
const newHtmls = [openRowHtml];

const mapping = indexPattern.fields.getByName;
const hideTimeColumn = config.get('doc_table:hideTimeColumn');
const hideTimeColumn = getServices().uiSettings.get('doc_table:hideTimeColumn');
if (indexPattern.timeFieldName && !hideTimeColumn) {
newHtmls.push(
cellTemplate({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@
* under the License.
*/

import { IUiSettingsClient } from 'kibana/public';
import html from './doc_table.html';
import { dispatchRenderComplete } from '../../../../../../../../plugins/kibana_utils/public';
// @ts-ignore
import { getLimitedSearchResultsMessage } from './doc_table_strings';
import { getServices } from '../../../kibana_services';

interface LazyScope extends ng.IScope {
[key: string]: any;
}

export function createDocTableDirective(
config: IUiSettingsClient,
pagerFactory: any,
$filter: any
) {
export function createDocTableDirective(pagerFactory: any, $filter: any) {
return {
restrict: 'E',
template: html,
Expand Down Expand Up @@ -68,7 +64,7 @@ export function createDocTableDirective(
};

$scope.limitedResultsWarning = getLimitedSearchResultsMessage(
config.get('discover:sampleSize')
getServices().uiSettings.get('discover:sampleSize')
);

$scope.addRows = function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import {
KBN_FIELD_TYPES,
} from '../../../../../../../../plugins/data/public';
import { getMapsAppUrl, isFieldVisualizable, isMapsAppRegistered } from './lib/visualize_url_utils';
import { getServices } from '../../../kibana_services';

export function createFieldChooserDirective($location, config) {
export function createFieldChooserDirective($location) {
return {
restrict: 'E',
scope: {
Expand All @@ -49,6 +50,7 @@ export function createFieldChooserDirective($location, config) {
$scope.showFilter = false;
$scope.toggleShowFilter = () => ($scope.showFilter = !$scope.showFilter);
$scope.indexPatternList = _.sortBy($scope.indexPatternList, o => o.get('title'));
const config = getServices().uiSettings;

const filter = ($scope.filter = {
props: ['type', 'aggregatable', 'searchable', 'missing', 'name'],
Expand Down

0 comments on commit 9dd5154

Please sign in to comment.