Skip to content

Commit

Permalink
Move subscribe_with_scope to kibana_legacy (#59781)
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal authored Mar 13, 2020
1 parent 0c1c8f8 commit 8609aa0
Show file tree
Hide file tree
Showing 18 changed files with 241 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

export { npSetup, npStart } from 'ui/new_platform';
export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';

export { KbnUrl } from 'ui/url/kbn_url';
// @ts-ignore
export { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url/index';
Expand All @@ -38,4 +38,5 @@ export {
migrateLegacyQuery,
PrivateProvider,
PromiseServiceCreator,
subscribeWithScope,
} from '../../../../../plugins/kibana_legacy/public';
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ import {
removeQueryParam,
unhashUrl,
} from '../../../../../../plugins/kibana_utils/public';
import { KibanaLegacyStart } from '../../../../../../plugins/kibana_legacy/public';
import {
addFatalError,
AngularHttpError,
KibanaLegacyStart,
} from '../../../../../../plugins/kibana_legacy/public';

export interface DashboardAppControllerDependencies extends RenderDeps {
$scope: DashboardAppScope;
Expand Down Expand Up @@ -115,6 +119,7 @@ export class DashboardAppController {
overlays,
chrome,
injectedMetadata,
fatalErrors,
uiSettings,
savedObjects,
http,
Expand Down Expand Up @@ -592,21 +597,31 @@ export class DashboardAppController {
$scope.timefilterSubscriptions$ = new Subscription();

$scope.timefilterSubscriptions$.add(
subscribeWithScope($scope, timefilter.getRefreshIntervalUpdate$(), {
next: () => {
updateState();
refreshDashboardContainer();
subscribeWithScope(
$scope,
timefilter.getRefreshIntervalUpdate$(),
{
next: () => {
updateState();
refreshDashboardContainer();
},
},
})
(error: AngularHttpError | Error | string) => addFatalError(fatalErrors, error)
)
);

$scope.timefilterSubscriptions$.add(
subscribeWithScope($scope, timefilter.getTimeUpdate$(), {
next: () => {
updateState();
refreshDashboardContainer();
subscribeWithScope(
$scope,
timefilter.getTimeUpdate$(),
{
next: () => {
updateState();
refreshDashboardContainer();
},
},
})
(error: AngularHttpError | Error | string) => addFatalError(fatalErrors, error)
)
);

function updateViewMode(newMode: ViewMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const { getRequestInspectorStats, getResponseInspectorStats, tabifyAggRes
export { shortenDottedString } from '../../common/utils/shorten_dotted_string';
// @ts-ignore
export { intervalOptions } from 'ui/agg_types';
export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
export { subscribeWithScope } from '../../../../../plugins/kibana_legacy/public';
// @ts-ignore
export { timezoneProvider } from 'ui/vis/lib/timezone';
export { unhashUrl } from '../../../../../plugins/kibana_utils/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {
getDefaultQuery,
} from '../../../../../../../plugins/data/public';
import { getIndexPatternId } from '../helpers/get_index_pattern_id';
import { addFatalError } from '../../../../../../../plugins/kibana_legacy/public';

const fetchStatuses = {
UNINITIALIZED: 'uninitialized',
Expand Down Expand Up @@ -255,11 +256,16 @@ function discoverController(

// update data source when filters update
subscriptions.add(
subscribeWithScope($scope, filterManager.getUpdates$(), {
next: () => {
$scope.updateDataSource();
subscribeWithScope(
$scope,
filterManager.getUpdates$(),
{
next: () => {
$scope.updateDataSource();
},
},
})
error => addFatalError(core.fatalErrors, error)
)
);

const inspectorAdapters = {
Expand Down Expand Up @@ -621,16 +627,26 @@ function discoverController(
).pipe(debounceTime(100));

subscriptions.add(
subscribeWithScope($scope, searchBarChanges, {
next: $scope.fetch,
})
subscribeWithScope(
$scope,
searchBarChanges,
{
next: $scope.fetch,
},
error => addFatalError(core.fatalErrors, error)
)
);
subscriptions.add(
subscribeWithScope($scope, timefilter.getTimeUpdate$(), {
next: () => {
$scope.updateTime();
subscribeWithScope(
$scope,
timefilter.getTimeUpdate$(),
{
next: () => {
$scope.updateTime();
},
},
})
error => addFatalError(core.fatalErrors, error)
)
);
//Handling change oft the histogram interval
$scope.$watch('state.interval', function(newInterval, oldInterval) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import uiRoutes from 'ui/routes';
import { uiModules } from 'ui/modules';
import template from './edit_index_pattern.html';
import { fieldWildcardMatcher } from '../../../../../../../../plugins/kibana_utils/public';
import { subscribeWithScope } from '../../../../../../../../plugins/kibana_legacy/public';
import { setup as managementSetup } from '../../../../../../management/public/legacy';
import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
Expand All @@ -37,7 +38,6 @@ import { ScriptedFieldsTable } from './scripted_fields_table';
import { i18n } from '@kbn/i18n';
import { I18nContext } from 'ui/i18n';
import { npStart } from 'ui/new_platform';
import { subscribeWithScope } from 'ui/utils/subscribe_with_scope';

import { getEditBreadcrumbs } from '../breadcrumbs';
import { createEditIndexPatternPageStateContainer } from './edit_index_pattern_state_container';
Expand Down Expand Up @@ -214,11 +214,16 @@ uiModules
$scope.getCurrentTab = getCurrentTab;
$scope.setCurrentTab = setCurrentTab;

const stateChangedSub = subscribeWithScope($scope, state$, {
next: ({ tab }) => {
handleTabChange($scope, tab);
const stateChangedSub = subscribeWithScope(
$scope,
state$,
{
next: ({ tab }) => {
handleTabChange($scope, tab);
},
},
});
fatalError
);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* directly where they are needed.
*/

export { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
// @ts-ignore
export { KbnUrlProvider, RedirectWhenMissingProvider } from 'ui/url';
export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url';
Expand All @@ -39,4 +38,5 @@ export {
migrateLegacyQuery,
PrivateProvider,
PromiseServiceCreator,
subscribeWithScope,
} from '../../../../../plugins/kibana_legacy/public';
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { getEditBreadcrumbs } from '../breadcrumbs';

import { addHelpMenuToAppChrome } from '../help_menu/help_menu_util';
import { unhashUrl } from '../../../../../../../plugins/kibana_utils/public';
import { kbnBaseUrl } from '../../../../../../../plugins/kibana_legacy/public';
import { addFatalError, kbnBaseUrl } from '../../../../../../../plugins/kibana_legacy/public';
import {
SavedObjectSaveModal,
showSaveModal,
Expand Down Expand Up @@ -88,7 +88,7 @@ function VisualizeAppController(
toastNotifications,
chrome,
getBasePath,
core: { docLinks },
core: { docLinks, fatalErrors },
savedQueryService,
uiSettings,
I18nContext,
Expand Down Expand Up @@ -455,16 +455,26 @@ function VisualizeAppController(
const subscriptions = new Subscription();

subscriptions.add(
subscribeWithScope($scope, timefilter.getRefreshIntervalUpdate$(), {
next: () => {
$scope.refreshInterval = timefilter.getRefreshInterval();
subscribeWithScope(
$scope,
timefilter.getRefreshIntervalUpdate$(),
{
next: () => {
$scope.refreshInterval = timefilter.getRefreshInterval();
},
},
})
error => addFatalError(fatalErrors, error)
)
);
subscriptions.add(
subscribeWithScope($scope, timefilter.getTimeUpdate$(), {
next: updateTimeRange,
})
subscribeWithScope(
$scope,
timefilter.getTimeUpdate$(),
{
next: updateTimeRange,
},
error => addFatalError(fatalErrors, error)
)
);

subscriptions.add(
Expand All @@ -487,16 +497,26 @@ function VisualizeAppController(

// update the searchSource when filters update
subscriptions.add(
subscribeWithScope($scope, filterManager.getUpdates$(), {
next: () => {
$scope.filters = filterManager.getFilters();
subscribeWithScope(
$scope,
filterManager.getUpdates$(),
{
next: () => {
$scope.filters = filterManager.getFilters();
},
},
})
error => addFatalError(fatalErrors, error)
)
);
subscriptions.add(
subscribeWithScope($scope, filterManager.getFetches$(), {
next: $scope.fetch,
})
subscribeWithScope(
$scope,
filterManager.getFetches$(),
{
next: $scope.fetch,
},
error => addFatalError(fatalErrors, error)
)
);

$scope.$on('$destroy', () => {
Expand Down
16 changes: 11 additions & 5 deletions src/legacy/ui/public/chrome/directives/kbn_chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import $ from 'jquery';
import { fatalError } from 'ui/notify/fatal_error';

import { uiModules } from '../../modules';
import template from './kbn_chrome.html';
Expand All @@ -30,7 +31,7 @@ import {
chromeHeaderNavControlsRegistry,
NavControlSide,
} from '../../registry/chrome_header_nav_controls';
import { subscribeWithScope } from '../../utils/subscribe_with_scope';
import { subscribeWithScope } from '../../../../../plugins/kibana_legacy/public';

export function kbnChromeProvider(chrome, internals) {
uiModules.get('kibana').directive('kbnChrome', () => {
Expand Down Expand Up @@ -84,11 +85,16 @@ export function kbnChromeProvider(chrome, internals) {
);
}

const chromeVisibility = subscribeWithScope($scope, chrome.visible$, {
next: () => {
// just makes sure change detection is triggered when chrome visibility changes
const chromeVisibility = subscribeWithScope(
$scope,
chrome.visible$,
{
next: () => {
// just makes sure change detection is triggered when chrome visibility changes
},
},
});
fatalError
);
$scope.$on('$destroy', () => {
chromeVisibility.unsubscribe();
});
Expand Down
18 changes: 12 additions & 6 deletions src/legacy/ui/public/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
*/

import angular from 'angular';
import { fatalError } from 'ui/notify/fatal_error';
import chrome from '../chrome';
import { isPlainObject } from 'lodash';
import { uiModules } from '../modules';
import { subscribeWithScope } from '../utils/subscribe_with_scope';
import { subscribeWithScope } from '../../../../plugins/kibana_legacy/public';

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

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

const subscription = subscribeWithScope($rootScope, uiSettings.getUpdate$(), {
next: ({ key, newValue, oldValue }) => {
$rootScope.$broadcast('change:config', newValue, oldValue, key, this);
$rootScope.$broadcast(`change:config.${key}`, newValue, oldValue, key, this);
const subscription = subscribeWithScope(
$rootScope,
uiSettings.getUpdate$(),
{
next: ({ key, newValue, oldValue }) => {
$rootScope.$broadcast('change:config', newValue, oldValue, key, this);
$rootScope.$broadcast(`change:config.${key}`, newValue, oldValue, key, this);
},
},
});
fatalError
);
$rootScope.$on('$destroy', () => subscription.unsubscribe());

this.watchAll = function(handler, scope = $rootScope) {
Expand Down
19 changes: 2 additions & 17 deletions src/legacy/ui/public/notify/fatal_error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,8 @@
*/

import { npSetup } from 'ui/new_platform';
import {
AngularHttpError,
formatAngularHttpError,
isAngularHttpError,
} from '../../../../plugins/kibana_legacy/public';

export function addFatalErrorCallback(callback: () => void) {
npSetup.core.fatalErrors.get$().subscribe(() => {
callback();
});
}
import { AngularHttpError, addFatalError } from '../../../../plugins/kibana_legacy/public';

export function fatalError(error: AngularHttpError | Error | string, location?: string) {
// add support for angular http errors to newPlatformFatalErrors
if (isAngularHttpError(error)) {
error = formatAngularHttpError(error);
}

npSetup.core.fatalErrors.add(error, location);
addFatalError(npSetup.core.fatalErrors, error, location);
}
2 changes: 1 addition & 1 deletion src/legacy/ui/public/notify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* under the License.
*/

export { fatalError, addFatalErrorCallback } from './fatal_error';
export { fatalError } from './fatal_error';
export { toastNotifications } from './toasts';
export { banners } from './banners';
Loading

0 comments on commit 8609aa0

Please sign in to comment.