Skip to content

Commit

Permalink
[Discover] Move State to inner angular (#52369) (#52848)
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal authored Dec 12, 2019
1 parent a75e5d3 commit b2ad421
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const {
data,
docTitle,
filterManager,
State,
share,
timefilter,
toastNotifications,
Expand Down Expand Up @@ -121,7 +120,7 @@ app.config($routeProvider => {
template: indexTemplate,
reloadOnSearch: false,
resolve: {
savedObjects: function (redirectWhenMissing, $route, kbnUrl, Promise, $rootScope) {
savedObjects: function (redirectWhenMissing, $route, kbnUrl, Promise, $rootScope, State) {
const indexPatterns = getServices().indexPatterns;
const savedSearchId = $route.current.params.id;
return ensureDefaultIndexPattern(core, getServices().data, $rootScope, kbnUrl).then(() => {
Expand All @@ -137,7 +136,6 @@ app.config($routeProvider => {
* @type {State}
*/
const state = new State('_a', {});

const id = getIndexPatternId(state.index, indexPatternList, uiSettings.get('defaultIndex'));
state.destroy();
return Promise.props({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ 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
Expand Down Expand Up @@ -277,6 +279,9 @@ function createLocalAppStateModule() {
})
.service('getAppState', function(Private: any) {
return Private(AppStateProvider).getAppState;
})
.service('State', function(Private: any) {
return Private(StateProvider);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ import chromeLegacy from 'ui/chrome';
import { IPrivate } from 'ui/private';
import { FilterManager, TimefilterContract, IndexPatternsContract } from 'src/plugins/data/public';
// @ts-ignore
import { StateProvider } from 'ui/state_management/state';
// @ts-ignore
import { createSavedSearchesService } from '../saved_searches/saved_searches';
// @ts-ignore
import { createSavedSearchFactory } from '../saved_searches/_saved_search';
Expand All @@ -57,21 +55,18 @@ export interface DiscoverServices {
// legacy
getSavedSearchById: (id: string) => Promise<SavedSearch>;
getSavedSearchUrlById: (id: string) => Promise<string>;
State: unknown;
uiSettings: IUiSettingsClient;
}

export async function buildGlobalAngularServices() {
const injector = await chromeLegacy.dangerouslyGetActiveInjector();
const Private = injector.get<IPrivate>('Private');
const kbnUrl = injector.get<IPrivate>('kbnUrl');
const State = Private(StateProvider);
const SavedSearchFactory = createSavedSearchFactory(Private);
const service = createSavedSearchesService(Private, SavedSearchFactory, kbnUrl, chromeLegacy);
return {
getSavedSearchById: async (id: string) => service.get(id),
getSavedSearchUrlById: async (id: string) => service.urlFor(id),
State,
};
}

Expand Down

0 comments on commit b2ad421

Please sign in to comment.