Skip to content

Commit 91ad1c8

Browse files
committed
Move subscribe_with_scope to kibana_legacy
1 parent eb533c8 commit 91ad1c8

File tree

16 files changed

+215
-81
lines changed

16 files changed

+215
-81
lines changed

src/legacy/core_plugins/kibana/public/dashboard/legacy_imports.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
export { npSetup, npStart } from 'ui/new_platform';
28-
export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
28+
2929
export { KbnUrl } from 'ui/url/kbn_url';
3030
// @ts-ignore
3131
export { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url/index';
@@ -38,4 +38,5 @@ export {
3838
migrateLegacyQuery,
3939
PrivateProvider,
4040
PromiseServiceCreator,
41+
subscribeWithScope,
4142
} from '../../../../../plugins/kibana_legacy/public';

src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ import {
7878
removeQueryParam,
7979
unhashUrl,
8080
} from '../../../../../../plugins/kibana_utils/public';
81-
import { KibanaLegacyStart } from '../../../../../../plugins/kibana_legacy/public';
81+
import {
82+
addFatalError,
83+
AngularHttpError,
84+
KibanaLegacyStart,
85+
} from '../../../../../../plugins/kibana_legacy/public';
8286

8387
export interface DashboardAppControllerDependencies extends RenderDeps {
8488
$scope: DashboardAppScope;
@@ -115,6 +119,7 @@ export class DashboardAppController {
115119
overlays,
116120
chrome,
117121
injectedMetadata,
122+
fatalErrors,
118123
uiSettings,
119124
savedObjects,
120125
http,
@@ -592,21 +597,31 @@ export class DashboardAppController {
592597
$scope.timefilterSubscriptions$ = new Subscription();
593598

594599
$scope.timefilterSubscriptions$.add(
595-
subscribeWithScope($scope, timefilter.getRefreshIntervalUpdate$(), {
596-
next: () => {
597-
updateState();
598-
refreshDashboardContainer();
600+
subscribeWithScope(
601+
$scope,
602+
timefilter.getRefreshIntervalUpdate$(),
603+
{
604+
next: () => {
605+
updateState();
606+
refreshDashboardContainer();
607+
},
599608
},
600-
})
609+
(error: AngularHttpError | Error | string) => addFatalError(fatalErrors, error)
610+
)
601611
);
602612

603613
$scope.timefilterSubscriptions$.add(
604-
subscribeWithScope($scope, timefilter.getTimeUpdate$(), {
605-
next: () => {
606-
updateState();
607-
refreshDashboardContainer();
614+
subscribeWithScope(
615+
$scope,
616+
timefilter.getTimeUpdate$(),
617+
{
618+
next: () => {
619+
updateState();
620+
refreshDashboardContainer();
621+
},
608622
},
609-
})
623+
(error: AngularHttpError | Error | string) => addFatalError(fatalErrors, error)
624+
)
610625
);
611626

612627
function updateViewMode(newMode: ViewMode) {

src/legacy/core_plugins/kibana/public/discover/kibana_services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export { wrapInI18nContext } from 'ui/i18n';
5353
export { getRequestInspectorStats, getResponseInspectorStats } from '../../../data/public';
5454
// @ts-ignore
5555
export { intervalOptions } from 'ui/agg_types';
56-
export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
56+
export { subscribeWithScope } from '../../../../../plugins/kibana_legacy/public';
5757
// @ts-ignore
5858
export { timezoneProvider } from 'ui/vis/lib/timezone';
5959
export { tabifyAggResponse } from '../../../data/public';

src/legacy/core_plugins/kibana/public/discover/np_ready/angular/discover.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import {
7777
getDefaultQuery,
7878
} from '../../../../../../../plugins/data/public';
7979
import { getIndexPatternId } from '../helpers/get_index_pattern_id';
80+
import { addFatalError } from '../../../../../../../plugins/kibana_legacy/public';
8081

8182
const fetchStatuses = {
8283
UNINITIALIZED: 'uninitialized',
@@ -274,11 +275,16 @@ function discoverController(
274275

275276
// update data source when filters update
276277
subscriptions.add(
277-
subscribeWithScope($scope, filterManager.getUpdates$(), {
278-
next: () => {
279-
$scope.updateDataSource();
278+
subscribeWithScope(
279+
$scope,
280+
filterManager.getUpdates$(),
281+
{
282+
next: () => {
283+
$scope.updateDataSource();
284+
},
280285
},
281-
})
286+
error => addFatalError(core.fatalErrors, error)
287+
)
282288
);
283289

284290
const inspectorAdapters = {
@@ -640,16 +646,26 @@ function discoverController(
640646
).pipe(debounceTime(100));
641647

642648
subscriptions.add(
643-
subscribeWithScope($scope, searchBarChanges, {
644-
next: $scope.fetch,
645-
})
649+
subscribeWithScope(
650+
$scope,
651+
searchBarChanges,
652+
{
653+
next: $scope.fetch,
654+
},
655+
error => addFatalError(core.fatalErrors, error)
656+
)
646657
);
647658
subscriptions.add(
648-
subscribeWithScope($scope, timefilter.getTimeUpdate$(), {
649-
next: () => {
650-
$scope.updateTime();
659+
subscribeWithScope(
660+
$scope,
661+
timefilter.getTimeUpdate$(),
662+
{
663+
next: () => {
664+
$scope.updateTime();
665+
},
651666
},
652-
})
667+
error => addFatalError(core.fatalErrors, error)
668+
)
653669
);
654670
//Handling change oft the histogram interval
655671
$scope.$watch('state.interval', function(newInterval, oldInterval) {

src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/edit_index_pattern.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import uiRoutes from 'ui/routes';
2828
import { uiModules } from 'ui/modules';
2929
import template from './edit_index_pattern.html';
3030
import { fieldWildcardMatcher } from '../../../../../../../../plugins/kibana_utils/public';
31+
import { subscribeWithScope } from '../../../../../../../../plugins/kibana_legacy/public';
3132
import { setup as managementSetup } from '../../../../../../management/public/legacy';
3233
import React from 'react';
3334
import { render, unmountComponentAtNode } from 'react-dom';
@@ -37,7 +38,6 @@ import { ScriptedFieldsTable } from './scripted_fields_table';
3738
import { i18n } from '@kbn/i18n';
3839
import { I18nContext } from 'ui/i18n';
3940
import { npStart } from 'ui/new_platform';
40-
import { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
4141

4242
import { getEditBreadcrumbs } from '../breadcrumbs';
4343
import { createEditIndexPatternPageStateContainer } from './edit_index_pattern_state_container';
@@ -214,11 +214,16 @@ uiModules
214214
$scope.getCurrentTab = getCurrentTab;
215215
$scope.setCurrentTab = setCurrentTab;
216216

217-
const stateChangedSub = subscribeWithScope($scope, state$, {
218-
next: ({ tab }) => {
219-
handleTabChange($scope, tab);
217+
const stateChangedSub = subscribeWithScope(
218+
$scope,
219+
state$,
220+
{
221+
next: ({ tab }) => {
222+
handleTabChange($scope, tab);
223+
},
220224
},
221-
});
225+
setup.fatalErrors
226+
);
222227

223228
handleTabChange($scope, getCurrentTab()); // setup initial tab depending on initial tab state
224229

src/legacy/core_plugins/kibana/public/visualize/legacy_imports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
* directly where they are needed.
2525
*/
2626

27-
export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
2827
// @ts-ignore
2928
export { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url';
3029
export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url';
@@ -39,4 +38,5 @@ export {
3938
migrateLegacyQuery,
4039
PrivateProvider,
4140
PromiseServiceCreator,
41+
subscribeWithScope,
4242
} from '../../../../../plugins/kibana_legacy/public';

src/legacy/core_plugins/kibana/public/visualize/np_ready/editor/editor.js

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { getEditBreadcrumbs } from '../breadcrumbs';
3131

3232
import { addHelpMenuToAppChrome } from '../help_menu/help_menu_util';
3333
import { unhashUrl } from '../../../../../../../plugins/kibana_utils/public';
34-
import { kbnBaseUrl } from '../../../../../../../plugins/kibana_legacy/public';
34+
import { addFatalError, kbnBaseUrl } from '../../../../../../../plugins/kibana_legacy/public';
3535
import {
3636
SavedObjectSaveModal,
3737
showSaveModal,
@@ -88,7 +88,7 @@ function VisualizeAppController(
8888
toastNotifications,
8989
chrome,
9090
getBasePath,
91-
core: { docLinks },
91+
core: { docLinks, fatalErrors },
9292
savedQueryService,
9393
uiSettings,
9494
I18nContext,
@@ -444,16 +444,26 @@ function VisualizeAppController(
444444
const subscriptions = new Subscription();
445445

446446
subscriptions.add(
447-
subscribeWithScope($scope, timefilter.getRefreshIntervalUpdate$(), {
448-
next: () => {
449-
$scope.refreshInterval = timefilter.getRefreshInterval();
447+
subscribeWithScope(
448+
$scope,
449+
timefilter.getRefreshIntervalUpdate$(),
450+
{
451+
next: () => {
452+
$scope.refreshInterval = timefilter.getRefreshInterval();
453+
},
450454
},
451-
})
455+
error => addFatalError(fatalErrors, error)
456+
)
452457
);
453458
subscriptions.add(
454-
subscribeWithScope($scope, timefilter.getTimeUpdate$(), {
455-
next: updateTimeRange,
456-
})
459+
subscribeWithScope(
460+
$scope,
461+
timefilter.getTimeUpdate$(),
462+
{
463+
next: updateTimeRange,
464+
},
465+
error => addFatalError(fatalErrors, error)
466+
)
457467
);
458468

459469
subscriptions.add(
@@ -476,16 +486,26 @@ function VisualizeAppController(
476486

477487
// update the searchSource when filters update
478488
subscriptions.add(
479-
subscribeWithScope($scope, filterManager.getUpdates$(), {
480-
next: () => {
481-
$scope.filters = filterManager.getFilters();
489+
subscribeWithScope(
490+
$scope,
491+
filterManager.getUpdates$(),
492+
{
493+
next: () => {
494+
$scope.filters = filterManager.getFilters();
495+
},
482496
},
483-
})
497+
error => addFatalError(fatalErrors, error)
498+
)
484499
);
485500
subscriptions.add(
486-
subscribeWithScope($scope, filterManager.getFetches$(), {
487-
next: $scope.fetch,
488-
})
501+
subscribeWithScope(
502+
$scope,
503+
filterManager.getFetches$(),
504+
{
505+
next: $scope.fetch,
506+
},
507+
error => addFatalError(fatalErrors, error)
508+
)
489509
);
490510

491511
$scope.$on('$destroy', () => {

src/legacy/ui/public/chrome/directives/kbn_chrome.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import React from 'react';
2121
import ReactDOM from 'react-dom';
2222
import $ from 'jquery';
23+
import { fatalError } from 'ui/notify/fatal_error';
2324

2425
import { uiModules } from '../../modules';
2526
import template from './kbn_chrome.html';
@@ -30,7 +31,7 @@ import {
3031
chromeHeaderNavControlsRegistry,
3132
NavControlSide,
3233
} from '../../registry/chrome_header_nav_controls';
33-
import { subscribeWithScope } from '../../utils/subscribe_with_scope';
34+
import { subscribeWithScope } from '../../../../../plugins/kibana_legacy/public';
3435

3536
export function kbnChromeProvider(chrome, internals) {
3637
uiModules.get('kibana').directive('kbnChrome', () => {
@@ -84,11 +85,16 @@ export function kbnChromeProvider(chrome, internals) {
8485
);
8586
}
8687

87-
const chromeVisibility = subscribeWithScope($scope, chrome.visible$, {
88-
next: () => {
89-
// just makes sure change detection is triggered when chrome visibility changes
88+
const chromeVisibility = subscribeWithScope(
89+
$scope,
90+
chrome.visible$,
91+
{
92+
next: () => {
93+
// just makes sure change detection is triggered when chrome visibility changes
94+
},
9095
},
91-
});
96+
fatalError
97+
);
9298
$scope.$on('$destroy', () => {
9399
chromeVisibility.unsubscribe();
94100
});

src/legacy/ui/public/config/config.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
*/
1919

2020
import angular from 'angular';
21+
import { fatalError } from 'ui/notify/fatal_error';
2122
import chrome from '../chrome';
2223
import { isPlainObject } from 'lodash';
2324
import { uiModules } from '../modules';
24-
import { subscribeWithScope } from '../utils/subscribe_with_scope';
25+
import { subscribeWithScope } from '../../../../plugins/kibana_legacy/public';
2526

2627
const module = uiModules.get('kibana/config');
2728

@@ -52,12 +53,17 @@ module.service(`config`, function($rootScope, Promise) {
5253
//* angular specific methods *
5354
//////////////////////////////
5455

55-
const subscription = subscribeWithScope($rootScope, uiSettings.getUpdate$(), {
56-
next: ({ key, newValue, oldValue }) => {
57-
$rootScope.$broadcast('change:config', newValue, oldValue, key, this);
58-
$rootScope.$broadcast(`change:config.${key}`, newValue, oldValue, key, this);
56+
const subscription = subscribeWithScope(
57+
$rootScope,
58+
uiSettings.getUpdate$(),
59+
{
60+
next: ({ key, newValue, oldValue }) => {
61+
$rootScope.$broadcast('change:config', newValue, oldValue, key, this);
62+
$rootScope.$broadcast(`change:config.${key}`, newValue, oldValue, key, this);
63+
},
5964
},
60-
});
65+
fatalError
66+
);
6167
$rootScope.$on('$destroy', () => subscription.unsubscribe());
6268

6369
this.watchAll = function(handler, scope = $rootScope) {

0 commit comments

Comments
 (0)