Skip to content

Commit

Permalink
[Discover] Migrate AppState/GlobalState to new app state helpers (#57175
Browse files Browse the repository at this point in the history
) (#59687)

* Replace AppState

* Replace GlobalState

* Adapt functional test

* Sync initial app state to URL

* Add jest tests

* Refactoring to use use-default-behaviors="true" in kbn-top-nav

* Cleanup code remove unnecessary imports and variables

* Refactor to use syncQueryStateWithUrl & stopSyncingQueryAppStateWithStateContainer

* Remove discoverPersistedState

* Allow indexPattern switch without $route.reload()

* Remove timeRangeObj because it's not needed

* Create new getDefaultQuery in data plugin

* Simplify check for null in sync_state_with_url.ts

* Remove unused stateMonitorFactory

Co-authored-by: Alexey Antonov <alexwizp@gmail.com>

Co-authored-by: Alexey Antonov <alexwizp@gmail.com>
  • Loading branch information
kertal and alexwizp authored Mar 10, 2020
1 parent e3af5aa commit b8b7bbb
Show file tree
Hide file tree
Showing 24 changed files with 606 additions and 322 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,9 @@
// They can stay even after NP cutover
import angular from 'angular';
import { EuiIcon } from '@elastic/eui';
// @ts-ignore
import { StateProvider } from 'ui/state_management/state';
import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular';
import { CoreStart, LegacyCoreStart, IUiSettingsClient } from 'kibana/public';
// @ts-ignore
import { AppStateProvider } from 'ui/state_management/app_state';
// @ts-ignore
import { GlobalStateProvider } from 'ui/state_management/global_state';
// @ts-ignore
import { StateManagementConfigProvider } from 'ui/state_management/config_provider';
// @ts-ignore
import { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url';
Expand Down Expand Up @@ -117,8 +111,6 @@ export function initializeInnerAngularModule(
createLocalConfigModule(core.uiSettings);
createLocalKbnUrlModule();
createLocalTopNavModule(navigation);
createLocalGlobalStateModule();
createLocalAppStateModule();
createLocalStorageModule();
createElasticSearchModule(data);
createPagerFactoryModule();
Expand All @@ -136,6 +128,7 @@ export function initializeInnerAngularModule(
'discoverPrivate',
'discoverDocTable',
'discoverPagerFactory',
'discoverPromise',
])
.config(watchMultiDecorator)
.directive('icon', reactDirective => reactDirective(EuiIcon))
Expand All @@ -153,9 +146,8 @@ export function initializeInnerAngularModule(
'discoverConfig',
'discoverI18n',
'discoverPrivate',
'discoverPromise',
'discoverTopNav',
'discoverGlobalState',
'discoverAppState',
'discoverLocalStorageProvider',
'discoverEs',
'discoverDocTable',
Expand All @@ -178,19 +170,6 @@ export function initializeInnerAngularModule(
.service('debounce', ['$timeout', DebounceProviderTimeout]);
}

export function createLocalGlobalStateModule() {
angular
.module('discoverGlobalState', [
'discoverPrivate',
'discoverConfig',
'discoverKbnUrl',
'discoverPromise',
])
.service('globalState', function(Private: IPrivate) {
return Private(GlobalStateProvider);
});
}

function createLocalKbnUrlModule() {
angular
.module('discoverKbnUrl', ['discoverPrivate', 'ngRoute'])
Expand Down Expand Up @@ -236,26 +215,6 @@ function createLocalI18nModule() {
.directive('i18nId', i18nDirective);
}

function createLocalAppStateModule() {
angular
.module('discoverAppState', [
'discoverGlobalState',
'discoverPrivate',
'discoverConfig',
'discoverKbnUrl',
'discoverPromise',
])
.service('AppState', function(Private: IPrivate) {
return Private(AppStateProvider);
})
.service('getAppState', function(Private: any) {
return Private(AppStateProvider).getAppState;
})
.service('State', function(Private: any) {
return Private(StateProvider);
});
}

function createLocalStorageModule() {
angular
.module('discoverLocalStorageProvider', ['discoverPrivate'])
Expand Down Expand Up @@ -287,7 +246,6 @@ function createDocTableModule() {
.module('discoverDocTable', [
'discoverKbnUrl',
'discoverConfig',
'discoverAppState',
'discoverPagerFactory',
'react',
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ export { wrapInI18nContext } from 'ui/i18n';
export { getRequestInspectorStats, getResponseInspectorStats } from '../../../data/public';
// @ts-ignore
export { intervalOptions } from 'ui/agg_types';
export { stateMonitorFactory } from 'ui/state_management/state_monitor_factory';
export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
// @ts-ignore
export { timezoneProvider } from 'ui/vis/lib/timezone';
export { tabifyAggResponse } from '../../../data/public';
export { unhashUrl } from '../../../../../plugins/kibana_utils/public';
export {
migrateLegacyQuery,
ensureDefaultIndexPattern,
formatMsg,
formatStack,
Expand All @@ -80,7 +78,6 @@ export {
SortDirection,
} from '../../../../../plugins/data/public';
export { ElasticSearchHit } from './np_ready/doc_views/doc_views_types';
export { registerTimefilterWithGlobalStateFactory } from 'ui/timefilter/setup_router';
export { getFormat } from 'ui/visualize/loader/pipeline_helpers/utilities';
// @ts-ignore
export { buildPointSeriesData } from 'ui/agg_response/point_series/point_series';
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ <h1 class="euiScreenReaderOnly">{{screenTitle}}</h1>
<kbn-top-nav
app-name="'discover'"
config="topNavMenu"
screen-title="screenTitle"
show-search-bar="true"
show-date-picker="enableTimeRangeSelector"
index-patterns="[indexPattern]"

query="state.query"
on-query-submit="updateQuery"

show-save-query="showSaveQuery"
saved-query-id="state.savedQuery"
on-saved-query-id-change="updateSavedQueryId"

query="state.query"
saved-query-id="state.savedQuery"
screen-title="screenTitle"
show-date-picker="enableTimeRangeSelector"
show-save-query="showSaveQuery"
show-search-bar="true"
use-default-behaviors="true"
>
</kbn-top-nav>
Expand Down Expand Up @@ -186,7 +183,6 @@ <h1 class="euiScreenReaderOnly">{{screenTitle}}</h1>
columns="state.columns"
infinite-scroll="true"
filter="filterQuery"
filters="state.filters"
data-shared-item
data-title="{{opts.savedSearch.lastSavedTitle}}"
data-description="{{opts.savedSearch.description}}"
Expand Down
Loading

0 comments on commit b8b7bbb

Please sign in to comment.